RED-7763 - Use EntityLog in tests in persistence-service #186

Merged
corina.olariu.ext1 merged 3 commits from RED-7763 into master 2023-10-19 08:53:11 +02:00
24 changed files with 323 additions and 1123 deletions

View File

@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.RestController;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.utils.StringEncodingUtils;
import com.iqser.red.service.persistence.service.v1.api.external.resource.DocumentResource;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
@ -33,7 +32,6 @@ import lombok.SneakyThrows;
@RequiredArgsConstructor
public class DocumentController implements DocumentResource {
private final RedactionLogService redactionLogService;
private final FileStatusService fileStatusService;
private final FileManagementStorageService fileManagementStorageService;

View File

@ -37,6 +37,7 @@ public class AdminInterfaceController {
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.SECTION_GRID);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.REDACTION_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.ENTITY_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_PAGES);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_TEXT);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_POSITION);
@ -139,6 +140,7 @@ public class AdminInterfaceController {
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.SECTION_GRID);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.REDACTION_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.ENTITY_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_STRUCTURE);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_TEXT);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_PAGES);

View File

@ -1,73 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.IdRemovalEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRedactionEntryEntity;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.manualredactions.ManualRedactionProviderService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.RemoveRedactionPersistenceService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class DeleteRemovedManualAddRedactions7 extends Migration {
private static final String NAME = "Delete removed ManualAddRedactions";
private static final long VERSION = 7;
@Autowired
private AddRedactionPersistenceService addRedactionPersistenceService;
@Autowired
private RemoveRedactionPersistenceService removeRedactionPersistenceService;
@Autowired
private ManualRedactionProviderService manualRedactionProviderService;
public DeleteRemovedManualAddRedactions7() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
List<ManualRedactionEntryEntity> addRedactions = addRedactionPersistenceService.findAllAddRedactions();
for (IdRemovalEntity idRemovalEntity : removeRedactionPersistenceService.findAllRemoveRedactions()) {
if (manualAddRedactionsContains(addRedactions, idRemovalEntity.getId().getAnnotationId())) {
log.info("hard delete ManualRedactions for file {} and annotation {}", idRemovalEntity.getId().getFileId(), idRemovalEntity.getId().getAnnotationId());
manualRedactionProviderService.hardDeleteManualRedactions(idRemovalEntity.getId().getFileId(), idRemovalEntity.getId().getAnnotationId());
}
}
}
private boolean manualAddRedactionsContains(List<ManualRedactionEntryEntity> addRedactions, String annotationId) {
for (ManualRedactionEntryEntity manualRedactionEntryEntity : addRedactions) {
if (StringUtils.equals(annotationId, manualRedactionEntryEntity.getId().getAnnotationId())) {
return true;
}
}
return false;
}
}

View File

@ -1,89 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class DictionaryToEntityMigration2 extends Migration {
private static final String NAME = "Migrate RedactionLogs remove false_positive and recommendation_ prefix";
private static final long VERSION = 2;
@Autowired
private DossierPersistenceService dossierPersistenceService;
@Autowired
private FileStatusPersistenceService fileStatusPersistenceService;
@Autowired
private FileManagementStorageService fileManagementStorageService;
@Autowired
private ObjectMapper objectMapper;
public DictionaryToEntityMigration2() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var dossiers = dossierPersistenceService.findAllDossiers();
dossiers.forEach(dossier -> {
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId());
log.info("Start migration of dossier {}", dossier.getId());
files.forEach(file -> {
log.info("Start migration of file {}", file.getId());
if (file.getHardDeletedTime() == null) {
try {
var newRedactionLogEntries = new ArrayList<RedactionLogEntry>();
var redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), file.getId());
redactionLog.getRedactionLogEntry().forEach(entry -> {
if (entry.getType().equals("false_positive")) {
log.info("skipping false_positive for dossier {} and file {}", dossier.getId(), file.getId());
return;
}
if (entry.getType().startsWith("recommendation_")) {
entry.setType(entry.getType().substring(15));
entry.setRecommendation(true);
log.info("removed _recommendation for file {} and annotation {}", file.getId(), entry.getId());
}
newRedactionLogEntries.add(entry);
});
if (newRedactionLogEntries.size() != redactionLog.getRedactionLogEntry().size()) {
redactionLog.setRedactionLogEntry(newRedactionLogEntries);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
log.info("Stored redactionLog for dossierId: {} and fileId: {}", dossier.getId(), file.getId());
}
} catch (Exception e) {
log.info("redactionLog {} does not exsist", file.getId());
}
}
});
});
}
}

View File

@ -1,74 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.BaseDictionaryEntry;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.TypeEntity;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class EntityTypesMigration4 extends Migration {
private static final String NAME = "Set flags systemManaged, autoHideSkipped and hasDictionary for all entity types";
private static final long VERSION = 4;
@Autowired
private DictionaryPersistenceService dictionaryPersistenceService;
@Autowired
private EntryPersistenceService entryPersistenceService;
public EntityTypesMigration4() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
Set<String> systemManagedTypes = Set.of("ocr", "image", "logo", "signature", "formula", "imported_redaction", "dossier_redaction");
Set<String> autoHideSkippedTypes = Set.of("imported_redaction");
log.info("Will check all type entities and set systemManaged flag true for {}", systemManagedTypes);
log.info("Will check all type entities and set autoHideSkipped flag true for {}", autoHideSkippedTypes);
log.info("Will check all type entities and set hasDictionary flag true for types with entities");
List<TypeEntity> types = dictionaryPersistenceService.getAllTypes(false);
for (TypeEntity type : types) {
if (type != null) {
// Check if type is systemManaged
type.setSystemManaged(type.getType() != null && systemManagedTypes.contains(type.getType()));
// Check if type is autoHideSkipped
type.setAutoHideSkipped(type.getType() != null && autoHideSkippedTypes.contains(type.getType()));
// Check if type has dictionaries
List<? extends BaseDictionaryEntry> entries = entryPersistenceService.getEntries(type.getId(), DictionaryEntryType.ENTRY, null);
type.setHasDictionary(entries != null && !entries.isEmpty());
}
}
log.info("Save all types");
dictionaryPersistenceService.saveAllTypes(types);
}
}

View File

@ -1,66 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class
FileSizeMigration8 extends Migration {
private static final String NAME = "Update file size";
private static final long VERSION = 8;
@Autowired
private FileStatusPersistenceService fileStatusPersistenceService;
@Autowired
private FileManagementStorageService fileManagementStorageService;
public FileSizeMigration8() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
List<FileEntity> allFiles = fileStatusPersistenceService.getAllFiles();
log.info("Number of all files: {}", allFiles.size());
allFiles.forEach(file -> {
// not hard deleted
if (file.getHardDeletedTime() == null) {
try {
var originFile = fileManagementStorageService.getStoredObjectBytes(file.getDossierId(), file.getId(), FileType.ORIGIN);
fileStatusPersistenceService.updateFileSize(file.getId(), originFile.length);
} catch (Exception e) {
log.warn("Failed to load file bytes for file: {} in dossier {}. Error message: {} ", file.getId(), file.getDossierId(), e.getMessage());
}
}
});
}
}

View File

@ -1,36 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.IndexingService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class IndexMigration1 extends Migration {
private static final String NAME = "Recreate index and index all files";
private static final long VERSION = 1;
@Autowired
private IndexingService indexingService;
public IndexMigration1() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
log.info("Will call SearchService via queue to close, drop, recreate index and reindex all files");
indexingService.reindex(null, null, true);
}
}

View File

@ -1,84 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierTemplateRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.TypeRepository;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class ManualRedactionTypeMigration9 extends Migration {
private static final String NAME = "Add Manual Redaction Type";
private static final long VERSION = 9;
private static final String MANUAL_TYPE = "manual";
@Autowired
private DictionaryPersistenceService dictionaryPersistenceService;
@Autowired
private DossierTemplateRepository dossierTemplateRepository;
@Autowired
private TypeRepository typeRepository;
public ManualRedactionTypeMigration9() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var allDossierTemplates = dossierTemplateRepository.findAll();
allDossierTemplates.forEach(dossierTemplateEntity -> {
var entitiesForDossierTemplate = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateEntity.getId(), true);
var manualType = entitiesForDossierTemplate.stream().filter(e -> MANUAL_TYPE.equals(e.getType())).findAny();
manualType.ifPresent(typeEntity -> typeRepository.deleteById(typeEntity.getId()));
var rank = 1;
for (var entity : entitiesForDossierTemplate) {
if (entity.getRank() > rank) {
rank = entity.getRank();
}
}
rank += 1000;
dictionaryPersistenceService.addType(MANUAL_TYPE,
dossierTemplateEntity.getId(),
"#9398a0",
"#c5d3eb",
"#c498fa",
rank,
false,
false,
false,
"Manual Redactions",
false,
"Manual Redactions",
null,
false,
true,
false,
true);
});
}
}

View File

