RED-4525 - migration of manual redaction type
This commit is contained in:
parent
b56fc3cb95
commit
65519efc20
@ -39,4 +39,8 @@ public abstract class Migration {
|
||||
|
||||
protected abstract void migrate();
|
||||
|
||||
public final long getVersion(){
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.iqser.red.service.peristence.v1.server.migration;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.migration.migrations.*;
|
||||
import com.iqser.red.service.peristence.v1.server.settings.FileManagementServiceSettings;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.MigrationPersistenceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -11,6 +10,9 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -20,20 +22,11 @@ public class MigrationStarterService {
|
||||
// After migration to 3.3.x we must fix this.
|
||||
public static final long MIGRATION_SEED_VERSION = 1;
|
||||
|
||||
private final IndexMigration1 indexMigration1;
|
||||
private final DictionaryToEntityMigration2 dictionaryToEntityMigration2;
|
||||
private final MigrateHighlights3 migrateHighlights3;
|
||||
private final EntityTypesMigration4 entityTypesMigration4;
|
||||
private final TypeToEntityMigration5 typeToEntityMigration5;
|
||||
private final RemoveFalsePositiveManualRedactions6 removeFalsePositiveManualRedactions6;
|
||||
private final DeleteRemovedManualAddRedactions7 deleteRemovedManualAddRedactions7;
|
||||
|
||||
private final List<Migration> migrations;
|
||||
private final FileManagementServiceSettings settings;
|
||||
private final ApplicationContext ctx;
|
||||
private final MigrationPersistenceService migrationPersistenceService;
|
||||
|
||||
private final FileSizeMigration8 fileSizeMigration8;
|
||||
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void migrate() {
|
||||
@ -45,14 +38,11 @@ public class MigrationStarterService {
|
||||
if (settings.isMigrateOnly()) {
|
||||
log.info("Start migration");
|
||||
|
||||
indexMigration1.run();
|
||||
dictionaryToEntityMigration2.run();
|
||||
migrateHighlights3.run();
|
||||
entityTypesMigration4.run();
|
||||
typeToEntityMigration5.run();
|
||||
removeFalsePositiveManualRedactions6.run();
|
||||
deleteRemovedManualAddRedactions7.run();
|
||||
fileSizeMigration8.run();
|
||||
migrations.sort(Comparator.comparing(Migration::getVersion));
|
||||
|
||||
for (var migration : migrations) {
|
||||
migration.run();
|
||||
}
|
||||
|
||||
log.info("Migration is finished");
|
||||
System.exit(SpringApplication.exit(ctx, () -> 0));
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.iqser.red.service.peristence.v1.server.migration.migrations;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.migration.Migration;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.DictionaryPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierTemplateRepository;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.TypeRepository;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Setter
|
||||
@Service
|
||||
public class ManualRedactionTypeMigration9 extends Migration {
|
||||
|
||||
private static final String NAME = "Add Manual Redaction Type";
|
||||
private static final long VERSION = 9;
|
||||
private static final String MANUAL_TYPE = "manual";
|
||||
|
||||
@Autowired
|
||||
private DictionaryPersistenceService dictionaryPersistenceService;
|
||||
@Autowired
|
||||
private DossierTemplateRepository dossierTemplateRepository;
|
||||
@Autowired
|
||||
private TypeRepository typeRepository;
|
||||
|
||||
|
||||
public ManualRedactionTypeMigration9() {
|
||||
|
||||
super(NAME, VERSION);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void migrate() {
|
||||
|
||||
var allDossierTemplates = dossierTemplateRepository.findAll();
|
||||
|
||||
allDossierTemplates.forEach(dossierTemplateEntity -> {
|
||||
|
||||
var entitiesForDossierTemplate = dictionaryPersistenceService.getAllTypesForDossierTemplate(dossierTemplateEntity.getId(), true);
|
||||
|
||||
var manualType = entitiesForDossierTemplate.stream().filter(e -> MANUAL_TYPE.equals(e.getType())).findAny();
|
||||
manualType.ifPresent(typeEntity -> typeRepository.deleteById(typeEntity.getId()));
|
||||
|
||||
var rank = 1;
|
||||
for (var entity : entitiesForDossierTemplate) {
|
||||
if (entity.getRank() > rank) {
|
||||
rank = entity.getRank();
|
||||
}
|
||||
}
|
||||
rank += 1000;
|
||||
|
||||
dictionaryPersistenceService.addType(MANUAL_TYPE, dossierTemplateEntity.getId(),
|
||||
"#9398a0", "#c5d3eb", "#c498fa",
|
||||
rank, false, false, false, "Manual Redactions", false,
|
||||
"Manual Redactions", null, false, true, false);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user