|
22 | 22 | import java.io.File; |
23 | 23 | import java.io.IOException; |
24 | 24 | import java.lang.reflect.InvocationTargetException; |
| 25 | +import java.util.List; |
25 | 26 | import java.util.function.Consumer; |
26 | 27 |
|
27 | 28 | import org.apache.commons.lang3.StringUtils; |
|
38 | 39 | import de.symeda.sormas.api.event.EventParticipantDto; |
39 | 40 | import de.symeda.sormas.api.event.EventParticipantFacade; |
40 | 41 | import de.symeda.sormas.api.event.EventReferenceDto; |
| 42 | +import de.symeda.sormas.api.facility.FacilityReferenceDto; |
41 | 43 | import de.symeda.sormas.api.i18n.I18nProperties; |
42 | 44 | import de.symeda.sormas.api.i18n.Strings; |
43 | 45 | import de.symeda.sormas.api.i18n.Validations; |
|
46 | 48 | import de.symeda.sormas.api.person.PersonFacade; |
47 | 49 | import de.symeda.sormas.api.person.PersonReferenceDto; |
48 | 50 | import de.symeda.sormas.api.person.SimilarPersonDto; |
| 51 | +import de.symeda.sormas.api.region.CommunityReferenceDto; |
| 52 | +import de.symeda.sormas.api.region.DistrictReferenceDto; |
49 | 53 | import de.symeda.sormas.api.user.UserReferenceDto; |
| 54 | +import de.symeda.sormas.api.utils.DataHelper; |
50 | 55 | import de.symeda.sormas.api.utils.ValidationRuntimeException; |
51 | 56 | import de.symeda.sormas.ui.importer.DataImporter; |
52 | 57 | import de.symeda.sormas.ui.importer.EventParticipantImportSimilarityResult; |
53 | 58 | import de.symeda.sormas.ui.importer.ImportErrorException; |
54 | 59 | import de.symeda.sormas.ui.importer.ImportLineResult; |
55 | 60 | import de.symeda.sormas.ui.importer.ImportSimilarityResultOption; |
| 61 | +import de.symeda.sormas.ui.importer.ImporterPersonHelper; |
56 | 62 | import de.symeda.sormas.ui.person.PersonSelectionField; |
57 | 63 | import de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent; |
58 | 64 | import de.symeda.sormas.ui.utils.VaadinUiUtil; |
@@ -286,6 +292,69 @@ private void insertColumnEntryIntoData(EventParticipantDto eventParticipant, Per |
286 | 292 | // according to the types of the eventparticipant or person fields |
287 | 293 | if (executeDefaultInvokings(pd, currentElement, entry, entryHeaderPath)) { |
288 | 294 | continue; |
| 295 | + } else if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) { |
| 296 | + List<DistrictReferenceDto> district = FacadeProvider.getDistrictFacade() |
| 297 | + .getByName(entry, ImporterPersonHelper.getRegionBasedOnDistrict(pd.getName(), null, null, person, currentElement), false); |
| 298 | + if (district.isEmpty()) { |
| 299 | + throw new ImportErrorException( |
| 300 | + I18nProperties |
| 301 | + .getValidationError(Validations.importEntryDoesNotExistDbOrRegion, entry, buildEntityProperty(entryHeaderPath))); |
| 302 | + } else if (district.size() > 1) { |
| 303 | + throw new ImportErrorException( |
| 304 | + I18nProperties.getValidationError(Validations.importDistrictNotUnique, entry, buildEntityProperty(entryHeaderPath))); |
| 305 | + } else { |
| 306 | + pd.getWriteMethod().invoke(currentElement, district.get(0)); |
| 307 | + } |
| 308 | + } else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) { |
| 309 | + List<CommunityReferenceDto> community = |
| 310 | + FacadeProvider.getCommunityFacade().getByName(entry, ImporterPersonHelper.getPersonDistrict(pd.getName(), person), false); |
| 311 | + if (community.isEmpty()) { |
| 312 | + throw new ImportErrorException( |
| 313 | + I18nProperties.getValidationError( |
| 314 | + Validations.importEntryDoesNotExistDbOrDistrict, |
| 315 | + entry, |
| 316 | + buildEntityProperty(entryHeaderPath))); |
| 317 | + } else if (community.size() > 1) { |
| 318 | + throw new ImportErrorException( |
| 319 | + I18nProperties.getValidationError(Validations.importCommunityNotUnique, entry, buildEntityProperty(entryHeaderPath))); |
| 320 | + } else { |
| 321 | + pd.getWriteMethod().invoke(currentElement, community.get(0)); |
| 322 | + } |
| 323 | + } else if (propertyType.isAssignableFrom(FacilityReferenceDto.class)) { |
| 324 | + DataHelper.Pair<DistrictReferenceDto, CommunityReferenceDto> infrastructureData = |
| 325 | + ImporterPersonHelper.getPersonDistrictAndCommunity(pd.getName(), person); |
| 326 | + List<FacilityReferenceDto> facility = FacadeProvider.getFacilityFacade() |
| 327 | + .getByNameAndType( |
| 328 | + entry, |
| 329 | + infrastructureData.getElement0(), |
| 330 | + infrastructureData.getElement1(), |
| 331 | + getTypeOfFacility(pd.getName(), currentElement), |
| 332 | + false); |
| 333 | + if (facility.isEmpty()) { |
| 334 | + if (infrastructureData.getElement1() != null) { |
| 335 | + throw new ImportErrorException( |
| 336 | + I18nProperties.getValidationError( |
| 337 | + Validations.importEntryDoesNotExistDbOrCommunity, |
| 338 | + entry, |
| 339 | + buildEntityProperty(entryHeaderPath))); |
| 340 | + } else { |
| 341 | + throw new ImportErrorException( |
| 342 | + I18nProperties.getValidationError( |
| 343 | + Validations.importEntryDoesNotExistDbOrDistrict, |
| 344 | + entry, |
| 345 | + buildEntityProperty(entryHeaderPath))); |
| 346 | + } |
| 347 | + } else if (facility.size() > 1 && infrastructureData.getElement1() == null) { |
| 348 | + throw new ImportErrorException( |
| 349 | + I18nProperties |
| 350 | + .getValidationError(Validations.importFacilityNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath))); |
| 351 | + } else if (facility.size() > 1 && infrastructureData.getElement1() != null) { |
| 352 | + throw new ImportErrorException( |
| 353 | + I18nProperties |
| 354 | + .getValidationError(Validations.importFacilityNotUniqueInCommunity, entry, buildEntityProperty(entryHeaderPath))); |
| 355 | + } else { |
| 356 | + pd.getWriteMethod().invoke(currentElement, facility.get(0)); |
| 357 | + } |
289 | 358 | } else { |
290 | 359 | throw new UnsupportedOperationException( |
291 | 360 | I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName())); |
|
0 commit comments