RED-7382: Delete section grid for migrated files

This commit is contained in:
Dominique Eifländer 2024-03-12 13:17:17 +01:00
parent 3b448f1fd9
commit d3ab2d66ab

View File

@ -88,16 +88,10 @@ public class SaasMigrationService implements TenantSyncService {
log.info("Finished uncompressed files migration ..."); log.info("Finished uncompressed files migration ...");
int numberOfFiles = 0; int numberOfFiles = 0;
var dossiers = dossierService.getAllDossiers() var dossiers = dossierService.getAllDossiers().stream().filter(dossier -> dossier.getHardDeletedTime() == null).toList();
.stream()
.filter(dossier -> dossier.getHardDeletedTime() == null)
.toList();
for (var dossier : dossiers) { for (var dossier : dossiers) {
var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId()) var files = fileStatusPersistenceService.getStatusesForDossier(dossier.getId()).stream().filter(file -> file.getHardDeletedTime() == null).toList();
.stream()
.filter(file -> file.getHardDeletedTime() == null)
.toList();
var migrationStati = saasMigrationStatusPersistenceService.findAll() var migrationStati = saasMigrationStatusPersistenceService.findAll()
.stream() .stream()
@ -163,12 +157,12 @@ public class SaasMigrationService implements TenantSyncService {
String dossierTemplateId = dossierService.getDossierById(dossierId).getDossierTemplateId(); String dossierTemplateId = dossierService.getDossierById(dossierId).getDossierTemplateId();
rabbitTemplate.convertAndSend(MIGRATION_QUEUE, rabbitTemplate.convertAndSend(MIGRATION_QUEUE,
MigrationRequest.builder() MigrationRequest.builder()
.dossierTemplateId(dossierTemplateId) .dossierTemplateId(dossierTemplateId)
.dossierId(dossierId) .dossierId(dossierId)
.fileId(fileId) .fileId(fileId)
.manualRedactions(manualRedactionProviderService.getManualRedactions(fileId, ManualChangesQueryOptions.allWithoutDeleted())) .manualRedactions(manualRedactionProviderService.getManualRedactions(fileId, ManualChangesQueryOptions.allWithoutDeleted()))
.build()); .build());
log.info("Layout Parsing finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId); log.info("Layout Parsing finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId);
} catch (Exception e) { } catch (Exception e) {
log.error("Queuing of entityLog migration failed with {}", e.getMessage()); log.error("Queuing of entityLog migration failed with {}", e.getMessage());
@ -181,9 +175,9 @@ public class SaasMigrationService implements TenantSyncService {
private boolean layoutParsingFilesExist(String dossierId, String fileId) { private boolean layoutParsingFilesExist(String dossierId, String fileId) {
return storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_STRUCTURE)) // return storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_STRUCTURE)) //
&& storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_TEXT)) // && storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_TEXT)) //
&& storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_PAGES)) // && storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_PAGES)) //
&& storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_POSITION)); && storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_POSITION));
} }
@ -196,7 +190,7 @@ public class SaasMigrationService implements TenantSyncService {
saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.REDACTION_LOGS_MIGRATED); saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.REDACTION_LOGS_MIGRATED);
log.info("EntityLog migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId); log.info("EntityLog migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId);
migrateAnnotationIdsAndAddManualAddRedactions(dossierId, fileId); migrateAnnotationIdsAndAddManualAddRedactionsAndDeleteSectionGrid(dossierId, fileId);
} }
@ -223,7 +217,7 @@ public class SaasMigrationService implements TenantSyncService {
} }
private void migrateAnnotationIdsAndAddManualAddRedactions(String dossierId, String fileId) { private void migrateAnnotationIdsAndAddManualAddRedactionsAndDeleteSectionGrid(String dossierId, String fileId) {
MigratedIds migratedIds = getMigratedIds(dossierId, fileId); MigratedIds migratedIds = getMigratedIds(dossierId, fileId);
Map<String, String> oldToNewMapping = migratedIds.buildOldToNewMapping(); Map<String, String> oldToNewMapping = migratedIds.buildOldToNewMapping();
@ -231,6 +225,7 @@ public class SaasMigrationService implements TenantSyncService {
List<ManualRedactionEntry> manualRedactionEntriesToAdd = migratedIds.getManualRedactionEntriesToAdd(); List<ManualRedactionEntry> manualRedactionEntriesToAdd = migratedIds.getManualRedactionEntriesToAdd();
int count = addManualRedactionEntries(manualRedactionEntriesToAdd); int count = addManualRedactionEntries(manualRedactionEntriesToAdd);
log.info("Added {} additional manual entries.", count); log.info("Added {} additional manual entries.", count);
deleteSectionGrid(dossierId, fileId);
saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED); saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED);
log.info("AnnotationIds migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId); log.info("AnnotationIds migration finished for saas migration for tenant {} dossier {} and file {}", TenantContext.getTenantId(), dossierId, fileId);
@ -238,15 +233,25 @@ public class SaasMigrationService implements TenantSyncService {
} }
private void deleteSectionGrid(String dossierId, String fileId) {
try {
storageService.deleteObject(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.SECTION_GRID));
} catch (StorageObjectDoesNotExist e) {
log.info("No sectiongrid found for {}, {}, ignoring....", dossierId, fileId);
}
}
private int addManualRedactionEntries(List<ManualRedactionEntry> manualRedactionEntriesToAdd) { private int addManualRedactionEntries(List<ManualRedactionEntry> manualRedactionEntriesToAdd) {
manualRedactionEntriesToAdd.forEach(add -> { manualRedactionEntriesToAdd.forEach(add -> {
if(add.getSection() != null && add.getSection().length() > 254){ if (add.getSection() != null && add.getSection().length() > 254) {
add.setSection(add.getSection().substring(0, 254)); add.setSection(add.getSection().substring(0, 254));
} }
}); });
return manualRedactionService.addManualRedactionEntries(manualRedactionEntriesToAdd, true); return manualRedactionService.addManualRedactionEntries(manualRedactionEntriesToAdd, true);
} }
@ -273,10 +278,10 @@ public class SaasMigrationService implements TenantSyncService {
updateAnnotationIds(fileId, idMapping); updateAnnotationIds(fileId, idMapping);
} catch (Exception e) { } catch (Exception e) {
String message = String.format("Error during annotation id migration for tenant %s dossier %s and file %s, cause %s", String message = String.format("Error during annotation id migration for tenant %s dossier %s and file %s, cause %s",
TenantContext.getTenantId(), TenantContext.getTenantId(),
dossierId, dossierId,
fileId, fileId,
e.getMessage()); e.getMessage());
saasMigrationStatusPersistenceService.updateErrorStatus(fileId, message); saasMigrationStatusPersistenceService.updateErrorStatus(fileId, message);
log.error(message); log.error(message);
throw e; throw e;