RED-3723 Made creating and updating entry types more strictly. Added migration step for entry type flags

This commit is contained in:
Philipp Schramm 2022-04-06 14:05:21 +02:00
parent 6e38ace691
commit 961ca37d40
4 changed files with 118 additions and 9 deletions

View File

@ -72,7 +72,14 @@ public class DictionaryPersistenceService {
typeRepository.findById(typeId).ifPresent((type) -> {
type.setVersion(type.getVersion() + 1);
checkRankAlreadyExists(type.getType(), type.getDossierTemplate().getId(), typeValueRequest.getRank(), type.getDossier() == null ? null : type.getDossier().getId());
BeanUtils.copyProperties(typeValueRequest, type, "dossierTemplateId", "dossierId", "entries","falsePositiveEntries", "falseRecommendationEntries", "dossierTemplate", "dossier", "id", "version");
if (type.isSystemManaged()) {
type.setHexColor(typeValueRequest.getHexColor());
type.setRecommendationHexColor(typeValueRequest.getRecommendationHexColor());
type.setDescription(typeValueRequest.getDescription());
type.setLabel(typeValueRequest.getLabel());
} else {
BeanUtils.copyProperties(typeValueRequest, type, "type", "dossierTemplateId", "dossierId", "entries", "falsePositiveEntries", "falseRecommendationEntries", "dossierTemplate", "dossier", "id", "version");
}
});
}
@ -112,6 +119,12 @@ public class DictionaryPersistenceService {
}
public List<TypeEntity> getAllTypes() {
return typeRepository.findAll();
}
@Transactional
public void deleteType(String typeId) {
@ -180,4 +193,10 @@ public class DictionaryPersistenceService {
typeRepository.deleteById(typeId);
}
public void saveAllTypes(List<TypeEntity> types) {
typeRepository.saveAll(types);
}
}

View File

@ -144,13 +144,11 @@ public class DictionaryController implements DictionaryResource {
Type typeResult = convert(dictionaryPersistenceService.getType(typeId), Type.class);
if (typeValueRequest.getLabel() != null) {
checkForDuplicateLabels(typeResult.getDossierTemplateId(), typeResult.getDossierId(), typeValueRequest.getType(), typeValueRequest
.getLabel());
}
if (typeValueRequest.getLabel() == null) {
checkForDuplicateLabels(typeResult.getDossierTemplateId(), typeResult.getDossierId(), typeResult.getType(), typeValueRequest.getLabel());
} else {
typeValueRequest.setLabel(typeResult.getLabel());
}
dictionaryPersistenceService.updateType(typeId, convert(typeValueRequest, TypeEntity.class));
if (typeResult.isHint() != typeValueRequest.isHint() || typeResult.isCaseInsensitive() != typeValueRequest.isCaseInsensitive() || typeResult

View File

@ -7,6 +7,7 @@ import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import com.iqser.red.service.peristence.v1.server.migration.migrations.DictionaryToEntityMigration2;
import com.iqser.red.service.peristence.v1.server.migration.migrations.EntityTypesMigration4;
import com.iqser.red.service.peristence.v1.server.migration.migrations.IndexMigration1;
import com.iqser.red.service.peristence.v1.server.migration.migrations.MigrateHighlights3;
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
@ -27,6 +28,7 @@ public class MigrationStarterService {
private final IndexMigration1 indexMigration1;
private final DictionaryToEntityMigration2 dictionaryToEntityMigration2;
private final MigrateHighlights3 migrateHighlights3;
private final EntityTypesMigration4 entityTypesMigration4;
private final FileManagementServiceSettings settings;
private final ApplicationContext ctx;
@ -41,19 +43,23 @@ public class MigrationStarterService {
// This should only run in post upgrade hook
if (settings.isMigrateOnly()) {
log.info("Start migration");
indexMigration1.run();
dictionaryToEntityMigration2.run();
migrateHighlights3.run();
entityTypesMigration4.run();
log.info("Migration is finished");
System.exit(SpringApplication.exit(ctx, () -> 0));
}
}
private void seedMigration(){
if(migrationPersistenceService.getLatestProcessedVersion() == null){
migrationPersistenceService.insertMigration("migration start version" , MIGRATION_SEED_VERSION);
private void seedMigration() {
if (migrationPersistenceService.getLatestProcessedVersion() == null) {
migrationPersistenceService.insertMigration("migration start version", MIGRATION_SEED_VERSION);
}
}

View File

@ -0,0 +1,86 @@
package com.iqser.red.service.peristence.v1.server.migration.migrations;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iqser.red.service.peristence.v1.server.migration.Migration;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.BaseDictionaryEntry;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.TypeEntity;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.EntryPersistenceService;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.type.DictionaryEntryType;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Setter
@Service
public class EntityTypesMigration4 extends Migration {
private static final String NAME = "Set flags systemManaged, autoHideSkipped and hasDictionary for all entity types";
private static final long VERSION = 4;
@Autowired
private DictionaryPersistenceService dictionaryPersistenceService;
@Autowired
private EntryPersistenceService entryPersistenceService;
public EntityTypesMigration4() {
super(NAME, VERSION);
}
@Override
protected void migrate() {
Set<String> systemManagedTypes = Set.of("ocr", "image", "logo", "signature", "formula", "imported_redaction", "dossier_redaction");
Set<String> autoHideSkippedTypes = Set.of("imported_redaction");
log.info("Will check all type entities and set systemManaged flag true for {}", systemManagedTypes);
log.info("Will check all type entities and set autoHideSkipped flag true for {}", autoHideSkippedTypes);
log.info("Will check all type entities and set hasDictionary flag true for types with entities");
List<TypeEntity> types = dictionaryPersistenceService.getAllTypes();
for (TypeEntity type : types) {
if (type != null) {
// Check if type is systemManaged
if (type.getType() != null && systemManagedTypes.contains(type.getType())) {
type.setSystemManaged(true);
} else {
type.setSystemManaged(false);
}
// Check if type is autoHideSkipped
if (type.getType() != null && autoHideSkippedTypes.contains(type.getType())) {
type.setAutoHideSkipped(true);
} else {
type.setAutoHideSkipped(false);
}
// Check if type has dictionaries
List<? extends BaseDictionaryEntry> entries = entryPersistenceService.getEntries(type.getId(), DictionaryEntryType.ENTRY, null);
if (entries != null && !entries.isEmpty()) {
type.setHasDictionary(true);
} else {
type.setHasDictionary(false);
}
}
}
log.info("Save all types");
dictionaryPersistenceService.saveAllTypes(types);
}
}