DictionaryModel Incremental build

This commit is contained in:
Timo Bejan 2022-03-14 13:42:43 +02:00
parent 47a45e9650
commit a896c51335

View File

@ -87,8 +87,24 @@ public class DictionaryService {
List<DictionaryModel> 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<DictionaryModel> 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<DictionaryEntry> 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());