From a896c513354a05d258123cba8c54eaaa185634b3 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Mon, 14 Mar 2022 13:42:43 +0200 Subject: [PATCH] DictionaryModel Incremental build --- .../redaction/service/DictionaryService.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 77ee9094..07947dfd 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 @@ -87,8 +87,24 @@ public class DictionaryService { List dictionary = typeResponse .stream() - .map(t -> new DictionaryModel(t.getType(), t.getRank(), convertColor(t.getHexColor()), t.isCaseInsensitive(), t - .isHint(), t.isRecommendation(), convertEntries(t.getId(), currentVersion), new HashSet<>(), dossierId != null)) + .map(t -> { + + Optional oldModel; + if (dossierId == null) { + oldModel = dictionariesByDossierTemplate.get(dossierTemplateId).getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny(); + } else { + oldModel = dictionariesByDossier.get(dossierId).getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny(); + } + + Set entries = new HashSet<>(); + // add old entries from existing DictionaryModel + oldModel.ifPresent(dictionaryModel -> entries.addAll(dictionaryModel.getEntries())); + // Add Increments + entries.addAll(convertEntries(t.getId(), currentVersion)); + + return new DictionaryModel(t.getType(), t.getRank(), convertColor(t.getHexColor()), t.isCaseInsensitive(), t + .isHint(), t.isRecommendation(), entries, new HashSet<>(), dossierId != null); + }) .sorted(Comparator.comparingInt(DictionaryModel::getRank).reversed()) .collect(Collectors.toList());