Compare commits

...

2 Commits

Author SHA1 Message Date
Ali Oezyetimoglu
3a0ffaef72 RED-8480: adjusted tests 2024-02-16 13:11:29 +01:00
Ali Oezyetimoglu
bb3d6f5d74 RED-8480: updated persistence service version and added legalBasis in ManualChangeOverwrite 2024-02-16 08:49:38 +01:00
7 changed files with 83 additions and 57 deletions

View File

@ -7,7 +7,7 @@ description = "redaction-service-api-v1"
dependencies { dependencies {
implementation("org.springframework:spring-web:6.0.12") implementation("org.springframework:spring-web:6.0.12")
implementation("com.iqser.red.service:persistence-service-internal-api-v1:2.338.0") implementation("com.iqser.red.service:persistence-service-internal-api-v1:2.351.0")
} }
publishing { publishing {

View File

@ -16,7 +16,7 @@ val layoutParserVersion = "0.86.0"
val jacksonVersion = "2.15.2" val jacksonVersion = "2.15.2"
val droolsVersion = "9.44.0.Final" val droolsVersion = "9.44.0.Final"
val pdfBoxVersion = "3.0.0" val pdfBoxVersion = "3.0.0"
val persistenceServiceVersion = "2.338.0" val persistenceServiceVersion = "2.351.0"
val springBootStarterVersion = "3.1.5" val springBootStarterVersion = "3.1.5"
configurations { configurations {

View File

@ -27,12 +27,12 @@ import lombok.experimental.FieldDefaults;
public class ManualChangeOverwrite { public class ManualChangeOverwrite {
private static final Map<Class<? extends BaseAnnotation>, String> MANUAL_CHANGE_DESCRIPTIONS = Map.of(// private static final Map<Class<? extends BaseAnnotation>, String> MANUAL_CHANGE_DESCRIPTIONS = Map.of(//
ManualRedactionEntry.class, "created by manual change", // ManualRedactionEntry.class, "created by manual change", //
ManualLegalBasisChange.class, "legal basis was manually changed", // ManualLegalBasisChange.class, "legal basis was manually changed", //
ManualResizeRedaction.class, "resized by manual override", // ManualResizeRedaction.class, "resized by manual override", //
ManualForceRedaction.class, "forced by manual override", // ManualForceRedaction.class, "forced by manual override", //
IdRemoval.class, "removed by manual override", // IdRemoval.class, "removed by manual override", //
ManualRecategorization.class, "recategorized by manual override"); ManualRecategorization.class, "recategorized by manual override");
List<BaseAnnotation> manualChanges = new LinkedList<>(); List<BaseAnnotation> manualChanges = new LinkedList<>();
boolean changed; boolean changed;
@ -80,7 +80,8 @@ public class ManualChangeOverwrite {
manualChanges.sort(Comparator.comparing(BaseAnnotation::getRequestDate)); manualChanges.sort(Comparator.comparing(BaseAnnotation::getRequestDate));
updateFields(manualChanges); updateFields(manualChanges);
// make list unmodifiable. // make list unmodifiable.
return manualChanges.stream().toList(); return manualChanges.stream()
.toList();
} }
@ -121,14 +122,18 @@ public class ManualChangeOverwrite {
resized = true; resized = true;
// This is only for not found Manual Entities. // This is only for not found Manual Entities.
value = manualResizeRedaction.getValue(); value = manualResizeRedaction.getValue();
positions = manualResizeRedaction.getPositions().stream().map(RectangleWithPage::fromAnnotationRectangle).toList(); positions = manualResizeRedaction.getPositions()
.stream()
.map(RectangleWithPage::fromAnnotationRectangle)
.toList();
} }
if (manualChange instanceof ManualRecategorization recategorization) { if (manualChange instanceof ManualRecategorization recategorization) {
// recategorization logic happens in ManualChangesApplicationService.
recategorized = true; recategorized = true;
// this is only relevant for ManualEntities. Image and TextEntity is recategorized in the ManualChangesApplicationService.
type = recategorization.getType(); type = recategorization.getType();
if (recategorization.getLegalBasis() != null && !recategorization.getLegalBasis().isEmpty()) {
legalBasis = recategorization.getLegalBasis();
}
} }
descriptions.add(MANUAL_CHANGE_DESCRIPTIONS.get(manualChange.getClass())); descriptions.add(MANUAL_CHANGE_DESCRIPTIONS.get(manualChange.getClass()));

View File

@ -4,8 +4,8 @@ import java.time.OffsetDateTime;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualChange;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualRedactionType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.BaseAnnotation; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.BaseAnnotation;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.IdRemoval; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.IdRemoval;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualForceRedaction; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualForceRedaction;
@ -13,8 +13,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRecategorization; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRecategorization;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRedactionEntry; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualRedactionEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualResizeRedaction; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.ManualResizeRedaction;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualChange;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.ManualRedactionType;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
@ -23,7 +21,9 @@ public class ManualChangeFactory {
public List<ManualChange> toManualChangeList(List<BaseAnnotation> manualChanges, boolean isHint) { public List<ManualChange> toManualChangeList(List<BaseAnnotation> manualChanges, boolean isHint) {
return manualChanges.stream().map(baseAnnotation -> toManualChange(baseAnnotation, isHint)).collect(Collectors.toList()); return manualChanges.stream()
.map(baseAnnotation -> toManualChange(baseAnnotation, isHint))
.collect(Collectors.toList());
} }
@ -37,7 +37,8 @@ public class ManualChangeFactory {
} else if (baseAnnotation instanceof ManualForceRedaction) { } else if (baseAnnotation instanceof ManualForceRedaction) {
manualChange.withManualRedactionType(isHint ? ManualRedactionType.FORCE_HINT : ManualRedactionType.FORCE_REDACT); manualChange.withManualRedactionType(isHint ? ManualRedactionType.FORCE_HINT : ManualRedactionType.FORCE_REDACT);
} else if (baseAnnotation instanceof ManualResizeRedaction manualResizeRedact) { } else if (baseAnnotation instanceof ManualResizeRedaction manualResizeRedact) {
manualChange.withManualRedactionType(manualResizeRedact.getUpdateDictionary() ? ManualRedactionType.RESIZE_IN_DICTIONARY : ManualRedactionType.RESIZE).withChange("value", manualResizeRedact.getValue()); manualChange.withManualRedactionType(manualResizeRedact.getUpdateDictionary() ? ManualRedactionType.RESIZE_IN_DICTIONARY : ManualRedactionType.RESIZE)
.withChange("value", manualResizeRedact.getValue());
} else if (baseAnnotation instanceof ManualRedactionEntry manualRedactionEntry) { } else if (baseAnnotation instanceof ManualRedactionEntry manualRedactionEntry) {
manualChange.withManualRedactionType(manualRedactionEntry.isAddToDictionary() ? ManualRedactionType.ADD_TO_DICTIONARY : ManualRedactionType.ADD_LOCALLY) manualChange.withManualRedactionType(manualRedactionEntry.isAddToDictionary() ? ManualRedactionType.ADD_TO_DICTIONARY : ManualRedactionType.ADD_LOCALLY)
.withChange("value", manualRedactionEntry.getValue()); .withChange("value", manualRedactionEntry.getValue());

View File

@ -57,18 +57,23 @@ public class SectionFinderService {
if (entry.getContainingNodeId().isEmpty()) { if (entry.getContainingNodeId().isEmpty()) {
continue; // Empty list means either Entity has not been found or it is between main sections. Thus, this might lead to wrong reanalysis. continue; // Empty list means either Entity has not been found or it is between main sections. Thus, this might lead to wrong reanalysis.
} }
sectionsToReanalyse.add(entry.getContainingNodeId().get(0)); sectionsToReanalyse.add(entry.getContainingNodeId()
.get(0));
} }
} }
var dictionaryIncrementsSearch = new SearchImplementation(dictionaryIncrement.getValues().stream().map(DictionaryIncrementValue::getValue).collect(Collectors.toList()), var dictionaryIncrementsSearch = new SearchImplementation(dictionaryIncrement.getValues()
true); .stream()
.map(DictionaryIncrementValue::getValue)
.toList(), true);
document.streamChildren().forEach(mainNode -> { document.streamChildren()
if (dictionaryIncrementsSearch.atLeastOneMatches(mainNode.getTextBlock().getSearchText())) { .forEach(mainNode -> {
sectionsToReanalyse.add(mainNode.getTreeId().get(0)); if (dictionaryIncrementsSearch.atLeastOneMatches(mainNode.getTextBlock().getSearchText())) {
} sectionsToReanalyse.add(mainNode.getTreeId()
}); .get(0));
}
});
Set<Integer> relevantPagesForReanalysis = getRelevantPageNumbersForAddRedactions(analyzeRequest); Set<Integer> relevantPagesForReanalysis = getRelevantPageNumbersForAddRedactions(analyzeRequest);
relevantPagesForReanalysis.addAll(getRelevantPageNumbersForImportedRedactions(importedRedactions, relevantManuallyModifiedAnnotationIds)); relevantPagesForReanalysis.addAll(getRelevantPageNumbersForImportedRedactions(importedRedactions, relevantManuallyModifiedAnnotationIds));
@ -87,8 +92,11 @@ public class SectionFinderService {
return document.getPages() return document.getPages()
.stream() .stream()
.filter(page -> relevantPagesForReanalysis.contains(page.getNumber())) .filter(page -> relevantPagesForReanalysis.contains(page.getNumber()))
.flatMap(page -> Stream.concat(page.getMainBody().stream().filter(node -> node.getType().equals(NodeType.SECTION)), Stream.of(page.getHeader(), page.getFooter()))) .flatMap(page -> Stream.concat(page.getMainBody()
.map(node -> node.getTreeId().get(0)) .stream()
.filter(node -> node.getType().equals(NodeType.SECTION)), Stream.of(page.getHeader(), page.getFooter())))
.map(node -> node.getTreeId()
.get(0))
.toList(); .toList();
} }
@ -99,8 +107,7 @@ public class SectionFinderService {
return Collections.emptySet(); return Collections.emptySet();
} }
return analyzeRequest.getManualRedactions() return analyzeRequest.getManualRedactions().getEntriesToAdd()
.getEntriesToAdd()
.stream() .stream()
.filter(addRedaction -> !(addRedaction.isAddToDictionary() || addRedaction.isAddToDossierDictionary())) .filter(addRedaction -> !(addRedaction.isAddToDictionary() || addRedaction.isAddToDossierDictionary()))
.map(ManualRedactionEntry::getPositions) .map(ManualRedactionEntry::getPositions)
@ -132,11 +139,22 @@ public class SectionFinderService {
return new HashSet<>(); return new HashSet<>();
} }
return Stream.concat(manualRedactions.getResizeRedactions().stream().map(ManualResizeRedaction::getAnnotationId), return Stream.concat(manualRedactions.getResizeRedactions()
Stream.concat(manualRedactions.getLegalBasisChanges().stream().map(ManualLegalBasisChange::getAnnotationId), .stream()
Stream.concat(manualRedactions.getRecategorizations().stream().map(ManualRecategorization::getAnnotationId), .map(ManualResizeRedaction::getAnnotationId),
Stream.concat(manualRedactions.getIdsToRemove().stream().map(IdRemoval::getAnnotationId), Stream.concat(manualRedactions.getLegalBasisChanges()
manualRedactions.getForceRedactions().stream().map(ManualForceRedaction::getAnnotationId))))).collect(Collectors.toSet()); .stream()
.map(ManualLegalBasisChange::getAnnotationId),
Stream.concat(manualRedactions.getRecategorizations()
.stream()
.map(ManualRecategorization::getAnnotationId),
Stream.concat(manualRedactions.getIdsToRemove()
.stream()
.map(IdRemoval::getAnnotationId),
manualRedactions.getForceRedactions()
.stream()
.map(ManualForceRedaction::getAnnotationId)))))
.collect(Collectors.toSet());
} }
} }

