RED-7241: refactored some code and deleted dead code

This commit is contained in:
Ali Oezyetimoglu 2023-08-11 11:24:59 +02:00
parent 8f8981b84b
commit 1617fb0a19
9 changed files with 80 additions and 637 deletions

View File

@ -492,7 +492,6 @@ public class ManualRedactionController implements ManualRedactionResource {
public List<ManualAddResponse> resizeRedactionBulk(@PathVariable(DOSSIER_ID) String dossierId,
@PathVariable(FILE_ID) String fileId,
@RequestBody Set<ResizeRedactionRequest> resizeRedactionRequests) {
log.info("method resizeRedactionBulk({}, {}, {})", dossierId, fileId, resizeRedactionRequests);
accessControlService.verifyFileIsNotApproved(dossierId, fileId);
accessControlService.verifyUserIsMemberOrApprover(dossierId);

View File

@ -2,7 +2,9 @@ package com.iqser.red.service.persistence.management.v1.processor.entity.annotat
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
@ -67,4 +69,7 @@ public class ManualResizeRedactionEntity implements IBaseAnnotation {
@Column
private boolean addToAllDossiers;
@ElementCollection
@Fetch(value = FetchMode.SUBSELECT)
private Set<String> typeIdsOfModifiedDictionaries = new HashSet<>();
}

View File

@ -230,8 +230,6 @@ public class DictionaryManagementService {
@Transactional
public void addEntries(String typeId, List<String> entries, boolean removeCurrent, boolean ignoreInvalidEntries, DictionaryEntryType dictionaryEntryType) {
log.info("method addEntries({}, {}, {}, {}, {})", typeId, entries, removeCurrent, ignoreInvalidEntries, dictionaryEntryType);
checkForDossierTypeExistenceAndCreate(typeId);
Set<String> cleanEntries = entries.stream().map(this::cleanDictionaryEntry).collect(toSet());

View File

@ -100,7 +100,9 @@ public class ManualRedactionService {
dossierPersistenceService.getAndValidateDossier(dossierId);
var actionPerformed = false;
// validate add to dossier template dictionaries
addRedactionRequests.forEach(request -> dictionaryManagementService.validateAddRemoveToDossierTemplateDictionary(request.getDossierTemplateTypeId(), request.isAddToDictionary(), request.isAddToAllDossiers()));
addRedactionRequests.forEach(request -> dictionaryManagementService.validateAddRemoveToDossierTemplateDictionary(request.getDossierTemplateTypeId(),
request.isAddToDictionary(),
request.isAddToAllDossiers()));
for (var addRedactionRequest : addRedactionRequests) {
if (addRedactionRequest.isAddToDictionary()) {
@ -269,8 +271,6 @@ public class ManualRedactionService {
private void addToDictionary(String typeId, String value, String dossierId, String fileId, DictionaryEntryType dictionaryEntryType) {
log.info("method addToDictionary({}, {}, {})", dossierId, fileId, dictionaryEntryType);
try {
log.debug("Adding entry: {} to {} for {} / {}", value, typeId, dossierId, fileId);
dictionaryManagementService.addEntries(typeId, List.of(value), false, false, dictionaryEntryType != null ? dictionaryEntryType : DictionaryEntryType.ENTRY);
@ -282,8 +282,6 @@ public class ManualRedactionService {
public List<ManualAddResponse> addRemoveRedaction(String dossierId, String fileId, List<RemoveRedactionRequest> removeRedactionRequests) {
var response = new ArrayList<ManualAddResponse>();
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
RedactionLog redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), fileId);
@ -292,11 +290,13 @@ public class ManualRedactionService {
var manualRedactions = manualRedactionProviderService.getManualRedactions(fileId);
//validate removing from dossier template dictionary
removeRedactionRequests.forEach(request -> {
removeRedactionRequests.forEach(request -> {
if (request.isRemoveFromDictionary()) {
RedactionLogEntry redactionLogEntry = getRedactionLogEntry(redactionLog, request.getAnnotationId());
var dossierTemplateTypeId = toTypeId(redactionLogEntry.getType(), dossier.getDossierTemplateId());
dictionaryManagementService.validateAddRemoveToDossierTemplateDictionary(dossierTemplateTypeId, request.isRemoveFromDictionary(), request.isRemoveFromAllDossiers());
dictionaryManagementService.validateAddRemoveToDossierTemplateDictionary(dossierTemplateTypeId,
request.isRemoveFromDictionary(),
request.isRemoveFromAllDossiers());
}
});
@ -389,8 +389,8 @@ public class ManualRedactionService {
});
} else {
if (removeFromAllDossiers) {
var dictionaryEntriesToRemove = dictionaryManagementService.getAllEntriesInDossierTemplate(toTypeId(redactionLogEntry.getType(),dossier.getDossierTemplateId()),
redactionLogEntry.getValue());
var dictionaryEntriesToRemove = dictionaryManagementService.getAllEntriesInDossierTemplate(toTypeId(redactionLogEntry.getType(),
dossier.getDossierTemplateId()), redactionLogEntry.getValue());
dictionaryEntriesToRemove.forEach(entry -> {
typeIdsOfModifiedDictionaries.add(entry.getTypeId());
removeFromDictionary(entry.getTypeId(), entry.getValue(), dossier.getId(), fileId, DictionaryEntryType.ENTRY);
@ -419,10 +419,7 @@ public class ManualRedactionService {
private RedactionLogEntry getRedactionLogEntry(RedactionLog redactionLog, String annotationId) {
Optional<RedactionLogEntry> redactionLogEntryOptional = redactionLog.getRedactionLogEntry()
.stream()
.filter(entry -> entry.getId().equals(annotationId))
.findFirst();
Optional<RedactionLogEntry> redactionLogEntryOptional = redactionLog.getRedactionLogEntry().stream().filter(entry -> entry.getId().equals(annotationId)).findFirst();
if (redactionLogEntryOptional.isEmpty()) {
throw new NotFoundException("Annotation does not exist in redaction log.");
@ -682,8 +679,6 @@ public class ManualRedactionService {
@Transactional
public List<ManualAddResponse> addResizeRedaction(String dossierId, String fileId, List<ResizeRedactionRequest> resizeRedactionRequests) {
log.info("method addResizeRedaction({}, {}, {})", dossierId, fileId, resizeRedactionRequests);
var response = new ArrayList<ManualAddResponse>();
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true, true);
@ -712,21 +707,11 @@ public class ManualRedactionService {
private void updateDictionaryForResizeRedactions(String dossierId, String fileId, ManualResizeRedactionEntity resizeRedaction, RedactionLog redactionLog) {
log.info("method updateDictionaryForResizeRedactions({}, {}, {}, {})", dossierId, fileId, resizeRedaction, redactionLog);
RedactionLogEntry redactionLogEntry = null;
try {
log.info("Will get redaction log entry");
redactionLogEntry = getRedactionLogEntry(redactionLog, resizeRedaction.getId().getAnnotationId());
log.info("Got redaction log entry!");
} catch (NotFoundException e) {
log.info("Oh no! Cannot get redaction log entry!");
return;
}
RedactionLogEntry redactionLogEntry = getRedactionLogEntry(redactionLog, resizeRedaction.getId().getAnnotationId());
if (resizeRedaction.getUpdateDictionary() != null && resizeRedaction.getUpdateDictionary() && resizeRedaction.getStatus()
.equals(AnnotationStatus.APPROVED) && (redactionLogEntry.isDictionaryEntry() || redactionLogEntry.isDossierDictionaryEntry())) {
log.info("We will update the resize redaction");
var dossier = dossierPersistenceService.findByDossierId(dossierId);
var typeId = buildTypeId(redactionLogEntry, resizeRedaction, dossier);
@ -736,10 +721,12 @@ public class ManualRedactionService {
boolean isShrinking = oldValue != null && oldValue.length() > newValue.length();
log.info("isShrinking: ", isShrinking);
Set<String> typeIdsOfModifiedDictionaries = new HashSet<>();
if (isShrinking) {
log.info("Remove old value '{}' from dictionary", oldValue);
removeFromDictionary(typeId, oldValue, dossierId, fileId, dictionaryEntryType);
typeIdsOfModifiedDictionaries.add(typeId);
if (resizeRedaction.isAddToAllDossiers() && redactionLogEntry.isDictionaryEntry()) {
String dossierTemplateId = dossier.getDossierTemplateId();
@ -748,20 +735,23 @@ public class ManualRedactionService {
dossiersOfThisDossierTemplate.forEach(dossierEntity -> {
var typeIdOfDossierEntity = toTypeId(type, dossierTemplateId, dossierEntity.getId());
removeFromDictionary(typeIdOfDossierEntity, oldValue, dossierId, fileId, dictionaryEntryType);
typeIdsOfModifiedDictionaries.add(typeIdOfDossierEntity);
});
}
}
log.info("redactionLogEntry: {}, dossier: {}, typeId: {}, newValue: {}, oldValue: {}, dictionaryEntryType: {}", redactionLogEntry, dossier, typeId, newValue, oldValue, dictionaryEntryType);
log.info("Add new value '{}' to dictionary", newValue);
addToDictionary(typeId, newValue, dossierId, fileId, dictionaryEntryType);
typeIdsOfModifiedDictionaries.add(typeId);
resizeRedactionPersistenceService.updateStatus(resizeRedaction.getId().getFileId(), resizeRedaction.getId().getAnnotationId(), resizeRedaction.getStatus(), typeIdsOfModifiedDictionaries);
}
}
private String buildTypeId(RedactionLogEntry redactionLogEntry, ManualResizeRedactionEntity resizeRedaction, DossierEntity dossier) {
if (resizeRedaction.isAddToAllDossiers()) {
return toTypeId(redactionLogEntry.getType(), dossier.getDossierTemplateId());
} else {
@ -783,96 +773,12 @@ public class ManualRedactionService {
}
private void approveStatusForRedactionsWithSameValue(DossierEntity dossier, boolean addToDictionary, boolean addToDossierDictionary, String value) {
List<DossierEntity> dossiers = new ArrayList<>();
if (addToDictionary) {
dossiers = dossierTemplatePersistenceService.getDossierTemplate(dossier.getDossierTemplateId()).getDossiers();
}
if (addToDossierDictionary) {
dossiers.add(dossier);
}
Set<String> fileIds = new HashSet<>();
for (DossierEntity d : dossiers) {
var files = fileStatusService.getDossierStatus(d.getId());
files.forEach(f -> fileIds.add(f.getId()));
}
if (!fileIds.isEmpty()) {
log.debug("Approve status for requested redactions with same value '{}' for files {}", value, fileIds);
addRedactionPersistenceService.approveStatusForRequestedRedactionsWithSameValue(fileIds, value);
}
}
@Transactional
public void updateForceRedactionStatus(String dossierId, String fileId, List<String> annotationIds, AnnotationStatus annotationStatus) {
dossierPersistenceService.getAndValidateDossier(dossierId);
var actionPerformed = false;
for (var annotationId : annotationIds) {
var forceRedaction = forceRedactionPersistenceService.findForceRedaction(fileId, annotationId);
forceRedactionPersistenceService.updateStatus(fileId, annotationId, annotationStatus);
boolean isDeclined = forceRedaction.getStatus() == AnnotationStatus.REQUESTED && annotationStatus == AnnotationStatus.DECLINED;
actionPerformed = actionPerformed || !isDeclined;
if (isDeclined) {
forceRedactionPersistenceService.markAsProcessed(annotationId, fileId);
}
}
if (actionPerformed) {
reprocess(dossierId, fileId);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
public ManualRedactions getManualRedactions(String fileId) {
return manualRedactionProviderService.getManualRedactions(fileId);
}
@Transactional
public void updateLegalBasisChangeStatus(String dossierId, String fileId, List<String> annotationIds, AnnotationStatus annotationStatus) {
dossierPersistenceService.getAndValidateDossier(dossierId);
for (var annotationId : annotationIds) {
legalBasisChangePersistenceService.updateStatus(fileId, annotationId, annotationStatus);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
@Transactional
public void updateImageRecategorizationStatus(String dossierId, String fileId, List<String> annotationIds, AnnotationStatus annotationStatus) {
dossierPersistenceService.getAndValidateDossier(dossierId);
var actionPerformed = false;
for (var annotationId : annotationIds) {
var imageRecategorization = recategorizationPersistenceService.findRecategorization(fileId, annotationId);
recategorizationPersistenceService.updateStatus(fileId, annotationId, annotationStatus);
boolean isDeclined = imageRecategorization.getStatus() == AnnotationStatus.REQUESTED && annotationStatus == AnnotationStatus.DECLINED;
actionPerformed = actionPerformed || !isDeclined;
if (isDeclined) {
recategorizationPersistenceService.markAsProcessed(annotationId, fileId);
}
}
if (actionPerformed) {
reprocess(dossierId, fileId);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
@Transactional
public void updateSurroundingText(String fileId, ManualRedactions manualRedactions) {
@ -882,64 +788,6 @@ public class ManualRedactionService {
}
@Transactional
public void updateResizeRedactionStatus(String dossierId, String fileId, List<String> annotationIds, AnnotationStatus annotationStatus) {
dossierPersistenceService.getAndValidateDossier(dossierId);
var actionPerformed = false;
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId, true, true);
for (var annotationId : annotationIds) {
var resizeRedaction = resizeRedactionPersistenceService.findResizeRedaction(fileId, annotationId);
actionPerformed = actionPerformed || !(resizeRedaction.getStatus() == AnnotationStatus.REQUESTED && annotationStatus == AnnotationStatus.DECLINED);
resizeRedactionPersistenceService.updateStatus(fileId, annotationId, annotationStatus);
resizeRedaction.setStatus(annotationStatus);
updateDictionaryForResizeRedactions(dossierId, fileId, resizeRedaction, redactionLog);
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
if (actionPerformed) {
reprocess(dossierId, fileId);
}
}
@SuppressWarnings("PMD")
@Transactional
public void updateAddRedactionStatus(String dossierId, String fileId, List<String> annotationIds, AnnotationStatus annotationStatus) {
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
for (var annotationId : annotationIds) {
ManualRedactionEntryEntity manualRedactionEntry = addRedactionPersistenceService.findAddRedaction(fileId, annotationId);
if (manualRedactionEntry.isAddToDictionary() || manualRedactionEntry.isAddToDossierDictionary()) {
if (annotationStatus == AnnotationStatus.APPROVED) {
addToDictionary(manualRedactionEntry.getTypeId(), manualRedactionEntry.getValue(), dossierId, fileId, manualRedactionEntry.getDictionaryEntryType());
reprocess(dossierId, fileId);
approveStatusForRedactionsWithSameValue(dossier,
manualRedactionEntry.isAddToDictionary(),
manualRedactionEntry.isAddToDossierDictionary(),
manualRedactionEntry.getValue());
} else if (annotationStatus == AnnotationStatus.DECLINED) {
// if it was previously approved, revert the add
if (manualRedactionEntry.getStatus() == AnnotationStatus.APPROVED) {
removeFromDictionary(manualRedactionEntry.getTypeId(), manualRedactionEntry.getValue(), dossierId, fileId, manualRedactionEntry.getDictionaryEntryType());
}
}
}
addRedactionPersistenceService.updateStatus(fileId, annotationId, annotationStatus, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
}
analysisFlagsCalculationService.calculateFlags(dossierId, fileId);
}
@Transactional
public void updateProcessedDate(String fileId, ManualRedactions manualRedactions) {

View File

@ -103,14 +103,11 @@ public class EntryPersistenceService {
@Transactional
public void addEntries(String typeId, Set<String> entries, long version, DictionaryEntryType dictionaryEntryType, boolean deleted) {
log.info("method addEntries({}, {}, {}, {}, {})", typeId, entries, version, dictionaryEntryType, deleted);
var type = typeRepository.getById(typeId);
switch (dictionaryEntryType) {
case ENTRY -> {
var undeletedEntries = entryRepository.undeleteEntries(typeId, entries, version);
log.info("undeleted entries: {}", undeletedEntries);
undeletedEntries.forEach(entries::remove);
@ -124,8 +121,6 @@ public class EntryPersistenceService {
}).collect(Collectors.toList());
log.info("entry entities: {}", entryEntities);
jdbcWriteUtils.saveBatch(entryEntities);
}
case FALSE_POSITIVE -> {

View File

@ -3,6 +3,7 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Set;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
@ -12,6 +13,7 @@ import com.iqser.red.service.persistence.management.v1.processor.entity.annotati
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualResizeRedactionEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.RectangleEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.annotationentity.ManualRedactionRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.annotationentity.ResizeRedactionRepository;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AnnotationStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ResizeRedactionRequest;
@ -25,12 +27,13 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor
public class ResizeRedactionPersistenceService {
private final ManualRedactionRepository manualRedactionRepository;
private final ResizeRedactionRepository resizeRedactionRepository;
@Transactional
public ManualResizeRedactionEntity insert(String fileId, ResizeRedactionRequest resizeRedactionRequest) {
log.info("method insert({}, {})", fileId, resizeRedactionRequest);
ManualResizeRedactionEntity manualResizeRedaction = new ManualResizeRedactionEntity();
manualResizeRedaction.setId(new AnnotationEntityId(resizeRedactionRequest.getAnnotationId(), fileId));
@ -53,11 +56,14 @@ public class ResizeRedactionPersistenceService {
resizeRedactionRepository.updateSurroundingText(id, textBefore, textAfter);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus, Set<String> typeIdsOfModifiedDictionaries) {
resizeRedactionRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), annotationStatus, OffsetDateTime.now());
var resizeRedaction = resizeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId))
.orElseThrow(() -> new NotFoundException("Unknown file/annotation combination: " + fileId + "/" + annotationId));
resizeRedaction.setStatus(annotationStatus);
resizeRedaction.setTypeIdsOfModifiedDictionaries(typeIdsOfModifiedDictionaries);
}

View File

@ -8,4 +8,39 @@ databaseChangeLog:
- column:
name: add_to_all_dossiers
type: BOOLEAN
tableName: manual_resize_redaction
tableName: manual_resize_redaction
- changeSet:
id: add-add-to-all-dossiers-to-resize-redactions-2
author: ali
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
name: manual_resize_redaction_entity_annotation_id
type: VARCHAR(255)
- column:
constraints:
nullable: false
name: manual_resize_redaction_entity_file_id
type: VARCHAR(255)
- column:
name: type_ids_of_modified_dictionaries
type: VARCHAR(255)
tableName: manual_resize_redaction_entity_type_ids_of_modified_dictionaries
- changeSet:
id: add-add-to-all-dossiers-to-resize-redactions-3
author: ali
changes:
- addForeignKeyConstraint:
baseColumnNames: manual_resize_redaction_entity_annotation_id, manual_resize_redaction_entity_file_id
baseTableName: manual_resize_redaction_entity_type_ids_of_modified_dictionaries
constraintName: fk_resize_entity_annotation_id_file_id_for_type_ids_of_modified_dictionaries
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: annotation_id, file_id
referencedTableName: manual_resize_redaction
validate: true

View File

@ -424,7 +424,7 @@ public class FileTest extends AbstractPersistenceServerServiceTest {
fileId,
Set.of(AddRedactionRequest.builder()
.addToDictionary(true)
.addToAllDossiers(false)
.addToAllDossiers(true)
.comment(new AddCommentRequest("comment"))
.type(type.getType())
.reason("1")

View File

@ -362,457 +362,6 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
assertThat(dossierTemplateDictionary.getEntries().size()).isEqualTo(0);
}
// @Test
// @SneakyThrows
// public void testManualRedaction3641() {
//
// var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
//
// var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate);
//
// var file = fileTesterAndProvider.testAndProvideFile(dossier);
//
// var type = typeProvider.testAndProvideType(dossierTemplate, null, "manual");
//
// var userId = userProvider.getUserId();
//
// fileClient.setStatusUnderReview(dossier.getId(), file.getId(), userId);
//
// var addRedaction = manualRedactionClient.requestBulkAddRedaction(dossier.getId(),
// file.getId(),
// Set.of(AddRedactionRequest.builder()
// .positions(List.of(Rectangle.builder().topLeftY(1).topLeftX(1).height(1).width(1).build()))
// .section("section test")
// .addToDictionary(false)
// .addToDossierDictionary(false)
// .type(type.getType())
// .reason("1")
// .value("test")
// .legalBasis("1")
// .rectangle(true)
// .sourceId("SourceId")
// .build())).iterator().next();
// var loadedAddRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId()).getEntriesToAdd().iterator().next();
// assertThat(loadedAddRedaction.isRectangle()).isEqualTo(true);
//
// var change = ManualChange.from(new BaseAnnotation(addRedaction.getAnnotationId(),
// file.getFileId(),
// userId,
// AnnotationStatus.REQUESTED,
// OffsetDateTime.now(),
// OffsetDateTime.now(),
// null)).withManualRedactionType(ManualRedactionType.ADD_LOCALLY);
// List<ManualChange> changeList = new ArrayList<>();
// changeList.add(change);
//
// var entry = RedactionLogEntry.builder()
// .id(loadedAddRedaction.getAnnotationId())
// .reason(loadedAddRedaction.getReason())
// .isDictionaryEntry(loadedAddRedaction.isAddToDictionary())
// .isDossierDictionaryEntry(loadedAddRedaction.isAddToDossierDictionary())
// .legalBasis(loadedAddRedaction.getLegalBasis())
// .value(loadedAddRedaction.getValue())
// .section(loadedAddRedaction.getSection())
// .type(loadedAddRedaction.getType())
// .redacted(true)
// .isHint(false)
// .sectionNumber(-1)
// .manualChanges(changeList)
// .rectangle(loadedAddRedaction.isRectangle())
// .build();
// when(redactionLogMergeService.provideRedactionLog(Mockito.any())).thenReturn(new RedactionLog(1, 1, List.of(entry), null, 0, 0, 0, 0));
//
// fileClient.setStatusUnderApproval(dossier.getId(), file.getId(), userId);
// var fileStatus = fileClient.getFileStatus(dossier.getId(), file.getId());
// assertThat(fileStatus.isHasSuggestions()).isTrue();
// assertThat(fileStatus.getWorkflowStatus()).isEqualTo(WorkflowStatus.UNDER_APPROVAL);
//
// changeList.get(0).setAnnotationStatus(AnnotationStatus.DECLINED);
// entry.setManualChanges(changeList);
// when(redactionLogMergeService.provideRedactionLog(Mockito.any())).thenReturn(new RedactionLog(1, 1, List.of(entry), null, 0, 0, 0, 0));
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(addRedaction.getAnnotationId()));
// loadedAddRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId()).getEntriesToAdd().iterator().next();
// assertThat(loadedAddRedaction.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// fileStatus = fileClient.getFileStatus(dossier.getId(), file.getId());
// assertThat(fileStatus.isHasSuggestions()).isFalse();
//
// ManualRedactions manualRedactions = manualRedactionClient.getManualRedactions(dossier.getId(), file.getId());
// assertThat(manualRedactions.getEntriesToAdd()).isNotEmpty();
//
// }
//
//
// @Test
// @SneakyThrows
// public void testAddToDictionaryRequiresReanalysis() {
//
// TenantContext.setTenantId("redaction");
//
// var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
//
// var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate);
//
// var file = fileTesterAndProvider.testAndProvideFile(dossier);
//
// var type = typeProvider.testAndProvideType(dossierTemplate, null, "PII");
//
// // assume file is already proccessed once, test that add to dict triggers reanalysis
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.DOCUMENT_TEXT, "{}");
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.DOCUMENT_PAGES, "{}");
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.DOCUMENT_STRUCTURE, "{}");
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.DOCUMENT_POSITION, "{}");
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.NER_ENTITIES, "{}");
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.IMAGE_INFO, "{}");
// fileStatusPersistenceService.updateProcessingStatus(file.getId(), ProcessingStatus.PROCESSED);
//
// var userId = userProvider.getUserId();
// fileClient.setStatusUnderReview(dossier.getId(), file.getId(), userId);
//
// var addRedaction = manualRedactionClient.requestBulkAddRedaction(dossier.getId(),
// file.getId(),
// Set.of(AddRedactionRequest.builder()
// .positions(List.of(Rectangle.builder().topLeftY(1).topLeftX(1).height(1).width(1).build()))
// .section("section test")
// .addToDictionary(true)
// .addToDossierDictionary(false)
// .type(type.getType())
// .reason("1")
// .value("test")
// .legalBasis("1")
// .rectangle(true)
// .sourceId("SourceId")
// .build())).iterator().next();
//
// var loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
// assertThat(loadedFile.getProcessingStatus()).isEqualTo(ProcessingStatus.PROCESSED);
//
// }
//
//
// @Test
// @SneakyThrows
// public void testManualRedaction() {
//
// var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
//
// var dossier = dossierTesterAndProvider.provideTestDossier(dossierTemplate);
//
// var file = fileTesterAndProvider.testAndProvideFile(dossier);
//
// var type = typeProvider.testAndProvideType(dossierTemplate, null, "manual");
//
// var userId = userProvider.getUserId();
//
// try {
// manualRedactionClient.addRedactionBulk(dossier.getId(),
// file.getId(),
// Set.of(AddRedactionRequest.builder()
// .positions(List.of(Rectangle.builder().page(100).topLeftY(1).topLeftX(1).height(1).width(1).build()))
// .section("section test")
// .addToDictionary(true)
// .addToAllDossiers(true)
// .type(type.getType())
// .reason("1")
// .value("test")
// .legalBasis("1")
// .rectangle(true)
// .sourceId("SourceId")
// .build()));
// } catch (FeignException e) {
// assertThat(e.status()).isEqualTo(400);
// }
//
// var addRedaction = manualRedactionClient.addRedactionBulk(dossier.getId(),
// file.getId(),
// Set.of(AddRedactionRequest.builder()
// .positions(List.of(Rectangle.builder().topLeftY(1).topLeftX(1).height(1).width(1).build()))
// .section("section test")
// .addToDictionary(true)
// .addToAllDossiers(true)
// .type(type.getType())
// .reason("1")
// .value("test")
// .legalBasis("1")
// .rectangle(true)
// .sourceId("SourceId")
// .build())).iterator().next();
//
// var loadedAddRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId()).getEntriesToAdd().iterator().next();
// assertThat(loadedAddRedaction.getUser()).isEqualTo(userId);
// assertThat(loadedAddRedaction.getType()).contains("manual");
// assertThat(loadedAddRedaction.getSection()).contains("section test");
// assertThat(loadedAddRedaction.isRectangle()).isEqualTo(true);
// assertThat(loadedAddRedaction.getSourceId()).isEqualTo("SourceId");
//
// fileClient.setStatusUnderReview(dossier.getId(), file.getId(), userId);
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(addRedaction.getAnnotationId()));
// loadedAddRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getEntriesToAdd()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(addRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedAddRedaction.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(addRedaction.getAnnotationId()));
// loadedAddRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getEntriesToAdd()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(addRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedAddRedaction.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
// fileClient.setStatusUnderReview(dossier.getId(), file.getId(), userId);
//
// var addRedaction2 = manualRedactionClient.requestBulkAddRedaction(dossier.getId(),
// file.getId(),
// Set.of(AddRedactionRequest.builder()
// .addToDictionary(true)
// .addToDossierDictionary(true)
// .type(type.getType())
// .reason("1")
// .value("test")
// .legalBasis("1")
// .comment(new AddCommentRequest("comment"))
// .section("section2")
// .build())).iterator().next();
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(addRedaction2.getAnnotationId()));
// var loadedAddRedaction2 = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getEntriesToAdd()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(addRedaction2.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedAddRedaction2.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
// assertThat(loadedAddRedaction2.isAddToDossierDictionary()).isEqualTo(false);
// assertThat(loadedAddRedaction2.isAddToDictionary()).isEqualTo(true);
// assertThat(loadedAddRedaction2.getSection()).contains("section2");
//
// var removeRedaction = manualRedactionClient.requestBulkRemoveRedaction(dossier.getId(),
// file.getId(),
// Set.of(RemoveRedactionRequest.builder().annotationId(addRedaction.getAnnotationId()).comment("comment").removeFromDictionary(false).build())).get(0);
//
// var redactionLog = new RedactionLog(1,
// 1,
// List.of(RedactionLogEntry.builder().id(addRedaction.getAnnotationId()).type("manual").value("value entry").build()),
// null,
// 0,
// 0,
// 0,
// 0);
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
//
// when(redactionLogMergeService.provideRedactionLog(Mockito.any())).thenReturn(redactionLog);
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(removeRedaction.getAnnotationId()));
//
// var loadedRemoveRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getIdsToRemove()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(removeRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedRemoveRedaction.isRemoveFromDictionary()).isEqualTo(false);
// assertThat(loadedRemoveRedaction.getSoftDeletedTime()).isNull();
// assertThat(loadedRemoveRedaction.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(removeRedaction.getAnnotationId()));
// loadedRemoveRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getIdsToRemove()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(removeRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedRemoveRedaction.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// var redLog = new RedactionLog(1, 1, List.of(RedactionLogEntry.builder().id("annotationId").type("manual").value("value entry").build()), null, 0, 0, 0, 0);
// fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redLog);
//
// when(redactionLogMergeService.provideRedactionLog(Mockito.any())).thenReturn(redLog);
// var removeRedaction2 = manualRedactionClient.requestBulkRemoveRedaction(dossier.getId(),
// file.getId(),
// Set.of(RemoveRedactionRequest.builder().annotationId("annotationId").comment("comment").removeFromDictionary(true).build())).get(0);
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(removeRedaction2.getAnnotationId()));
//
// var loadedRemoveRedaction2 = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getIdsToRemove()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(removeRedaction2.getAnnotationId()))
// .findAny()
// .get();
//
// assertThat(loadedRemoveRedaction2.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
// assertThat(dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null).getEntries().isEmpty());
// assertThat(loadedRemoveRedaction2.isRemoveFromDictionary()).isTrue();
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(removeRedaction2.getAnnotationId()));
// loadedRemoveRedaction2 = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getIdsToRemove()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(removeRedaction2.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedRemoveRedaction2.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// var forceRedaction = manualRedactionClient.requestBulkForceRedaction(dossier.getId(),
// file.getId(),
// Set.of(ForceRedactionRequest.builder().annotationId(addRedaction.getAnnotationId()).comment("comment").legalBasis("1").build())).get(0);
//
// var loadedForceRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getForceRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(forceRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedForceRedaction.getLegalBasis()).isEqualTo("1");
// assertThat(loadedForceRedaction.getUser()).isEqualTo(userId);
// assertThat(loadedForceRedaction.getAnnotationId()).isEqualTo(loadedForceRedaction.getAnnotationId());
// assertThat(loadedForceRedaction.getFileId()).isEqualTo(loadedForceRedaction.getFileId());
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(forceRedaction.getAnnotationId()));
// loadedForceRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getForceRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(forceRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedForceRedaction.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(forceRedaction.getAnnotationId()));
// loadedForceRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getForceRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(forceRedaction.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedForceRedaction.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// var legalBasisChange = manualRedactionClient.requestBulkLegalBasisChange(dossier.getId(),
// file.getId(),
// Set.of(LegalBasisChangeRequest.builder().annotationId(addRedaction.getAnnotationId()).comment("comment").legalBasis("1").build())).get(0);
//
// var loadedLegalBasisChange = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getLegalBasisChanges()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedLegalBasisChange.getAnnotationId()).isEqualTo(legalBasisChange.getAnnotationId());
// assertThat(loadedLegalBasisChange.getUser()).isEqualTo(userId);
// assertThat(loadedLegalBasisChange.getLegalBasis()).isEqualTo("1");
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(loadedLegalBasisChange.getAnnotationId()));
// loadedLegalBasisChange = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getLegalBasisChanges()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedLegalBasisChange.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(loadedLegalBasisChange.getAnnotationId()));
// loadedLegalBasisChange = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getLegalBasisChanges()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedLegalBasisChange.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// var imageRecategorization = manualRedactionClient.requestBulkImageRecategorization(dossier.getId(),
// file.getId(),
// Set.of(ImageRecategorizationRequest.builder().annotationId(addRedaction.getAnnotationId()).comment("comment").type("new-type").build())).get(0);
//
// var loadedImageRecategorization = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getImageRecategorization()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedImageRecategorization.getAnnotationId()).isEqualTo(imageRecategorization.getAnnotationId());
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(imageRecategorization.getAnnotationId()));
// loadedImageRecategorization = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getImageRecategorization()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedImageRecategorization.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(imageRecategorization.getAnnotationId()));
// loadedImageRecategorization = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getImageRecategorization()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedImageRecategorization.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// var resizeRedaction = manualRedactionClient.requestBulkResizeRedaction(dossier.getId(),
// file.getId(),
// Set.of(ResizeRedactionRequest.builder()
// .annotationId(addRedaction.getAnnotationId())
// .comment("comment")
// .positions(List.of(Rectangle.builder().topLeftY(2).topLeftX(2).height(2).width(2).build()))
// .value("some value")
// .build())).get(0);
// var loadedResizeRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getResizeRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedResizeRedaction.getStatus()).isEqualTo(AnnotationStatus.REQUESTED);
// assertThat(loadedResizeRedaction.getUser()).isEqualTo(userId);
// assertThat(loadedResizeRedaction.getPositions()).isNotEmpty();
// assertThat(loadedResizeRedaction.getValue()).isEqualTo("some value");
//
// manualRedactionClient.approveRequestBulk(dossier.getId(), file.getId(), Set.of(loadedResizeRedaction.getAnnotationId()));
// loadedResizeRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getResizeRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedResizeRedaction.getStatus()).isEqualTo(AnnotationStatus.APPROVED);
//
// manualRedactionClient.declineRequestBulk(dossier.getId(), file.getId(), Set.of(loadedResizeRedaction.getAnnotationId()));
// loadedResizeRedaction = manualRedactionClient.getManualRedactions(file.getDossierId(), file.getFileId())
// .getResizeRedactions()
// .stream()
// .filter(a -> a.getAnnotationId().equalsIgnoreCase(legalBasisChange.getAnnotationId()))
// .findAny()
// .get();
// assertThat(loadedResizeRedaction.getStatus()).isEqualTo(AnnotationStatus.DECLINED);
//
// ManualRedactions manualRedactions = manualRedactionClient.getManualRedactions(dossier.getId(), file.getId());
// assertThat(manualRedactions.getForceRedactions()).isNotEmpty();
// assertThat(manualRedactions.getLegalBasisChanges()).isNotEmpty();
// assertThat(manualRedactions.getEntriesToAdd()).isNotEmpty();
// assertThat(manualRedactions.getIdsToRemove()).isNotEmpty();
// assertThat(manualRedactions.getImageRecategorization()).isNotEmpty();
// assertThat(manualRedactions.getComments()).isNotEmpty();
// assertThat(manualRedactions.getResizeRedactions()).isNotEmpty();
//
// manualRedactions.getForceRedactions().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
// manualRedactions.getLegalBasisChanges().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
// manualRedactions.getEntriesToAdd().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
// manualRedactions.getIdsToRemove().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
// manualRedactions.getImageRecategorization().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
// manualRedactions.getResizeRedactions().forEach(e -> manualRedactionClient.undo(dossier.getId(), file.getId(), Set.of(e.getAnnotationId())));
//
// manualRedactions.getComments()
// .forEach((key, value) -> value.forEach(c -> manualRedactionClient.undoComment(dossier.getId(), file.getId(), c.getAnnotationId(), String.valueOf(c.getId()))));
//
// MetricValidationUtils.validateMetric(prometheusMeterRegistry, "redactmanager_calculateFlags", 1, null);
// }
//
@Test
public void testEnlargeResizeRedactionInDossierDictionaryWithAddToAllDossiers() {
@ -829,6 +378,8 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var typeDosDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosDict", false, 99);
var typeDosTempDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosTempDict", false, 101);
var userId = userProvider.getUserId();
var redactionDos = AddRedactionRequest.builder()
.positions(List.of(Rectangle.builder().page(1).topLeftY(1).topLeftX(1).height(1).width(1).build()))
.section("section test")
@ -976,6 +527,8 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var typeDosDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosDict", false, 99);
var typeDosTempDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosTempDict", false, 101);
var userId = userProvider.getUserId();
var redactionDos = AddRedactionRequest.builder()
.positions(List.of(Rectangle.builder().page(1).topLeftY(1).topLeftX(1).height(1).width(1).build()))
.section("section test")
@ -1126,6 +679,8 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var typeDosDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosDict", false, 99);
var typeDosTempDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosTempDict", false, 101);
var userId = userProvider.getUserId();
var redactionDos = AddRedactionRequest.builder()
.positions(List.of(Rectangle.builder().page(1).topLeftY(1).topLeftX(1).height(1).width(1).build()))
.section("section test")
@ -1272,6 +827,8 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var typeDosDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosDict", false, 99);
var typeDosTempDict = typeProvider.testAndProvideType(dossierTemplate, null, "typeDosTempDict", false, 101);
var userId = userProvider.getUserId();
var redactionDos = AddRedactionRequest.builder()
.positions(List.of(Rectangle.builder().page(1).topLeftY(1).topLeftX(1).height(1).width(1).build()))
.section("section test")