RED-6744 - erge dossier and template dictionaries in redaction-service
- extend DictionaryEntry from persistence to use it in merging dictionaries and to override the hascode and equals - use this DictionaryEntryModel instead of DictionaryEntry
This commit is contained in:
parent
a6be7c9cfd
commit
2c6e397247
@ -17,10 +17,10 @@ import lombok.NoArgsConstructor;
|
||||
public class DictionaryEntries {
|
||||
|
||||
@Builder.Default
|
||||
Set<DictionaryEntry> entries = new HashSet<>();
|
||||
Set<DictionaryEntryModel> entries = new HashSet<>();
|
||||
@Builder.Default
|
||||
Set<DictionaryEntry> falsePositives = new HashSet<>();
|
||||
Set<DictionaryEntryModel> falsePositives = new HashSet<>();
|
||||
@Builder.Default
|
||||
Set<DictionaryEntry> falseRecommendations = new HashSet<>();
|
||||
Set<DictionaryEntryModel> falseRecommendations = new HashSet<>();
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
package com.iqser.red.service.redaction.v1.server.redaction.model;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntry;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class DictionaryEntryModel extends DictionaryEntry {
|
||||
|
||||
public DictionaryEntryModel() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DictionaryEntryModel(long entryId, String value, long version, boolean deleted, String typeId) {
|
||||
|
||||
super(entryId, value, version, deleted, typeId);
|
||||
}
|
||||
|
||||
public DictionaryEntryModel(DictionaryEntry entry) {
|
||||
super(entry.getEntryId(), entry.getValue(), entry.getVersion(), entry.isDeleted(), entry.getTypeId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@EqualsAndHashCode.Include
|
||||
public String getValue(){
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,9 +21,9 @@ public class DictionaryModel implements Serializable {
|
||||
private final boolean caseInsensitive;
|
||||
private final boolean hint;
|
||||
private final boolean isDossierDictionary;
|
||||
private final Set<DictionaryEntry> entries;
|
||||
private final Set<DictionaryEntry> falsePositives;
|
||||
private final Set<DictionaryEntry> falseRecommendations;
|
||||
private final Set<DictionaryEntryModel> entries;
|
||||
private final Set<DictionaryEntryModel> falsePositives;
|
||||
private final Set<DictionaryEntryModel> falseRecommendations;
|
||||
|
||||
private transient SearchImplementation entriesSearch;
|
||||
private transient SearchImplementation falsePositiveSearch;
|
||||
@ -38,9 +38,9 @@ public class DictionaryModel implements Serializable {
|
||||
float[] color,
|
||||
boolean caseInsensitive,
|
||||
boolean hint,
|
||||
Set<DictionaryEntry> entries,
|
||||
Set<DictionaryEntry> falsePositives,
|
||||
Set<DictionaryEntry> falseRecommendations,
|
||||
Set<DictionaryEntryModel> entries,
|
||||
Set<DictionaryEntryModel> falsePositives,
|
||||
Set<DictionaryEntryModel> falseRecommendations,
|
||||
boolean isDossierDictionary) {
|
||||
|
||||
this.type = type;
|
||||
@ -54,9 +54,9 @@ public class DictionaryModel implements Serializable {
|
||||
this.falsePositives = falsePositives;
|
||||
this.falseRecommendations = falseRecommendations;
|
||||
|
||||
this.entriesSearch = new SearchImplementation(this.entries.stream().filter(e -> !e.isDeleted()).map(DictionaryEntry::getValue).collect(Collectors.toList()),
|
||||
this.entriesSearch = new SearchImplementation(this.entries.stream().filter(e -> !e.isDeleted()).map(DictionaryEntryModel::getValue).collect(Collectors.toList()),
|
||||
caseInsensitive);
|
||||
this.falsePositiveSearch = new SearchImplementation(this.falsePositives.stream().filter(e -> !e.isDeleted()).map(DictionaryEntry::getValue).collect(Collectors.toList()),
|
||||
this.falsePositiveSearch = new SearchImplementation(this.falsePositives.stream().filter(e -> !e.isDeleted()).map(DictionaryEntryModel::getValue).collect(Collectors.toList()),
|
||||
caseInsensitive);
|
||||
this.falseRecommendationsSearch = new SearchImplementation(this.falseRecommendations.stream()
|
||||
.filter(e -> !e.isDeleted())
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package com.iqser.red.service.redaction.v1.server.redaction.service;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -24,6 +25,7 @@ import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
|
||||
import com.iqser.red.service.redaction.v1.server.multitenancy.TenantContext;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.Dictionary;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryEntries;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryEntryModel;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryIncrement;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryIncrementValue;
|
||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryModel;
|
||||
@ -160,9 +162,9 @@ public class DictionaryService {
|
||||
oldModel = representation != null ? representation.getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny() : Optional.empty();
|
||||
}
|
||||
|
||||
Set<DictionaryEntry> entries = new HashSet<>();
|
||||
Set<DictionaryEntry> falsePositives = new HashSet<>();
|
||||
Set<DictionaryEntry> falseRecommendations = new HashSet<>();
|
||||
Set<DictionaryEntryModel> entries = new HashSet<>();
|
||||
Set<DictionaryEntryModel> falsePositives = new HashSet<>();
|
||||
Set<DictionaryEntryModel> falseRecommendations = new HashSet<>();
|
||||
|
||||
DictionaryEntries newEntries = getEntries(t.getId(), currentVersion);
|
||||
|
||||
@ -232,9 +234,12 @@ public class DictionaryService {
|
||||
|
||||
var type = dictionaryClient.getDictionaryForType(typeId, fromVersion);
|
||||
|
||||
Set<DictionaryEntry> entries = type.getEntries() != null ? new HashSet<>(type.getEntries()) : new HashSet<>();
|
||||
Set<DictionaryEntry> falsePositives = type.getFalsePositiveEntries() != null ? new HashSet<>(type.getFalsePositiveEntries()) : new HashSet<>();
|
||||
Set<DictionaryEntry> falseRecommendations = type.getFalseRecommendationEntries() != null ? new HashSet<>(type.getFalseRecommendationEntries()) : new HashSet<>();
|
||||
Set<DictionaryEntryModel> entries = type.getEntries() != null ? new HashSet<>(type.getEntries().stream().map(DictionaryEntryModel::new).collect(Collectors.toSet())) : new HashSet<>();
|
||||
Set<DictionaryEntryModel> falsePositives = type.getFalsePositiveEntries() != null ? new HashSet<>(type.getFalsePositiveEntries().stream().map(DictionaryEntryModel::new).collect(
|
||||
Collectors.toSet())) : new HashSet<>();
|
||||
Set<DictionaryEntryModel> falseRecommendations = type.getFalseRecommendationEntries() != null ? new HashSet<>(type.getFalseRecommendationEntries().stream().map(
|
||||
DictionaryEntryModel::new).collect(
|
||||
Collectors.toSet())) : new HashSet<>();
|
||||
|
||||
if (type.isCaseInsensitive()) {
|
||||
entries.forEach(entry -> entry.setValue(entry.getValue().toLowerCase(Locale.ROOT)));
|
||||
@ -283,24 +288,33 @@ public class DictionaryService {
|
||||
@Timed("redactmanager_getDeepCopyDictionary")
|
||||
public Dictionary getDeepCopyDictionary(String dossierTemplateId, String dossierId) {
|
||||
|
||||
List<DictionaryModel> copy = new ArrayList<>();
|
||||
Map<String, DictionaryModel> mergedDictionaries = new HashMap<>();
|
||||
|
||||
var dossierTemplateRepresentation = getDossierTemplateDictionary(dossierTemplateId);
|
||||
dossierTemplateRepresentation.getDictionary().forEach(dm -> {
|
||||
copy.add(SerializationUtils.clone(dm));
|
||||
});
|
||||
dossierTemplateRepresentation.getDictionary().forEach(dm -> mergedDictionaries.put(dm.getType(), SerializationUtils.clone(dm)));
|
||||
|
||||
//TODO merge dictionaries if they have same names
|
||||
// merge dictionaries if they have same names
|
||||
long dossierDictionaryVersion = -1;
|
||||
if (dossierDictionaryExists(dossierId)) {
|
||||
var dossierRepresentation = getDossierDictionary(dossierId);
|
||||
dossierRepresentation.getDictionary().forEach(dm -> {
|
||||
copy.add(SerializationUtils.clone(dm));
|
||||
if (mergedDictionaries.containsKey(dm.getType())) {
|
||||
//merge dictionary entries, false positives and false recommendations
|
||||
Set<DictionaryEntryModel> dossierEntries = dm.getEntries();
|
||||
mergedDictionaries.get(dm.getType()).getEntries().removeAll(dossierEntries);
|
||||
mergedDictionaries.get(dm.getType()).getEntries().addAll(dossierEntries);
|
||||
mergedDictionaries.get(dm.getType()).getFalsePositives().removeAll(dm.getFalsePositives());
|
||||
mergedDictionaries.get(dm.getType()).getFalsePositives().addAll(dm.getFalsePositives());
|
||||
mergedDictionaries.get(dm.getType()).getFalseRecommendations().removeAll(dm.getFalseRecommendations());
|
||||
mergedDictionaries.get(dm.getType()).getFalseRecommendations().addAll(dm.getFalseRecommendations());
|
||||
} else {
|
||||
mergedDictionaries.put(dm.getType(), SerializationUtils.clone(dm));
|
||||
}
|
||||
});
|
||||
dossierDictionaryVersion = dossierRepresentation.getDictionaryVersion();
|
||||
}
|
||||
|
||||
return new Dictionary(copy.stream().sorted(Comparator.comparingInt(DictionaryModel::getRank).reversed()).collect(Collectors.toList()),
|
||||
return new Dictionary(mergedDictionaries.values().stream().sorted(Comparator.comparingInt(DictionaryModel::getRank).reversed()).collect(Collectors.toList()),
|
||||
DictionaryVersion.builder().dossierTemplateVersion(dossierTemplateRepresentation.getDictionaryVersion()).dossierVersion(dossierDictionaryVersion).build());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user