View File

@ -1014,7 +1014,7 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
.annotationId("675eba69b0c2917de55462c817adaa05") .annotationId("675eba69b0c2917de55462c817adaa05")
.fileId("fileId") .fileId("fileId")
.legalBasis("Something") .legalBasis("Something")
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.processedDate(OffsetDateTime.now()) .processedDate(OffsetDateTime.now())
.build())); .build()));
@ -1040,14 +1040,14 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
manualRedactions.setIdsToRemove(Set.of(IdRemoval.builder() manualRedactions.setIdsToRemove(Set.of(IdRemoval.builder()
.annotationId("5b940b2cb401ed9f5be6fc24f6e77bcf") .annotationId("5b940b2cb401ed9f5be6fc24f6e77bcf")
.fileId("fileId") .fileId("fileId")
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.processedDate(OffsetDateTime.now()) .processedDate(OffsetDateTime.now())
.build())); .build()));
manualRedactions.setLegalBasisChanges((Set.of(ManualLegalBasisChange.builder() manualRedactions.setLegalBasisChanges((Set.of(ManualLegalBasisChange.builder()
.annotationId("675eba69b0c2917de55462c817adaa05") .annotationId("675eba69b0c2917de55462c817adaa05")
.fileId("fileId") .fileId("fileId")
.legalBasis("Manual Legal Basis Change") .legalBasis("Manual Legal Basis Change")
.processedDate(OffsetDateTime.now()) .processedDate(OffsetDateTime.now())
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.build()))); .build())));
manualRedactions.setResizeRedactions(Set.of(ManualResizeRedaction.builder() manualRedactions.setResizeRedactions(Set.of(ManualResizeRedaction.builder()
@ -1060,7 +1060,7 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
Rectangle.builder().topLeftX(298.67056f).topLeftY(327.567f).width(7.648041f).height(75.32377f).page(1).build(), Rectangle.builder().topLeftX(298.67056f).topLeftY(327.567f).width(7.648041f).height(75.32377f).page(1).build(),
Rectangle.builder().topLeftX(307.89517f).topLeftY(327.567f).width(7.648041f).height(61.670967f).page(1).build(), Rectangle.builder().topLeftX(307.89517f).topLeftY(327.567f).width(7.648041f).height(61.670967f).page(1).build(),
Rectangle.builder().topLeftX(316.99985f).topLeftY(327.567f).width(7.648041f).height(38.104286f).page(1).build())) Rectangle.builder().topLeftX(316.99985f).topLeftY(327.567f).width(7.648041f).height(38.104286f).page(1).build()))
.updateDictionary(false) .updateDictionary(false)
.build())); .build()));
analyzeService.reanalyze(request); analyzeService.reanalyze(request);
@ -1193,7 +1193,7 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
.section("[19, 2]: Paragraph: Contact point: LexCo Contact:") .section("[19, 2]: Paragraph: Contact point: LexCo Contact:")
.value("0049 331 441 551 14") .value("0049 331 441 551 14")
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.fileId(TEST_FILE_ID) .fileId(TEST_FILE_ID)
.legalBasis("Article 39(e)(2) of Regulation (EC) No 178/2002") .legalBasis("Article 39(e)(2) of Regulation (EC) No 178/2002")
.build())) .build()))
.build()); .build());
@ -1230,14 +1230,15 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
.section("[19, 2]: Paragraph: Contact point: LexCo Contact:") .section("[19, 2]: Paragraph: Contact point: LexCo Contact:")
.value("0049 331 441 551 14") .value("0049 331 441 551 14")
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.fileId(TEST_FILE_ID) .fileId(TEST_FILE_ID)
.legalBasis("Article 39(e)(2) of Regulation (EC) No 178/2002") .legalBasis("Article 39(e)(2) of Regulation (EC) No 178/2002")
.build())) .build()))
.recategorizations(Set.of(ManualRecategorization.builder() .recategorizations(Set.of(ManualRecategorization.builder()
.annotationId("3029651d0842a625f2d23f8375c23600") .annotationId("3029651d0842a625f2d23f8375c23600")
.type("CBI_author") .type("CBI_author")
.legalBasis("")
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.fileId(TEST_FILE_ID) .fileId(TEST_FILE_ID)
.build())) .build()))
.build()); .build());
@ -1331,6 +1332,7 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
assertEquals(entityLog.getEntityLogEntry().stream().filter(entityLogEntry -> entityLogEntry.getId().equals(manualAddId2)).findFirst().get().getState(), EntryState.REMOVED); assertEquals(entityLog.getEntityLogEntry().stream().filter(entityLogEntry -> entityLogEntry.getId().equals(manualAddId2)).findFirst().get().getState(), EntryState.REMOVED);
} }
@Test @Test
@SneakyThrows @SneakyThrows
public void testResizeWithUpdateDictionaryTrue() { public void testResizeWithUpdateDictionaryTrue() {
@ -1345,14 +1347,14 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
var david = entityLog.getEntityLogEntry().stream().filter(e -> e.getValue().equals("David")).findFirst().get(); var david = entityLog.getEntityLogEntry().stream().filter(e -> e.getValue().equals("David")).findFirst().get();
request.setManualRedactions(ManualRedactions.builder() request.setManualRedactions(ManualRedactions.builder()
.resizeRedactions(Set.of(ManualResizeRedaction.builder() .resizeRedactions(Set.of(ManualResizeRedaction.builder()
.updateDictionary(true) .updateDictionary(true)
.annotationId(david.getId()) .annotationId(david.getId())
.requestDate(OffsetDateTime.now()) .requestDate(OffsetDateTime.now())
.value("David Ksenia") .value("David Ksenia")
.positions(List.of(Rectangle.builder().topLeftX(56.8f).topLeftY(293.564f).width(65.592f).height(15.408f).page(1).build())) .positions(List.of(Rectangle.builder().topLeftX(56.8f).topLeftY(293.564f).width(65.592f).height(15.408f).page(1).build()))
.addToAllDossiers(false) .addToAllDossiers(false)
.build())) .build()))
.build()); .build());
analyzeService.reanalyze(request); analyzeService.reanalyze(request);
entityLog = redactionStorageService.getEntityLog(TEST_DOSSIER_ID, TEST_FILE_ID); entityLog = redactionStorageService.getEntityLog(TEST_DOSSIER_ID, TEST_FILE_ID);
@ -1364,12 +1366,7 @@ public class RedactionIntegrationTest extends AbstractRedactionIntegrationTest {
private IdRemoval getIdRemoval(String id) { private IdRemoval getIdRemoval(String id) {
return IdRemoval.builder() return IdRemoval.builder().annotationId(id).removeFromAllDossiers(false).removeFromDictionary(false).requestDate(OffsetDateTime.now()).build();
.annotationId(id)
.removeFromAllDossiers(false)
.removeFromDictionary(false)
.requestDate(OffsetDateTime.now())
.build();
} }

View File

@ -115,7 +115,12 @@ public class ManualChangesUnitTest extends BuildDocumentIntegrationTest {
assertEquals(legalBasis, entity.getManualOverwrite().getLegalBasis().orElse(entity.getMatchedRule().getLegalBasis())); assertEquals(legalBasis, entity.getManualOverwrite().getLegalBasis().orElse(entity.getMatchedRule().getLegalBasis()));
assertEquals(section, entity.getManualOverwrite().getSection().orElse(entity.getDeepestFullyContainingNode().toString())); assertEquals(section, entity.getManualOverwrite().getSection().orElse(entity.getDeepestFullyContainingNode().toString()));
ManualRecategorization imageRecategorizationRequest = ManualRecategorization.builder().type("type").requestDate(start.plusSeconds(5)).annotationId(annotationId).build(); ManualRecategorization imageRecategorizationRequest = ManualRecategorization.builder()
.type("type")
.requestDate(start.plusSeconds(5))
.annotationId(annotationId)
.legalBasis("")
.build();
entity.getManualOverwrite().addChange(imageRecategorizationRequest); entity.getManualOverwrite().addChange(imageRecategorizationRequest);
assertTrue(entity.getManualOverwrite().getRecategorized().isPresent()); assertTrue(entity.getManualOverwrite().getRecategorized().isPresent());
assertTrue(entity.getManualOverwrite().getRecategorized().get()); assertTrue(entity.getManualOverwrite().getRecategorized().get());