RED-2386: Avoid insert duplications to dictionaries

This commit is contained in:
Dominique Eifländer 2021-10-11 15:46:48 +02:00
parent a7e3b43bb9
commit f2e1f409f9

View File

@ -56,16 +56,15 @@ public class DictionaryController implements DictionaryResource {
// To check whether the type exists, type should not be added into database implicitly by addEntry.
Type typeResult = convert(dictionaryPersistenceService.getType(typeId), Type.class);
// List<String> entriesToSearch = new ArrayList<>();
var currentVersion = getCurrentVersion(typeResult);
List<String> existing = entryPersistenceService.getEntries(typeId)
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntryEntity::getValue)
.collect(toList());
if (removeCurrent) {
List<String> existing = entryPersistenceService.getEntries(typeId)
.stream()
.filter(e -> !e.isDeleted())
.map(DictionaryEntryEntity::getValue)
.collect(toList());
List<String> removed = new ArrayList<>(existing);
removed.removeAll(cleanEntries);
@ -76,11 +75,14 @@ public class DictionaryController implements DictionaryResource {
entryPersistenceService.deleteEntries(typeId, removed, currentVersion + 1);
entryPersistenceService.addEntry(typeId, added, currentVersion + 1);
// entriesToSearch.addAll(added);
// entriesToSearch.addAll(removed);
} else {
entryPersistenceService.addEntry(typeId, cleanEntries, currentVersion + 1);
// entriesToSearch.addAll(cleanEntries);
List<String> added = new ArrayList<>(cleanEntries);
added.removeAll(existing);
if(added.isEmpty()){
return;
}
entryPersistenceService.addEntry(typeId, added, currentVersion + 1);
}
dictionaryPersistenceService.incrementVersion(typeId);