use of de.symeda.sormas.api.HasUuid in project SORMAS-Project by hzi-braunschweig.
the class InfrastructureController method archiveOrDearchiveAllSelectedItems.
@SuppressWarnings("unchecked")
public void archiveOrDearchiveAllSelectedItems(boolean archive, Collection<?> selectedRows, InfrastructureType infrastructureType, Runnable callback) {
// Check that at least one entry is selected
if (selectedRows.isEmpty()) {
new Notification(I18nProperties.getString(Strings.headingNoRowsSelected), I18nProperties.getString(Strings.messageNoRowsSelected), Type.WARNING_MESSAGE, false).show(Page.getCurrent());
return;
}
// Check if archiving/dearchiving is allowed concerning the hierarchy
Set<String> selectedRowsUuids = selectedRows.stream().map(row -> ((HasUuid) row).getUuid()).collect(Collectors.toSet());
if (InfrastructureType.AREA.equals(infrastructureType) && FacadeProvider.getAreaFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.CONTINENT.equals(infrastructureType) && FacadeProvider.getContinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.REGION.equals(infrastructureType) && FacadeProvider.getRegionFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().isUsedInOtherInfrastructureData(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().isUsedInOtherInfrastructureData(selectedRowsUuids)) {
showArchivingNotPossibleWindow(infrastructureType, true);
return;
}
if (InfrastructureType.COUNTRY.equals(infrastructureType) && FacadeProvider.getCountryFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.SUBCONTINENT.equals(infrastructureType) && FacadeProvider.getSubcontinentFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.DISTRICT.equals(infrastructureType) && FacadeProvider.getDistrictFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.COMMUNITY.equals(infrastructureType) && FacadeProvider.getCommunityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.FACILITY.equals(infrastructureType) && FacadeProvider.getFacilityFacade().hasArchivedParentInfrastructure(selectedRowsUuids) || InfrastructureType.POINT_OF_ENTRY.equals(infrastructureType) && FacadeProvider.getPointOfEntryFacade().hasArchivedParentInfrastructure(selectedRowsUuids)) {
showDearchivingNotPossibleWindow(infrastructureType, false);
return;
}
final String confirmationMessage;
final String notificationMessage;
switch(infrastructureType) {
case CONTINENT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveContinents) : I18nProperties.getString(Strings.confirmationDearchiveContinents);
notificationMessage = archive ? I18nProperties.getString(Strings.messageContinentsArchived) : I18nProperties.getString(Strings.messageContinentsDearchived);
break;
case SUBCONTINENT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveSubcontinents) : I18nProperties.getString(Strings.confirmationDearchiveSubcontinents);
notificationMessage = archive ? I18nProperties.getString(Strings.messageSubcontinentsArchived) : I18nProperties.getString(Strings.messageSubcontinentsDearchived);
break;
case AREA:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveAreas) : I18nProperties.getString(Strings.confirmationDearchiveAreas);
notificationMessage = archive ? I18nProperties.getString(Strings.messageAreasArchived) : I18nProperties.getString(Strings.messageAreasDearchived);
break;
case COUNTRY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCountries) : I18nProperties.getString(Strings.confirmationDearchiveCountries);
notificationMessage = archive ? I18nProperties.getString(Strings.messageCountriesArchived) : I18nProperties.getString(Strings.messageCountriesDearchived);
break;
case REGION:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveRegions) : I18nProperties.getString(Strings.confirmationDearchiveRegions);
notificationMessage = archive ? I18nProperties.getString(Strings.messageRegionsArchived) : I18nProperties.getString(Strings.messageRegionsDearchived);
break;
case DISTRICT:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveDistricts) : I18nProperties.getString(Strings.confirmationDearchiveDistricts);
notificationMessage = archive ? I18nProperties.getString(Strings.messageDistrictsArchived) : I18nProperties.getString(Strings.messageDistrictsDearchived);
break;
case COMMUNITY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveCommunities) : I18nProperties.getString(Strings.confirmationDearchiveCommunities);
notificationMessage = archive ? I18nProperties.getString(Strings.messageCommunitiesArchived) : I18nProperties.getString(Strings.messageCommunitiesDearchived);
break;
case FACILITY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchiveFacilities) : I18nProperties.getString(Strings.confirmationDearchiveFacilities);
notificationMessage = archive ? I18nProperties.getString(Strings.messageFacilitiesArchived) : I18nProperties.getString(Strings.messageFacilitiesDearchived);
break;
case POINT_OF_ENTRY:
confirmationMessage = archive ? I18nProperties.getString(Strings.confirmationArchivePointsOfEntry) : I18nProperties.getString(Strings.confirmationDearchivePointsOfEntry);
notificationMessage = archive ? I18nProperties.getString(Strings.messagePointsOfEntryArchived) : I18nProperties.getString(Strings.messagePointsOfEntryDearchived);
break;
default:
throw new IllegalArgumentException(infrastructureType.name());
}
VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmArchiving), new Label(String.format(confirmationMessage, selectedRows.size())), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> {
if (e.booleanValue()) {
switch(infrastructureType) {
case CONTINENT:
for (ContinentDto selectedRow : (Collection<ContinentDto>) selectedRows) {
if (archive) {
FacadeProvider.getContinentFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getContinentFacade().dearchive(selectedRow.getUuid());
}
}
break;
case SUBCONTINENT:
for (SubcontinentDto selectedRow : (Collection<SubcontinentDto>) selectedRows) {
if (archive) {
FacadeProvider.getSubcontinentFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getSubcontinentFacade().dearchive(selectedRow.getUuid());
}
}
break;
case AREA:
for (AreaDto selectedRow : (Collection<AreaDto>) selectedRows) {
if (archive) {
FacadeProvider.getAreaFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getAreaFacade().dearchive(selectedRow.getUuid());
}
}
break;
case COUNTRY:
for (CountryIndexDto selectedRow : (Collection<CountryIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getCountryFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getCountryFacade().dearchive(selectedRow.getUuid());
}
}
break;
case REGION:
for (RegionIndexDto selectedRow : (Collection<RegionIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getRegionFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getRegionFacade().dearchive(selectedRow.getUuid());
}
}
break;
case DISTRICT:
for (DistrictIndexDto selectedRow : (Collection<DistrictIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getDistrictFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getDistrictFacade().dearchive(selectedRow.getUuid());
}
}
break;
case COMMUNITY:
for (CommunityDto selectedRow : (Collection<CommunityDto>) selectedRows) {
if (archive) {
FacadeProvider.getCommunityFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getCommunityFacade().dearchive(selectedRow.getUuid());
}
}
break;
case FACILITY:
for (FacilityIndexDto selectedRow : (Collection<FacilityIndexDto>) selectedRows) {
if (archive) {
FacadeProvider.getFacilityFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getFacilityFacade().dearchive(selectedRow.getUuid());
}
}
break;
case POINT_OF_ENTRY:
for (PointOfEntryDto selectedRow : (Collection<PointOfEntryDto>) selectedRows) {
if (archive) {
FacadeProvider.getPointOfEntryFacade().archive(selectedRow.getUuid());
} else {
FacadeProvider.getPointOfEntryFacade().dearchive(selectedRow.getUuid());
}
}
break;
default:
throw new IllegalArgumentException(infrastructureType.name());
}
callback.run();
Notification.show(notificationMessage, Type.ASSISTIVE_NOTIFICATION);
}
});
}
use of de.symeda.sormas.api.HasUuid in project SORMAS-Project by hzi-braunschweig.
the class DocumentTemplateFacadeEjb method prepareProperties.
private Properties prepareProperties(DocumentWorkflow documentWorkflow, DocumentTemplateEntities entities, Properties extraProperties, DocumentVariables documentVariables) {
Properties properties = new Properties();
// 1. Map template variables to entity data if possible
// Naming conventions according sormas-api/src/main/resources/doc/SORMAS_Data_Dictionary.xlsx, e.g.:
// <CaseDataDto>.person.firstName
// <CaseDataDto>.quarantineFrom
// Generic access as implemented in DataDictionaryGenerator.java
EntityDtoAccessHelper.IReferenceDtoResolver referenceDtoResolver = getReferenceDtoResolver();
String propertySeparator = documentWorkflow.isDocx() ? "." : "_";
for (String propertyKey : documentVariables.getVariables()) {
if (isEntityVariable(documentWorkflow, propertyKey)) {
String variableBaseName = getVariableBaseName(propertyKey);
RootEntityType rootEntityType = RootEntityType.ofEntityName(variableBaseName);
if (rootEntityType == null) {
continue;
}
Object entity = entities.getEntity(rootEntityType);
if (entity instanceof HasUuid) {
if (documentWorkflow.isDocx() || propertyKey.contains(propertySeparator)) {
String propertyPath = propertyKey.replaceFirst("(?i)" + variableBaseName + "[" + propertySeparator + "]", "");
if (!".".equals(propertySeparator)) {
propertyPath = propertyPath.replaceAll(propertySeparator, ".");
}
Object propertyValue;
try {
propertyValue = EntityDtoAccessHelper.getPropertyPathValueString((HasUuid) entity, propertyPath, referenceDtoResolver);
} catch (Exception e) {
propertyValue = "*** " + e.getMessage().replaceAll("(Reference)?Dto$", "") + " ***";
}
if (propertyValue != null) {
properties.put(propertyKey, propertyValue);
}
}
}
}
}
if (!documentWorkflow.isDocx()) {
for (RootEntityType entityType : entities.getEntities().keySet()) {
Object entity = entities.getEntity(entityType);
if (ReferenceDto.class.isAssignableFrom(entity.getClass())) {
entity = referenceDtoResolver.resolve((ReferenceDto) entity);
}
properties.put(entityType.getEntityName(), entity);
}
}
if (extraProperties != null) {
for (String extraPropertyKey : extraProperties.stringPropertyNames()) {
String propertyValue = extraProperties.getProperty(extraPropertyKey);
properties.setProperty(extraPropertyKey, propertyValue);
}
}
// 3. fill null properties
String nullReplacement = configFacade.getDocgenerationNullReplacement();
if (nullReplacement.isEmpty()) {
nullReplacement = " ";
}
for (String variable : documentVariables.getVariables()) {
Object property = properties.get(variable);
if ((property == null || StringUtils.isBlank(property.toString())) && !documentVariables.isNullableVariable(variable)) {
properties.setProperty(variable, nullReplacement);
}
}
properties.put("F", new ObjectFormatter());
return properties;
}
Aggregations