Pull request #53: RED-2386: Avoid insert duplications to dictionaries
Merge in RED/persistence-service from RED-2386 to master * commit 'f2e1f409f915ca3d83ddba09ff8d8163fe60bd08': RED-2386: Avoid insert duplications to dictionaries
This commit is contained in:
commit
b00696c636
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user