RED-5624: migration

working on migration
This commit is contained in:
yhampe 2024-08-09 09:38:23 +02:00
parent cff6826424
commit 79fec2e9c9
3 changed files with 25 additions and 0 deletions

View File

@ -69,6 +69,8 @@ public class MigrationStarterService {
private void seedMigration() {
log.info("seeding migration");
log.info("latest version {}", migrationPersistenceService.getLatestProcessedVersion());
if (migrationPersistenceService.getLatestProcessedVersion() == null) {
migrations.sort(Comparator.comparing(Migration::getVersion).reversed());
migrationPersistenceService.insertMigration("migration start version", migrations.get(0).getVersion());

View File

@ -1,7 +1,9 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
@ -53,6 +55,14 @@ public class LegalBasisMigrationService {
public void migrate() {
log.info("Starting migration: Adding technical names to legal basis");
List<String> approvedFileIds = fileRepository.getApprovedFiles()
.stream()
.map(file -> file.getId())
.collect(Collectors.toList());
List<String> hardDeletedFileIds = fileRepository.getHardDeletedFiles()
.stream()
.map(file -> file.getId())
.collect(Collectors.toList());
this.legalBasisMappingRepository.findAll()
.stream()
.peek(entry -> entry.getLegalBasis()
@ -62,6 +72,12 @@ public class LegalBasisMigrationService {
.forEach(legalBasisMappingRepository::save);
this.entityLogDocumentRepository.findAll()
.stream()
.filter(ent -> {
if (approvedFileIds.contains(ent.getFileId()) || hardDeletedFileIds.contains(ent.getFileId())) {
return false;
}
return true;
})
.peek(entry -> entry.getLegalBasis()
.forEach(lb -> {
lb.setTechnicalName(getOrDefault(lb.getName()));

View File

@ -304,6 +304,13 @@ public interface FileRepository extends JpaRepository<FileEntity, String> {
List<FileEntity> getSoftDeletedFiles(@Param("dossierIds") List<String> dossierIds);
@Query("select f from FileEntity f where f.workflowStatus = 'APPROVED'")
List<FileEntity> getApprovedFiles();
@Query("select f from FileEntity f where f.hardDeletedTime is not null")
List<FileEntity> getHardDeletedFiles();
@Query("select f from FileEntity f where f.processingStatus = 'ERROR' and f.deleted is null and f.hardDeletedTime is null ")
List<FileEntity> getAllErrorFilesExcludeDeleted();