@ -1,86 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.io.ByteArrayInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class MigrateHighlights3 extends Migration {
private static final String NAME = "Migrate Highlights";
private static final long VERSION = 3;
@Autowired
private DossierPersistenceService dossierPersistenceService;
@Autowired
private FileStatusPersistenceService fileStatusPersistenceService;
@Autowired
private FileManagementStorageService fileManagementStorageService;
@Autowired
private FileStatusService fileStatusService;
public MigrateHighlights3() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var dossiers = dossierPersistenceService.findAllDossiers();
dossiers.forEach(dossier -> {
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId());
files.forEach(file -> {
if (file.getHardDeletedTime() == null) {
try {
if (fileManagementStorageService.objectExists(dossier.getId(), file.getId(), FileType.ORIGIN)) {
var untouchedExists = fileManagementStorageService.objectExists(dossier.getId(), file.getId(), FileType.UNTOUCHED);
if (!untouchedExists) {
var originExists = fileManagementStorageService.objectExists(dossier.getId(), file.getId(), FileType.ORIGIN);
if (!originExists) {
log.warn("Invalid file {} / {} Neither untouched nor origin files exists!", dossier.getId(), file.getId());
return;
}
fileManagementStorageService.storeObject(dossier.getId(),
file.getId(),
FileType.UNTOUCHED,
new ByteArrayInputStream(fileManagementStorageService.getStoredObjectBytes(dossier.getId(), file.getId(), FileType.ORIGIN)));
}
fileStatusService.addToPreprocessingQueue(file.getId(), file.getDossierId(), file.getFilename());
} else {
log.warn("Invalid file: {} in dossier: {}. File Data ( PDF ) does not exist", file.getId(), file.getDossierId());
}
} catch (Exception e) {
log.warn("Failed to extract text highlights for document: {}", file.getId());
}
}
});
});
}
}

View File

@ -1,78 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.manualredactions.ManualRedactionService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class RemoveFalsePositiveManualRedactions6 extends Migration {
private static final String NAME = "Remove false positives manual redactions";
private static final long VERSION = 6;
@Autowired
private DossierPersistenceService dossierPersistenceService;
@Autowired
private FileStatusPersistenceService fileStatusPersistenceService;
@Autowired
private ManualRedactionService manualRedactionService;
@Autowired
private AddRedactionPersistenceService addRedactionPersistenceService;
public RemoveFalsePositiveManualRedactions6() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var dossiers = dossierPersistenceService.findAllDossiers();
dossiers.forEach(dossier -> {
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId());
files.forEach(file -> {
if (file.getHardDeletedTime() == null) {
var annotationIdsToRemove = new ArrayList<String>();
var manualRedactions = manualRedactionService.getManualRedactions( file.getId());
if (manualRedactions != null && manualRedactions.getEntriesToAdd() != null) {
manualRedactions.getEntriesToAdd().forEach(addRedaction -> {
if (addRedaction.getType().contains("false_positive")) {
annotationIdsToRemove.add(addRedaction.getAnnotationId());
}
});
}
log.info("Hard deleting false positive annotations for file: {} / {}", file.getId(), annotationIdsToRemove);
if (!annotationIdsToRemove.isEmpty()) {
annotationIdsToRemove.forEach(id -> addRedactionPersistenceService.hardDelete(file.getId(), id));
}
}
});
});
}
}

View File

@ -1,84 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.migration.migrations.model.simplifiedtext.Text;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.utils.StorageIdUtils;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
import com.iqser.red.storage.commons.service.StorageService;
import com.knecon.fforesight.tenantcommons.TenantContext;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class SimplifiedTextMigration12 extends Migration {
private static final String NAME = "Add simplified text file if missing";
private static final long VERSION = 12;
@Autowired
private DossierPersistenceService dossierPersistenceService;
@Autowired
private FileStatusPersistenceService fileStatusPersistenceService;
@Autowired
private StorageService storageService;
public SimplifiedTextMigration12() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var dossiers = dossierPersistenceService.findAllDossiers();
dossiers.forEach(dossier -> {
if (dossier.getHardDeletedTime() == null) {
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId());
log.info("Start migration of dossier {}", dossier.getId());
files.forEach(file -> {
if (file.getHardDeletedTime() == null) {
log.info("Start migration of file {}", file.getId());
migrateFile(dossier.getId(), file.getId());
log.info("Finished migration of file {}", file.getId());
}
});
log.info("Finished migration of dossier {}", dossier.getId());
}
});
}
@SneakyThrows
public void migrateFile(String dossierId, String fileId) {
try {
if (!storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.SIMPLIFIED_TEXT))) {
var text = storageService.readJSONObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.TEXT), Text.class);
storageService.storeJSONObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.SIMPLIFIED_TEXT), text);
}
} catch (StorageObjectDoesNotExist e) {
log.warn("Text not found for dossier {} and file {}, ignoring....", dossierId, fileId);
}
}
}

View File

@ -1,142 +0,0 @@
package com.iqser.red.service.persistence.management.v1.processor.migration.migrations;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.BaseDictionaryEntry;
import com.iqser.red.service.persistence.management.v1.processor.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.service.DictionaryManagementService;
import com.iqser.red.service.persistence.management.v1.processor.service.DictionaryService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierTemplateRepository;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class TypeToEntityMigration5 extends Migration {
private static final String NAME = "Migrate false positives, set recommendation color, remove unneeded dictionaries";
private static final long VERSION = 5;
@Autowired
private DictionaryPersistenceService dictionaryPersistenceService;
@Autowired
private DossierTemplateRepository dossierTemplateRepository;
@Autowired
private EntryPersistenceService entryPersistenceService;
@Autowired
private DictionaryManagementService dictionaryManagementService;
public TypeToEntityMigration5() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
var types = dictionaryPersistenceService.getAllTypes(false);
types.forEach(type -> type.setRecommendationHexColor("#8df06c"));
dictionaryPersistenceService.saveAllTypes(types);
var dossierTemplates = dossierTemplateRepository.findAllWhereDeletedIsFalse();
dossierTemplates.forEach(dossierTemplate -> {
log.info("Starting false positive migration of dossierTemplate {}", dossierTemplate.getId());
var typeIdsToDelete = new HashSet<String>();
var typesOfDossierTemplate = dictionaryPersistenceService.getAllTypes(false);
var falsePositive = typesOfDossierTemplate.stream().filter(t -> t.getType().equals("false_positive")).findFirst();
if (falsePositive.isEmpty()) {
log.info("False positive type does no longer exist in dossierTemplate: {}. Skipping.", dossierTemplate.getName());
return;
}
typeIdsToDelete.add(falsePositive.get().getId());
var falsePositiveEntries = entryPersistenceService.getEntries(falsePositive.get().getId(), DictionaryEntryType.ENTRY, null)
.stream()
.map(BaseDictionaryEntry::getValue)
.collect(Collectors.toSet());
log.info("False positive migration of dossierTemplate {} has {} false positive entries", dossierTemplate.getId(), falsePositiveEntries.size());
typesOfDossierTemplate.stream().filter(t -> !t.getType().equals("false_positive")).forEach(typeEntity -> {
log.info("Start processing type {}", typeEntity.getType());
if (typeEntity.getType().startsWith("recommendation_")) {
typeIdsToDelete.add(typeEntity.getId());
log.info("Finished processing type {}", typeEntity.getType());
return;
}
var entries = entryPersistenceService.getEntries(typeEntity.getId(), DictionaryEntryType.ENTRY, null)
.stream()
.map(BaseDictionaryEntry::getValue)
.collect(Collectors.toSet());
log.info("type {} has {} entries", typeEntity.getType(), entries);
var typeFalsePositives = new HashSet<String>();
falsePositiveEntries.forEach(falsePositiveValue -> {
if (containsAnyWord(falsePositiveValue, entries, typeEntity.isCaseInsensitive())) {
typeFalsePositives.add(falsePositiveValue);
}
});
if (!typeFalsePositives.isEmpty()) {
dictionaryManagementService.addEntries(typeEntity.getId(), new ArrayList<>(typeFalsePositives), false, false, DictionaryEntryType.FALSE_POSITIVE);
log.info("Added {} for type {}", typeFalsePositives.size(), typeEntity.getType());
}
log.info("Finished processing type {}", typeEntity.getType());
});
typeIdsToDelete.forEach(typeIdToDelete -> dictionaryManagementService.deleteType(typeIdToDelete));
log.info("Finished false positive migration of dossierTemplate {}", dossierTemplate.getId());
});
}
public boolean containsAnyWord(String text, Set<String> values, boolean isCaseInsensitive) {
String inputString = isCaseInsensitive ? text.toLowerCase(Locale.ROOT) : text;
for (String value : values) {
String cleanValue = isCaseInsensitive ? value.toLowerCase(Locale.ROOT).trim() : value.trim();
int startIndex;
int stopIndex = 0;
do {
startIndex = inputString.indexOf(cleanValue, stopIndex);
stopIndex = startIndex + cleanValue.length();
if (startIndex > -1 && (startIndex == 0 || Character.isWhitespace(inputString.charAt(startIndex - 1)) || isSeparator(inputString.charAt(startIndex - 1))) && (stopIndex == inputString.length() || isSeparator(
inputString.charAt(stopIndex)))) {
return true;
}
} while (startIndex > -1);
}
return false;
}
private boolean isSeparator(char c) {
return Character.isWhitespace(c) || Pattern.matches("\\p{Punct}", String.valueOf(c)) || c == '\"' || c == '' || c == '';
}
}

View File

