RED-6224: Fixed pr findings
This commit is contained in:
parent
ec0de5b6a2
commit
9330551859
@ -34,6 +34,7 @@ import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryModel
|
|||||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryRepresentation;
|
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryRepresentation;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryVersion;
|
import com.iqser.red.service.redaction.v1.server.redaction.model.DictionaryVersion;
|
||||||
import com.iqser.red.service.redaction.v1.server.redaction.model.TenantDictionary;
|
import com.iqser.red.service.redaction.v1.server.redaction.model.TenantDictionary;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.settings.RedactionServiceSettings;
|
||||||
|
|
||||||
import feign.FeignException;
|
import feign.FeignException;
|
||||||
import io.micrometer.core.annotation.Timed;
|
import io.micrometer.core.annotation.Timed;
|
||||||
@ -49,11 +50,7 @@ public class DictionaryService {
|
|||||||
private static final String DEFAULT_COLOR = "#cccccc";
|
private static final String DEFAULT_COLOR = "#cccccc";
|
||||||
private final DictionaryClient dictionaryClient;
|
private final DictionaryClient dictionaryClient;
|
||||||
|
|
||||||
@Value("${multitenancy.dictionary-cache.maximumSize:100}")
|
private final RedactionServiceSettings settings;
|
||||||
private Long maximumSize;
|
|
||||||
|
|
||||||
@Value("${multitenancy.dictionary-cache.expireAfterAccess:3}")
|
|
||||||
private Integer expireAfterAccess;
|
|
||||||
|
|
||||||
private LoadingCache<String, TenantDictionary> tenantDictionaryCache;
|
private LoadingCache<String, TenantDictionary> tenantDictionaryCache;
|
||||||
|
|
||||||
@ -61,12 +58,15 @@ public class DictionaryService {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
protected void createCache() {
|
protected void createCache() {
|
||||||
|
|
||||||
tenantDictionaryCache = CacheBuilder.newBuilder().maximumSize(maximumSize).expireAfterAccess(expireAfterAccess, TimeUnit.DAYS).build(new CacheLoader<>() {
|
tenantDictionaryCache = CacheBuilder.newBuilder()
|
||||||
public TenantDictionary load(String key) {
|
.maximumSize(settings.getDictionaryCacheMaximumSize())
|
||||||
|
.expireAfterAccess(settings.getDictionaryCacheExpireAfterAccessDays(), TimeUnit.DAYS)
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
public TenantDictionary load(String key) {
|
||||||
|
|
||||||
return new TenantDictionary();
|
return new TenantDictionary();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -76,13 +76,13 @@ public class DictionaryService {
|
|||||||
|
|
||||||
log.info("Updating dictionary data for dossierTemplate {} and dossier {}", dossierTemplateId, dossierId);
|
log.info("Updating dictionary data for dossierTemplate {} and dossier {}", dossierTemplateId, dossierId);
|
||||||
long dossierTemplateDictionaryVersion = dictionaryClient.getVersion(dossierTemplateId);
|
long dossierTemplateDictionaryVersion = dictionaryClient.getVersion(dossierTemplateId);
|
||||||
var dossierTemplateDictionary = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId);
|
var dossierTemplateDictionary = getDossierTemplateDictionary(dossierTemplateId);
|
||||||
if (dossierTemplateDictionary == null || dossierTemplateDictionaryVersion > dossierTemplateDictionary.getDictionaryVersion()) {
|
if (dossierTemplateDictionary == null || dossierTemplateDictionaryVersion > dossierTemplateDictionary.getDictionaryVersion()) {
|
||||||
updateDictionaryEntry(dossierTemplateId, dossierTemplateDictionaryVersion, getVersion(dossierTemplateDictionary), null);
|
updateDictionaryEntry(dossierTemplateId, dossierTemplateDictionaryVersion, getVersion(dossierTemplateDictionary), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
long dossierDictionaryVersion = dictionaryClient.getVersionForDossier(dossierId);
|
long dossierDictionaryVersion = dictionaryClient.getVersionForDossier(dossierId);
|
||||||
var dossierDictionary = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().get(dossierId);
|
var dossierDictionary = getDossierDictionary(dossierId);
|
||||||
if (dossierDictionary == null || dossierDictionaryVersion > dossierDictionary.getDictionaryVersion()) {
|
if (dossierDictionary == null || dossierDictionaryVersion > dossierDictionary.getDictionaryVersion()) {
|
||||||
updateDictionaryEntry(dossierTemplateId, dossierDictionaryVersion, getVersion(dossierDictionary), dossierId);
|
updateDictionaryEntry(dossierTemplateId, dossierDictionaryVersion, getVersion(dossierDictionary), dossierId);
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class DictionaryService {
|
|||||||
DictionaryVersion version = updateDictionary(dossierTemplateId, dossierId);
|
DictionaryVersion version = updateDictionary(dossierTemplateId, dossierId);
|
||||||
|
|
||||||
Set<DictionaryIncrementValue> newValues = new HashSet<>();
|
Set<DictionaryIncrementValue> newValues = new HashSet<>();
|
||||||
List<DictionaryModel> dictionaryModels = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId).getDictionary();
|
List<DictionaryModel> dictionaryModels = getDossierTemplateDictionary(dossierTemplateId).getDictionary();
|
||||||
dictionaryModels.forEach(dictionaryModel -> {
|
dictionaryModels.forEach(dictionaryModel -> {
|
||||||
dictionaryModel.getEntries().forEach(dictionaryEntry -> {
|
dictionaryModel.getEntries().forEach(dictionaryEntry -> {
|
||||||
if (dictionaryEntry.getVersion() > fromVersion.getDossierTemplateVersion()) {
|
if (dictionaryEntry.getVersion() > fromVersion.getDossierTemplateVersion()) {
|
||||||
@ -117,8 +117,8 @@ public class DictionaryService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().containsKey(dossierId)) {
|
if (dossierDictionaryExists(dossierId)) {
|
||||||
dictionaryModels = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().get(dossierId).getDictionary();
|
dictionaryModels = getDossierDictionary(dossierId).getDictionary();
|
||||||
dictionaryModels.forEach(dictionaryModel -> {
|
dictionaryModels.forEach(dictionaryModel -> {
|
||||||
dictionaryModel.getEntries().forEach(dictionaryEntry -> {
|
dictionaryModel.getEntries().forEach(dictionaryEntry -> {
|
||||||
if (dictionaryEntry.getVersion() > fromVersion.getDossierVersion()) {
|
if (dictionaryEntry.getVersion() > fromVersion.getDossierVersion()) {
|
||||||
@ -156,20 +156,10 @@ public class DictionaryService {
|
|||||||
|
|
||||||
Optional<DictionaryModel> oldModel;
|
Optional<DictionaryModel> oldModel;
|
||||||
if (dossierId == null) {
|
if (dossierId == null) {
|
||||||
DictionaryRepresentation representation = null;
|
var representation = getDossierTemplateDictionary(dossierTemplateId);
|
||||||
try {
|
|
||||||
representation = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw new RuntimeException("Failed to load Dictionary cache for tenant: " + TenantContext.getTenantId());
|
|
||||||
}
|
|
||||||
oldModel = representation != null ? representation.getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny() : Optional.empty();
|
oldModel = representation != null ? representation.getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny() : Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
DictionaryRepresentation representation = null;
|
var representation = getDossierDictionary(dossierId);
|
||||||
try {
|
|
||||||
representation = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().get(dossierId);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
throw new RuntimeException("Failed to load Dictionary cache for tenant: " + TenantContext.getTenantId());
|
|
||||||
}
|
|
||||||
oldModel = representation != null ? representation.getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny() : Optional.empty();
|
oldModel = representation != null ? representation.getDictionary().stream().filter(f -> f.getType().equals(t.getType())).findAny() : Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,18 +263,18 @@ public class DictionaryService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public float[] getColor(String type, String dossierTemplateId) {
|
public float[] getColor(String type, String dossierTemplateId) {
|
||||||
|
|
||||||
DictionaryModel model = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId).getLocalAccessMap().get(type);
|
DictionaryModel model = getDossierTemplateDictionary(dossierTemplateId).getLocalAccessMap().get(type);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
return model.getColor();
|
return model.getColor();
|
||||||
}
|
}
|
||||||
return tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId).getDefaultColor();
|
return getDossierTemplateDictionary(dossierTemplateId).getDefaultColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public boolean isHint(String type, String dossierTemplateId) {
|
public boolean isHint(String type, String dossierTemplateId) {
|
||||||
|
|
||||||
DictionaryModel model = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId).getLocalAccessMap().get(type);
|
DictionaryModel model = getDossierTemplateDictionary(dossierTemplateId).getLocalAccessMap().get(type);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
return model.isHint();
|
return model.isHint();
|
||||||
}
|
}
|
||||||
@ -298,15 +288,15 @@ public class DictionaryService {
|
|||||||
|
|
||||||
List<DictionaryModel> copy = new ArrayList<>();
|
List<DictionaryModel> copy = new ArrayList<>();
|
||||||
|
|
||||||
var dossierTemplateRepresentation = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId);
|
var dossierTemplateRepresentation = getDossierTemplateDictionary(dossierTemplateId);
|
||||||
dossierTemplateRepresentation.getDictionary().forEach(dm -> {
|
dossierTemplateRepresentation.getDictionary().forEach(dm -> {
|
||||||
copy.add(SerializationUtils.clone(dm));
|
copy.add(SerializationUtils.clone(dm));
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO merge dictionaries if they have same names
|
//TODO merge dictionaries if they have same names
|
||||||
long dossierDictionaryVersion = -1;
|
long dossierDictionaryVersion = -1;
|
||||||
if (tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().containsKey(dossierId)) {
|
if (dossierDictionaryExists(dossierId)) {
|
||||||
var dossierRepresentation = tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().get(dossierId);
|
var dossierRepresentation = getDossierDictionary(dossierId);
|
||||||
dossierRepresentation.getDictionary().forEach(dm -> {
|
dossierRepresentation.getDictionary().forEach(dm -> {
|
||||||
copy.add(SerializationUtils.clone(dm));
|
copy.add(SerializationUtils.clone(dm));
|
||||||
});
|
});
|
||||||
@ -321,7 +311,28 @@ public class DictionaryService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public float[] getNotRedactedColor(String dossierTemplateId) {
|
public float[] getNotRedactedColor(String dossierTemplateId) {
|
||||||
|
|
||||||
return tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId).getNotRedactedColor();
|
return getDossierTemplateDictionary(dossierTemplateId).getNotRedactedColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private DictionaryRepresentation getDossierTemplateDictionary(String dossierTemplateId) {
|
||||||
|
|
||||||
|
return tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossierTemplate().get(dossierTemplateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private DictionaryRepresentation getDossierDictionary(String dossierId) {
|
||||||
|
|
||||||
|
return tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().get(dossierId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private boolean dossierDictionaryExists(String dossierId) {
|
||||||
|
|
||||||
|
return tenantDictionaryCache.get(TenantContext.getTenantId()).getDictionariesByDossier().containsKey(dossierId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -24,4 +24,8 @@ public class RedactionServiceSettings {
|
|||||||
|
|
||||||
private boolean priorityMode;
|
private boolean priorityMode;
|
||||||
|
|
||||||
|
private long dictionaryCacheMaximumSize = 100;
|
||||||
|
|
||||||
|
private int dictionaryCacheExpireAfterAccessDays = 3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user