Pull request #17: Fixed duplicate label validation

Merge in RED/persistence-service from DuplLabelValidationFix to master

* commit '980d370e4d11082af57e409c0c3325a15da6923b':
  Fixed duplicate label validation
This commit is contained in:
Dominique Eiflaender 2021-09-28 11:27:48 +02:00
commit 713172d948

View File

@ -119,7 +119,7 @@ public class DictionaryController implements DictionaryResource {
if (typeValueRequest.getLabel() != null) {
checkForDuplicateLabels(typeResult.getDossierTemplateId(), typeResult.getDossierId(), typeId, typeValueRequest.getLabel());
checkForDuplicateLabels(typeResult.getDossierTemplateId(), typeResult.getDossierId(), typeValueRequest.getType(), typeValueRequest.getLabel());
}
@ -154,11 +154,12 @@ public class DictionaryController implements DictionaryResource {
typeRequest.setLabel(label);
}
checkForDuplicateLabels(typeRequest.getDossierTemplateId(), typeRequest.getDossierId(), typeRequest.getId(), typeRequest.getLabel());
checkForDuplicateLabels(typeRequest.getDossierTemplateId(), typeRequest.getDossierId(), typeRequest.getType(), typeRequest.getLabel());
if (dictionaryPersistenceService.getCumulatedTypes(typeRequest.getDossierTemplateId(), typeRequest.getDossierId())
.stream()
.anyMatch(typeResult -> typeResult.getType().equals(typeRequest.getType()))) {
.anyMatch(typeResult -> typeRequest.getDossierId() != null && typeResult.getDossierId() != null && typeRequest.getDossierId().equals(typeResult.getDossierId()) && typeRequest.getType().equals(typeResult.getType()) && typeRequest.getDossierTemplateId().equals(typeResult.getDossierTemplateId())
|| typeRequest.getType().equals(typeResult.getType()) && typeRequest.getDossierTemplateId().equals(typeResult.getDossierTemplateId()))) {
throw new ConflictException("The type already exists, could not be added again.");
}
String color = typeRequest.getHexColor();
@ -276,11 +277,12 @@ public class DictionaryController implements DictionaryResource {
}
private void checkForDuplicateLabels(String dossierTemplateId, String dossierId, String typeId, String labelToCheck) {
private void checkForDuplicateLabels(String dossierTemplateId, String dossierId, String type, String labelToCheck) {
List<Type> typeResponse = dictionaryPersistenceService.getCumulatedTypes(dossierTemplateId, dossierId);
for (Type res : typeResponse) {
if (!typeId.equals(res.getId()) && labelToCheck.equals(res.getLabel())) {
if (dossierId != null && res.getDossierId() != null && res.getDossierId().equals(dossierId) && !type.equals(res.getType()) && res.getDossierTemplateId().equals(dossierTemplateId) && dossierId.equals(dossierId) && labelToCheck.equals(res.getLabel())
|| !type.equals(res.getType()) && res.getDossierTemplateId().equals(dossierTemplateId) && labelToCheck.equals(res.getLabel())) {
throw new ConflictException("Label must be unique.");
}
}