@ -10,11 +10,11 @@ import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ViewedPageEntity;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.ViewedPagesPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AnnotationStatus;
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.ManualRedactionType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.ChangeType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.ManualRedactionType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j;
public class AnalysisFlagsCalculationService {
private final FileStatusPersistenceService fileStatusPersistenceService;
private final RedactionLogService redactionLogService;
private final EntityLogService entityLogService;
private final ViewedPagesPersistenceService viewedPagesPersistenceService;
@ -36,7 +36,7 @@ public class AnalysisFlagsCalculationService {
long startTime = System.currentTimeMillis();
var file = fileStatusPersistenceService.getStatus(fileId);
var redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
var entityLog = entityLogService.getEntityLog(dossierId, fileId);
var viewedPagesForCurrentAssignee = viewedPagesPersistenceService.findViewedPages(fileId, file.getAssignee());
@ -52,7 +52,7 @@ public class AnalysisFlagsCalculationService {
OffsetDateTime lastRedactionModification = null;
OffsetDateTime lastManualChangeDate = null;
for (RedactionLogEntry entry : redactionLog.getRedactionLogEntry()) {
for (EntityLogEntry entry : entityLog.getEntityLogEntry()) {
if (entry.isExcluded()) {
continue;
}
@ -60,11 +60,11 @@ public class AnalysisFlagsCalculationService {
String type = getType(entry.getType());
var lastChange = entry.getChanges().isEmpty() ? null : entry.getChanges().get(entry.getChanges().size() - 1);
var entryType = entry.getEntryType();
if (entry.getManualChanges() != null && !entry.getManualChanges().isEmpty()) {
for (var manualChange : entry.getManualChanges()) {
if (!entry.isHint() && !entry.isRecommendation() && StringUtils.isNotEmpty(entry.getReason()) && (manualChange.getManualRedactionType()
if (!entryType.equals(EntryType.HINT) && !entryType.equals(EntryType.RECOMMENDATION) && StringUtils.isNotEmpty(entry.getReason()) && (manualChange.getManualRedactionType()
.equals(ManualRedactionType.ADD_LOCALLY) || manualChange.getManualRedactionType()
.equals(ManualRedactionType.RECATEGORIZE) || manualChange.getManualRedactionType()
.equals(ManualRedactionType.REMOVE_LOCALLY) || manualChange.getManualRedactionType()
@ -87,33 +87,24 @@ public class AnalysisFlagsCalculationService {
}
if (lastChange != null && (lastRedactionModification == null || lastChange.getDateTime()
.isAfter(lastRedactionModification)) && !entry.isHint() && !entry.isRecommendation()) {
.isAfter(lastRedactionModification)) && !entryType.equals(EntryType.HINT) && !entryType.equals(EntryType.RECOMMENDATION)) {
lastRedactionModification = lastChange.getDateTime();
}
if (!hasRedactions && entry.isRedacted() && !entry.isRecommendation()) {
if (!hasRedactions && entry.getState().equals(EntryState.APPLIED) && !entryType.equals(EntryType.RECOMMENDATION)) {
hasRedactions = true;
}
if (!hasHints && entry.isHint()) {
if (!hasHints && entryType.equals(EntryType.HINT)) {
hasHints = true;
}
if (!hasImages && (type.equals("image") || entry.isImage())) {
if (!hasImages && (type.equals("image") || entryType.equals(EntryType.IMAGE))) {
hasImages = true;
}
if (!hasSuggestions && (lastChange == null || lastChange.getType() != ChangeType.REMOVED) && entry.getManualChanges()
.stream()
.anyMatch(e -> e.getAnnotationStatus().name().equals(AnnotationStatus.REQUESTED.name()))) {
hasSuggestions = true;
}
if (!hasComments && entry.getComments() != null && !entry.getComments().isEmpty()) {
hasComments = true;
}
var viewedPage = entry.getPositions().isEmpty() ? null : viewedPages.get(entry.getPositions().get(0).getPage());
var viewedPage = entry.getPositions().isEmpty() ? null : viewedPages.get(entry.getPositions().get(0).getPageNumber());
if (file.getWorkflowStatus() != WorkflowStatus.APPROVED && lastChange != null && lastChange.getDateTime() != null && viewedPage != null && viewedPage.isBefore(
lastChange.getDateTime())) {

View File

@ -17,9 +17,6 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.Comment;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.CommentRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.Comments;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.ProcessingStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogComment;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import lombok.AccessLevel;
@ -34,7 +31,6 @@ public class CommentService {
CommentPersistenceService commentPersistenceService;
FileStatusPersistenceService fileStatusPersistenceService;
FileStatusService fileStatusService;
RedactionLogService redactionLogService;
FileManagementStorageService fileManagementStorageService;
private final int COMMENT_MAX_LENGTH = 4000;
@ -48,18 +44,19 @@ public class CommentService {
// update indicator
fileStatusPersistenceService.updateHasComments(fileId, commentPersistenceService.fileHasComments(fileId));
// This is an ugly workaround, don't even look at it!
// Basically we should change how comments work and not merge them into the redaction log.
// if file is currently not analyzing, we can quickly change the redaction log, else we must wait for the analysis to finish.
if (!fileStatusService.getStatus(fileId).getProcessingStatus().equals(ProcessingStatus.PROCESSED)) {
reprocess(dossierId, fileId);
return;
}
fileStatusService.setStatusProcessing(fileId);
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
redactionLog.getRedactionLogEntry().forEach(entry -> entry.getComments().removeIf(comment -> commentIds.contains(comment.getId())));
fileManagementStorageService.storeRedactionLog(dossierId, fileId, redactionLog);
fileStatusService.setStatusProcessed(fileId);
// Since entityLog does not have comments, no need to trigger reprocess or to store them
// // This is an ugly workaround, don't even look at it!
// // Basically we should change how comments work and not merge them into the redaction log.
// // if file is currently not analyzing, we can quickly change the redaction log, else we must wait for the analysis to finish.
// if (!fileStatusService.getStatus(fileId).getProcessingStatus().equals(ProcessingStatus.PROCESSED)) {
// reprocess(dossierId, fileId);
// return;
// }
// fileStatusService.setStatusProcessing(fileId);
// RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
// redactionLog.getRedactionLogEntry().forEach(entry -> entry.getComments().removeIf(comment -> commentIds.contains(comment.getId())));
// fileManagementStorageService.storeRedactionLog(dossierId, fileId, redactionLog);
// fileStatusService.setStatusProcessed(fileId);
}
@ -81,20 +78,21 @@ public class CommentService {
fileStatusPersistenceService.updateHasComments(fileId, true);
// This is an ugly workaround, don't even look at it!
// Basically we should change how comments work and not merge them into the redaction log.
if (!fileStatusService.getStatus(fileId).getProcessingStatus().equals(ProcessingStatus.PROCESSED)) {
reprocess(dossierId, fileId);
return createdComment;
}
fileStatusService.setStatusProcessing(fileId);
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
redactionLog.getRedactionLogEntry()
.stream()
.filter(entry -> entry.getId().equals(annotationId))
.forEach(entry -> entry.getComments().add(MagicConverter.convert(createdComment, RedactionLogComment.class)));
fileManagementStorageService.storeRedactionLog(dossierId, fileId, redactionLog);
fileStatusService.setStatusProcessed(fileId);
// Since entityLog does not have comments, no need to trigger reprocess or to store them
// // This is an ugly workaround, don't even look at it!
// // Basically we should change how comments work and not merge them into the redaction log.
// if (!fileStatusService.getStatus(fileId).getProcessingStatus().equals(ProcessingStatus.PROCESSED)) {
// reprocess(dossierId, fileId);
// return createdComment;
// }
// fileStatusService.setStatusProcessing(fileId);
// RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
// redactionLog.getRedactionLogEntry()
// .stream()
// .filter(entry -> entry.getId().equals(annotationId))
// .forEach(entry -> entry.getComments().add(MagicConverter.convert(createdComment, RedactionLogComment.class)));
// fileManagementStorageService.storeRedactionLog(dossierId, fileId, redactionLog);
// fileStatusService.setStatusProcessed(fileId);
return createdComment;
}
@ -130,10 +128,10 @@ public class CommentService {
.build());
}
private void reprocess(String dossierId, String fileId) {
fileStatusService.setStatusReprocessForManual(dossierId, fileId, true);
}
//
// private void reprocess(String dossierId, String fileId) {
//
// fileStatusService.setStatusReprocessForManual(dossierId, fileId, true);
// }
}

View File

@ -639,6 +639,7 @@ public class FileStatusService {
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.ORIGIN);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.REDACTION_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.ENTITY_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.SECTION_GRID);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.IMAGE_INFO);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_STRUCTURE);
@ -668,6 +669,7 @@ public class FileStatusService {
OffsetDateTime now = OffsetDateTime.now();
// remove everything related to redaction
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.REDACTION_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.ENTITY_LOG);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.SECTION_GRID);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.IMAGE_INFO);

View File

@ -23,12 +23,13 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ResizeRedactionPersistenceService;
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.EntryType;
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.ManualRequestWithAddToDictionary;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRequestWithRemoveFromDictionary;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.WorkflowStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import feign.FeignException;
import lombok.AccessLevel;
@ -134,17 +135,17 @@ public class ManualRedactionDictionaryUpdateHandler {
}
public Set<String> updateDictionaryForResizeRedactions(String dossierId, String fileId, ManualResizeRedactionEntity resizeRedaction, RedactionLogEntry redactionLogEntry) {
public Set<String> updateDictionaryForResizeRedactions(String dossierId, String fileId, ManualResizeRedactionEntity resizeRedaction, EntityLogEntry entityLogEntry) {
if (resizeRedaction.getUpdateDictionary() != null && resizeRedaction.getUpdateDictionary() && resizeRedaction.getStatus()
.equals(AnnotationStatus.APPROVED) && (redactionLogEntry.isDictionaryEntry() || redactionLogEntry.isDossierDictionaryEntry())) {
.equals(AnnotationStatus.APPROVED) && (entityLogEntry.isDictionaryEntry() || entityLogEntry.isDossierDictionaryEntry())) {
var dossier = dossierPersistenceService.findByDossierId(dossierId);
var typeId = buildTypeId(redactionLogEntry.getType(), resizeRedaction, dossier);
var typeId = buildTypeId(entityLogEntry.getType(), resizeRedaction, dossier);
var newValue = resizeRedaction.getValue();
var oldValue = redactionLogEntry.getValue();
var dictionaryEntryType = getDictionaryEntryType(redactionLogEntry);
var oldValue = entityLogEntry.getValue();
var dictionaryEntryType = getDictionaryEntryType(entityLogEntry);
boolean isShrinking = oldValue != null && oldValue.length() > newValue.length();
@ -155,10 +156,10 @@ public class ManualRedactionDictionaryUpdateHandler {
removeFromDictionary(typeId, oldValue, dossierId, fileId, dictionaryEntryType);
typeIdsOfModifiedDictionaries.add(typeId);
if (resizeRedaction.isAddToAllDossiers() && redactionLogEntry.isDictionaryEntry()) {
if (resizeRedaction.isAddToAllDossiers() && entityLogEntry.isDictionaryEntry()) {
String dossierTemplateId = dossier.getDossierTemplateId();
var dossiersOfThisDossierTemplate = dossierPersistenceService.findAllDossiersForDossierTemplateId(dossierTemplateId);
var type = redactionLogEntry.getType();
var type = entityLogEntry.getType();
dossiersOfThisDossierTemplate.forEach(dossierEntity -> {
var typeIdOfDossierEntity = toTypeId(type, dossierTemplateId, dossierEntity.getId());
removeFromDictionary(typeIdOfDossierEntity, oldValue, dossierId, fileId, dictionaryEntryType);
@ -189,11 +190,11 @@ public class ManualRedactionDictionaryUpdateHandler {
}
private DictionaryEntryType getDictionaryEntryType(RedactionLogEntry redactionLogEntry) {
private DictionaryEntryType getDictionaryEntryType(EntityLogEntry entityLogEntry) {
if (redactionLogEntry.isRecommendation() && redactionLogEntry.isFalsePositive()) {
if (entityLogEntry.getEntryType().equals(EntryType.RECOMMENDATION) && entityLogEntry.getEntryType().equals(EntryType.FALSE_POSITIVE)) {
return DictionaryEntryType.FALSE_RECOMMENDATION;
} else if (redactionLogEntry.isFalsePositive()) {
} else if (entityLogEntry.getEntryType().equals(EntryType.FALSE_POSITIVE)) {
return DictionaryEntryType.FALSE_POSITIVE;
} else {
return DictionaryEntryType.ENTRY;
@ -295,9 +296,9 @@ public class ManualRedactionDictionaryUpdateHandler {
}
private void removeResizeRedactionsWithAddToDictionary(String dossierTemplateId, String redactionLogEntryValue) {
private void removeResizeRedactionsWithAddToDictionary(String dossierTemplateId, String entityLogEntryValue) {
var resizeRedactionsWithSameValue = resizeRedactionPersistenceService.findByAnnotationStatusAndValue(AnnotationStatus.APPROVED, redactionLogEntryValue);
var resizeRedactionsWithSameValue = resizeRedactionPersistenceService.findByAnnotationStatusAndValue(AnnotationStatus.APPROVED, entityLogEntryValue);
resizeRedactionsWithSameValue.forEach(resizeRedaction -> {
var file = fileStatusPersistenceService.getStatus(resizeRedaction.getId().getFileId());
var dossierForResizeRedaction = dossierPersistenceService.findByDossierId(file.getDossierId());

View File

@ -10,7 +10,10 @@ import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.EntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AddRedactionRequest;
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.ForceRedactionRequest;
@ -26,8 +29,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.Lega
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RecategorizationRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RemoveRedactionRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.ResizeRedactionRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
import lombok.AccessLevel;
@ -39,7 +40,7 @@ import lombok.experimental.FieldDefaults;
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class ManualRedactionMapper {
RedactionLogService redactionLogService;
EntityLogService entityLogService;
public List<AddRedactionRequest> toAddRedactionRequestList(String dossierId, Set<AddRedactionRequestModel> addRedactionRequests, Dossier dossier) {
@ -79,18 +80,18 @@ public class ManualRedactionMapper {
Set<RemoveRedactionRequestModel> removeRedactionRequests) {
List<RemoveRedactionRequest> requests = new ArrayList<>();
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
EntityLog entityLog = entityLogService.getEntityLog(dossierId, fileId);
for (var removeRedactionRequest : removeRedactionRequests) {
RedactionLogEntry redactionLogEntry = getRedactionLogEntry(redactionLog, removeRedactionRequest.getAnnotationId());
EntityLogEntry entityLogEntry = getEntityLogEntry(entityLog, removeRedactionRequest.getAnnotationId());
var removeRedactionRequestBuilder = RemoveRedactionRequest.builder()
.annotationId(removeRedactionRequest.getAnnotationId())
.user(KeycloakSecurity.getUserId())
.status(AnnotationStatus.APPROVED)
.removeFromDictionary(removeRedactionRequest.isRemoveFromDictionary())
.removeFromAllDossiers(removeRedactionRequest.isRemoveFromAllDossiers())
.value(redactionLogEntry.getValue())
.dictionaryEntryType(getDictionaryEntryType(redactionLogEntry))
.typeToRemove(redactionLogEntry.getType())
.value(entityLogEntry.getValue())
.dictionaryEntryType(getDictionaryEntryType(entityLogEntry))
.typeToRemove(entityLogEntry.getType())
.dossierId(dossierId)
.dossierTemplateId(dossierTemplateId);
@ -139,10 +140,10 @@ public class ManualRedactionMapper {
String dossierTemplateId,
Set<RecategorizationRequestModel> recategorizationRequests) {
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
EntityLog entityLog = entityLogService.getEntityLog(dossierId, fileId);
List<RecategorizationRequest> requests = new ArrayList<>();
for (RecategorizationRequestModel recategorizationRequest : recategorizationRequests) {
RedactionLogEntry redactionLogEntry = getRedactionLogEntry(redactionLog, recategorizationRequest.getAnnotationId());
EntityLogEntry entityLogEntry = getEntityLogEntry(entityLog, recategorizationRequest.getAnnotationId());
RecategorizationRequest build = RecategorizationRequest.builder()
.annotationId(recategorizationRequest.getAnnotationId())
.user(KeycloakSecurity.getUserId())
@ -152,9 +153,9 @@ public class ManualRedactionMapper {
.dossierId(dossierId)
.addToDictionary(recategorizationRequest.isAddToDictionary())
.addToAllDossiers(recategorizationRequest.isAddToAllDossiers())
.dictionaryEntryType(getDictionaryEntryType(redactionLogEntry))
.value(redactionLogEntry.getValue())
.typeToRemove(redactionLogEntry.getType())
.dictionaryEntryType(getDictionaryEntryType(entityLogEntry))
.value(entityLogEntry.getValue())
.typeToRemove(entityLogEntry.getType())
.dossierTemplateTypeId(toTypeId(recategorizationRequest.getType(), dossierTemplateId))
.build();
requests.add(build);
@ -181,21 +182,21 @@ public class ManualRedactionMapper {
}
private RedactionLogEntry getRedactionLogEntry(RedactionLog redactionLog, String annotationId) {
private EntityLogEntry getEntityLogEntry(EntityLog entityLog, String annotationId) {
return redactionLog.getRedactionLogEntry()
return entityLog.getEntityLogEntry()
.stream()
.filter(entry -> entry.getId().equals(annotationId))
.findFirst()
.orElseThrow(() -> new NotFoundException("Annotation does not exist in redaction log."));
.orElseThrow(() -> new NotFoundException("Annotation does not exist in entity log."));
}
private DictionaryEntryType getDictionaryEntryType(RedactionLogEntry redactionLogEntry) {
private DictionaryEntryType getDictionaryEntryType(EntityLogEntry entityLogEntry) {
if (redactionLogEntry.isRecommendation() && redactionLogEntry.isFalsePositive()) {
if (entityLogEntry.getEntryType().equals(EntryType.RECOMMENDATION) && entityLogEntry.getEntryType().equals(EntryType.FALSE_POSITIVE)) {
return DictionaryEntryType.FALSE_RECOMMENDATION;
} else if (redactionLogEntry.isFalsePositive()) {
} else if (entityLogEntry.getEntryType().equals(EntryType.FALSE_POSITIVE)) {
return DictionaryEntryType.FALSE_POSITIVE;
} else {
return DictionaryEntryType.ENTRY;

View File

@ -15,8 +15,8 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.NotFo
import com.iqser.red.service.persistence.management.v1.processor.service.AnalysisFlagsCalculationService;
import com.iqser.red.service.persistence.management.v1.processor.service.CommentService;
import com.iqser.red.service.persistence.management.v1.processor.service.DictionaryManagementService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ForceRedactionPersistenceService;
@ -24,6 +24,8 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.RecategorizationPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.RemoveRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ResizeRedactionPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.annotations.AddRedactionRequest;
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.ForceRedactionRequest;
@ -33,8 +35,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.RecategorizationRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.RemoveRedactionRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ResizeRedactionRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
@ -58,7 +58,7 @@ public class ManualRedactionService {
FileStatusService fileStatusService;
ManualRedactionProviderService manualRedactionProviderService;
AnalysisFlagsCalculationService analysisFlagsCalculationService;
RedactionLogService redactionLogService;
EntityLogService entityLogService;
DictionaryManagementService dictionaryManagementService;
HashFunction hashFunction = Hashing.murmur3_128();
ManualRedactionDictionaryUpdateHandler manualRedactionDictionaryUpdateHandler;
@ -242,7 +242,7 @@ public class ManualRedactionService {
List<ManualAddResponse> response = new ArrayList<>();
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
EntityLog entityLog = entityLogService.getEntityLog(dossierId, fileId);
for (ResizeRedactionRequest resizeRedactionRequest : resizeRedactionRequests) {
@ -259,7 +259,7 @@ public class ManualRedactionService {
Set<String> typeIdsOfModifiedDictionaries = manualRedactionDictionaryUpdateHandler.updateDictionaryForResizeRedactions(dossierId,
fileId,
resizeRedaction,
getRedactionLogEntry(redactionLog, resizeRedaction.getId().getAnnotationId()));
getEntityLogEntry(entityLog, resizeRedaction.getId().getAnnotationId()));
resizeRedactionPersistenceService.updateStatus(resizeRedaction.getId().getFileId(),
resizeRedaction.getId().getAnnotationId(),
@ -294,13 +294,13 @@ public class ManualRedactionService {
}
private RedactionLogEntry getRedactionLogEntry(RedactionLog redactionLog, String annotationId) {
private EntityLogEntry getEntityLogEntry(EntityLog entityLog, String annotationId) {
return redactionLog.getRedactionLogEntry()
return entityLog.getEntityLogEntry()
.stream()
.filter(entry -> entry.getId().equals(annotationId))
.findFirst()
.orElseThrow(() -> new NotFoundException("Annotation does not exist in redaction log."));
.orElseThrow(() -> new NotFoundException("Annotation does not exist in entity log."));
}

View File

@ -22,8 +22,8 @@ import com.iqser.red.service.persistence.management.v1.processor.entity.annotati
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRedactionEntryEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.NotFoundException;
import com.iqser.red.service.persistence.management.v1.processor.service.AnalysisFlagsCalculationService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.AuditPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DossierPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.AddRedactionPersistenceService;
@ -33,6 +33,8 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.RemoveRedactionPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.annotations.ResizeRedactionPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.AuditCategory;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.annotations.AnnotationStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.ManualRedactions;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.entitymapped.IdRemoval;
@ -44,8 +46,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations
import com.iqser.red.service.persistence.service.v1.api.shared.model.audit.AuditRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.ManualRedactionWrapperModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
import lombok.AccessLevel;
@ -68,7 +68,7 @@ public class ManualRedactionUndoService {
ForceRedactionPersistenceService forceRedactionPersistenceService;
LegalBasisChangePersistenceService legalBasisChangePersistenceService;
ResizeRedactionPersistenceService resizeRedactionPersistenceService;
RedactionLogService redactionLogService;
EntityLogService entityLogService;
ManualRedactionDictionaryUpdateHandler manualRedactionDictionaryUpdateHandler;
@ -191,11 +191,11 @@ public class ManualRedactionUndoService {
private void deleteRecategorization(String dossierId, String fileId, List<String> annotationIds) {
dossierPersistenceService.getAndValidateDossier(dossierId);
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
EntityLog entityLog = entityLogService.getEntityLog(dossierId, fileId);
for (var annotationId : annotationIds) {
ManualRecategorizationEntity recategorizationEntity = recategorizationPersistenceService.findRecategorization(fileId, annotationId);
String originalValue = getRedactionLogEntry(redactionLog, annotationId).getValue();
String originalValue = getEntityLogEntry(entityLog, annotationId).getValue();
manualRedactionDictionaryUpdateHandler.revertRemoveFromDictionary(originalValue, dossierId, fileId, recategorizationEntity.getTypeIdsOfDictionariesWithDelete());
manualRedactionDictionaryUpdateHandler.revertAddToDictionary(originalValue,
DictionaryEntryType.ENTRY,
@ -265,12 +265,12 @@ public class ManualRedactionUndoService {
private void deleteRemoveRedaction(String dossierId, String fileId, List<String> annotationIds) {
dossierPersistenceService.getAndValidateDossier(dossierId);
RedactionLog redactionLog = redactionLogService.getRedactionLog(dossierId, fileId);
EntityLog entityLog = entityLogService.getEntityLog(dossierId, fileId);
for (String annotationId : annotationIds) {
IdRemovalEntity removeRedaction = removeRedactionPersistenceService.findRemoveRedaction(fileId, annotationId);
String originalValue = getRedactionLogEntry(redactionLog, annotationId).getValue();
String originalValue = getEntityLogEntry(entityLog, annotationId).getValue();
boolean dictionaryChanged = manualRedactionDictionaryUpdateHandler.revertRemoveFromDictionary(originalValue, dossierId, fileId, removeRedaction);
removeRedactionPersistenceService.updateStatus(fileId, annotationId, removeRedaction.getStatus(), dictionaryChanged, Collections.emptySet());
removeRedactionPersistenceService.softDelete(fileId, annotationId, OffsetDateTime.now());
@ -317,13 +317,13 @@ public class ManualRedactionUndoService {
}
private RedactionLogEntry getRedactionLogEntry(RedactionLog redactionLog, String annotationId) {
private EntityLogEntry getEntityLogEntry(EntityLog entityLog, String annotationId) {
return redactionLog.getRedactionLogEntry()
return entityLog.getEntityLogEntry()
.stream()
.filter(entry -> entry.getId().equals(annotationId))
.findFirst()
.orElseThrow(() -> new NotFoundException("Annotation does not exist in redaction log."));
.orElseThrow(() -> new NotFoundException("Annotation does not exist in entity log."));
}

View File

@ -18,12 +18,13 @@ import com.iqser.red.service.persistence.management.v1.processor.service.FileMan
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.AnalyzeResult;
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.dossiertemplate.dossier.Dossier;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.AddFileRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.section.SectionGrid;
import lombok.SneakyThrows;
@ -65,9 +66,9 @@ public class FileTesterAndProvider {
fileManagementStorageService.storeJSONObject(dossier.getId(),
file.getFileId(),
FileType.REDACTION_LOG,
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.getFileId(), FileType.SECTION_GRID, new SectionGrid());
FileType.ENTITY_LOG,
new EntityLog(1, 1, List.of(EntityLogEntry.builder().id("annotationId").type("manual").value("value entry").entryType(EntryType.ENTITY).state(EntryState.APPLIED).build()), null, 0, 0, 0, 0));
fileManagementStorageService.storeObject(dossier.getId(), file.getFileId(), FileType.ORIGIN, new ByteArrayInputStream(objectMapper.writeValueAsBytes("bytes of the file")));
return file;

View File

@ -71,7 +71,7 @@ public class DossierTest extends AbstractPersistenceServerServiceTest {
public void testDossierRaceCondition() {
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
dossierTemplateTesterAndProvider.provideDefaultColors(dossierTemplate.getDossierTemplateId());
dossierTemplateTesterAndProvider.provideDefaultColors(dossierTemplate.getId());
IntStream.range(0, 10).parallel().forEach(x -> dossierTesterAndProvider.provideTestDossier(dossierTemplate, "race condition dossier: " + x));
var allDossiers = dossierClient.getDossiers(true, true);
var dossierCount = allDossiers.size();
@ -84,8 +84,8 @@ public class DossierTest extends AbstractPersistenceServerServiceTest {
public void testCreateDuplicateDossier() {
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
dossierTemplateTesterAndProvider.provideDefaultColors(dossierTemplate.getDossierTemplateId());
IntStream.range(0, 8).parallel().forEach(x -> {
dossierTemplateTesterAndProvider.provideDefaultColors(dossierTemplate.getId());
IntStream.range(0, 4).parallel().forEach(x -> {
try {
dossierTesterAndProvider.provideTestDossier(dossierTemplate, "sameNameDossier");
} catch (Exception e) {
@ -105,7 +105,7 @@ public class DossierTest extends AbstractPersistenceServerServiceTest {
var dossier = dossierTesterAndProvider.provideTestDossier();
var returnedTypes = dictionaryClient.getAllTypes(dossier.getDossierTemplateId(), dossier.getDossierId(), false);
var returnedTypes = dictionaryClient.getAllTypes(dossier.getDossierTemplateId(), dossier.getId(), false);
assertThat(returnedTypes.getTypes().size()).isEqualTo(0);
var watermark = new WatermarkModel();

View File

@ -28,7 +28,6 @@ import com.iqser.red.service.peristence.v1.server.integration.client.FileClient;
import com.iqser.red.service.peristence.v1.server.integration.client.FileManagementClient;
import com.iqser.red.service.peristence.v1.server.integration.client.ManualRedactionClient;
import com.iqser.red.service.peristence.v1.server.integration.client.ReanalysisClient;
import com.iqser.red.service.peristence.v1.server.integration.client.RedactionLogClient;
import com.iqser.red.service.peristence.v1.server.integration.client.UploadClient;
import com.iqser.red.service.peristence.v1.server.integration.client.ViewedPagesClient;
import com.iqser.red.service.peristence.v1.server.integration.service.DossierTemplateTesterAndProvider;
@ -47,6 +46,10 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.FileUploadR
import com.iqser.red.service.persistence.service.v1.api.shared.model.PageExclusionRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.PageRange;
import com.iqser.red.service.persistence.service.v1.api.shared.model.ViewedPagesRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.Dossier;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileAttributeConfig;
@ -60,8 +63,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.Forc
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.LegalBasisChangeRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RecategorizationRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RemoveRedactionRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import feign.FeignException;
import lombok.SneakyThrows;
@ -95,9 +96,6 @@ public class FileTest extends AbstractPersistenceServerServiceTest {
@Autowired
private ViewedPagesClient viewedPagesClient;
@Autowired
private RedactionLogClient redactionLogClient;
@Autowired
private FileAttributeClient fileAttributeClient;
@ -203,7 +201,6 @@ public class FileTest extends AbstractPersistenceServerServiceTest {
fileClient.setStatusUnderReview(dossier.getId(), file.getId(), userId);
reanalysisClient.excludePages(dossier.getId(), file.getId(), new PageExclusionRequest(List.of(new PageRange(1, 1))));
var redactionLog = redactionLogClient.getRedactionLog(dossier.getId(), file.getId(), null, false, true);
assertThat(fileClient.getDossierStatus(dossier.getId()).size()).isEqualTo(1);
var loadedFile = fileClient.getFileStatus(dossier.getId(), file.getId());
@ -361,11 +358,10 @@ public class FileTest extends AbstractPersistenceServerServiceTest {
var type = typeProvider.testAndProvideType(dossierTemplate, null, "manual");
var annotationId = "imagine_this_makes_sense";
RedactionLog redactionLog = new RedactionLog();
RedactionLogEntry redactionLogEntry = RedactionLogEntry.builder().type(type.getType()).id(annotationId).build();
redactionLog.getRedactionLogEntry().add(redactionLogEntry);
EntityLog entityLog = new EntityLog(1, 1,
List.of(EntityLogEntry.builder().id(annotationId).type(type.getType()).value("value entry").state(EntryState.APPLIED).entryType(EntryType.ENTITY).build()), null, 0, 0, 0, 0);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
assertThat(fileClient.getDossierStatus(dossier.getId()).size()).isEqualTo(1);
@ -569,18 +565,14 @@ public class FileTest extends AbstractPersistenceServerServiceTest {
assertThat(loadedFile.getLastReviewer()).isNull();
assertThat(loadedFile.getLastApprover()).isNull();
Exception exception = Assertions.assertThrows(FeignException.BadRequest.class, () -> {
fileClient.setStatusUnderReview(dossier.getId(), file.getId(), null);
});
Exception exception = Assertions.assertThrows(FeignException.BadRequest.class, () -> fileClient.setStatusUnderReview(dossier.getId(), file.getId(), null));
String expectedMessage = "File is already unassigned!";
String actualMessage = exception.getMessage();
assertThat(actualMessage).contains(expectedMessage);
exception = Assertions.assertThrows(FeignException.BadRequest.class, () -> {
fileClient.setStatusUnderReview(dossier.getId(), file.getId(), user2);
});
exception = Assertions.assertThrows(FeignException.BadRequest.class, () -> fileClient.setStatusUnderReview(dossier.getId(), file.getId(), user2));
expectedMessage = "User must be dossier member";
actualMessage = exception.getMessage();

View File

@ -25,12 +25,16 @@ import com.iqser.red.service.peristence.v1.server.integration.service.TypeProvid
import com.iqser.red.service.peristence.v1.server.integration.service.UserProvider;
import com.iqser.red.service.peristence.v1.server.integration.utils.AbstractPersistenceServerServiceTest;
import com.iqser.red.service.persistence.management.v1.processor.service.DictionaryManagementService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.redactionlog.RedactionRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.Dictionary;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
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.annotations.Rectangle;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;
@ -38,8 +42,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.AddR
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RecategorizationRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.RemoveRedactionRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.manual.ResizeRedactionRequestModel;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLogEntry;
import feign.FeignException;
@ -82,7 +84,7 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
private InternalDictionaryClient internalDictionaryClient;
@Autowired
private RedactionLogService redactionLogService;
private EntityLogService entityLogService;
@Autowired
private DictionaryManagementService dictionaryManagementService;
@ -101,26 +103,26 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var type = typeProvider.testAndProvideType(dossierTemplate, null, "type", true);
assertThat(type.isDossierDictionaryOnly()).isTrue();
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getDossierId(), DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getId(), DictionaryEntryType.ENTRY);
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id("AnnotationId").type(type.getType()).value("Luke Skywalker").isDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id("AnnotationId").type(type.getType()).value("Luke Skywalker").entryType(EntryType.ENTITY).state(EntryState.APPLIED).dictionaryEntry(true).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
Assertions.assertThrows(FeignException.Forbidden.class,
() -> manualRedactionClient.removeRedactionBulk(dossier.getId(),
file.getId(),
Set.of(RemoveRedactionRequestModel.builder().annotationId("AnnotationId").removeFromDictionary(true).removeFromAllDossiers(true).build())));//.get(0);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().size()).isZero();
}
@ -151,7 +153,7 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build())));
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().size()).isZero();
}
@ -166,9 +168,9 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
var type = typeProvider.testAndProvideType(dossierTemplate);
dictionaryClient.deleteEntries(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), dossier.getDossierId(), DictionaryEntryType.ENTRY);
dictionaryClient.deleteEntries(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), dossier.getId(), DictionaryEntryType.ENTRY);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId()), null);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId(), dossier.getId()), null);
assertThat(dossierDictionary.getEntries().size()).isEqualTo(1);
assertThat(dossierDictionary.getEntries().get(0).isDeleted()).isTrue();
@ -187,11 +189,11 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build()));
dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId()), null);
dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId(), dossier.getId()), null);
assertThat(dossierDictionary.getEntries().size()).isEqualTo(1);
assertThat(dossierDictionary.getEntries().get(0).isDeleted()).isFalse();
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().size()).isEqualTo(1);
assertThat(dossierTemplateDictionary.getEntries().get(0).isDeleted()).isFalse();
@ -221,11 +223,11 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build()));
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId()), null);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId(), dossier.getId()), null);
assertThat(dossierDictionary.getEntries().size()).isEqualTo(1);
assertThat(dossierDictionary.getEntries().get(0).isDeleted()).isFalse();
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().isEmpty()).isTrue();
}
@ -244,25 +246,25 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
entries.add("Darth Vader");
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), entries, false, null, DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getDossierId(), DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getId(), DictionaryEntryType.ENTRY);
Dictionary dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder("Luke Skywalker", "Darth Vader");
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder("Luke Skywalker");
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").isDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").entryType(EntryType.ENTITY).state(EntryState.APPLIED).dictionaryEntry(true).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
manualRedactionClient.removeRedactionBulk(dossier.getId(),
file.getId(),
@ -270,14 +272,14 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder("Darth Vader");
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).isEmpty();
manualRedactionClient.undo(dossier.getDossierId(), file.getFileId(), Set.of("AnnotationId"));
manualRedactionClient.undo(dossier.getId(), file.getFileId(), Set.of("AnnotationId"));
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder("Luke Skywalker", "Darth Vader");
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder("Luke Skywalker");
}
@ -298,27 +300,27 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
//FIXME should be created on the fly.
// CreateTypeValue dossierDictionaryType = MagicConverter.convert(type, CreateTypeValue.class);
// dictionaryClient.addType(dossierDictionaryType, dossier.getDossierId());
// dictionaryClient.addType(dossierDictionaryType, dossier.getId());
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").isDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").entryType(EntryType.ENTITY).state(EntryState.APPLIED).dictionaryEntry(true).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
manualRedactionClient.removeRedactionBulk(dossier.getId(),
file.getId(),
Set.of(RemoveRedactionRequestModel.builder().annotationId("AnnotationId").removeFromDictionary(true).build())).get(0);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId()), null);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId(), dossier.getId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().size()).isEqualTo(2);
assertThat(dossierTemplateDictionary.getEntries().stream().filter(e -> e.getValue().equals("Luke Skywalker")).findFirst().get().isDeleted()).isFalse();
@ -338,30 +340,30 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
//FIXME should be created on the fly.
// CreateTypeValue dossierDictionaryType = MagicConverter.convert(type, CreateTypeValue.class);
// dictionaryClient.addType(dossierDictionaryType, dossier.getDossierId());
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getDossierId(), DictionaryEntryType.ENTRY);
// dictionaryClient.addType(dossierDictionaryType, dossier.getId());
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of("Luke Skywalker"), false, dossier.getId(), DictionaryEntryType.ENTRY);
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").isDictionaryEntry(true).isDossierDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id("AnnotationId").type("test").value("Luke Skywalker").entryType(EntryType.ENTITY).state(EntryState.APPLIED).dictionaryEntry(true).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
manualRedactionClient.removeRedactionBulk(dossier.getId(),
file.getId(),
Set.of(RemoveRedactionRequestModel.builder().annotationId("AnnotationId").removeFromDictionary(true).removeFromAllDossiers(true).build())).get(0);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId(), dossier.getDossierId()), null);
var dossierDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId(), dossier.getId()), null);
assertThat(dossierDictionary.getEntries().size()).isEqualTo(1);
assertThat(dossierDictionary.getEntries().get(0).isDeleted()).isTrue();
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getDossierTemplateId()), null);
var dossierTemplateDictionary = internalDictionaryClient.getDictionaryForType(toTypeId(type.getType(), dossierTemplate.getId()), null);
assertThat(dossierTemplateDictionary.getEntries().size()).isEqualTo(0);
}
@ -411,48 +413,54 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build();
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getDossierId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var loadedRedactionsFile1 = manualRedactionClient.getManualRedactions(file1.getDossierId(), file1.getFileId());
var redactionLog1 = new RedactionLog(1,
var entityLog1 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(0).getAnnotationId())
.type(typeDosDict.getType())
.value("test redaction in dossier")
.isDossierDictionaryEntry(true)
.dossierDictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build(),
RedactionLogEntry.builder()
EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.REDACTION_LOG, redactionLog1);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.ENTITY_LOG, entityLog1);
var redactionRequest1 = RedactionRequest.builder().dossierId(file1.getDossierId()).fileId(file1.getFileId()).dossierTemplateId(file1.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file1.getDossierId(), file1.getFileId())).thenReturn(redactionLog1);
when(entityLogService.getEntityLog(file1.getDossierId(), file1.getFileId())).thenReturn(entityLog1);
var redactionLog2 = new RedactionLog(1,
var entityLog2 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.REDACTION_LOG, redactionLog2);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.ENTITY_LOG, entityLog2);
var redactionRequest2 = RedactionRequest.builder().dossierId(file2.getDossierId()).fileId(file2.getFileId()).dossierTemplateId(file2.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file2.getDossierId(), file2.getFileId())).thenReturn(redactionLog2);
when(entityLogService.getEntityLog(file2.getDossierId(), file2.getFileId())).thenReturn(entityLog2);
// resize redaction in dossier 1
var resizeRedactionDosAndAddToAllDos = ResizeRedactionRequestModel.builder()
@ -463,53 +471,53 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.addToAllDossiers(true)
.build();
manualRedactionClient.resizeRedactionBulk(dossier1.getDossierId(), file1.getFileId(), Set.of(resizeRedactionDosAndAddToAllDos));
manualRedactionClient.resizeRedactionBulk(dossier1.getId(), file1.getFileId(), Set.of(resizeRedactionDosAndAddToAllDos));
loadedRedactionsFile1 = manualRedactionClient.getManualRedactions(file1.getDossierId(), file1.getFileId());
assertThat(loadedRedactionsFile1.getResizeRedactions()).hasSize(1);
assertThat(loadedRedactionsFile1.getResizeRedactions().stream().toList().get(0).getValue()).isEqualTo("test redaction in dossier dictionary");
var dictEntries = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntries = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier dictionary",
DictionaryEntryType.ENTRY);
assertThat(dictEntries.stream().filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier dictionary"))).isNotEmpty();
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier");
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier dictionary");
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier1.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier template");
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosDictInDossier1.getEntries()).hasSize(2);
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier");
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(1)).isEqualTo("test redaction in dossier dictionary");
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier template");
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosDictInDossier2.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier dictionary");
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier template");
}
@ -560,48 +568,54 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build();
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getDossierId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var loadedRedactionsFile1 = manualRedactionClient.getManualRedactions(file1.getDossierId(), file1.getFileId());
var redactionLog1 = new RedactionLog(1,
var entityLog1 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(0).getAnnotationId())
.type(typeDosDict.getType())
.value("test redaction in dossier yayy")
.isDossierDictionaryEntry(true)
.dossierDictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build(),
RedactionLogEntry.builder()
EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template yayy")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.REDACTION_LOG, redactionLog1);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.ENTITY_LOG, entityLog1);
var redactionRequest1 = RedactionRequest.builder().dossierId(file1.getDossierId()).fileId(file1.getFileId()).dossierTemplateId(file1.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file1.getDossierId(), file1.getFileId())).thenReturn(redactionLog1);
when(entityLogService.getEntityLog(file1.getDossierId(), file1.getFileId())).thenReturn(entityLog1);
var redactionLog2 = new RedactionLog(1,
var entityLog2 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template yayy")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.REDACTION_LOG, redactionLog2);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.ENTITY_LOG, entityLog2);
var redactionRequest2 = RedactionRequest.builder().dossierId(file2.getDossierId()).fileId(file2.getFileId()).dossierTemplateId(file2.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file2.getDossierId(), file2.getFileId())).thenReturn(redactionLog2);
when(entityLogService.getEntityLog(file2.getDossierId(), file2.getFileId())).thenReturn(entityLog2);
// resize redaction in dossier 1
var resizeRedactionDosAndAddToAllDos = ResizeRedactionRequestModel.builder()
@ -612,60 +626,60 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.addToAllDossiers(true)
.build();
manualRedactionClient.resizeRedactionBulk(dossier1.getDossierId(), file1.getFileId(), Set.of(resizeRedactionDosAndAddToAllDos));
manualRedactionClient.resizeRedactionBulk(dossier1.getId(), file1.getFileId(), Set.of(resizeRedactionDosAndAddToAllDos));
loadedRedactionsFile1 = manualRedactionClient.getManualRedactions(file1.getDossierId(), file1.getFileId());
assertThat(loadedRedactionsFile1.getResizeRedactions()).hasSize(1);
assertThat(loadedRedactionsFile1.getResizeRedactions().stream().toList().get(0).getValue()).isEqualTo("test redaction in dossier");
var dictEntriesOldValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntriesOldValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier yayy",
DictionaryEntryType.ENTRY);
assertThat(dictEntriesOldValue.stream()
.filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier yayy") && dictionaryEntry.isDeleted())).hasSize(1);
assertThat(dictEntriesOldValue.stream()
.filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier yayy") && !dictionaryEntry.isDeleted())).hasSize(1);
var dictEntriesNewValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntriesNewValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier",
DictionaryEntryType.ENTRY);
assertThat(dictEntriesNewValue.stream().filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier"))).isNotEmpty();
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier yayy");
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier");
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier1.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier template yayy");
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosDictInDossier1.getEntries()).hasSize(2);
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier");
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(1)).isEqualTo("test redaction in dossier yayy");
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier template yayy");
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosDictInDossier2.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier");
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier template yayy");
}
@ -716,47 +730,53 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build();
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getDossierId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var redactionLog1 = new RedactionLog(1,
var entityLog1 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(0).getAnnotationId())
.type(typeDosDict.getType())
.value("test redaction in dossier")
.isDossierDictionaryEntry(true)
.dossierDictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build(),
RedactionLogEntry.builder()
EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.REDACTION_LOG, redactionLog1);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.ENTITY_LOG, entityLog1);
var redactionRequest1 = RedactionRequest.builder().dossierId(file1.getDossierId()).fileId(file1.getFileId()).dossierTemplateId(file1.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file1.getDossierId(), file1.getFileId())).thenReturn(redactionLog1);
when(entityLogService.getEntityLog(file1.getDossierId(), file1.getFileId())).thenReturn(entityLog1);
var redactionLog2 = new RedactionLog(1,
var entityLog2 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.REDACTION_LOG, redactionLog2);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.ENTITY_LOG, entityLog2);
var redactionRequest2 = RedactionRequest.builder().dossierId(file2.getDossierId()).fileId(file2.getFileId()).dossierTemplateId(file2.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file2.getDossierId(), file2.getFileId())).thenReturn(redactionLog2);
when(entityLogService.getEntityLog(file2.getDossierId(), file2.getFileId())).thenReturn(entityLog2);
// resize redaction in dossier dict
var resizeRedactionDosTemp = ResizeRedactionRequestModel.builder()
@ -767,52 +787,52 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.addToAllDossiers(true)
.build();
var resizeRedactions = manualRedactionClient.resizeRedactionBulk(dossier2.getDossierId(), file2.getFileId(), Set.of(resizeRedactionDosTemp));
var resizeRedactions = manualRedactionClient.resizeRedactionBulk(dossier2.getId(), file2.getFileId(), Set.of(resizeRedactionDosTemp));
var loadedRedactionsFile2 = manualRedactionClient.getManualRedactions(file2.getDossierId(), file2.getFileId());
assertThat(loadedRedactionsFile2.getResizeRedactions()).hasSize(1);
assertThat(loadedRedactionsFile2.getResizeRedactions().stream().toList().get(0).getValue()).isEqualTo("test redaction in dossier template dictionary");
var dictEntries = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntries = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier template dictionary",
DictionaryEntryType.ENTRY);
assertThat(dictEntries.stream().filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier template dictionary"))).hasSize(1);
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier");
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier1.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries()).hasSize(2);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier template");
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries().get(1)).isEqualTo("test redaction in dossier template dictionary");
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier");
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries()).hasSize(2);
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier template");
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries().get(1)).isEqualTo("test redaction in dossier template dictionary");
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosDictInDossier2.getEntries()).isEmpty();
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries()).hasSize(2);
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier template");
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries().get(1)).isEqualTo("test redaction in dossier template dictionary");
@ -864,47 +884,53 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.sourceId("SourceId")
.build();
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getDossierId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var addRedactions = manualRedactionClient.addRedactionBulk(dossier1.getId(), file1.getId(), Set.of(redactionDos, redactionDosTempDict));
var redactionLog1 = new RedactionLog(1,
var entityLog1 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(0).getAnnotationId())
.type(typeDosDict.getType())
.value("test redaction in dossier yayy")
.isDossierDictionaryEntry(true)
.dossierDictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build(),
RedactionLogEntry.builder()
EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template yayy")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.REDACTION_LOG, redactionLog1);
fileManagementStorageService.storeJSONObject(dossier1.getId(), file1.getId(), FileType.ENTITY_LOG, entityLog1);
var redactionRequest1 = RedactionRequest.builder().dossierId(file1.getDossierId()).fileId(file1.getFileId()).dossierTemplateId(file1.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file1.getDossierId(), file1.getFileId())).thenReturn(redactionLog1);
when(entityLogService.getEntityLog(file1.getDossierId(), file1.getFileId())).thenReturn(entityLog1);
var redactionLog2 = new RedactionLog(1,
var entityLog2 = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder()
List.of(EntityLogEntry.builder()
.id(addRedactions.get(1).getAnnotationId())
.type(typeDosTempDict.getType())
.value("test redaction in dossier template yayy")
.isDictionaryEntry(true)
.dictionaryEntry(true)
.entryType(EntryType.ENTITY)
.state(EntryState.APPLIED)
.build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.REDACTION_LOG, redactionLog2);
fileManagementStorageService.storeJSONObject(dossier2.getId(), file2.getId(), FileType.ENTITY_LOG, entityLog2);
var redactionRequest2 = RedactionRequest.builder().dossierId(file2.getDossierId()).fileId(file2.getFileId()).dossierTemplateId(file2.getDossierTemplateId()).build();
when(redactionLogService.getRedactionLog(file2.getDossierId(), file2.getFileId())).thenReturn(redactionLog2);
when(entityLogService.getEntityLog(file2.getDossierId(), file2.getFileId())).thenReturn(entityLog2);
// resize redaction in dossier dict
var resizeRedactionDosTemp = ResizeRedactionRequestModel.builder()
@ -915,57 +941,57 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
.addToAllDossiers(true)
.build();
var resizeRedactions = manualRedactionClient.resizeRedactionBulk(dossier2.getDossierId(), file2.getFileId(), Set.of(resizeRedactionDosTemp));
var resizeRedactions = manualRedactionClient.resizeRedactionBulk(dossier2.getId(), file2.getFileId(), Set.of(resizeRedactionDosTemp));
var loadedRedactionsFile2 = manualRedactionClient.getManualRedactions(file2.getDossierId(), file2.getFileId());
assertThat(loadedRedactionsFile2.getResizeRedactions()).hasSize(1);
assertThat(loadedRedactionsFile2.getResizeRedactions().stream().toList().get(0).getValue()).isEqualTo("test redaction in dossier template");
var dictEntriesOldValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntriesOldValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier template yayy",
DictionaryEntryType.ENTRY);
assertThat(dictEntriesOldValue.stream()
.filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier template yayy") && dictionaryEntry.isDeleted())).hasSize(3);
assertThat(dictEntriesOldValue.stream()
.filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier template yayy") && !dictionaryEntry.isDeleted())).isEmpty();
var dictEntriesNewValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getDossierTemplateId(),
var dictEntriesNewValue = dictionaryManagementService.getAllEntriesInDossierTemplate(dossierTemplate.getId(),
"test redaction in dossier template",
DictionaryEntryType.ENTRY);
assertThat(dictEntriesNewValue.stream().filter(dictionaryEntry -> dictionaryEntry.getValue().equals("test redaction in dossier template"))).isNotEmpty();
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier yayy");
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosDictInDossierTemplate.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var dictionaryOfTypeDosTempDictInDossier1 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier1.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var dictionaryOfTypeDosTempDictInDossier2 = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(dictionaryOfTypeDosTempDictInDossier2.getEntries()).isEmpty();
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getDossierTemplateId(), null);
var dictionaryOfTypeDosTempDictInDossierTemplate = dictionaryClient.getDictionaryForType(typeDosTempDict.getType(), dossierTemplate.getId(), null);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries()).hasSize(1);
assertThat(dictionaryOfTypeDosTempDictInDossierTemplate.getEntries().get(0)).isEqualTo("test redaction in dossier template");
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosDictInDossier1.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier yayy");
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getDossierId());
var mergedDictForTypeDosTempDictInDossier1 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier1.getDossierTemplateId(), dossier1.getId());
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier1.getEntries().get(0)).isEqualTo("test redaction in dossier template");
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosDictInDossier2.getEntries()).isEmpty();
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getDossierId());
var mergedDictForTypeDosTempDictInDossier2 = dictionaryClient.getMergedDictionaries(typeDosTempDict.getType(), dossier2.getDossierTemplateId(), dossier2.getId());
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries()).hasSize(1);
assertThat(mergedDictForTypeDosTempDictInDossier2.getEntries().get(0)).isEqualTo("test redaction in dossier template");
}
@ -989,30 +1015,30 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
entries.add(darthVader);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), entries, false, null, DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of(lukeSkywalker), false, dossier.getDossierId(), DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), List.of(lukeSkywalker), false, dossier.getId(), DictionaryEntryType.ENTRY);
Dictionary dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker, darthVader);
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker);
Dictionary dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).isEmpty();
Dictionary dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
Dictionary dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).isEmpty();
var annotationId = "AnnotationId";
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id(annotationId).type(type.getType()).value(lukeSkywalker).isDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id(annotationId).type(type.getType()).value(lukeSkywalker).dictionaryEntry(true).entryType(EntryType.ENTITY).state(EntryState.APPLIED).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
manualRedactionClient.recategorizeBulk(dossier.getId(),
file.getId(),
@ -1020,24 +1046,24 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder(darthVader);
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).isEmpty();
dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).containsExactlyInAnyOrder(lukeSkywalker);
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).isEmpty();
manualRedactionClient.undo(dossier.getDossierId(), file.getFileId(), Set.of(annotationId));
manualRedactionClient.undo(dossier.getId(), file.getFileId(), Set.of(annotationId));
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker, darthVader);
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker);
dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).isEmpty();
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).isEmpty();
}
@ -1059,30 +1085,30 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
entries.add(lukeSkywalker);
entries.add(darthVader);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), entries, false, dossier.getDossierId(), DictionaryEntryType.ENTRY);
dictionaryClient.addEntry(type.getType(), type.getDossierTemplateId(), entries, false, dossier.getId(), DictionaryEntryType.ENTRY);
Dictionary dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).isEmpty();
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
Dictionary dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker, darthVader);
Dictionary dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).isEmpty();
Dictionary dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
Dictionary dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).isEmpty();
var annotationId = "AnnotationId";
var redactionLog = new RedactionLog(1,
var entityLog = new EntityLog(1,
1,
List.of(RedactionLogEntry.builder().id(annotationId).type(type.getType()).value(lukeSkywalker).isDictionaryEntry(true).build()),
List.of(EntityLogEntry.builder().id(annotationId).type(type.getType()).value(lukeSkywalker).dictionaryEntry(true).entryType(EntryType.ENTITY).state(EntryState.APPLIED).build()),
null,
0,
0,
0,
0);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.REDACTION_LOG, redactionLog);
fileManagementStorageService.storeJSONObject(dossier.getId(), file.getId(), FileType.ENTITY_LOG, entityLog);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(redactionLog);
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(entityLog);
manualRedactionClient.recategorizeBulk(dossier.getId(),
file.getId(),
@ -1090,24 +1116,24 @@ public class ManualRedactionTest extends AbstractPersistenceServerServiceTest {
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).isEmpty();
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder(darthVader);
dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).isEmpty();
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).containsExactlyInAnyOrder(lukeSkywalker);
manualRedactionClient.undo(dossier.getDossierId(), file.getFileId(), Set.of(annotationId));
manualRedactionClient.undo(dossier.getId(), file.getFileId(), Set.of(annotationId));
dossierTemplateDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary.getEntries()).isEmpty();
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary = dictionaryClient.getDictionaryForType(type.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary.getEntries()).containsExactlyInAnyOrder(lukeSkywalker, darthVader);
dossierTemplateDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), null);
assertThat(dossierTemplateDictionary2.getEntries()).isEmpty();
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getDossierId());
dossierDictionary2 = dictionaryClient.getDictionaryForType(type2.getType(), type.getDossierTemplateId(), dossier.getId());
assertThat(dossierDictionary2.getEntries()).isEmpty();
}

