use of de.symeda.sormas.app.backend.region.RegionDtoHelper in project SORMAS-Project by hzi-braunschweig.
the class RegionBackendTest method testHandlePulledList.
@Test
public void testHandlePulledList() {
long startRegionCount = DatabaseHelper.getRegionDao().countOf();
List<RegionDto> regions = new ArrayList<>();
RegionDto region1 = RegionDto.build();
region1.setCreationDate(new Date());
region1.setChangeDate(new Date());
region1.setName("TestA");
regions.add(region1);
RegionDto region2 = RegionDto.build();
region2.setCreationDate(new Date());
region2.setChangeDate(new Date());
region2.setName("TestB");
regions.add(region2);
// this should cause a roll-back
region2.setUuid(null);
boolean hadException = false;
try {
new RegionDtoHelper().handlePulledList(DatabaseHelper.getRegionDao(), regions);
} catch (DaoException | NoConnectionException | ServerConnectionException | ServerCommunicationException e) {
hadException = true;
}
assertTrue(hadException);
long regionCount = DatabaseHelper.getRegionDao().countOf();
assertEquals(startRegionCount, regionCount);
// now it should work
region2.setUuid(DataHelper.createUuid());
hadException = false;
try {
new RegionDtoHelper().handlePulledList(DatabaseHelper.getRegionDao(), regions);
} catch (DaoException | NoConnectionException | ServerConnectionException | ServerCommunicationException e) {
hadException = true;
}
assertFalse(hadException);
regionCount = DatabaseHelper.getRegionDao().countOf();
assertEquals(startRegionCount + 2, regionCount);
}
use of de.symeda.sormas.app.backend.region.RegionDtoHelper in project SORMAS-Project by hzi-braunschweig.
the class SynchronizeDataAsync method pullMissingAndDeleteInvalidInfrastructure.
@AddTrace(name = "pullMissingAndDeleteInvalidInfrastructureTrace")
private void pullMissingAndDeleteInvalidInfrastructure() throws NoConnectionException, ServerConnectionException, ServerCommunicationException, DaoException {
// ATTENTION: Since we are working with UUID lists we have no type safety. Look for typos!
Log.d(SynchronizeDataAsync.class.getSimpleName(), "pullMissingAndDeleteInvalidInfrastructure");
// TODO get a count first and only retrieve all uuids when count is different?
// users
List<String> userUuids = executeUuidCall(RetroProvider.getUserFacade().pullUuids());
DatabaseHelper.getUserDao().deleteInvalid(userUuids);
// disease configurations
List<String> diseaseConfigurationUuids = executeUuidCall(RetroProvider.getDiseaseConfigurationFacade().pullUuids());
DatabaseHelper.getDiseaseConfigurationDao().deleteInvalid(diseaseConfigurationUuids);
// Disease variants
List<String> customizableEnumValueUuids = executeUuidCall(RetroProvider.getCustomizableEnumValueFacade().pullUuids());
DatabaseHelper.getCustomizableEnumValueDao().deleteInvalid(customizableEnumValueUuids);
// feature configurations
List<String> featureConfigurationUuids = executeUuidCall(RetroProvider.getFeatureConfigurationFacade().pullUuids());
DatabaseHelper.getFeatureConfigurationDao().deleteInvalid(featureConfigurationUuids);
// user role config
List<String> userRoleConfigUuids = executeUuidCall(RetroProvider.getUserRoleConfigFacade().pullUuids());
DatabaseHelper.getUserRoleConfigDao().deleteInvalid(userRoleConfigUuids);
// points of entry
List<String> pointOfEntryUuids = executeUuidCall(RetroProvider.getPointOfEntryFacade().pullUuids());
DatabaseHelper.getPointOfEntryDao().deleteInvalid(pointOfEntryUuids);
// facilities
List<String> facilityUuids = executeUuidCall(RetroProvider.getFacilityFacade().pullUuids());
DatabaseHelper.getFacilityDao().deleteInvalid(facilityUuids);
// communities
List<String> communityUuids = executeUuidCall(RetroProvider.getCommunityFacade().pullUuids());
DatabaseHelper.getCommunityDao().deleteInvalid(communityUuids);
// districts
List<String> districtUuids = executeUuidCall(RetroProvider.getDistrictFacade().pullUuids());
DatabaseHelper.getDistrictDao().deleteInvalid(districtUuids);
// regions
List<String> regionUuids = executeUuidCall(RetroProvider.getRegionFacade().pullUuids());
DatabaseHelper.getRegionDao().deleteInvalid(regionUuids);
// areas
List<String> areaUuids = executeUuidCall(RetroProvider.getAreaFacade().pullUuids());
DatabaseHelper.getAreaDao().deleteInvalid(areaUuids);
// countries
List<String> countryUuids = executeUuidCall(RetroProvider.getCountryFacade().pullUuids());
DatabaseHelper.getCountryDao().deleteInvalid(countryUuids);
// subcontinents
List<String> subcontinentUuids = executeUuidCall(RetroProvider.getSubcontinentFacade().pullUuids());
DatabaseHelper.getSubcontinentDao().deleteInvalid(subcontinentUuids);
// continents
List<String> continentUuids = executeUuidCall(RetroProvider.getContinentFacade().pullUuids());
DatabaseHelper.getContinentDao().deleteInvalid(continentUuids);
// order is important, due to dependencies
new ContinentDtoHelper().pullMissing(continentUuids);
new SubcontinentDtoHelper().pullMissing(subcontinentUuids);
new CountryDtoHelper().pullMissing(countryUuids);
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.INFRASTRUCTURE_TYPE_AREA)) {
new AreaDtoHelper().pullMissing(areaUuids);
}
new RegionDtoHelper().pullMissing(regionUuids);
new DistrictDtoHelper().pullMissing(districtUuids);
new CommunityDtoHelper().pullMissing(communityUuids);
new FacilityDtoHelper().pullMissing(facilityUuids);
new PointOfEntryDtoHelper().pullMissing(pointOfEntryUuids);
new UserRoleConfigDtoHelper().pullMissing(userRoleConfigUuids);
new UserDtoHelper().pullMissing(userUuids);
new DiseaseConfigurationDtoHelper().pullMissing(diseaseConfigurationUuids);
new CustomizableEnumValueDtoHelper().pullMissing(customizableEnumValueUuids);
new FeatureConfigurationDtoHelper().pullMissing(featureConfigurationUuids);
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.CAMPAIGNS)) {
// campaigns
List<String> campaignUuids = executeUuidCall(RetroProvider.getCampaignFacade().pullUuids());
DatabaseHelper.getCampaignDao().deleteInvalid(campaignUuids);
// campaignFormMetas
List<String> campaignFormMetaUuids = executeUuidCall(RetroProvider.getCampaignFormMetaFacade().pullUuids());
DatabaseHelper.getCampaignFormMetaDao().deleteInvalid(campaignFormMetaUuids);
new CampaignFormMetaDtoHelper().pullMissing(campaignFormMetaUuids);
new CampaignDtoHelper().pullMissing(campaignUuids);
}
}
use of de.symeda.sormas.app.backend.region.RegionDtoHelper in project SORMAS-Project by hzi-braunschweig.
the class SynchronizeDataAsync method pullInitialInfrastructure.
@AddTrace(name = "pullInitialInfrastructureTrace")
private void pullInitialInfrastructure() throws DaoException, ServerCommunicationException, ServerConnectionException, NoConnectionException {
new ContinentDtoHelper().pullEntities(false, context);
new SubcontinentDtoHelper().pullEntities(false, context);
new CountryDtoHelper().pullEntities(false, context);
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.INFRASTRUCTURE_TYPE_AREA)) {
new AreaDtoHelper().pullEntities(false, context);
}
new RegionDtoHelper().pullEntities(false, context);
new DistrictDtoHelper().pullEntities(false, context);
new CommunityDtoHelper().pullEntities(false, context);
new FacilityDtoHelper().pullEntities(false, context);
new PointOfEntryDtoHelper().pullEntities(false, context);
new UserDtoHelper().pullEntities(false, context);
new DiseaseClassificationDtoHelper().pullEntities(false, context);
new DiseaseConfigurationDtoHelper().pullEntities(false, context);
new CustomizableEnumValueDtoHelper().pullEntities(false, context);
// user role configurations may be removed, so have to pull the deleted uuids
// this may be applied to other entities later as well
Date latestChangeDate = DatabaseHelper.getUserRoleConfigDao().getLatestChangeDate();
List<String> userRoleConfigUuids = executeUuidCall(RetroProvider.getUserRoleConfigFacade().pullDeletedUuidsSince(latestChangeDate != null ? latestChangeDate.getTime() : 0));
DatabaseHelper.getUserRoleConfigDao().delete(userRoleConfigUuids);
new UserRoleConfigDtoHelper().pullEntities(false, context);
Date featureConfigurationChangeDate = DatabaseHelper.getFeatureConfigurationDao().getLatestChangeDate();
List<String> featureConfigurationConfigUuids = executeUuidCall(RetroProvider.getFeatureConfigurationFacade().pullDeletedUuidsSince(featureConfigurationChangeDate != null ? featureConfigurationChangeDate.getTime() : 0));
DatabaseHelper.getFeatureConfigurationDao().delete(featureConfigurationConfigUuids);
new FeatureConfigurationDtoHelper().pullEntities(false, context);
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.CAMPAIGNS)) {
new CampaignFormMetaDtoHelper().pullEntities(false, context);
new CampaignDtoHelper().pullEntities(false, context);
}
ConfigProvider.setInitialSyncRequired(false);
}
use of de.symeda.sormas.app.backend.region.RegionDtoHelper in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureHelper method handlePulledInfrastructureData.
public static void handlePulledInfrastructureData(InfrastructureSyncDto infrastructureData) throws DaoException, NoConnectionException, ServerConnectionException, ServerCommunicationException {
new ContinentDtoHelper().handlePulledList(DatabaseHelper.getContinentDao(), infrastructureData.getContinents());
new SubcontinentDtoHelper().handlePulledList(DatabaseHelper.getSubcontinentDao(), infrastructureData.getSubcontinents());
new CountryDtoHelper().handlePulledList(DatabaseHelper.getCountryDao(), infrastructureData.getCountries());
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.INFRASTRUCTURE_TYPE_AREA)) {
new AreaDtoHelper().handlePulledList(DatabaseHelper.getAreaDao(), infrastructureData.getAreas());
}
new RegionDtoHelper().handlePulledList(DatabaseHelper.getRegionDao(), infrastructureData.getRegions());
new DistrictDtoHelper().handlePulledList(DatabaseHelper.getDistrictDao(), infrastructureData.getDistricts());
new CommunityDtoHelper().handlePulledList(DatabaseHelper.getCommunityDao(), infrastructureData.getCommunities());
new FacilityDtoHelper().handlePulledList(DatabaseHelper.getFacilityDao(), infrastructureData.getFacilities());
new PointOfEntryDtoHelper().handlePulledList(DatabaseHelper.getPointOfEntryDao(), infrastructureData.getPointsOfEntry());
new UserDtoHelper().handlePulledList(DatabaseHelper.getUserDao(), infrastructureData.getUsers());
new DiseaseClassificationDtoHelper().handlePulledList(DatabaseHelper.getDiseaseClassificationCriteriaDao(), infrastructureData.getDiseaseClassifications());
new DiseaseConfigurationDtoHelper().handlePulledList(DatabaseHelper.getDiseaseConfigurationDao(), infrastructureData.getDiseaseConfigurations());
DatabaseHelper.getUserRoleConfigDao().delete(infrastructureData.getDeletedUserRoleConfigurationUuids());
new UserRoleConfigDtoHelper().handlePulledList(DatabaseHelper.getUserRoleConfigDao(), infrastructureData.getUserRoleConfigurations());
DatabaseHelper.getFeatureConfigurationDao().delete(infrastructureData.getDeletedFeatureConfigurationUuids());
new FeatureConfigurationDtoHelper().handlePulledList(DatabaseHelper.getFeatureConfigurationDao(), infrastructureData.getFeatureConfigurations());
if (!DatabaseHelper.getFeatureConfigurationDao().isFeatureDisabled(FeatureType.CAMPAIGNS)) {
new CampaignDtoHelper().handlePulledList(DatabaseHelper.getCampaignDao(), infrastructureData.getCampaigns());
new CampaignFormMetaDtoHelper().handlePulledList(DatabaseHelper.getCampaignFormMetaDao(), infrastructureData.getCampaignFormMetas());
}
}
Aggregations