use of de.symeda.sormas.api.infrastructure.region.RegionDto in project SORMAS-Project by hzi-braunschweig.
the class DataImporter method executeDefaultInvoke.
/**
* Contains checks for the most common data types for entries in the import file. This method should be called
* in every subclass whenever data from the import file is supposed to be written to the entity in question.
* Additional invokes need to be executed manually in the subclass.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected boolean executeDefaultInvoke(PropertyDescriptor pd, Object element, String entry, String[] entryHeaderPath) throws InvocationTargetException, IllegalAccessException, ImportErrorException {
Class<?> propertyType = pd.getPropertyType();
if (propertyType.isEnum()) {
Enum enumValue = null;
Class<Enum> enumType = (Class<Enum>) propertyType;
try {
enumValue = Enum.valueOf(enumType, entry.toUpperCase());
} catch (IllegalArgumentException e) {
// ignore
}
if (enumValue == null) {
enumValue = enumCaptionCache.getEnumByCaption(enumType, entry);
}
pd.getWriteMethod().invoke(element, enumValue);
return true;
}
if (propertyType.isAssignableFrom(Date.class)) {
String dateFormat = I18nProperties.getUserLanguage().getDateFormat();
try {
pd.getWriteMethod().invoke(element, DateHelper.parseDateWithException(entry, dateFormat));
return true;
} catch (ParseException e) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importInvalidDate, pd.getName(), DateHelper.getAllowedDateFormats(dateFormat)));
}
}
if (propertyType.isAssignableFrom(Integer.class)) {
pd.getWriteMethod().invoke(element, Integer.parseInt(entry));
return true;
}
if (propertyType.isAssignableFrom(Double.class)) {
pd.getWriteMethod().invoke(element, Double.parseDouble(entry));
return true;
}
if (propertyType.isAssignableFrom(Float.class)) {
pd.getWriteMethod().invoke(element, Float.parseFloat(entry));
return true;
}
if (propertyType.isAssignableFrom(Boolean.class) || propertyType.isAssignableFrom(boolean.class)) {
pd.getWriteMethod().invoke(element, DataHelper.parseBoolean(entry));
return true;
}
if (propertyType.isAssignableFrom(AreaReferenceDto.class)) {
List<AreaReferenceDto> areas = FacadeProvider.getAreaFacade().getByName(entry, false);
if (areas.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
} else if (areas.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importAreaNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(element, areas.get(0));
return true;
}
}
if (propertyType.isAssignableFrom(SubcontinentReferenceDto.class)) {
List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getByDefaultName(entry, false);
if (subcontinents.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
} else if (subcontinents.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(element, subcontinents.get(0));
return true;
}
}
if (propertyType.isAssignableFrom(CountryReferenceDto.class)) {
List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getByDefaultName(entry, false);
if (countries.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
} else if (countries.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(element, countries.get(0));
return true;
}
}
if (propertyType.isAssignableFrom(ContinentReferenceDto.class)) {
List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getByDefaultName(entry, false);
if (continents.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
} else if (continents.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(element, continents.get(0));
return true;
}
}
if (propertyType.isAssignableFrom(RegionReferenceDto.class)) {
List<RegionDto> regions = FacadeProvider.getRegionFacade().getByName(entry, false);
if (regions.isEmpty()) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
} else if (regions.size() > 1) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importRegionNotUnique, entry, buildEntityProperty(entryHeaderPath)));
} else {
RegionDto region = regions.get(0);
CountryReferenceDto serverCountry = FacadeProvider.getCountryFacade().getServerCountry();
if (region.getCountry() != null && !region.getCountry().equals(serverCountry)) {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importRegionNotInServerCountry, entry, buildEntityProperty(entryHeaderPath)));
} else {
pd.getWriteMethod().invoke(element, region.toReference());
return true;
}
}
}
if (propertyType.isAssignableFrom(UserReferenceDto.class)) {
UserDto user = FacadeProvider.getUserFacade().getByUserName(entry);
if (user != null) {
pd.getWriteMethod().invoke(element, user.toReference());
return true;
} else {
throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
}
}
if (propertyType.isAssignableFrom(String.class)) {
pd.getWriteMethod().invoke(element, entry);
return true;
}
return false;
}
use of de.symeda.sormas.api.infrastructure.region.RegionDto in project SORMAS-Project by hzi-braunschweig.
the class CaseStatisticsFacadeEjbTest method testQueryCaseCountPopulation.
@Test
public void testQueryCaseCountPopulation() {
RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
cazePerson.setApproximateAge(30);
cazePerson.setApproximateAgeReferenceDate(new Date());
cazePerson.setApproximateAgeType(ApproximateAgeType.YEARS);
cazePerson = getPersonFacade().savePerson(cazePerson);
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
caze = getCaseFacade().getCaseDataByUuid(caze.getUuid());
StatisticsCaseCriteria criteria = new StatisticsCaseCriteria();
criteria.regions(Arrays.asList(rdcf.region));
List<StatisticsCaseCountDto> results = getCaseStatisticsFacade().queryCaseCount(criteria, StatisticsCaseAttribute.JURISDICTION, StatisticsCaseSubAttribute.REGION, null, null, true, false, null);
assertNull(results.get(0).getPopulation());
PopulationDataDto populationData = PopulationDataDto.build(new Date());
RegionDto region = getRegionFacade().getByUuid(rdcf.region.getUuid());
region.setGrowthRate(10f);
getRegionFacade().save(region);
populationData.setRegion(rdcf.region);
populationData.setPopulation(new Integer(10000));
getPopulationDataFacade().savePopulationData(Arrays.asList(populationData));
results = getCaseStatisticsFacade().queryCaseCount(criteria, StatisticsCaseAttribute.JURISDICTION, StatisticsCaseSubAttribute.REGION, null, null, true, false, LocalDate.now().getYear() + 2);
// List should have one entry
assertEquals(Integer.valueOf(12214), results.get(0).getPopulation());
}
use of de.symeda.sormas.api.infrastructure.region.RegionDto in project SORMAS-Project by hzi-braunschweig.
the class RegionFacadeEjb method toDto.
public RegionDto toDto(Region entity) {
if (entity == null) {
return null;
}
RegionDto dto = new RegionDto();
DtoHelper.fillDto(dto, entity);
dto.setName(entity.getName());
dto.setEpidCode(entity.getEpidCode());
dto.setGrowthRate(entity.getGrowthRate());
dto.setArchived(entity.isArchived());
dto.setExternalID(entity.getExternalID());
dto.setArea(AreaFacadeEjb.toReferenceDto(entity.getArea()));
dto.setCountry(CountryFacadeEjb.toReferenceDto(entity.getCountry()));
dto.setCentrallyManaged(entity.isCentrallyManaged());
return dto;
}
use of de.symeda.sormas.api.infrastructure.region.RegionDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method createRDP.
public RDP createRDP() {
RegionDto region = createRegion("Region");
DistrictDto district = createDistrict("District", region.toReference());
PointOfEntryDto pointOfEntry = createPointOfEntry("POE", region.toReference(), district.toReference());
return new RDP(region, district, pointOfEntry);
}
use of de.symeda.sormas.api.infrastructure.region.RegionDto in project SORMAS-Project by hzi-braunschweig.
the class DtoEntityTest method testDtoTooOld.
@Test(expected = OutdatedEntityException.class)
public void testDtoTooOld() {
RegionDto region = RegionDto.build();
region.setName("Region1");
getRegionFacade().save(region);
region.setName("Region2");
getRegionFacade().save(region);
}
Aggregations