use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureImporter method insertColumnEntryIntoData.
/**
* Inserts the entry of a single cell into the infrastructure object.
*/
private void insertColumnEntryIntoData(EntityDto newEntityDto, String value, String[] entityPropertyPath) throws InvalidColumnException, ImportErrorException {
Object currentElement = newEntityDto;
for (int i = 0; i < entityPropertyPath.length; i++) {
String headerPathElementName = entityPropertyPath[i];
try {
if (i != entityPropertyPath.length - 1) {
currentElement = new PropertyDescriptor(headerPathElementName, currentElement.getClass()).getReadMethod().invoke(currentElement);
} else {
PropertyDescriptor pd = new PropertyDescriptor(headerPathElementName, currentElement.getClass());
Class<?> propertyType = pd.getPropertyType();
// is referenced in the imported object does not exist in the database
if (!executeDefaultInvoke(pd, currentElement, value, entityPropertyPath)) {
if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
List<DistrictReferenceDto> district;
switch(type) {
case COMMUNITY:
district = FacadeProvider.getDistrictFacade().getByName(value, ((CommunityDto) newEntityDto).getRegion(), false);
break;
case FACILITY:
district = FacadeProvider.getDistrictFacade().getByName(value, ((FacilityDto) newEntityDto).getRegion(), false);
break;
case POINT_OF_ENTRY:
district = FacadeProvider.getDistrictFacade().getByName(value, ((PointOfEntryDto) newEntityDto).getRegion(), false);
break;
default:
throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
}
if (district.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, value, buildEntityProperty(entityPropertyPath)));
} else if (district.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, value, buildEntityProperty(entityPropertyPath)));
} else {
pd.getWriteMethod().invoke(currentElement, district.get(0));
}
} else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
List<CommunityReferenceDto> community;
if (type == InfrastructureType.FACILITY) {
community = FacadeProvider.getCommunityFacade().getByName(value, ((FacilityDto) newEntityDto).getDistrict(), false);
} else {
throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
}
if (community.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, value, buildEntityProperty(entityPropertyPath)));
} else if (community.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, value, buildEntityProperty(entityPropertyPath)));
} else {
pd.getWriteMethod().invoke(currentElement, community.get(0));
}
} else {
throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
}
}
}
} catch (IntrospectionException e) {
throw new InvalidColumnException(buildEntityProperty(entityPropertyPath));
} catch (InvocationTargetException | IllegalAccessException e) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entityPropertyPath)));
} catch (IllegalArgumentException e) {
throw new ImportErrorException(value, buildEntityProperty(entityPropertyPath));
} catch (ImportErrorException e) {
throw e;
} catch (Exception e) {
logger.error("Unexpected error when trying to import infrastructure data: " + e.getMessage());
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importUnexpectedError));
}
}
ImportLineResultDto<EntityDto> constraintErrors = validateConstraints(newEntityDto);
if (constraintErrors.isError()) {
throw new ImportErrorException(constraintErrors.getMessage());
}
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class TravelEntryCreateForm method setValue.
@Override
public void setValue(TravelEntryDto newFieldValue) throws ReadOnlyException, Converter.ConversionException {
super.setValue(newFieldValue);
buildDeaContent(newFieldValue);
UserProvider currentUserProvider = UserProvider.getCurrent();
JurisdictionLevel userJurisditionLevel = currentUserProvider != null ? UserRole.getJurisdictionLevel(currentUserProvider.getUserRoles()) : JurisdictionLevel.NONE;
if (userJurisditionLevel == JurisdictionLevel.HEALTH_FACILITY) {
FacilityDto facility = FacadeProvider.getFacilityFacade().getByUuid(currentUserProvider.getUser().getHealthFacility().getUuid());
responsibleRegion.setValue(facility.getRegion());
responsibleRegion.setReadOnly(true);
responsibleDistrict.setValue(facility.getDistrict());
responsibleDistrict.setReadOnly(true);
responsibleCommunity.setValue(facility.getCommunity());
responsibleCommunity.setReadOnly(true);
}
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method createRDCF.
public RDCF createRDCF(String regionName, String districtName, String communityName, String facilityName) {
RegionDto region = createRegion(regionName);
DistrictDto district = createDistrict(districtName, region.toReference());
CommunityDto community = createCommunity(communityName, district.toReference());
FacilityDto facility = createFacility(facilityName, region.toReference(), district.toReference(), community.toReference());
return new RDCF(region, district, community, facility);
}
use of de.symeda.sormas.api.infrastructure.facility.FacilityDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method createCase.
public CaseDataDto createCase(UserReferenceDto user, PersonReferenceDto cazePerson, Disease disease, CaseClassification caseClassification, InvestigationStatus investigationStatus, Date reportDate, RDCF rdcf, String caseUuid) {
CaseDataDto caze = CaseDataDto.build(cazePerson, disease);
if (caseUuid != null) {
caze.setUuid(caseUuid);
}
caze.setReportDate(reportDate);
caze.setReportingUser(user);
caze.setCaseClassification(caseClassification);
caze.setInvestigationStatus(investigationStatus);
caze.setResponsibleRegion(FacadeProvider.getRegionFacade().getReferenceByUuid(rdcf.region.getUuid()));
caze.setResponsibleDistrict(FacadeProvider.getDistrictFacade().getReferenceByUuid(rdcf.district.getUuid()));
caze.setResponsibleCommunity(FacadeProvider.getCommunityFacade().getReferenceByUuid(rdcf.community.getUuid()));
FacilityDto facility = FacadeProvider.getFacilityFacade().getByUuid(rdcf.facility.getUuid());
caze.setFacilityType(facility.getType());
caze.setHealthFacility(facility.toReference());
caze = FacadeProviderMock.getCaseFacade().save(caze);
return caze;
}
Aggregations