RED-10200: fix failing acceptance, function tests

This commit is contained in:
maverickstuder 2024-12-04 10:55:35 +01:00
parent dd545daeb7
commit d022b1a5c9
5 changed files with 45 additions and 27 deletions

View File

@ -4,16 +4,12 @@ import static java.lang.String.format;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import com.iqser.red.service.redaction.v1.server.model.document.entity.Containment;
import com.iqser.red.service.redaction.v1.server.model.document.entity.EntityType;
import com.iqser.red.service.redaction.v1.server.model.document.entity.Equality;
import com.iqser.red.service.redaction.v1.server.model.document.entity.Intersection;
import com.iqser.red.service.redaction.v1.server.model.document.entity.TextEntity;
import com.iqser.red.service.redaction.v1.server.model.document.nodes.Document;
import com.iqser.red.service.redaction.v1.server.model.document.nodes.GenericSemanticNode;
@ -380,24 +376,7 @@ public class DocumentTree {
return;
}
for (TextEntity textEntity : entity.getDeepestFullyContainingNode().getEntities()) {
if (entity.intersects(textEntity) && !entity.equals(textEntity) && !textEntity.getEntityType().equals(EntityType.TEMPORARY)) {
if (textEntity.getTextRange().equals(entity.getTextRange())) {
textEntity.getRelations().computeIfAbsent(entity, k -> new HashSet<>()).add(new Equality(entity, textEntity));
entity.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Equality(textEntity, entity));
} else if (textEntity.containedBy(entity)) {
textEntity.getRelations().computeIfAbsent(entity, k -> new HashSet<>()).add(new Intersection(textEntity, entity));
entity.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Containment(entity, textEntity));
} else if (entity.containedBy(textEntity)) {
textEntity.getRelations().computeIfAbsent(entity, k -> new HashSet<>()).add(new Containment(textEntity, entity));
entity.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Intersection(entity, textEntity));
} else {
textEntity.getRelations().computeIfAbsent(entity, k -> new HashSet<>()).add(new Intersection(textEntity, entity));
entity.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Intersection(entity, textEntity));
}
}
}
entity.computeRelations();
}

View File

@ -367,6 +367,13 @@ public interface IEntity {
void removeEntityEventListener(EntityEventListener listener);
default void notifyEntityInserted() {
for (EntityEventListener listener : getEntityEventListeners()) {
listener.onEntityInserted(this);
}
}
default void notifyEntityUpdated() {
for (EntityEventListener listener : getEntityEventListeners()) {

View File

@ -339,6 +339,7 @@ public class TextEntity implements IEntity {
.orElse(getMatchedRule().isWriteValueWithLineBreaks() ? getValueWithLineBreaks() : value);
}
@Override
public void addEntityEventListener(EntityEventListener listener) {
@ -353,4 +354,27 @@ public class TextEntity implements IEntity {
}
public void computeRelations() {
for (TextEntity textEntity : this.getDeepestFullyContainingNode().getEntities()) {
if (this.intersects(textEntity) && !this.equals(textEntity) && !textEntity.getEntityType().equals(EntityType.TEMPORARY)) {
if (textEntity.getTextRange().equals(this.getTextRange())) {
textEntity.getRelations().computeIfAbsent(this, k -> new HashSet<>()).add(new Equality(this, textEntity));
this.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Equality(textEntity, this));
} else if (textEntity.containedBy(this)) {
textEntity.getRelations().computeIfAbsent(this, k -> new HashSet<>()).add(new Intersection(textEntity, this));
this.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Containment(this, textEntity));
} else if (this.containedBy(textEntity)) {
textEntity.getRelations().computeIfAbsent(this, k -> new HashSet<>()).add(new Containment(textEntity, this));
this.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Intersection(this, textEntity));
} else {
textEntity.getRelations().computeIfAbsent(this, k -> new HashSet<>()).add(new Intersection(textEntity, this));
this.getRelations().computeIfAbsent(textEntity, k -> new HashSet<>()).add(new Intersection(this, textEntity));
}
}
}
}
}

View File

@ -3,6 +3,7 @@ package com.iqser.red.service.redaction.v1.server.service;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -79,6 +80,9 @@ public class ManualChangesApplicationService {
@Deprecated
public void resizeEntityAndReinsert(TextEntity entityToBeResized, ManualResizeRedaction manualResizeRedaction) {
entityToBeResized.notifyEntityRemoved();
entityToBeResized.removeFromGraph();
PositionOnPage positionOnPageToBeResized = entityToBeResized.getPositionsOnPagePerPage()
.stream()
.filter(redactionPosition -> redactionPosition.getId().equals(manualResizeRedaction.getAnnotationId()))
@ -120,7 +124,12 @@ public class ManualChangesApplicationService {
node = null;
}
}
entityToBeResized.notifyEntityUpdated();
entityToBeResized.getRelations().keySet()
.forEach(textEntity -> textEntity.getRelations().remove(entityToBeResized));
entityToBeResized.setRelations(new HashMap<>());
entityToBeResized.computeRelations();
entityToBeResized.notifyEntityInserted();
}

View File

@ -1653,16 +1653,15 @@ public class RedactionIntegrationTest extends RulesIntegrationTest {
.findFirst()
.get();
List<Rectangle> positions = List.of(Rectangle.builder().topLeftX(56.8f).topLeftY(293.564f).width(29.2922f).height(15.408f).page(1).build());
request.setManualRedactions(ManualRedactions.builder()
.entriesToAdd(Set.of(ManualRedactionEntry.builder()
.annotationId("newId")
.fileId(TEST_FILE_ID)
.user("user")
.requestDate(OffsetDateTime.now())
.value("David")
.value("David Ksenia")
.type("CBI_author")
.positions(positions)
.positions(List.of(Rectangle.builder().topLeftX(56.8f).topLeftY(295.2f).width(65.59f).height(12.64f).page(1).build()))
.build()))
.resizeRedactions(Set.of(ManualResizeRedaction.builder()
.updateDictionary(false)
@ -1671,7 +1670,7 @@ public class RedactionIntegrationTest extends RulesIntegrationTest {
.user("user")
.requestDate(OffsetDateTime.now())
.value("David")
.positions(positions)
.positions(List.of(Rectangle.builder().topLeftX(56.8f).topLeftY(293.564f).width(29.2922f).height(15.408f).page(1).build()))
.addToAllDossiers(false)
.build()))
.build());