RED-8876: updated pending dictionary reasons
This commit is contained in:
parent
d46ae2834a
commit
45e23018b7
@ -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;
|
||||
@ -25,6 +27,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 = 20;
|
||||
|
||||
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<String> list = new ArrayList<>(Arrays.asList(words).subList(0, bound));
|
||||
|
||||
return String.join(" ", list) + "...";
|
||||
}
|
||||
|
||||
|
||||
public EntityLogEntry buildAddToDictionaryEntry(ManualRedactionEntry manualRedactionEntry) {
|
||||
|
||||
var manualChanges = List.of(ManualChange.builder()
|
||||
@ -34,17 +57,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("")
|
||||
@ -81,6 +113,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())
|
||||
@ -89,8 +123,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("")
|
||||
@ -120,6 +154,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())
|
||||
@ -128,8 +172,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("")
|
||||
@ -177,6 +221,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())
|
||||
@ -185,8 +234,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("")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user