RED-8828 - Fix error when resizing dict based redaction

This commit is contained in:
Andrei Isvoran 2024-03-28 17:21:03 +02:00
parent d48e698167
commit b9553e1f8d

View File

@ -748,19 +748,19 @@ 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 but is missing textBefore/textAfter re-add it and enrich the entity with the missing values
if (entity.getTextBefore() == null || entity.getTextAfter() == null) {
node.getEntities().remove(entity);
addNewEntityToGraph(entity, documentTree);
} else {
// 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);