RED-8826: Added experimetal flag to entity types

This commit is contained in:
Dominique Eifländer 2024-04-23 12:18:33 +02:00
parent 7c37c16be7
commit 4a6777be71
10 changed files with 85 additions and 78 deletions

View File

@ -60,6 +60,8 @@ public class TypeEntity {
private boolean autoHideSkipped;
@Column
private OffsetDateTime softDeletedTime;
@Column
private boolean experimental;
@Column
private boolean dossierDictionaryOnly;

View File

@ -91,22 +91,23 @@ public class DictionaryManagementService {
}
return MagicConverter.convert(dictionaryPersistenceService.addType(typeRequest.getType(),
typeRequest.getDossierTemplateId(),
color,
recommendationHexColor,
skippedHexColor,
typeRequest.getRank(),
typeRequest.isHint(),
typeRequest.isCaseInsensitive(),
typeRequest.isRecommendation(),
typeRequest.getDescription(),
typeRequest.isAddToDictionaryAction(),
typeRequest.getLabel(),
typeRequest.getDossierId(),
typeRequest.isHasDictionary(),
typeRequest.isSystemManaged(),
typeRequest.isAutoHideSkipped(),
typeRequest.isDossierDictionaryOnly()), Type.class, new TypeMapper());
typeRequest.getDossierTemplateId(),
color,
recommendationHexColor,
skippedHexColor,
typeRequest.getRank(),
typeRequest.isHint(),
typeRequest.isCaseInsensitive(),
typeRequest.isRecommendation(),
typeRequest.getDescription(),
typeRequest.isAddToDictionaryAction(),
typeRequest.getLabel(),
typeRequest.getDossierId(),
typeRequest.isHasDictionary(),
typeRequest.isSystemManaged(),
typeRequest.isAutoHideSkipped(),
typeRequest.isDossierDictionaryOnly(),
typeRequest.isExperimental()), Type.class, new TypeMapper());
}
@ -132,11 +133,9 @@ public class DictionaryManagementService {
List<TypeEntity> typeResponse = dictionaryPersistenceService.getCumulatedTypes(dossierTemplateId, dossierId, false);
for (TypeEntity res : typeResponse) {
var dossierTemplateResponse = res.getDossierTemplateId() == null ? res.getDossierTemplate().getId() : res.getDossierTemplateId();
if (res.getDossierId() != null
&& res.getDossierId().equals(dossierId)
&& !type.equals(res.getType())
&& dossierTemplateResponse.equals(dossierTemplateId)
&& labelToCheck.equals(res.getLabel()) || !type.equals(res.getType()) && dossierTemplateResponse.equals(dossierTemplateId) && labelToCheck.equals(res.getLabel())) {
if (res.getDossierId() != null && res.getDossierId()
.equals(dossierId) && !type.equals(res.getType()) && dossierTemplateResponse.equals(dossierTemplateId) && labelToCheck.equals(res.getLabel()) || !type.equals(
res.getType()) && dossierTemplateResponse.equals(dossierTemplateId) && labelToCheck.equals(res.getLabel())) {
throw new ConflictException("Label must be unique.");
}
}
@ -147,13 +146,10 @@ public class DictionaryManagementService {
return dictionaryPersistenceService.getCumulatedTypes(typeRequest.getDossierTemplateId(), typeRequest.getDossierId(), false)
.stream()
.anyMatch(typeResult -> typeRequest.getDossierId() != null
&& typeResult.getDossierId() != null
&& typeRequest.getDossierId().equals(typeResult.getDossierId())
&& typeRequest.getType().equals(typeResult.getType())
&& typeRequest.getDossierTemplateId().equals(typeResult.getDossierTemplateId())
|| typeRequest.getDossierId() == null && typeRequest.getType().equals(typeResult.getType()) && typeRequest.getDossierTemplateId()
.equals(typeResult.getDossierTemplateId()));
.anyMatch(typeResult -> typeRequest.getDossierId() != null && typeResult.getDossierId() != null && typeRequest.getDossierId()
.equals(typeResult.getDossierId()) && typeRequest.getType().equals(typeResult.getType()) && typeRequest.getDossierTemplateId()
.equals(typeResult.getDossierTemplateId()) || typeRequest.getDossierId() == null && typeRequest.getType()
.equals(typeResult.getType()) && typeRequest.getDossierTemplateId().equals(typeResult.getDossierTemplateId()));
}
@ -239,9 +235,7 @@ public class DictionaryManagementService {
checkForDossierTypeExistenceAndCreate(typeId);
Set<String> cleanEntries = entries.stream()
.map(StringCleaningUtility::cleanString)
.collect(toSet());
Set<String> cleanEntries = entries.stream().map(StringCleaningUtility::cleanString).collect(toSet());
if (CollectionUtils.isEmpty(entries)) {
throw new BadRequestException("Entry list is empty.");
@ -275,8 +269,11 @@ public class DictionaryManagementService {
public void checkForDossierTypeExistenceAndCreate(String typeId) {
checkForDossierTypeExistenceAndCreate(typeId,false);
checkForDossierTypeExistenceAndCreate(typeId, false);
}
public void checkForDossierTypeExistenceAndCreate(String typeId, boolean includeDeleted) {
// check for the existence of dossier type and create in case it does not exist
if (isDossierTypeId(typeId)) {
@ -289,7 +286,7 @@ public class DictionaryManagementService {
log.info("--> " + dossierId + " - " + dossierTemplateId);
checkDossierMatchesDossierTemplate(dossierId, dossierTemplateId);
// type not found, it should be created based on the info from the dossier template type
var dossierTemplateType = dictionaryPersistenceService.getType(getDosssierTemplateTypeIdFromTypeId(typeId),includeDeleted);
var dossierTemplateType = dictionaryPersistenceService.getType(getDosssierTemplateTypeIdFromTypeId(typeId), includeDeleted);
Type dossierDictionaryType = MagicConverter.convert(dossierTemplateType, Type.class);
dossierDictionaryType.setVersion(0);
dossierDictionaryType.setDossierId(dossierId);
@ -311,13 +308,10 @@ public class DictionaryManagementService {
private Set<String> getInvalidEntries(Set<String> entries) {
Predicate<String> isDictionaryEntryNotValid = entry -> DictionaryValidator.validateDictionaryEntry(entry)
.isPresent();
Predicate<String> isDictionaryEntryNotValid = entry -> DictionaryValidator.validateDictionaryEntry(entry).isPresent();
Predicate<String> isStopword = stopwordService::isStopword;
return entries.stream()
.filter(isDictionaryEntryNotValid.or(isStopword))
.collect(toSet());
return entries.stream().filter(isDictionaryEntryNotValid.or(isStopword)).collect(toSet());
}
@ -330,40 +324,25 @@ public class DictionaryManagementService {
var currentVersion = getCurrentVersion(typeResult);
List<String> allExistingEntiesFromType = entryPersistenceService.getEntries(typeId, dictionaryEntryType, null)
.stream()
.map(BaseDictionaryEntry::getValue)
.toList();
List<String> allExistingEntiesFromType = entryPersistenceService.getEntries(typeId, dictionaryEntryType, null).stream().map(BaseDictionaryEntry::getValue).toList();
if (typeResult.isCaseInsensitive()) {
// Set existing entries to deleted.
var caseInsensitiveExistingEntries = allExistingEntiesFromType.stream()
.filter(e -> entries.stream()
.anyMatch(e::equalsIgnoreCase))
.collect(toSet());
var caseInsensitiveExistingEntries = allExistingEntiesFromType.stream().filter(e -> entries.stream().anyMatch(e::equalsIgnoreCase)).collect(toSet());
entryPersistenceService.deleteEntries(typeId, caseInsensitiveExistingEntries, currentVersion + 1, dictionaryEntryType);
// Create new deleted entries for not existing.
var caseInsensitiveNonExistingEntries = entries.stream()
.filter(e -> caseInsensitiveExistingEntries.stream()
.noneMatch(e::equalsIgnoreCase))
.collect(toSet());
var caseInsensitiveNonExistingEntries = entries.stream().filter(e -> caseInsensitiveExistingEntries.stream().noneMatch(e::equalsIgnoreCase)).collect(toSet());
entryPersistenceService.addDeleteEntries(typeId, caseInsensitiveNonExistingEntries, currentVersion + 1, dictionaryEntryType);
} else {
// Set existing entries to deleted.
var caseSensitiveExistingEntries = allExistingEntiesFromType.stream()
.filter(e -> entries.stream()
.anyMatch(e::equals))
.collect(toSet());
var caseSensitiveExistingEntries = allExistingEntiesFromType.stream().filter(e -> entries.stream().anyMatch(e::equals)).collect(toSet());
entryPersistenceService.deleteEntries(typeId, new HashSet<>(caseSensitiveExistingEntries), currentVersion + 1, dictionaryEntryType);
// Create new deleted entries for not existing.
var nonExistingEntries = entries.stream()
.filter(e -> caseSensitiveExistingEntries.stream()
.noneMatch(e::equals))
.collect(toSet());
var nonExistingEntries = entries.stream().filter(e -> caseSensitiveExistingEntries.stream().noneMatch(e::equals)).collect(toSet());
entryPersistenceService.addDeleteEntries(typeId, nonExistingEntries, currentVersion + 1, dictionaryEntryType);
}

View File

@ -274,6 +274,7 @@ public class DictionaryService {
.autoHideSkipped(typeResult.isAutoHideSkipped())
.dossierDictionaryOnly(typeResult.isDossierDictionaryOnly())
.softDeletedTime(typeResult.getSoftDeletedTime())
.experimental(typeResult.isExperimental())
.build())
.collect(Collectors.toList());
return new TypeResponse(typeValues);
@ -331,6 +332,7 @@ public class DictionaryService {
.systemManaged(dictionaryForType.isSystemManaged())
.autoHideSkipped(dictionaryForType.isAutoHideSkipped())
.dossierDictionaryOnly(dictionaryForType.isDossierDictionaryOnly())
.experimental(dictionaryForType.isExperimental())
.build();
}
@ -392,6 +394,7 @@ public class DictionaryService {
.systemManaged(entity.isSystemManaged())
.autoHideSkipped(entity.isAutoHideSkipped())
.dossierDictionaryOnly(entity.isDossierDictionaryOnly())
.experimental(entity.isExperimental())
.build();
dictionaries.add(dict);
});

View File

@ -97,7 +97,7 @@ public class DossierTemplateCloneService {
cloneLegalBasisMapping(dossierTemplate.getId(), clonedDossierTemplate.getId());
clonedDossierTemplate.setDossierTemplateStatus(DossierTemplateStatus.valueOf(dossierTemplatePersistenceService.computeDossierTemplateStatus(clonedDossierTemplate)
.name()));
.name()));
clonedDossierTemplate.setOcrByDefault(cloneDossierTemplateRequest.isOcrByDefault());
clonedDossierTemplate.setRemoveWatermark(cloneDossierTemplateRequest.isRemoveWatermark());
@ -149,8 +149,7 @@ public class DossierTemplateCloneService {
private void cloneLegalBasisMapping(String dossierTemplateId, String clonedDossierTemplateId) {
legalBasisMappingPersistenceService.setLegalBasisMapping(clonedDossierTemplateId,
MagicConverter.convert(legalBasisMappingPersistenceService.getLegalBasisMapping(dossierTemplateId),
LegalBasis.class));
MagicConverter.convert(legalBasisMappingPersistenceService.getLegalBasisMapping(dossierTemplateId), LegalBasis.class));
}
@ -159,22 +158,23 @@ public class DossierTemplateCloneService {
var types = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateId, false);
for (TypeEntity t : types) {
var type = dictionaryPersistenceService.addType(t.getType(),
clonedDossierTemplateId,
t.getHexColor(),
t.getRecommendationHexColor(),
t.getSkippedHexColor(),
t.getRank(),
t.isHint(),
t.isCaseInsensitive(),
t.isRecommendation(),
t.getDescription(),
t.isAddToDictionaryAction(),
t.getLabel(),
null,
t.isHasDictionary(),
t.isSystemManaged(),
t.isAutoHideSkipped(),
t.isDossierDictionaryOnly());
clonedDossierTemplateId,
t.getHexColor(),
t.getRecommendationHexColor(),
t.getSkippedHexColor(),
t.getRank(),
t.isHint(),
t.isCaseInsensitive(),
t.isRecommendation(),
t.getDescription(),
t.isAddToDictionaryAction(),
t.getLabel(),
null,
t.isHasDictionary(),
t.isSystemManaged(),
t.isAutoHideSkipped(),
t.isDossierDictionaryOnly(),
t.isExperimental());
entryPersistenceService.cloneEntries(t.getId(), type.getId());
}
}

View File

@ -53,7 +53,8 @@ public class DictionaryPersistenceService {
boolean hasDictionary,
boolean systemManaged,
boolean autoHideSkipped,
boolean dossierDictionaryOnly) {
boolean dossierDictionaryOnly,
boolean experimental) {
checkRankAlreadyExists(type, dossierTemplateId, rank, dossierId);
@ -78,6 +79,7 @@ public class DictionaryPersistenceService {
.autoHideSkipped(autoHideSkipped)
.softDeletedTime(null)
.dossierDictionaryOnly(dossierDictionaryOnly)
.experimental(experimental)
.build();
return typeRepository.saveAndFlush(t);

View File

@ -199,3 +199,5 @@ databaseChangeLog:
file: db/changelog/tenant/sql/207-acl-migration-cleanup.sql
- include:
file: db/changelog/tenant/125-add-max-size-for-legal-basis-in-manual-legal-basis-change.yaml
- include:
file: db/changelog/tenant/126-add-experimental-flag-to-entity.yaml

View File

@ -0,0 +1,12 @@
databaseChangeLog:
- changeSet:
id: add-experimental-flag-to-entity
author: dom
changes:
- addColumn:
columns:
- column:
name: experimental
type: BOOLEAN
defaultValueBoolean: false
tableName: entity

View File

@ -66,6 +66,9 @@ public class TypeValue {
@Schema(description = "Flag to indicate the dictionary is on dossier level only")
private boolean dossierDictionaryOnly;
@Schema(description = "Flag to indicate if a entity is experimental and should not be show in default mode")
private boolean experimental;
@Schema(description = "Time of soft deletion, will be null if it's not soft deleted")
private OffsetDateTime softDeletedTime;

View File

@ -70,4 +70,7 @@ public class Dictionary {
@Schema(description = "Flag to indicate the dictionary is on dossier level only")
private boolean dossierDictionaryOnly;
@Schema(description = "Flag to indicate if a entity is experimental and should not be show in default mode")
private boolean experimental;
}

View File

@ -42,6 +42,7 @@ public class Type {
private boolean systemManaged;
private boolean autoHideSkipped;
private OffsetDateTime softDeletedTime;
private boolean experimental;
// For auto-mappers