Skip to content

Commit 81acf7b

Browse files
fixed the possible issues.
1 parent d44c76c commit 81acf7b

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

sormas-api/src/main/resources/validations.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,4 @@ smsAuthKeyValueValidation = SMS Auth key value is not valid
332332
smsAuthSecretValueValidation = SMS Auth secret value is not valid
333333
systemConfigurationValueValidationInvalidBackgroundColor = Pre-defined values are: green, red, indigo, gray, default (case-sensitive) otherwise must match hexadecimal format (with or without hash "#"), example: #dd2b0e or #4AA or dd2b0e
334334
systemConfigurationValueValidationMenuSubtitle = Can be empty or up to 16 (any) characters. Can be used to define name of the environment: PRODUCTION - TEST etc.
335-
customizableEnumValueAlreadyInUse = The customizable value %s is being used for %s case(IDs) and therefore cannot be deleted or deactivated. Please remove all references to this value before attempting to deactivate.
335+
customizableEnumValueAlreadyInUse = The customizable value %s is being used by case IDs %s and therefore cannot be deleted or deactivated. Please remove all references to this value before attempting to deactivate.

sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjb.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,25 @@ public CustomizableEnumValueDto save(CustomizableEnumValueDto dto) {
170170

171171
CustomizableEnumValue existingEntity = service.getByUuid(dto.getUuid());
172172
// if existingEntity disease removed and it is mapped to the cases, shouldn't allow to save the entity
173-
if (existingEntity != null && CollectionUtils.isNotEmpty(existingEntity.getDiseases()) && CollectionUtils.isNotEmpty(dto.getDiseases())) {
174-
existingEntity.getDiseases().stream().filter(disease -> !dto.getDiseases().contains(disease)).findAny().ifPresent(disease -> {
175-
List<String> uuids = service.areCasesUsingCustomizableEnumValue(disease, getEnumValue(dto.getDataType(), disease, dto.getValue()));
176-
if (!uuids.isEmpty()) {
177-
throw new ValidationRuntimeException(
178-
I18nProperties.getValidationError(
179-
Validations.customizableEnumValueAlreadyInUse,
180-
disease.getName(),
181-
uuids.stream().filter(Objects::nonNull).collect(Collectors.joining(", "))));
173+
174+
if (existingEntity != null && CollectionUtils.isNotEmpty(existingEntity.getDiseases())) {
175+
Set<Disease> incomingDiseases = dto.getDiseases() != null ? dto.getDiseases() : Collections.emptySet();
176+
for (Disease removedDisease : existingEntity.getDiseases()) {
177+
if (!incomingDiseases.contains(removedDisease)) {
178+
List<String> uuids = service.areCasesUsingCustomizableEnumValue(
179+
removedDisease,
180+
getEnumValue(dto.getDataType(), removedDisease, existingEntity.getValue()));
181+
if (!uuids.isEmpty()) {
182+
throw new ValidationRuntimeException(
183+
I18nProperties.getValidationError(
184+
Validations.customizableEnumValueAlreadyInUse,
185+
removedDisease.getName(),
186+
uuids.stream().filter(Objects::nonNull).collect(Collectors.joining(", "))));
187+
}
182188
}
183-
});
189+
}
184190
}
191+
185192
for (Disease disease : dto.getDiseases()) {
186193
List<String> dataTypeValues = enumValues.get(dto.getDataType()).getOrDefault(disease, Collections.emptyList());
187194
if (existingEntity == null && dataTypeValues != null && dataTypeValues.contains(dto.getValue())) {

sormas-backend/src/main/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumValueService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public List<String> areCasesUsingCustomizableEnumValue(Disease disease, DiseaseV
9494
CaseCriteria caseCriteria = new CaseCriteria();
9595
caseCriteria.setDisease(disease);
9696
caseCriteria.setDiseaseVariant(diseaseVariant);
97-
List<Case> result = caseService.findBy(caseCriteria, false);
97+
List<Case> result = caseService.findBy(caseCriteria, true);
9898
return result.stream().map(Case::getUuid).collect(Collectors.toList());
9999
}
100100

0 commit comments

Comments
 (0)