View File

@ -12,16 +12,16 @@ import com.iqser.red.service.persistence.management.v1.processor.client.tenantus
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.ApplicationConfigurationEntity;
import com.iqser.red.service.persistence.management.v1.processor.roles.ApplicationRoles;
import com.iqser.red.service.persistence.management.v1.processor.service.ApplicationConfigService;
import com.iqser.red.service.persistence.management.v1.processor.service.EntityLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.FileManagementStorageService;
import com.iqser.red.service.persistence.management.v1.processor.service.RedactionLogService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.*;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.annotationentity.*;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.dictionaryentry.EntryRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.dictionaryentry.FalsePositiveEntryRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.dictionaryentry.FalseRecommendationEntryRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.users.UserService;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.ApplicationConfig;
import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlog.RedactionLog;
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
import com.iqser.red.storage.commons.service.StorageService;
import com.iqser.red.storage.commons.utils.FileSystemBackedStorageService;
@ -92,7 +92,7 @@ public abstract class AbstractPersistenceServerServiceTest {
@MockBean
protected SearchClient searchClient;
@MockBean
protected RedactionLogService redactionLogService;
protected EntityLogService entityLogService;
@MockBean
protected PDFTronClient pdfTronRedactionClient;
@Autowired
@ -245,7 +245,7 @@ public abstract class AbstractPersistenceServerServiceTest {
// doNothing().when(pdfTronRedactionClient).testDigitalCurrentSignature(Mockito.any());
when(amqpAdmin.getQueueInfo(Mockito.any())).thenReturn(null);
when(redactionLogService.getRedactionLog(Mockito.any(), Mockito.any())).thenReturn(new RedactionLog(1, 1, Lists.newArrayList(), null, 0, 0, 0, 0));
when(entityLogService.getEntityLog(Mockito.any(), Mockito.any())).thenReturn(new EntityLog(1, 1, Lists.newArrayList(), null, 0, 0, 0, 0));
when(redactionClient.testRules(Mockito.any())).thenReturn(DroolsSyntaxValidation.builder().droolsSyntaxErrorMessages(Collections.emptyList()).build());
}