From 146b0f5c8eb1fe8d8c530b940049e40a6eebc80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20Eifl=C3=A4nder?= Date: Wed, 22 Sep 2021 15:11:14 +0200 Subject: [PATCH] RED-2228: Use persistence-service instead of configuration/file-management-service --- .../redaction-service-api-v1/pom.xml | 10 +- .../redaction/v1/model/RedactionLog.java | 5 +- .../redaction-service-server-v1/pom.xml | 15 --- .../v1/server/client/DictionaryClient.java | 5 +- .../FileStatusProcessingUpdateClient.java | 5 +- .../v1/server/client/LegalBasisClient.java | 5 +- .../v1/server/client/RulesClient.java | 5 +- .../controller/RedactionController.java | 4 +- .../redaction/model/DictionaryModel.java | 3 +- .../redaction/service/AnalyzeService.java | 2 +- .../redaction/service/DictionaryService.java | 35 +++--- .../service/DroolsExecutionService.java | 7 +- .../redaction/service/NerAnalyserService.java | 2 +- .../storage/RedactionStorageService.java | 2 +- .../src/main/resources/application.yml | 3 +- .../v1/server/RedactionIntegrationTest.java | 104 +++++++++--------- .../src/test/resources/application.yml | 3 +- 17 files changed, 98 insertions(+), 117 deletions(-) diff --git a/redaction-service-v1/redaction-service-api-v1/pom.xml b/redaction-service-v1/redaction-service-api-v1/pom.xml index e4b7cd36..79cd421c 100644 --- a/redaction-service-v1/redaction-service-api-v1/pom.xml +++ b/redaction-service-v1/redaction-service-api-v1/pom.xml @@ -19,14 +19,8 @@ com.iqser.red.service - configuration-service-api-v1 - 2.11.0 - - - com.iqser.red.service - file-management-service-api-v1 - - + persistence-service-api-v1 + 0.4.0 diff --git a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/RedactionLog.java b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/RedactionLog.java index 942e36a6..2e404431 100644 --- a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/RedactionLog.java +++ b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/RedactionLog.java @@ -1,11 +1,12 @@ package com.iqser.red.service.redaction.v1.model; -import com.iqser.red.service.configuration.v1.api.model.LegalBasisMapping; import lombok.AllArgsConstructor; import lombok.Data; import java.util.List; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.LegalBasis; + @Data @AllArgsConstructor public class RedactionLog { @@ -18,7 +19,7 @@ public class RedactionLog { private long analysisVersion; private List redactionLogEntry; - private List legalBasis; + private List legalBasis; private long dictionaryVersion = -1; private long dossierDictionaryVersion = -1; diff --git a/redaction-service-v1/redaction-service-server-v1/pom.xml b/redaction-service-v1/redaction-service-server-v1/pom.xml index 67e97d07..52a51cb7 100644 --- a/redaction-service-v1/redaction-service-server-v1/pom.xml +++ b/redaction-service-v1/redaction-service-server-v1/pom.xml @@ -21,21 +21,6 @@ redaction-service-api-v1 ${project.version} - - com.iqser.red.service - file-management-service-api-v1 - 2.96.0 - - - com.iqser.red.service - redaction-service-api-v1 - - - com.iqser.red.service - configuration-service-api-v1 - - - org.drools drools-core diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/DictionaryClient.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/DictionaryClient.java index 422c97bb..2f8d8154 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/DictionaryClient.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/DictionaryClient.java @@ -1,8 +1,9 @@ package com.iqser.red.service.redaction.v1.server.client; -import com.iqser.red.service.configuration.v1.api.resource.DictionaryResource; import org.springframework.cloud.openfeign.FeignClient; -@FeignClient(name = "DictionaryResource", url = "${configuration-service.url}") +import com.iqser.red.service.persistence.service.v1.api.resources.DictionaryResource; + +@FeignClient(name = "DictionaryResource", url = "${persistence-service.url}") public interface DictionaryClient extends DictionaryResource { } \ No newline at end of file diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/FileStatusProcessingUpdateClient.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/FileStatusProcessingUpdateClient.java index 41182a31..dde47a5e 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/FileStatusProcessingUpdateClient.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/FileStatusProcessingUpdateClient.java @@ -1,9 +1,10 @@ package com.iqser.red.service.redaction.v1.server.client; -import com.iqser.red.service.file.management.v1.api.resources.FileStatusProcessingUpdateResource; import org.springframework.cloud.openfeign.FeignClient; -@FeignClient(name = "FileStatusProcessingUpdateResource", url = "${file-management-service.url}") +import com.iqser.red.service.persistence.service.v1.api.resources.FileStatusProcessingUpdateResource; + +@FeignClient(name = "FileStatusProcessingUpdateResource", url = "${persistence-service.url}") public interface FileStatusProcessingUpdateClient extends FileStatusProcessingUpdateResource { } diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/LegalBasisClient.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/LegalBasisClient.java index 1a68ab35..f51ca689 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/LegalBasisClient.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/LegalBasisClient.java @@ -1,8 +1,9 @@ package com.iqser.red.service.redaction.v1.server.client; -import com.iqser.red.service.configuration.v1.api.resource.LegalBasisMappingResource; import org.springframework.cloud.openfeign.FeignClient; -@FeignClient(name = "LegalBasisMappingResource", url = "${configuration-service.url}") +import com.iqser.red.service.persistence.service.v1.api.resources.LegalBasisMappingResource; + +@FeignClient(name = "LegalBasisMappingResource", url = "${persistence-service.url}") public interface LegalBasisClient extends LegalBasisMappingResource { } diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/RulesClient.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/RulesClient.java index 35ffba79..5e8fb5c2 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/RulesClient.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/client/RulesClient.java @@ -1,8 +1,9 @@ package com.iqser.red.service.redaction.v1.server.client; -import com.iqser.red.service.configuration.v1.api.resource.RulesResource; import org.springframework.cloud.openfeign.FeignClient; -@FeignClient(name = "RulesResource", url = "${configuration-service.url}") +import com.iqser.red.service.persistence.service.v1.api.resources.RulesResource; + +@FeignClient(name = "RulesResource", url = "${persistence-service.url}") public interface RulesClient extends RulesResource { } diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/controller/RedactionController.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/controller/RedactionController.java index 2ea691d7..c47022d0 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/controller/RedactionController.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/controller/RedactionController.java @@ -1,6 +1,6 @@ package com.iqser.red.service.redaction.v1.server.controller; -import com.iqser.red.service.file.management.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.FileType; import com.iqser.red.service.redaction.v1.model.*; import com.iqser.red.service.redaction.v1.resources.RedactionResource; import com.iqser.red.service.redaction.v1.server.classification.model.Document; @@ -11,7 +11,6 @@ import com.iqser.red.service.redaction.v1.server.redaction.service.DictionarySer import com.iqser.red.service.redaction.v1.server.redaction.service.DroolsExecutionService; import com.iqser.red.service.redaction.v1.server.redaction.service.RedactionLogMergeService; import com.iqser.red.service.redaction.v1.server.segmentation.PdfSegmentationService; -import com.iqser.red.service.redaction.v1.server.settings.RedactionServiceSettings; import com.iqser.red.service.redaction.v1.server.storage.RedactionStorageService; import com.iqser.red.service.redaction.v1.server.tableextraction.model.AbstractTextContainer; import com.iqser.red.service.redaction.v1.server.tableextraction.model.Table; @@ -20,7 +19,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.pdmodel.PDDocument; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/DictionaryModel.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/DictionaryModel.java index c3a80b96..e6c0eb09 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/DictionaryModel.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/DictionaryModel.java @@ -1,7 +1,6 @@ package com.iqser.red.service.redaction.v1.server.redaction.model; -import com.iqser.red.service.configuration.v1.api.model.DictionaryEntry; import lombok.AllArgsConstructor; import lombok.Data; @@ -9,6 +8,8 @@ import java.io.Serializable; import java.util.Set; import java.util.stream.Collectors; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.DictionaryEntry; + @Data @AllArgsConstructor public class DictionaryModel implements Serializable { diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/AnalyzeService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/AnalyzeService.java index c9dc03c8..85672d3e 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/AnalyzeService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/AnalyzeService.java @@ -12,7 +12,7 @@ import org.kie.api.runtime.KieContainer; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; -import com.iqser.red.service.file.management.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.FileType; import com.iqser.red.service.redaction.v1.model.AnalyzeRequest; import com.iqser.red.service.redaction.v1.model.AnalyzeResult; import com.iqser.red.service.redaction.v1.model.IdRemoval; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DictionaryService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DictionaryService.java index 9631d5b8..2e0d641d 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DictionaryService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DictionaryService.java @@ -1,9 +1,7 @@ package com.iqser.red.service.redaction.v1.server.redaction.service; -import com.iqser.red.service.configuration.v1.api.model.Colors; -import com.iqser.red.service.configuration.v1.api.model.DictionaryEntry; -import com.iqser.red.service.configuration.v1.api.model.TypeResponse; -import com.iqser.red.service.configuration.v1.api.model.TypeResult; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.Colors; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.DictionaryEntry; import com.iqser.red.service.redaction.v1.server.client.DictionaryClient; import com.iqser.red.service.redaction.v1.server.redaction.model.Dictionary; import com.iqser.red.service.redaction.v1.server.redaction.model.*; @@ -18,7 +16,6 @@ import java.awt.Color; import java.util.*; import java.util.stream.Collectors; -import static com.iqser.red.service.configuration.v1.api.resource.DictionaryResource.GLOBAL_DOSSIER; @Slf4j @Service @@ -34,13 +31,13 @@ public class DictionaryService { public DictionaryVersion updateDictionary(String dossierTemplateId, String dossierId) { log.info("Updating dictionary data for dossierTemplate {} and dossier {}", dossierTemplateId, dossierId); - long dossierTemplateDictionaryVersion = dictionaryClient.getVersion(dossierTemplateId, GLOBAL_DOSSIER); + long dossierTemplateDictionaryVersion = dictionaryClient.getVersion(dossierTemplateId); var dossierTemplateDictionary = dictionariesByDossierTemplate.get(dossierTemplateId); if (dossierTemplateDictionary == null || dossierTemplateDictionaryVersion > dossierTemplateDictionary.getDictionaryVersion()) { - updateDictionaryEntry(dossierTemplateId, dossierTemplateDictionaryVersion, GLOBAL_DOSSIER); + updateDictionaryEntry(dossierTemplateId, dossierTemplateDictionaryVersion, null); } - long dossierDictionaryVersion = dictionaryClient.getVersion(dossierTemplateId, dossierId); + long dossierDictionaryVersion = dictionaryClient.getVersionForDossier(dossierId); var dossierDictionary = dictionariesByDossier.get(dossierId); if (dossierDictionary == null || dossierDictionaryVersion > dossierDictionary.getDictionaryVersion()) { updateDictionaryEntry(dossierTemplateId, dossierDictionaryVersion, dossierId); @@ -84,13 +81,13 @@ public class DictionaryService { try { DictionaryRepresentation dictionaryRepresentation = new DictionaryRepresentation(); - TypeResponse typeResponse = dictionaryClient.getAllTypes(dossierTemplateId, dossierId); - if (typeResponse != null && CollectionUtils.isNotEmpty(typeResponse.getTypes())) { + var typeResponse = dossierId == null ? dictionaryClient.getAllTypesForDossierTemplate(dossierTemplateId) : dictionaryClient.getAllTypesForDossier(dossierId); + if (typeResponse != null && CollectionUtils.isNotEmpty(typeResponse)) { - List dictionary = typeResponse.getTypes() + List dictionary = typeResponse .stream() .map(t -> new DictionaryModel(t.getType(), t.getRank(), convertColor(t.getHexColor()), t.isCaseInsensitive(), t - .isHint(), t.isRecommendation(), convertEntries(t, dossierId), new HashSet<>(), !dossierId.equals(GLOBAL_DOSSIER))) + .isHint(), t.isRecommendation(), convertEntries(t.getId()), new HashSet<>(), dossierId != null)) .sorted(Comparator.comparingInt(DictionaryModel::getRank).reversed()) .collect(Collectors.toList()); @@ -106,7 +103,7 @@ public class DictionaryService { dictionaryRepresentation.setDictionaryVersion(version); dictionaryRepresentation.setDictionary(dictionary); - if(dossierId.equals(GLOBAL_DOSSIER)) { + if(dossierId == null) { dictionariesByDossierTemplate.put(dossierTemplateId, dictionaryRepresentation); } else { dictionariesByDossier.put(dossierId, dictionaryRepresentation); @@ -123,8 +120,8 @@ public class DictionaryService { dictionary.getDictionaryModels().forEach(dm -> { if (dm.isRecommendation() && !dm.getLocalEntries().isEmpty()) { - dictionaryClient.addEntries(dm.getType(), dossierTemplateId, new ArrayList<>(dm.getLocalEntries()), false, GLOBAL_DOSSIER); - long externalVersion = dictionaryClient.getVersion(dossierTemplateId, GLOBAL_DOSSIER); + dictionaryClient.addEntries(dm.getType(), new ArrayList<>(dm.getLocalEntries()), false); + long externalVersion = dictionaryClient.getVersion(dossierTemplateId); if (externalVersion == dictionary.getVersion().getDossierTemplateVersion() + 1) { dictionary.getVersion().setDossierTemplateVersion(externalVersion); } @@ -133,12 +130,14 @@ public class DictionaryService { } - private Set convertEntries(TypeResult t, String dossierId) { + private Set convertEntries(String typeId) { - Set entries = new HashSet<>(dictionaryClient.getDictionaryForType(t.getType(), t.getDossierTemplateId(), dossierId) + var type = dictionaryClient.getDictionaryForType(typeId); + + Set entries = new HashSet<>(type .getEntries()); - if (t.isCaseInsensitive()) { + if (type.isCaseInsensitive()) { entries.forEach(entry -> entry.setValue(entry.getValue().toLowerCase(Locale.ROOT))); } return entries; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DroolsExecutionService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DroolsExecutionService.java index 0ac53bc6..39893057 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DroolsExecutionService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/DroolsExecutionService.java @@ -1,6 +1,5 @@ package com.iqser.red.service.redaction.v1.server.redaction.service; -import com.iqser.red.service.configuration.v1.api.model.RulesResponse; import com.iqser.red.service.redaction.v1.server.client.RulesClient; import com.iqser.red.service.redaction.v1.server.exception.RulesValidationException; import com.iqser.red.service.redaction.v1.server.redaction.model.Section; @@ -76,13 +75,13 @@ public class DroolsExecutionService { try { - RulesResponse rules = rulesClient.getRules(dossierTemplateId); - if (rules == null || StringUtils.isEmpty(rules.getRules())) { + var rules = rulesClient.getRules(dossierTemplateId); + if (rules == null || StringUtils.isEmpty(rules.getValue())) { throw new RuntimeException("Rules cannot be empty."); } KieServices kieServices = KieServices.Factory.get(); - KieModule kieModule = getKieModule(dossierTemplateId, rules.getRules(), kieServices); + KieModule kieModule = getKieModule(dossierTemplateId, rules.getValue(), kieServices); var container = kieContainers.get(dossierTemplateId); if (container != null) { diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/NerAnalyserService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/NerAnalyserService.java index b7611b0d..32769c78 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/NerAnalyserService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/service/NerAnalyserService.java @@ -5,7 +5,7 @@ import java.util.stream.Collectors; import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Service; -import com.iqser.red.service.file.management.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.FileType; import com.iqser.red.service.redaction.v1.server.client.EntityRecognitionClient; import com.iqser.red.service.redaction.v1.server.client.model.EntityRecognitionRequest; import com.iqser.red.service.redaction.v1.server.client.model.EntityRecognitionSection; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/storage/RedactionStorageService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/storage/RedactionStorageService.java index 503b3a84..0ff294b0 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/storage/RedactionStorageService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/storage/RedactionStorageService.java @@ -1,7 +1,7 @@ package com.iqser.red.service.redaction.v1.server.storage; import com.fasterxml.jackson.databind.ObjectMapper; -import com.iqser.red.service.file.management.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.FileType; import com.iqser.red.service.redaction.v1.model.RedactionLog; import com.iqser.red.service.redaction.v1.model.SectionGrid; import com.iqser.red.service.redaction.v1.server.classification.model.Text; diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/resources/application.yml b/redaction-service-v1/redaction-service-server-v1/src/main/resources/application.yml index d8aa5ace..4d0ce6fe 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/resources/application.yml +++ b/redaction-service-v1/redaction-service-server-v1/src/main/resources/application.yml @@ -1,8 +1,7 @@ info: description: Redaction Service Server V1 -configuration-service.url: "http://configuration-service-v1:8080" -file-management-service.url: "http://file-management-service-v1:8080" +persistence-service.url: "http://persistence-service-v1:8080" image-service.url: "http://image-service-v1:8080" entity-recognition-service.url: "http://entity-recognition-service-v1:8080" diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java index eb29141a..8aa8e862 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java @@ -2,9 +2,11 @@ package com.iqser.red.service.redaction.v1.server; import com.amazonaws.services.s3.AmazonS3; import com.fasterxml.jackson.databind.ObjectMapper; -import com.iqser.red.service.configuration.v1.api.model.*; -import com.iqser.red.service.configuration.v1.api.resource.DictionaryResource; -import com.iqser.red.service.file.management.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.FileType; +import com.iqser.red.service.persistence.service.v1.api.model.JSONPrimitive; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.Colors; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.DictionaryEntry; +import com.iqser.red.service.persistence.service.v1.api.model.data.configuration.Type; import com.iqser.red.service.redaction.v1.model.*; import com.iqser.red.service.redaction.v1.server.classification.model.SectionText; import com.iqser.red.service.redaction.v1.server.client.DictionaryClient; @@ -176,69 +178,64 @@ public class RedactionIntegrationTest { @Before public void stubClients() { - //Testkommentar when(rulesClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(0L); - when(rulesClient.getRules(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(new RulesResponse(RULES)); + when(rulesClient.getRules(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(JSONPrimitive.of(RULES)); loadDictionaryForTest(); loadTypeForTest(); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(0L); - when(dictionaryClient.getAllTypes(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(TypeResponse - .builder() - .types(getTypeResponse()) - .build()); + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(0L); + when(dictionaryClient.getAllTypesForDossierTemplate(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getTypeResponse()); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, TEST_DOSSIER_ID)).thenReturn(0L); - when(dictionaryClient.getAllTypes(TEST_DOSSIER_TEMPLATE_ID, TEST_DOSSIER_ID)).thenReturn(TypeResponse.builder() - .types(List.of(TypeResult.builder() - .type(DOSSIER_REDACTIONS) - .dossierTemplateId(TEST_DOSSIER_TEMPLATE_ID) + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(0L); + when(dictionaryClient.getAllTypesForDossier(TEST_DOSSIER_ID)).thenReturn(List.of(Type.builder() + .id(DOSSIER_REDACTIONS +":"+ TEST_DOSSIER_TEMPLATE_ID) + .type(DOSSIER_REDACTIONS) + .dossierTemplateId(TEST_DOSSIER_ID) .hexColor("#ffe187") .isHint(hintTypeMap.get(DOSSIER_REDACTIONS)) .isCaseInsensitive(caseInSensitiveMap.get(DOSSIER_REDACTIONS)) .isRecommendation(recommendationTypeMap.get(DOSSIER_REDACTIONS)) .rank(rankTypeMap.get(DOSSIER_REDACTIONS)) - .build())) - .build()); + .build())); - when(dictionaryClient.getDictionaryForType(VERTEBRATE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(VERTEBRATE + ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(VERTEBRATE, false)); - when(dictionaryClient.getDictionaryForType(ADDRESS, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(ADDRESS+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(ADDRESS, false)); - when(dictionaryClient.getDictionaryForType(AUTHOR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(AUTHOR+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(AUTHOR, false)); - when(dictionaryClient.getDictionaryForType(SPONSOR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(SPONSOR+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(SPONSOR, false)); - when(dictionaryClient.getDictionaryForType(NO_REDACTION_INDICATOR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(NO_REDACTION_INDICATOR+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(NO_REDACTION_INDICATOR, false)); - when(dictionaryClient.getDictionaryForType(REDACTION_INDICATOR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(REDACTION_INDICATOR+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(REDACTION_INDICATOR, false)); - when(dictionaryClient.getDictionaryForType(HINT_ONLY, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(HINT_ONLY+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(HINT_ONLY, false)); - when(dictionaryClient.getDictionaryForType(MUST_REDACT, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(MUST_REDACT+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(MUST_REDACT, false)); - when(dictionaryClient.getDictionaryForType(PUBLISHED_INFORMATION, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(PUBLISHED_INFORMATION+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(PUBLISHED_INFORMATION, false)); - when(dictionaryClient.getDictionaryForType(TEST_METHOD, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(TEST_METHOD+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(TEST_METHOD, false)); - when(dictionaryClient.getDictionaryForType(PII, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(getDictionaryResponse(PII, false)); - when(dictionaryClient.getDictionaryForType(RECOMMENDATION_AUTHOR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(PII+ ":" + TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getDictionaryResponse(PII, false)); + when(dictionaryClient.getDictionaryForType(RECOMMENDATION_AUTHOR+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(RECOMMENDATION_AUTHOR, false)); - when(dictionaryClient.getDictionaryForType(RECOMMENDATION_ADDRESS, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(RECOMMENDATION_ADDRESS+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(RECOMMENDATION_ADDRESS, false)); - when(dictionaryClient.getDictionaryForType(FALSE_POSITIVE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(FALSE_POSITIVE+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(FALSE_POSITIVE, false)); - when(dictionaryClient.getDictionaryForType(PURITY, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(PURITY+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(PURITY, false)); - when(dictionaryClient.getDictionaryForType(IMAGE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(getDictionaryResponse(IMAGE, false)); - when(dictionaryClient.getDictionaryForType(OCR, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(getDictionaryResponse(OCR, false)); - when(dictionaryClient.getDictionaryForType(LOGO, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(getDictionaryResponse(LOGO, false)); - when(dictionaryClient.getDictionaryForType(SIGNATURE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(IMAGE+ ":" + TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getDictionaryResponse(IMAGE, false)); + when(dictionaryClient.getDictionaryForType(OCR+ ":" + TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getDictionaryResponse(OCR, false)); + when(dictionaryClient.getDictionaryForType(LOGO+ ":" + TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getDictionaryResponse(LOGO, false)); + when(dictionaryClient.getDictionaryForType(SIGNATURE+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(SIGNATURE, false)); - when(dictionaryClient.getDictionaryForType(FORMULA, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(FORMULA+ ":" + TEST_DOSSIER_TEMPLATE_ID)) .thenReturn(getDictionaryResponse(FORMULA, false)); - when(dictionaryClient.getDictionaryForType(DOSSIER_REDACTIONS, TEST_DOSSIER_TEMPLATE_ID, TEST_DOSSIER_ID)).thenReturn(getDictionaryResponse(DOSSIER_REDACTIONS, true)); + when(dictionaryClient.getDictionaryForType(DOSSIER_REDACTIONS+ ":" + TEST_DOSSIER_TEMPLATE_ID)).thenReturn(getDictionaryResponse(DOSSIER_REDACTIONS, true)); when(dictionaryClient.getColors(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(colors); } @@ -477,11 +474,12 @@ public class RedactionIntegrationTest { } - private List getTypeResponse() { + private List getTypeResponse() { return typeColorMap.entrySet() .stream() - .map(typeColor -> TypeResult.builder() + .map(typeColor -> Type.builder() + .id(typeColor.getKey() + ":" + TEST_DOSSIER_TEMPLATE_ID) .type(typeColor.getKey()) .dossierTemplateId(TEST_DOSSIER_TEMPLATE_ID) .hexColor(typeColor.getValue()) @@ -495,9 +493,10 @@ public class RedactionIntegrationTest { } - private DictionaryResponse getDictionaryResponse(String type, boolean isDossierDictionary) { + private Type getDictionaryResponse(String type, boolean isDossierDictionary) { - return DictionaryResponse.builder() + return Type.builder() + .id(type + ":" +TEST_DOSSIER_TEMPLATE_ID) .hexColor(typeColorMap.get(type)) .entries(isDossierDictionary ? toDictionaryEntry(dossierDictionary.get(type)) : toDictionaryEntry(dictionary .get(type))) @@ -513,8 +512,11 @@ public class RedactionIntegrationTest { List dictionaryEntries = new ArrayList<>(); entries.forEach(entry -> { - dictionaryEntries.add(new DictionaryEntry(entry, reanlysisVersions.containsKey(entry) ? reanlysisVersions.get(entry) : 0L, deleted - .contains(entry) ? true : false)); + dictionaryEntries.add(DictionaryEntry.builder() + .value(entry) + .version(reanlysisVersions.containsKey(entry) ? reanlysisVersions.get(entry) : 0L) + .deleted(deleted + .contains(entry) ? true : false).build()); }); return dictionaryEntries; } @@ -566,7 +568,7 @@ public class RedactionIntegrationTest { }); dictionary.get(AUTHOR).add("Drinking water"); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(1L); + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(1L); AnnotateResponse annotateResponse = redactionController.annotate(AnnotateRequest.builder() .dossierId(TEST_DOSSIER_ID) @@ -625,7 +627,7 @@ public class RedactionIntegrationTest { }); dictionary.get(AUTHOR).add("Drinking water"); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(1L); + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(1L); long rstart = System.currentTimeMillis(); analyzeService.reanalyze(request); @@ -730,12 +732,12 @@ public class RedactionIntegrationTest { reanlysisVersions.put("mouse", 3L); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(3L); + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(3L); - when(dictionaryClient.getDictionaryForType(VERTEBRATE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(VERTEBRATE)) .thenReturn(getDictionaryResponse(VERTEBRATE, false)); - when(dictionaryClient.getDictionaryForType(FALSE_POSITIVE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(FALSE_POSITIVE)) .thenReturn(getDictionaryResponse(FALSE_POSITIVE, false)); start = System.currentTimeMillis(); @@ -770,9 +772,9 @@ public class RedactionIntegrationTest { deleted.remove("mouse"); reanlysisVersions.put("mouse", 4L); - when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)).thenReturn(4L); + when(dictionaryClient.getVersion(TEST_DOSSIER_TEMPLATE_ID)).thenReturn(4L); - when(dictionaryClient.getDictionaryForType(VERTEBRATE, TEST_DOSSIER_TEMPLATE_ID, DictionaryResource.GLOBAL_DOSSIER)) + when(dictionaryClient.getDictionaryForType(VERTEBRATE)) .thenReturn(getDictionaryResponse(VERTEBRATE, false)); analyzeService.reanalyze(request); diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/resources/application.yml b/redaction-service-v1/redaction-service-server-v1/src/test/resources/application.yml index d8543d66..6cf7c053 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/resources/application.yml +++ b/redaction-service-v1/redaction-service-server-v1/src/test/resources/application.yml @@ -1,6 +1,5 @@ -configuration-service.url: "http://configuration-service-v1:8080" image-service.url: "http://image-service-v1:8080" -file-management-service.url: "http://file-management-service-v1:8080" +persistence-service.url: "http://persistence-service-v1:8080" entity-recognition-service.url: "localhost:8080" ribbon: