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:
commit
7b798ae543
@ -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,
|
||||
|
||||
@ -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()) {
|
||||
|
||||
|
||||
@ -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 -> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user