From b6c8ec2f7c33846b8940128446fd6dcf51fe4280 Mon Sep 17 00:00:00 2001 From: Kilian Schuettler Date: Tue, 23 Jul 2024 09:58:58 +0200 Subject: [PATCH] migration-fp-hotfix --- .../migration/SaasMigrationService.java | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/migration/SaasMigrationService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/migration/SaasMigrationService.java index 2b14a7384..a7abfe88d 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/migration/SaasMigrationService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/migration/SaasMigrationService.java @@ -130,11 +130,31 @@ public class SaasMigrationService implements TenantSyncService { } log.info("Added {} documents for tenant {} to Layout-Parsing queue for saas migration", numberOfFiles, TenantContext.getTenantId()); + if (numberOfFiles == 0) { + finalizeMigration(); + } } public void startMigrationForFile(String dossierId, String fileId) { + var dossier = dossierService.getDossierById(dossierId); + + if (dossier.getHardDeletedTime() != null) { + if (fileStatusPersistenceService.getStatus(fileId).getHardDeletedTime() != null) { + saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED); + return; + } else { + fileStatusPersistenceService.hardDelete(fileId, dossier.getHardDeletedTime()); + saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED); + return; + } + } + if (fileStatusPersistenceService.getStatus(fileId).getHardDeletedTime() != null) { + saasMigrationStatusPersistenceService.updateStatus(fileId, SaasMigrationStatus.FINISHED); + return; + } + log.info("Starting Migration for dossierId {} and fileId {}", dossierId, fileId); saasMigrationStatusPersistenceService.createMigrationRequiredStatus(dossierId, fileId); var layoutParsingRequest = layoutParsingRequestFactory.build(dossierId, fileId, false); @@ -142,15 +162,6 @@ public class SaasMigrationService implements TenantSyncService { } - public void requeueErrorFiles() { - - automaticAnalysisJob.stopForTenant(TenantContext.getTenantId()); - saasMigrationStatusPersistenceService.findAllByStatus(SaasMigrationStatus.ERROR) - .forEach(migrationStatus -> startMigrationForFile(migrationStatus.getDossierId(), migrationStatus.getFileId())); - - } - - public void handleLayoutParsingFinished(String dossierId, String fileId) { if (!layoutParsingFilesExist(dossierId, fileId)) { @@ -171,14 +182,14 @@ public class SaasMigrationService implements TenantSyncService { String dossierTemplateId = dossierService.getDossierById(dossierId).getDossierTemplateId(); rabbitTemplate.convertAndSend(MIGRATION_QUEUE, - MigrationRequest.builder() - .dossierTemplateId(dossierTemplateId) - .dossierId(dossierId) - .fileId(fileId) - .fileIsApproved(fileStatusPersistenceService.getStatus(fileId).getWorkflowStatus().equals(WorkflowStatus.APPROVED)) - .manualRedactions(manualRedactionProviderService.getManualRedactions(fileId, ManualChangesQueryOptions.allWithoutDeleted())) - .entitiesWithComments(commentService.getCommentCounts(fileId).keySet()) - .build()); + MigrationRequest.builder() + .dossierTemplateId(dossierTemplateId) + .dossierId(dossierId) + .fileId(fileId) + .fileIsApproved(fileStatusPersistenceService.getStatus(fileId).getWorkflowStatus().equals(WorkflowStatus.APPROVED)) + .manualRedactions(manualRedactionProviderService.getManualRedactions(fileId, ManualChangesQueryOptions.allWithoutDeleted())) + .entitiesWithComments(commentService.getCommentCounts(fileId).keySet()) + .build()); } catch (Exception e) { log.error("Queuing of entityLog migration failed with {}", e.getMessage()); saasMigrationStatusPersistenceService.updateErrorStatus(fileId, String.format("Queuing of entityLog migration failed with %s", e.getMessage())); @@ -190,9 +201,9 @@ public class SaasMigrationService implements TenantSyncService { private boolean layoutParsingFilesExist(String dossierId, String fileId) { 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_PAGES)) // - && storageService.objectExists(TenantContext.getTenantId(), StorageIdUtils.getStorageId(dossierId, fileId, FileType.DOCUMENT_POSITION)); + && 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_POSITION)); } @@ -299,10 +310,10 @@ public class SaasMigrationService implements TenantSyncService { updateAnnotationIds(fileId, idMapping); } catch (Exception e) { String message = String.format("Error during annotation id migration for tenant %s dossier %s and file %s, cause %s", - TenantContext.getTenantId(), - dossierId, - fileId, - e.getMessage()); + TenantContext.getTenantId(), + dossierId, + fileId, + e.getMessage()); saasMigrationStatusPersistenceService.updateErrorStatus(fileId, message); log.error(message); throw e; @@ -313,7 +324,7 @@ public class SaasMigrationService implements TenantSyncService { private void finalizeMigration() { if (saasMigrationStatusPersistenceService.countByStatus(SaasMigrationStatus.FINISHED) == saasMigrationStatusPersistenceService.countAll()) { -// automaticAnalysisJob.startForTenant(TenantContext.getTenantId()); +// automaticAnalysisJob.startForTenant(TenantContext.getTenantId()); // AutomaticAnalysisJob should be re-enabled by re-starting the persistence service pod after a rule change tenantProvider.updateDetails(TenantContext.getTenantId(), UpdateDetailsRequest.builder().key("persistence-service-ready").value(true).build()); log.info("Saas migration finished for tenantId {}, re-enabled scheduler", TenantContext.getTenantId()); }