RED-9555 - Keep force redacted image applied after changing legal basis
This commit is contained in:
parent
bba18e40b0
commit
b758c2f747
@ -35,6 +35,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryState;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryType;
|
||||
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.analysislog.entitylog.Position;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualChangeFactory;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRedactions;
|
||||
@ -399,6 +400,10 @@ public class EntityLogMergeService {
|
||||
|
||||
if (!Strings.isNullOrEmpty(recategorization.getLegalBasis())) {
|
||||
boolean isHint = isHint(entityLogEntry.getType(), dossier);
|
||||
if ((entityLogEntry.getEntryType().equals(EntryType.IMAGE) || entityLogEntry.getEntryType().equals(EntryType.IMAGE_HINT)) && !entityLogEntry.getManualChanges()
|
||||
.isEmpty() && determineHintForImages(entityLogEntry.getManualChanges())) {
|
||||
isHint = false;
|
||||
}
|
||||
entityLogEntry.setLegalBasis(recategorization.getLegalBasis());
|
||||
entityLogEntry.setState(isHint ? EntryState.SKIPPED : EntryState.APPLIED);
|
||||
}
|
||||
@ -447,6 +452,25 @@ public class EntityLogMergeService {
|
||||
}
|
||||
|
||||
|
||||
private boolean determineHintForImages(List<ManualChange> manualChanges) {
|
||||
|
||||
boolean hasForce = false;
|
||||
boolean hasRemoveAfterForce = false;
|
||||
|
||||
for (ManualChange change : manualChanges) {
|
||||
if (change.getManualRedactionType() == ManualRedactionType.FORCE) {
|
||||
hasForce = true;
|
||||
}
|
||||
if (hasForce && change.getManualRedactionType() == ManualRedactionType.REMOVE) {
|
||||
hasRemoveAfterForce = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return hasForce && !hasRemoveAfterForce;
|
||||
}
|
||||
|
||||
|
||||
public boolean isHint(String type, DossierEntity dossier) {
|
||||
|
||||
String typeId = toTypeId(type, dossier.getDossierTemplateId());
|
||||
|
||||
@ -45,6 +45,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLogEntry;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryState;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryType;
|
||||
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.analysislog.entitylog.Position;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRedactions;
|
||||
@ -52,6 +53,7 @@ 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.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.ManualLegalBasisChange;
|
||||
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.ManualResizeRedaction;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
|
||||
@ -354,6 +356,7 @@ public class EntityLogMergeTest {
|
||||
.get(index + 1).getState(), EntryState.PENDING);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testMergeEntityLogWithManualAddAndRemoveChanges() {
|
||||
|
||||
@ -367,7 +370,7 @@ public class EntityLogMergeTest {
|
||||
|
||||
String localId = UUID.randomUUID().toString();
|
||||
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder()
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder()
|
||||
.entriesToAdd(Set.of(provideManualAdd(localId, "Darth Vader")))
|
||||
.idsToRemove(Set.of(IdRemoval.builder().annotationId(localId).requestDate(OffsetDateTime.now()).user("user").fileId(FILE_ID).build()))
|
||||
.build();
|
||||
@ -397,6 +400,7 @@ public class EntityLogMergeTest {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testMergeEntityLogWithManualAddAndResizeAndRemoveChanges() {
|
||||
|
||||
@ -410,7 +414,7 @@ public class EntityLogMergeTest {
|
||||
|
||||
String localId = UUID.randomUUID().toString();
|
||||
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder()
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder()
|
||||
.entriesToAdd(Set.of(provideManualAdd(localId, "Darth Vader")))
|
||||
.resizeRedactions(Set.of(provideManualResize(localId, "Darth", dictEntryToResizeId)))
|
||||
.idsToRemove(Set.of(IdRemoval.builder().annotationId(localId).requestDate(OffsetDateTime.now()).user("user").fileId(FILE_ID).build()))
|
||||
@ -442,6 +446,74 @@ public class EntityLogMergeTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testForceAndRecategorizeImage() {
|
||||
|
||||
String dossierId = "dossierId";
|
||||
String dossierTemplateId = "dossierTemplateId";
|
||||
|
||||
String entryId = UUID.randomUUID().toString();
|
||||
|
||||
ManualRedactions manualRedactions = ManualRedactions.builder()
|
||||
.recategorizations(Set.of(ManualRecategorization.builder()
|
||||
.legalBasis("1")
|
||||
.type("manual")
|
||||
.annotationId(entryId)
|
||||
.fileId("file")
|
||||
.requestDate(OffsetDateTime.now())
|
||||
.user("user")
|
||||
.build()))
|
||||
.build();
|
||||
|
||||
List<ManualChange> manualChanges = new ArrayList<>();
|
||||
manualChanges.add(ManualChange.builder()
|
||||
.manualRedactionType(ManualRedactionType.FORCE)
|
||||
.processedDate(OffsetDateTime.now())
|
||||
.propertyChanges(Collections.emptyMap())
|
||||
.userId("user")
|
||||
.requestedDate(OffsetDateTime.now())
|
||||
.build());
|
||||
var entityLog = new EntityLog(1,
|
||||
1,
|
||||
Lists.newArrayList(EntityLogEntry.builder()
|
||||
.id(entryId)
|
||||
.type("manual")
|
||||
.value("Image:Other")
|
||||
.entryType(EntryType.IMAGE)
|
||||
.state(EntryState.APPLIED)
|
||||
.dictionaryEntry(false)
|
||||
.positions(List.of(new Position(1, 1, 1, 1, 1)))
|
||||
.manualChanges(manualChanges)
|
||||
.build()),
|
||||
Collections.emptyList(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0);
|
||||
|
||||
when(manualRedactionProviderService.getManualRedactions(any(), any())).thenReturn(manualRedactions);
|
||||
when(fileStatusService.getStatus(FILE_ID)).thenReturn(FileModel.builder().excluded(false).dossierStatusId(dossierTemplateId).id(FILE_ID).build());
|
||||
when(fileManagementStorageService.getEntityLog(dossierId, FILE_ID)).thenReturn(entityLog);
|
||||
when(dossierService.getDossierById(dossierId)).thenReturn(DossierEntity.builder().dossierTemplateId(dossierTemplateId).build());
|
||||
when(dictionaryPersistenceService.getType(anyString())).thenReturn(TypeEntity.builder().isHint(false).build());
|
||||
when(fileStatusPersistenceService.getStatus(FILE_ID)).thenReturn(FileEntity.builder().id(FILE_ID).fileAttributes(Collections.emptyList()).build());
|
||||
when(fileStatusService.convertAttributes(any(), anyString())).thenReturn(Collections.emptyList());
|
||||
|
||||
EntityLog response = entityLogMergeService.mergeEntityLog(manualRedactions, entityLog, DossierEntity.builder().dossierTemplateId(dossierTemplateId).build());
|
||||
|
||||
assertNotNull(response);
|
||||
assertFalse(response.getEntityLogEntry().isEmpty());
|
||||
|
||||
var optionalEntityLogEntry = response.getEntityLogEntry()
|
||||
.stream()
|
||||
.filter(entityLogEntry -> entityLogEntry.getId().equals(entryId))
|
||||
.findFirst();
|
||||
assertTrue(optionalEntityLogEntry.isPresent());
|
||||
assertEquals(EntryType.IMAGE, optionalEntityLogEntry.get().getEntryType());
|
||||
assertEquals(EntryState.APPLIED, optionalEntityLogEntry.get().getState());
|
||||
}
|
||||
|
||||
|
||||
private EntityLog provideEntityLog(String entryToRemoveId, String entryToResizeId, String entryLegalBasisId, String forceRedactionId, boolean dictEntry) {
|
||||
|
||||
List<Position> positions = new ArrayList<>();
|
||||
@ -563,7 +635,9 @@ public class EntityLogMergeTest {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private ManualRedactionEntry provideManualAdd(String entryToAddId, String valueToAdd) {
|
||||
|
||||
return ManualRedactionEntry.builder()
|
||||
.positions(List.of(new Rectangle(1f, 2f, 3f, 4f, 1)))
|
||||
.annotationId(entryToAddId)
|
||||
@ -580,7 +654,9 @@ public class EntityLogMergeTest {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private ManualResizeRedaction provideManualResize(String entryToResizeId, String resizedValue, String dictId) {
|
||||
|
||||
List<Rectangle> positions = new ArrayList<>();
|
||||
positions.add(new Rectangle(2, 2, 2, 2, 1));
|
||||
return ManualResizeRedaction.builder()
|
||||
@ -596,6 +672,5 @@ public class EntityLogMergeTest {
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user