RED-9515 - When locally added annotations are locally removed while... #577
@ -13,6 +13,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -349,6 +350,10 @@ public class EntityLogMergeService {
|
||||
addChanges(entityLogEntry, changes);
|
||||
|
||||
entityLogEntry.setState(EntryState.IGNORED);
|
||||
//special case, only for add local and remove only
|
||||
if (!entityLogEntry.getEngines().isEmpty() && Set.of(Engine.MANUAL).containsAll(entityLogEntry.getEngines())) {
|
||||
entityLogEntry.setState(EntryState.REMOVED);
|
||||
}
|
||||
entityLogEntry.getEngines().add(Engine.MANUAL);
|
||||
entityLogEntry.getManualChanges().add(ManualChangeFactory.toLocalManualChange(idRemoval, 0));
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.mongo.service.Ent
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
public class EntityLogMergeTest {
|
||||
|
||||
final String FILE_ID = "fileId";
|
||||
@MockBean
|
||||
private FileStatusService fileStatusService;
|
||||
|
||||
@ -317,6 +317,13 @@ public class EntityLogMergeTest {
|
||||
.findFirst();
|
||||
assertTrue(optionalForceRedactionEntryLogEntry.isPresent());
|
||||
assertEquals(EntryState.APPLIED, optionalForceRedactionEntryLogEntry.get().getState());
|
||||
|
||||
var optionalRemovedEntryLogEntry = response.getEntityLogEntry()
|
||||
.stream()
|
||||
.filter(entityLogEntry1 -> entityLogEntry1.getId().equals(entryToRemoveId))
|
||||
.findFirst();
|
||||
assertTrue(optionalRemovedEntryLogEntry.isPresent());
|
||||
assertEquals(EntryState.IGNORED, optionalRemovedEntryLogEntry.get().getState());
|
||||
}
|
||||
|
||||
|
||||
@ -371,6 +378,94 @@ public class EntityLogMergeTest {
|
||||
.get(index + 1).getState(), EntryState.PENDING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMergeEntityLogWithManualAddAndRemoveChanges() {
|
||||
|
||||
String dossierId = "dossierId";
|
||||
String dossierTemplateId = "dossierTemplateId";
|
||||
|
||||
String entryToRemoveId = UUID.randomUUID().toString();
|
||||
String dictEntryToResizeId = UUID.randomUUID().toString();
|
||||
String entryLegalBasisId = UUID.randomUUID().toString();
|
||||
String forceRedactionId = UUID.randomUUID().toString();
|
||||
String entryToRecategorizeId = UUID.randomUUID().toString();
|
||||
|
||||
String localId = UUID.randomUUID().toString();
|
||||
|
||||
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();
|
||||
|
||||
var entityLog = provideEntityLog(entryToRemoveId, dictEntryToResizeId, entryLegalBasisId, forceRedactionId, entryToRecategorizeId, true);
|
||||
|
||||
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(localId))
|
||||
.findFirst();
|
||||
assertTrue(optionalEntityLogEntry.isPresent());
|
||||
assertEquals(EntryType.ENTITY, optionalEntityLogEntry.get().getEntryType());
|
||||
assertEquals(EntryState.REMOVED, optionalEntityLogEntry.get().getState());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMergeEntityLogWithManualAddAndResizeAndRemoveChanges() {
|
||||
|
||||
String dossierId = "dossierId";
|
||||
String dossierTemplateId = "dossierTemplateId";
|
||||
|
||||
String entryToRemoveId = UUID.randomUUID().toString();
|
||||
String dictEntryToResizeId = UUID.randomUUID().toString();
|
||||
String entryLegalBasisId = UUID.randomUUID().toString();
|
||||
String forceRedactionId = UUID.randomUUID().toString();
|
||||
String entryToRecategorizeId = UUID.randomUUID().toString();
|
||||
|
||||
String localId = UUID.randomUUID().toString();
|
||||
|
||||
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()))
|
||||
.build();
|
||||
|
||||
var entityLog = provideEntityLog(entryToRemoveId, dictEntryToResizeId, entryLegalBasisId, forceRedactionId, entryToRecategorizeId, true);
|
||||
|
||||
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(localId))
|
||||
.findFirst();
|
||||
assertTrue(optionalEntityLogEntry.isPresent());
|
||||
assertEquals(EntryType.ENTITY, optionalEntityLogEntry.get().getEntryType());
|
||||
assertEquals(EntryState.REMOVED, optionalEntityLogEntry.get().getState());
|
||||
|
||||
}
|
||||
|
||||
private EntityLog provideEntityLog(String entryToRemoveId, String entryToResizeId, String entryLegalBasisId, String forceRedactionId, String entryToRecategorizeId, boolean dictEntry) {
|
||||
|
||||
@ -513,5 +608,38 @@ 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)
|
||||
.value(valueToAdd)
|
||||
.reason("Reason")
|
||||
.addToDictionary(false)
|
||||
.addToDossierDictionary(false)
|
||||
.fileId(FILE_ID)
|
||||
.rectangle(false)
|
||||
.requestDate(OffsetDateTime.now())
|
||||
.dictionaryEntryType(DictionaryEntryType.ENTRY)
|
||||
.type("manual")
|
||||
.user("User")
|
||||
.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()
|
||||
.fileId(FILE_ID)
|
||||
.value(resizedValue)
|
||||
.annotationId(entryToResizeId)
|
||||
.positions(positions)
|
||||
.requestDate(OffsetDateTime.now())
|
||||
.updateDictionary(false)
|
||||
.addToAllDossiers(false)
|
||||
.user("User")
|
||||
.fileId("file")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user