RED-8828 - Fix error when resizing dict based redaction

This commit is contained in:
Andrei Isvoran 2024-03-28 16:01:05 +02:00
parent 7dbc585274
commit d48e698167

View File

@ -664,6 +664,8 @@ public class EntityCreationService {
addEntityToGraph(mergedEntity, node); addEntityToGraph(mergedEntity, node);
insertToKieSession(mergedEntity); insertToKieSession(mergedEntity);
entitiesToMerge.stream().filter(e -> !e.equals(mergedEntity)).forEach(node.getEntities()::remove);
return mergedEntity; return mergedEntity;
} }
@ -746,26 +748,39 @@ public class EntityCreationService {
DocumentTree documentTree = node.getDocumentTree(); DocumentTree documentTree = node.getDocumentTree();
try { try {
if (node.getEntities().contains(entity)) { if (node.getEntities().contains(entity)) {
// If entity already exists and it has a different text range, we add the text range to the list of duplicated text ranges // If entity already exists but is missing textBefore/textAfter re-add it and enrich the entity with the missing values
node.getEntities().stream()// if (entity.getTextBefore() == null || entity.getTextAfter() == null) {
.filter(e -> e.equals(entity))// node.getEntities().remove(entity);
.filter(e -> !e.getTextRange().equals(entity.getTextRange()))// addNewEntityToGraph(entity, documentTree);
.findAny()// } else {
.ifPresent(entityToDuplicate -> addDuplicateEntityToGraph(entityToDuplicate, entity.getTextRange(), node)); // If entity already exists and it has a different text range, we add the text range to the list of duplicated text ranges
node.getEntities()
.stream()//
.filter(e -> e.equals(entity))//
.filter(e -> !e.getTextRange().equals(entity.getTextRange()))//
.findAny()//
.ifPresent(entityToDuplicate -> addDuplicateEntityToGraph(entityToDuplicate, entity.getTextRange(), node));
}
} else { } else {
entity.addIntersectingNode(documentTree.getRoot().getNode()); entity.addIntersectingNode(documentTree.getRoot().getNode());
addEntityToGraph(entity, documentTree); addEntityToGraph(entity, documentTree);
} }
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
entity.setDeepestFullyContainingNode(documentTree.getRoot().getNode()); addNewEntityToGraph(entity, documentTree);
entityEnrichmentService.enrichEntity(entity, entity.getDeepestFullyContainingNode().getTextBlock());
entity.addIntersectingNode(documentTree.getRoot().getNode());
addToPages(entity);
addEntityToNodeEntitySets(entity);
} }
} }
private void addNewEntityToGraph(TextEntity entity, DocumentTree documentTree) {
entity.setDeepestFullyContainingNode(documentTree.getRoot().getNode());
entityEnrichmentService.enrichEntity(entity, entity.getDeepestFullyContainingNode().getTextBlock());
entity.addIntersectingNode(documentTree.getRoot().getNode());
addToPages(entity);
addEntityToNodeEntitySets(entity);
}
private void addDuplicateEntityToGraph(TextEntity entityToDuplicate, TextRange newTextRange, SemanticNode node) { private void addDuplicateEntityToGraph(TextEntity entityToDuplicate, TextRange newTextRange, SemanticNode node) {
entityToDuplicate.addTextRange(newTextRange); entityToDuplicate.addTextRange(newTextRange);