Merge branch 'RED-8828-fix-npe-bp' into 'release/4.244.x'

RED-8828 - Fix error when resizing dict based redaction

See merge request redactmanager/redaction-service!354
This commit is contained in:
Andrei Isvoran 2024-04-02 08:33:37 +02:00
commit e5641d7097

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;
} }
@ -747,25 +749,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().stream()// Optional<TextEntity> optionalTextEntity = node.getEntities()
.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);