Merge branch 'RED-9257' into 'master'
RED-9257: intersectingNodes update crashes kieSession Closes RED-9257 See merge request redactmanager/redaction-service!419
This commit is contained in:
commit
98e9bf1d63
@ -10,6 +10,7 @@ import static com.iqser.red.service.redaction.v1.server.service.document.EntityC
|
|||||||
import static com.iqser.red.service.redaction.v1.server.utils.SeparatorUtils.boundaryIsSurroundedBySeparators;
|
import static com.iqser.red.service.redaction.v1.server.utils.SeparatorUtils.boundaryIsSurroundedBySeparators;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -49,12 +50,22 @@ public class EntityCreationService {
|
|||||||
|
|
||||||
private final EntityEnrichmentService entityEnrichmentService;
|
private final EntityEnrichmentService entityEnrichmentService;
|
||||||
private final KieSession kieSession;
|
private final KieSession kieSession;
|
||||||
|
private final Set<SemanticNode> nodesInKieSession; // empty set means all nodes are in kieSession
|
||||||
|
|
||||||
|
|
||||||
public EntityCreationService(EntityEnrichmentService entityEnrichmentService) {
|
public EntityCreationService(EntityEnrichmentService entityEnrichmentService) {
|
||||||
|
|
||||||
this.entityEnrichmentService = entityEnrichmentService;
|
this.entityEnrichmentService = entityEnrichmentService;
|
||||||
this.kieSession = null;
|
this.kieSession = null;
|
||||||
|
this.nodesInKieSession = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public EntityCreationService(EntityEnrichmentService entityEnrichmentService, KieSession kieSession) {
|
||||||
|
|
||||||
|
this.entityEnrichmentService = entityEnrichmentService;
|
||||||
|
this.kieSession = kieSession;
|
||||||
|
this.nodesInKieSession = Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -998,7 +1009,10 @@ public class EntityCreationService {
|
|||||||
}
|
}
|
||||||
return Optional.empty(); // Entity has been resized, if there are duplicates they should be treated there
|
return Optional.empty(); // Entity has been resized, if there are duplicates they should be treated there
|
||||||
}
|
}
|
||||||
addEntityToGraph(entity, node.getDocumentTree());
|
boolean added = addEntityToGraph(entity, node.getDocumentTree());
|
||||||
|
if (!added) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
entity.addEngines(engines);
|
entity.addEngines(engines);
|
||||||
insertToKieSession(entity);
|
insertToKieSession(entity);
|
||||||
return Optional.of(entity);
|
return Optional.of(entity);
|
||||||
@ -1295,15 +1309,23 @@ public class EntityCreationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addEntityToGraph(TextEntity entity, DocumentTree documentTree) {
|
private boolean addEntityToGraph(TextEntity entity, DocumentTree documentTree) {
|
||||||
|
|
||||||
documentTree.getRoot().getNode().addThisToEntityIfIntersects(entity);
|
documentTree.getRoot().getNode().addThisToEntityIfIntersects(entity);
|
||||||
|
|
||||||
|
if (!nodesInKieSession.isEmpty() && entity.getIntersectingNodes()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(node -> !nodesInKieSession.contains(node))) {
|
||||||
|
entity.removeFromGraph();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
TextBlock textBlock = entity.getDeepestFullyContainingNode().getTextBlock();
|
TextBlock textBlock = entity.getDeepestFullyContainingNode().getTextBlock();
|
||||||
entityEnrichmentService.enrichEntity(entity, textBlock);
|
entityEnrichmentService.enrichEntity(entity, textBlock);
|
||||||
|
|
||||||
addToPages(entity);
|
addToPages(entity);
|
||||||
addEntityToNodeEntitySets(entity);
|
addEntityToNodeEntitySets(entity);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.service.drools;
|
package com.iqser.red.service.redaction.v1.server.service.drools;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -80,7 +83,11 @@ public class EntityDroolsExecutionService {
|
|||||||
addNumberOfPagesAndSectionsToAnalyseToTrace(document.getNumberOfPages(), sectionsToAnalyze.size());
|
addNumberOfPagesAndSectionsToAnalyseToTrace(document.getNumberOfPages(), sectionsToAnalyze.size());
|
||||||
|
|
||||||
KieSession kieSession = kieContainer.newKieSession();
|
KieSession kieSession = kieContainer.newKieSession();
|
||||||
EntityCreationService entityCreationService = new EntityCreationService(entityEnrichmentService, kieSession);
|
|
||||||
|
Set<SemanticNode> nodesInKieSession = sectionsToAnalyze.size() == document.streamAllSubNodes()
|
||||||
|
.count() ? Collections.emptySet() : buildSet(sectionsToAnalyze, document);
|
||||||
|
|
||||||
|
EntityCreationService entityCreationService = new EntityCreationService(entityEnrichmentService, kieSession, nodesInKieSession);
|
||||||
|
|
||||||
kieSession.setGlobal("document", document);
|
kieSession.setGlobal("document", document);
|
||||||
kieSession.setGlobal("entityCreationService", entityCreationService);
|
kieSession.setGlobal("entityCreationService", entityCreationService);
|
||||||
@ -141,6 +148,17 @@ public class EntityDroolsExecutionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Set<SemanticNode> buildSet(List<SemanticNode> sectionsToAnalyze, Document document) {
|
||||||
|
|
||||||
|
Set<SemanticNode> nodes = new HashSet<>(sectionsToAnalyze);
|
||||||
|
sectionsToAnalyze.stream()
|
||||||
|
.flatMap(SemanticNode::streamAllSubNodes)
|
||||||
|
.forEach(nodes::add);
|
||||||
|
nodes.add(document);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<FileAttribute> getFileAttributes(KieSession kieSession) {
|
public List<FileAttribute> getFileAttributes(KieSession kieSession) {
|
||||||
|
|
||||||
List<FileAttribute> fileAttributes = new LinkedList<>();
|
List<FileAttribute> fileAttributes = new LinkedList<>();
|
||||||
|
|||||||
@ -1254,8 +1254,6 @@ public class RedactionIntegrationTest extends RulesIntegrationTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
|
||||||
// todo: fix me in RED-9257
|
|
||||||
public void signaturesAreRedactionAfterReanalyse() throws IOException {
|
public void signaturesAreRedactionAfterReanalyse() throws IOException {
|
||||||
|
|
||||||
AnalyzeRequest request = uploadFileToStorage("files/new/SYNGENTA_EFSA_sanitisation_GFL_v1 3.pdf");
|
AnalyzeRequest request = uploadFileToStorage("files/new/SYNGENTA_EFSA_sanitisation_GFL_v1 3.pdf");
|
||||||
@ -1297,8 +1295,6 @@ public class RedactionIntegrationTest extends RulesIntegrationTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
|
||||||
// todo: fix me in RED-9257
|
|
||||||
public void entityIsAppliedAfterRecategorize() throws IOException {
|
public void entityIsAppliedAfterRecategorize() throws IOException {
|
||||||
|
|
||||||
AnalyzeRequest request = uploadFileToStorage("files/new/SYNGENTA_EFSA_sanitisation_GFL_v1 (1).pdf");
|
AnalyzeRequest request = uploadFileToStorage("files/new/SYNGENTA_EFSA_sanitisation_GFL_v1 (1).pdf");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user