use of de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class CaseImportFacadeEjb method insertColumnEntryIntoData.
/**
* Inserts the entry of a single cell into the case or its person.
*/
private void insertColumnEntryIntoData(CaseDataDto caze, PersonDto person, String entry, String[] entryHeaderPath) throws InvalidColumnException, ImportErrorException {
Object currentElement = caze;
for (int i = 0; i < entryHeaderPath.length; i++) {
String headerPathElementName = entryHeaderPath[i];
Language language = I18nProperties.getUserLanguage();
try {
if (i != entryHeaderPath.length - 1) {
currentElement = new PropertyDescriptor(headerPathElementName, currentElement.getClass()).getReadMethod().invoke(currentElement);
// Set the current element to the created person
if (currentElement instanceof PersonReferenceDto) {
currentElement = person;
}
} else if (CaseExportDto.BIRTH_DATE.equals(headerPathElementName)) {
BirthDateDto birthDateDto = PersonHelper.parseBirthdate(entry, language);
if (birthDateDto != null) {
person.setBirthdateDD(birthDateDto.getDateOfBirthDD());
person.setBirthdateMM(birthDateDto.getDateOfBirthMM());
person.setBirthdateYYYY(birthDateDto.getDateOfBirthYYYY());
}
} else {
PropertyDescriptor pd = new PropertyDescriptor(headerPathElementName, currentElement.getClass());
Class<?> propertyType = pd.getPropertyType();
// according to the types of the case or person fields
if (importFacade.executeDefaultInvoke(pd, currentElement, entry, entryHeaderPath, false)) {
continue;
} else if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
List<DistrictReferenceDto> district = districtFacade.getByName(entry, ImportHelper.getRegionBasedOnDistrict(pd.getName(), caze, null, null, person, currentElement), false);
if (district.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, entry, buildEntityProperty(entryHeaderPath)));
} else if (district.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(currentElement, district.get(0));
}
} else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
List<CommunityReferenceDto> community = communityFacade.getByName(entry, ImportHelper.getDistrictBasedOnCommunity(pd.getName(), caze, person, currentElement), false);
if (community.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
} else if (community.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCommunityNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(currentElement, community.get(0));
}
} else if (propertyType.isAssignableFrom(FacilityReferenceDto.class)) {
DataHelper.Pair<DistrictReferenceDto, CommunityReferenceDto> infrastructureData = ImportHelper.getDistrictAndCommunityBasedOnFacility(pd.getName(), caze, person, currentElement);
if (I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.OTHER_FACILITY).equals(entry)) {
entry = FacilityDto.OTHER_FACILITY;
}
if (I18nProperties.getPrefixCaption(FacilityDto.I18N_PREFIX, FacilityDto.NO_FACILITY).equals(entry)) {
entry = FacilityDto.NO_FACILITY;
}
List<FacilityReferenceDto> facilities = facilityFacade.getByNameAndType(entry, infrastructureData.getElement0(), infrastructureData.getElement1(), getTypeOfFacility(pd.getName(), currentElement), false);
if (facilities.isEmpty()) {
if (infrastructureData.getElement1() != null) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrCommunity, entry, buildEntityProperty(entryHeaderPath)));
} else {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
}
} else if (facilities.size() > 1 && infrastructureData.getElement1() == null) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
} else if (facilities.size() > 1 && infrastructureData.getElement1() != null) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importFacilityNotUniqueInCommunity, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(currentElement, facilities.get(0));
}
} else if (propertyType.isAssignableFrom(PointOfEntryReferenceDto.class)) {
PointOfEntryReferenceDto pointOfEntryReference;
DistrictReferenceDto pointOfEntryDistrict = CaseLogic.getDistrictWithFallback(caze);
List<PointOfEntryReferenceDto> customPointsOfEntry = pointOfEntryFacade.getByName(entry, pointOfEntryDistrict, false);
if (customPointsOfEntry.isEmpty()) {
final String poeName = entry;
List<PointOfEntryDto> defaultPointOfEntries = pointOfEntryFacade.getByUuids(PointOfEntryDto.CONSTANT_POE_UUIDS);
Optional<PointOfEntryDto> defaultPointOfEntry = defaultPointOfEntries.stream().filter(defaultPoe -> InfrastructureHelper.buildPointOfEntryString(defaultPoe.getUuid(), defaultPoe.getName()).equals(poeName)).findFirst();
if (!defaultPointOfEntry.isPresent()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrDistrict, entry, buildEntityProperty(entryHeaderPath)));
}
pointOfEntryReference = defaultPointOfEntry.get().toReference();
} else if (customPointsOfEntry.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importPointOfEntryNotUniqueInDistrict, entry, buildEntityProperty(entryHeaderPath)));
} else {
pointOfEntryReference = customPointsOfEntry.get(0);
}
pd.getWriteMethod().invoke(currentElement, pointOfEntryReference);
} else {
throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importCasesPropertyTypeNotAllowed, propertyType.getName()));
}
}
} catch (IntrospectionException e) {
throw new InvalidColumnException(buildEntityProperty(entryHeaderPath));
} catch (InvocationTargetException | IllegalAccessException e) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entryHeaderPath)));
} catch (IllegalArgumentException | EnumService.InvalidEnumCaptionException e) {
throw new ImportErrorException(entry, buildEntityProperty(entryHeaderPath));
} catch (ParseException e) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importInvalidDate, buildEntityProperty(entryHeaderPath), DateHelper.getAllowedDateFormats(language.getDateFormat())));
} catch (ImportErrorException e) {
throw e;
} catch (Exception e) {
LOGGER.error("Unexpected error when trying to import a case: " + e.getMessage(), e);
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importCasesUnexpectedError));
}
}
}
use of de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class CaseCreateForm method updatePOEs.
private void updatePOEs() {
ComboBox comboBoxPOE = (ComboBox) getField(CaseDataDto.POINT_OF_ENTRY);
if (!comboBoxPOE.isReadOnly()) {
DistrictReferenceDto districtDto;
if (Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
districtDto = (DistrictReferenceDto) pointOfEntryDistrictCombo.getValue();
} else if (Boolean.TRUE.equals(differentPlaceOfStayJurisdiction.getValue())) {
districtDto = (DistrictReferenceDto) districtCombo.getValue();
} else {
districtDto = (DistrictReferenceDto) responsibleDistrictCombo.getValue();
}
List<PointOfEntryReferenceDto> POEs = districtDto == null ? Collections.emptyList() : FacadeProvider.getPointOfEntryFacade().getAllActiveByDistrict(districtDto.getUuid(), true);
FieldHelper.updateItems(comboBoxPOE, POEs);
}
}
use of de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureValidator method lookupPointOfEntry.
private WithDetails<PointOfEntryReferenceDto> lookupPointOfEntry(PointOfEntryReferenceDto pointOfEntry, String pointOfEntryDetails) {
String pointOfEntryUuid = pointOfEntry.getUuid();
if (PointOfEntryDto.CONSTANT_POE_UUIDS.contains(pointOfEntryUuid)) {
PointOfEntryReferenceDto localPointOfEntry = pointOfEntryDetails != null ? pointOfEntryFacade.getByName(pointOfEntryDetails.trim(), null, false).stream().findFirst().orElse(null) : null;
if (localPointOfEntry == null) {
localPointOfEntry = pointOfEntryFacade.getByUuid(pointOfEntryUuid).toReference();
} else {
pointOfEntryDetails = null;
}
return new WithDetails<>(localPointOfEntry, pointOfEntryDetails);
} else {
Optional<PointOfEntryReferenceDto> localPointOfEntry = pointOfEntry.getExternalId() != null ? pointOfEntryFacade.getByExternalId(pointOfEntry.getExternalId(), false).stream().findFirst() : Optional.empty();
if (!localPointOfEntry.isPresent()) {
localPointOfEntry = pointOfEntryFacade.getByName(pointOfEntry.getCaption(), null, false).stream().findFirst();
}
final String details;
if (!localPointOfEntry.isPresent()) {
details = pointOfEntry.getCaption();
localPointOfEntry = Optional.of(pointOfEntryFacade.getByUuid(PointOfEntryDto.getOtherPointOfEntryUuid(pointOfEntry.getPointOfEntryType())).toReference());
} else {
details = pointOfEntryDetails;
}
return localPointOfEntry.map(p -> new WithDetails<>(p, details)).orElse(null);
}
}
use of de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasCaseFacadeEjbTest method testSaveReturnedCaseWithKnownOtherPointOfEntry.
@Test
public void testSaveReturnedCaseWithKnownOtherPointOfEntry() throws SormasToSormasException {
UserReferenceDto officer = creator.createUser(rdcf, UserRole.SURVEILLANCE_OFFICER).toReference();
PersonDto person = creator.createPerson();
CaseDataDto caze = creator.createCase(officer, rdcf, c -> {
c.setPerson(person.toReference());
c.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
c.setPointOfEntry(new PointOfEntryReferenceDto(PointOfEntryDto.OTHER_SEAPORT_UUID, null, null, null));
c.setPointOfEntryDetails("Test Seaport");
});
User officerUser = getUserService().getByReferenceDto(officer);
getSormasToSormasShareInfoService().persist(createShareInfo(DEFAULT_SERVER_ID, true, i -> i.setCaze(getCaseService().getByReferenceDto(caze.toReference()))));
caze.setPointOfEntryDetails(rdcf.pointOfEntry.getCaption());
Calendar calendar = Calendar.getInstance();
calendar.setTime(caze.getChangeDate());
calendar.add(Calendar.DAY_OF_MONTH, 1);
caze.setChangeDate(calendar.getTime());
SormasToSormasOriginInfoDto originInfo = createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, true);
SormasToSormasDto shareData = new SormasToSormasDto();
shareData.setOriginInfo(originInfo);
shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
try {
getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
CaseDataDto returnedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
assertThat(returnedCase.getPointOfEntry(), is(rdcf.pointOfEntry));
assertThat(returnedCase.getPointOfEntryDetails(), is(nullValue()));
}
use of de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasTest method createRDCF.
protected MappableRdcf createRDCF(boolean withExternalId) {
String regionName = "Region";
String districtName = "District";
String communityName = "Community";
String facilityName = "Facility";
String pointOfEntryName = "Point of Entry";
String regionExternalId = null;
String districtExternalId = null;
String communityExternalId = null;
String facilityExternalId = null;
String pointOfEntryExternalId = null;
if (withExternalId) {
regionExternalId = "RegionExtId";
districtExternalId = "DistrictExtId";
communityExternalId = "CommunityExtId";
facilityExternalId = "FacilityExtId";
pointOfEntryExternalId = "Point of EntryExtId";
}
MappableRdcf rdcf = new MappableRdcf();
rdcf.invalidLocalRdcf = new TestDataCreator.RDCF(new RegionReferenceDto(DataHelper.createUuid(), withExternalId ? null : regionName, regionExternalId), new DistrictReferenceDto(DataHelper.createUuid(), withExternalId ? null : districtName, districtExternalId), new CommunityReferenceDto(DataHelper.createUuid(), withExternalId ? null : communityName, communityExternalId), new FacilityReferenceDto(DataHelper.createUuid(), withExternalId ? null : facilityName, facilityExternalId), new PointOfEntryReferenceDto(DataHelper.createUuid(), withExternalId ? null : pointOfEntryName, PointOfEntryType.AIRPORT, pointOfEntryExternalId));
Region region = creator.createRegionCentrally(regionName + "Central", regionExternalId);
District district = creator.createDistrictCentrally(districtName + "Central", region, districtExternalId);
Community community = creator.createCommunityCentrally(communityName + "Central", district, communityExternalId);
Facility facility = creator.createFacility(facilityName + "Central", FacilityType.HOSPITAL, region, district, community, facilityExternalId);
PointOfEntry pointOfEntry = creator.createPointOfEntry(pointOfEntryName + "Central", region, district, pointOfEntryExternalId);
rdcf.centralRdcf = new TestDataCreator.RDCF(new RegionReferenceDto(region.getUuid(), region.getName(), region.getExternalID()), new DistrictReferenceDto(district.getUuid(), district.getName(), district.getExternalID()), new CommunityReferenceDto(community.getUuid(), community.getName(), community.getExternalID()), new FacilityReferenceDto(facility.getUuid(), facility.getName(), facility.getExternalID()), new PointOfEntryReferenceDto(pointOfEntry.getUuid(), pointOfEntry.getName(), PointOfEntryType.AIRPORT, pointOfEntry.getExternalID()));
return rdcf;
}
Aggregations