Merge branch 'RED-8588' into 'master'

RED-8588 - Fix ADD_TO_DICT

Closes RED-8588

See merge request redactmanager/redaction-service!281
This commit is contained in:
Andrei Isvoran 2024-02-20 14:33:32 +01:00
commit 7b798ae543
3 changed files with 2 additions and 47 deletions

View File

@ -56,35 +56,12 @@ public class EntityChangeLogService {
ChangeType changeType = calculateChangeType(entityLogEntry.getState(), previousEntity.getState());
entityLogEntry.getChanges().add(new Change(analysisNumber, changeType, now));
}
addManualChanges(entityLogEntry, previousEntity);
}
addRemovedEntriesAsRemoved(previousEntityLogEntries, newEntityLogEntries, manualRedactions, analysisNumber, now);
return hasChanges;
}
// If a manual change is present in the previous entity but not in the new entity, add it to the new one and
// sort them, so they are displayed in the correct order.
private void addManualChanges(EntityLogEntry entityLogEntry, EntityLogEntry previousEntity) {
Comparator<ManualChange> manualChangeComparator =
Comparator.comparing(ManualChange::getManualRedactionType)
.thenComparing(ManualChange::getRequestedDate);
previousEntity.getManualChanges().forEach(manualChange -> {
boolean contains = entityLogEntry.getManualChanges()
.stream()
.anyMatch(existingChange -> manualChangeComparator.compare(existingChange, manualChange) == 0);
if (!contains) {
entityLogEntry.getManualChanges().add(manualChange);
entityLogEntry.getManualChanges().sort(Comparator.comparing(ManualChange::getRequestedDate));
}
});
}
private void addRemovedEntriesAsRemoved(List<EntityLogEntry> previousEntityLogEntries,
List<EntityLogEntry> newEntityLogEntries,
ManualRedactions manualRedactions,

View File

@ -137,22 +137,6 @@ public class EntityLogCreatorService {
private List<EntityLogEntry> createEntityLogEntries(Document document, AnalyzeRequest analyzeRequest, List<PrecursorEntity> notFoundPrecursorEntries) {
Set<ManualRedactionEntry> dictionaryEntries;
Set<String> dictionaryEntriesValues;
if (analyzeRequest.getManualRedactions() != null && !analyzeRequest.getManualRedactions().getEntriesToAdd().isEmpty()) {
dictionaryEntries = analyzeRequest.getManualRedactions().getEntriesToAdd()
.stream()
.filter(e -> e.isAddToDictionary() || e.isAddToDossierDictionary())
.collect(Collectors.toSet());
dictionaryEntriesValues = dictionaryEntries.stream()
.map(ManualRedactionEntry::getValue)
.collect(Collectors.toSet());
} else {
dictionaryEntriesValues = new HashSet<>();
dictionaryEntries = new HashSet<>();
}
String dossierTemplateId = analyzeRequest.getDossierTemplateId();
List<EntityLogEntry> entries = new ArrayList<>();
@ -162,22 +146,17 @@ public class EntityLogCreatorService {
.filter(entity -> !entity.getValue().isEmpty())
.filter(EntityLogCreatorService::notFalsePositiveOrFalseRecommendation)
.filter(entity -> !entity.removed())
.forEach(entityNode -> entries.addAll(toEntityLogEntries(entityNode, dictionaryEntries, dictionaryEntriesValues)));
.forEach(entityNode -> entries.addAll(toEntityLogEntries(entityNode)));
document.streamAllImages().filter(entity -> !entity.removed()).forEach(imageNode -> entries.add(createEntityLogEntry(imageNode, dossierTemplateId)));
notFoundPrecursorEntries.stream().filter(entity -> !entity.removed()).forEach(precursorEntity -> entries.add(createEntityLogEntry(precursorEntity, dossierTemplateId)));
return entries;
}
private List<EntityLogEntry> toEntityLogEntries(TextEntity textEntity, Set<ManualRedactionEntry> dictionaryEntries, Set<String> dictionaryEntriesValues) {
private List<EntityLogEntry> toEntityLogEntries(TextEntity textEntity) {
List<EntityLogEntry> entityLogEntries = new ArrayList<>();
// Adding ADD_TO_DICTIONARY manual change to the entity's manual overwrite
if (dictionaryEntriesValues.contains(textEntity.getValue())) {
textEntity.getManualOverwrite().addChange(dictionaryEntries.stream().filter(entry -> entry.getValue().equals(textEntity.getValue())).findFirst().get());
}
// split entity into multiple entries if it occurs on multiple pages, since FE can't handle multi page entities
for (PositionOnPage positionOnPage : textEntity.getPositionsOnPagePerPage()) {

View File

@ -60,7 +60,6 @@ public class EntityFromPrecursorCreationService {
.findFirst()
.get()
.getRequestDate())))
.filter(manualRedactionEntry -> !(manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()))
.map(manualRedactionEntry -> PrecursorEntity.fromManualRedactionEntry(manualRedactionEntry,
dictionaryService.isHint(manualRedactionEntry.getType(), dossierTemplateId)))
.peek(manualEntity -> {