diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/manualredactions/PendingDictionaryEntryFactory.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/manualredactions/PendingDictionaryEntryFactory.java index 79a09283f..e8e5cf73c 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/manualredactions/PendingDictionaryEntryFactory.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/manualredactions/PendingDictionaryEntryFactory.java @@ -1,5 +1,7 @@ package com.iqser.red.service.persistence.management.v1.processor.service.manualredactions; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,6 +28,27 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemp @Service public class PendingDictionaryEntryFactory { + private static String shortenValueIfNecessary(String value) { + + final int MAX_LENGTH = 100; + + if (value.length() <= MAX_LENGTH) { + return value; + } + + String[] words = value.split(" "); + + if (words.length == 1) { + return value.substring(0, MAX_LENGTH) + "..."; + } + + int bound = Math.min(words.length, 2); + List list = new ArrayList<>(Arrays.asList(words).subList(0, bound)); + + return String.join(" ", list) + "..."; + } + + public EntityLogEntry buildAddToDictionaryEntry(ManualRedactionEntry manualRedactionEntry) { var manualChanges = List.of(ManualChange.builder() @@ -35,17 +58,26 @@ public class PendingDictionaryEntryFactory { .userId(manualRedactionEntry.getUser()) .propertyChanges(Map.of("value", manualRedactionEntry.getValue())) .build()); + + DictionaryEntryType dictionaryEntryType = Optional.ofNullable(manualRedactionEntry.getDictionaryEntryType()) + .orElse(DictionaryEntryType.ENTRY); + + String reason = switch (dictionaryEntryType) { + case ENTRY -> String.format("%s has been added to the dictionary", shortenValueIfNecessary(manualRedactionEntry.getValue())); + case FALSE_POSITIVE -> String.format("%s has been added as a false positive", shortenValueIfNecessary(manualRedactionEntry.getValue())); + case FALSE_RECOMMENDATION -> String.format("%s has been added as a false recommendation", shortenValueIfNecessary(manualRedactionEntry.getValue())); + }; + return EntityLogEntry.builder() .id(manualRedactionEntry.getAnnotationId()) .value(manualRedactionEntry.getValue()) .type(manualRedactionEntry.getType()) - .entryType(Optional.ofNullable(manualRedactionEntry.getDictionaryEntryType()) - .orElse(DictionaryEntryType.ENTRY).toEntryType()) + .entryType(dictionaryEntryType.toEntryType()) .state(EntryState.PENDING) .dictionaryEntry(manualRedactionEntry.isAddToDictionary()) .dossierDictionaryEntry(manualRedactionEntry.isAddToDossierDictionary()) - .reason("Pending add to dictionary.") - .legalBasis("Pending add to dictionary.") + .reason(reason) + .legalBasis(reason) .matchedRule("") .containingNodeId(Collections.emptyList()) .closestHeadline("") @@ -82,6 +114,8 @@ public class PendingDictionaryEntryFactory { .propertyChanges(Map.of("remove", originalEntry.getValue())) .build()); + String reason = String.format("%s has been removed from the dictionary", shortenValueIfNecessary(originalEntry.getValue())); + return EntityLogEntry.builder() .id(originalEntry.getId()) .value(originalEntry.getValue()) @@ -90,8 +124,8 @@ public class PendingDictionaryEntryFactory { .state(EntryState.PENDING) .dictionaryEntry(manualChange.isRemoveFromDictionary()) .dossierDictionaryEntry(!manualChange.isRemoveFromAllDossiers()) - .reason("Pending remove from dictionary.") - .legalBasis("Pending remove from dictionary.") + .reason(reason) + .legalBasis(reason) .matchedRule("") .containingNodeId(Collections.emptyList()) .closestHeadline("") @@ -121,6 +155,16 @@ public class PendingDictionaryEntryFactory { .userId(manualChange.getUser()) .propertyChanges(propertyChanges) .build()); + + String reason; + if (manualChange.getValue().length() > originalEntry.getValue().length()) { + reason = String.format("%s has been added to the dictionary", shortenValueIfNecessary(manualChange.getValue())); + } else { + reason = String.format("%s has been added to the dictionary and %s has been removed", + shortenValueIfNecessary(manualChange.getValue()), + shortenValueIfNecessary(originalEntry.getValue())); + } + return EntityLogEntry.builder() .id(originalEntry.getId()) .value(manualChange.getValue()) @@ -129,8 +173,8 @@ public class PendingDictionaryEntryFactory { .state(EntryState.PENDING) .dictionaryEntry(manualChange.getUpdateDictionary()) .dossierDictionaryEntry(!manualChange.isAddToAllDossiers()) - .reason("Pending resize with dictionary.") - .legalBasis("Pending resize with dictionary.") + .reason(reason) + .legalBasis(reason) .matchedRule("") .containingNodeId(Collections.emptyList()) .closestHeadline("") @@ -178,6 +222,11 @@ public class PendingDictionaryEntryFactory { manualChange.getValue())) .build()); + String reason = String.format("%s has been added to dictionary %s and removed from dictionary %s", + shortenValueIfNecessary(originalEntry.getValue()), + manualChange.getType(), + originalEntry.getType()); + return EntityLogEntry.builder() .id(originalEntry.getId()) .value(originalEntry.getValue()) @@ -186,8 +235,8 @@ public class PendingDictionaryEntryFactory { .state(EntryState.PENDING) .dictionaryEntry(manualChange.isAddToDictionary()) .dossierDictionaryEntry(!manualChange.isAddToAllDossiers()) - .reason("Pending recategorize with dictionary.") - .legalBasis("Pending recategorize with dictionary.") + .reason(reason) + .legalBasis(reason) .matchedRule("") .containingNodeId(Collections.emptyList()) .closestHeadline("")