RED-8828 - Fix error when resizing dict based redaction

This commit is contained in:
Andrei Isvoran 2024-03-29 14:30:55 +02:00
parent 9354cbb6bc
commit bf638dac01

View File

@ -682,6 +682,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;
} }
@ -766,26 +768,38 @@ public class EntityCreationService {
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 and it has a different text range, we add the text range to the list of duplicated text ranges
node.getEntities() Optional<TextEntity> optionalTextEntity = node.getEntities()
.stream()// .stream()//
.filter(e -> e.equals(entity))// .filter(e -> e.equals(entity))//
.filter(e -> !e.getTextRange().equals(entity.getTextRange()))// .filter(e -> !e.getTextRange().equals(entity.getTextRange()))//
.findAny()// .findAny();
.ifPresent(entityToDuplicate -> addDuplicateEntityToGraph(entityToDuplicate, entity.getTextRange(), node)); if (optionalTextEntity.isPresent()) {
addDuplicateEntityToGraph(optionalTextEntity.get(), entity.getTextRange(), node);
} else {
node.getEntities().remove(entity);
addNewEntityToGraph(entity, documentTree);
}
} 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);