RED-7384: create shared models in persistence service #201

Merged
kilian.schuettler1 merged 3 commits from RED-7384 into master 2023-10-27 12:19:46 +02:00
5 changed files with 67 additions and 22 deletions

View File

@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(InternalApi.BASE_PATH+"/admin")
@RequestMapping(InternalApi.BASE_PATH + "/admin")
public class AdminInterfaceController {
private final FileManagementStorageService fileManagementStorageService;
@ -35,7 +35,6 @@ public class AdminInterfaceController {
@PostMapping("/reset-file")
public void resetFile(@RequestParam("dossierId") String dossierId, @RequestParam("fileId") String fileId) {
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);
@ -138,7 +137,6 @@ public class AdminInterfaceController {
var dossierId = file.getDossierId();
var fileId = file.getId();
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);

View File

@ -35,7 +35,6 @@ import com.iqser.red.service.persistence.management.v1.processor.exception.NotFo
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.utils.ColorUtils;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import com.iqser.red.service.persistence.service.v1.api.shared.model.CreateTypeValue;
import com.iqser.red.service.persistence.service.v1.api.shared.model.Dictionary;
import com.iqser.red.service.persistence.service.v1.api.shared.model.TypeResponse;
@ -44,6 +43,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.UpdateTypeV
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.configuration.Colors;
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.dossiertemplate.type.Type;
import com.knecon.fforesight.databasetenantcommons.providers.utils.MagicConverter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -307,6 +307,7 @@ public class DictionaryService {
}
}
@PreAuthorize("hasAuthority('" + READ_DICTIONARY_TYPES + "')")
public Dictionary getMergedDictionaryForType(String type, String dossierTemplateId, String dossierId) {
@ -327,7 +328,9 @@ public class DictionaryService {
}
}
private Dictionary convertMergedDictionaries (List<CommonsDictionaryModel> commonsDictionaries, String dossierTemplateId, String dossierId) {
private Dictionary convertMergedDictionaries(List<CommonsDictionaryModel> commonsDictionaries, String dossierTemplateId, String dossierId) {
List<Dictionary> dictionaries = new ArrayList<>();
commonsDictionaries.forEach(cdm -> {
var typeId = toTypeId(cdm.getType(), dossierTemplateId, dossierId);
@ -373,27 +376,29 @@ public class DictionaryService {
return dictionaries.get(0);
}
private List<CommonsDictionaryModel> convertType(TypeEntity typeEntity) {
return List.of(CommonsDictionaryModel.builder()
.type(typeEntity.getType())
.rank(typeEntity.getRank())
.color(ColorUtils.convertColor(typeEntity.getHexColor()))
.caseInsensitive(typeEntity.isCaseInsensitive())
.hint(typeEntity.isHint())
.entries(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.ENTRY))
.falsePositives(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_POSITIVE))
.falseRecommendations(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_RECOMMENDATION))
.build());
.type(typeEntity.getType())
.rank(typeEntity.getRank())
.color(ColorUtils.convertColor(typeEntity.getHexColor()))
.caseInsensitive(typeEntity.isCaseInsensitive())
.hint(typeEntity.isHint())
.entries(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.ENTRY))
.falsePositives(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_POSITIVE))
.falseRecommendations(getCommonsEntries(typeEntity.getId(), DictionaryEntryType.FALSE_RECOMMENDATION))
.build());
}
private Set<DictionaryEntryModel> getCommonsEntries(String typeId, DictionaryEntryType entryType) {
var entries = MagicConverter.convert(entryPersistenceService.getEntries(typeId, entryType, null), DictionaryEntry.class);
return CollectionUtils.isNotEmpty(entries) ? new HashSet<>(entries.stream()
.map(DictionaryEntryModel::new)
.collect(Collectors.toSet())) : new HashSet<>();
return CollectionUtils.isNotEmpty(entries) ? new HashSet<>(entries.stream().map(DictionaryEntryModel::new).collect(Collectors.toSet())) : new HashSet<>();
}
@PreAuthorize("hasAuthority('" + WRITE_COLORS + "')")
public void setColors(String dossierTemplateId, Colors colors) {
//validate all colors before setting them
@ -422,5 +427,4 @@ public class DictionaryService {
return MagicConverter.convert(colorsService.getColors(dossierTemplateId), Colors.class);
}
}

View File

@ -640,7 +640,6 @@ 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);
fileManagementStorageService.deleteObject(dossierId, fileId, FileType.DOCUMENT_PAGES);
@ -670,7 +669,6 @@ public class FileStatusService {
// 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);
// wipe comments

View File

@ -0,0 +1,43 @@
package com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.migration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MigratedIds {
List<Mapping> mappings;
public Map<String, String> buildOldToNewMapping() {
return mappings.stream().collect(Collectors.toMap(Mapping::oldId, Mapping::newId));
}
public Map<String, String> buildNewToOldMapping() {
return mappings.stream().collect(Collectors.toMap(Mapping::newId, Mapping::oldId));
}
public void addMapping(String oldId, String newId) {
mappings.add(new Mapping(oldId, newId));
}
private record Mapping(String oldId, String newId) {
}
}

View File

@ -9,7 +9,6 @@ public enum FileType {
VIEWER_DOCUMENT(".pdf"),
REDACTION_LOG(".json"),
SIMPLIFIED_TEXT(".json"),
SECTION_GRID(".json"),
TEXT(".json"), // deprecated file type, only present in legacy migrations
NER_ENTITIES(".json"),
IMAGE_INFO(".json"),
@ -24,7 +23,10 @@ public enum FileType {
DOCUMENT_POSITION(".json"),
DOCUMENT_PAGES(".json"),
ENTITY_LOG(".json"),
COMPONENT_LOG(".json");
COMPONENT_LOG(".json"),
MIGRATED_IDS(".json"),
@Deprecated(forRemoval = true) // still needed for migration to delete existing ones, can be removed as soon as migration is done
SECTION_GRID(".json");
@Getter
private final String extension;