From 768384a84ce09e2a680409676f2eee1a1e82db6f Mon Sep 17 00:00:00 2001 From: Kilian Schuettler Date: Mon, 12 Feb 2024 16:19:15 +0100 Subject: [PATCH] RED-8385: delete viewer doc, when rotating origin file, such that it is recreated with the rotation --- .../controller/FileManagementController.java | 2 + .../v1/processor/service/FileService.java | 254 ++++++++++-------- 2 files changed, 145 insertions(+), 111 deletions(-) diff --git a/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/FileManagementController.java b/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/FileManagementController.java index a678cd9cc..6560a9118 100644 --- a/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/FileManagementController.java +++ b/persistence-service-v1/persistence-service-external-api-impl-v1/src/main/java/com/iqser/red/persistence/service/v1/external/api/impl/controller/FileManagementController.java @@ -253,6 +253,8 @@ public class FileManagementController implements FileManagementResource { .pages(rotatePagesRequest.getPages()) .build()); + fileService.deleteViewerDocument(dossierId, fileId); + fileStatusManagementService.updateFileModificationDate(fileId); FileModel fileModel = fileStatusManagementService.getFileStatus(fileId); diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileService.java index 9afbb5b7a..d2361d745 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/FileService.java @@ -113,41 +113,47 @@ public class FileService { public void softDeleteFile(String dossierId, String fileId, OffsetDateTime softDeletedTime) { - forceRedactionPersistenceService.findForceRedactions(fileId, false).forEach(annotation -> { - forceRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + forceRedactionPersistenceService.findForceRedactions(fileId, false) + .forEach(annotation -> { + forceRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); - removeRedactionPersistenceService.findRemoveRedactions(fileId, false).forEach(annotation -> { - removeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + removeRedactionPersistenceService.findRemoveRedactions(fileId, false) + .forEach(annotation -> { + removeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); - addRedactionPersistenceService.findAddRedactions(fileId, false).forEach(annotation -> { - addRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + addRedactionPersistenceService.findAddRedactions(fileId, false) + .forEach(annotation -> { + addRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); - recategorizationPersistenceService.findRecategorizations(fileId, false).forEach(recatigorization -> { - recategorizationPersistenceService.softDelete(fileId, recatigorization.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + recategorizationPersistenceService.findRecategorizations(fileId, false) + .forEach(recatigorization -> { + recategorizationPersistenceService.softDelete(fileId, recatigorization.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); - resizeRedactionPersistenceService.findResizeRedactions(fileId, false).forEach(annotation -> { - resizeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + resizeRedactionPersistenceService.findResizeRedactions(fileId, false) + .forEach(annotation -> { + resizeRedactionPersistenceService.softDelete(fileId, annotation.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); - legalBasisChangePersistenceService.findLegalBasisChanges(fileId, false).forEach(legalBasisChange -> { - legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId().getAnnotationId(), softDeletedTime); - commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId().getAnnotationId(), false) - .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); - }); + legalBasisChangePersistenceService.findLegalBasisChanges(fileId, false) + .forEach(legalBasisChange -> { + legalBasisChangePersistenceService.softDelete(fileId, legalBasisChange.getId().getAnnotationId(), softDeletedTime); + commentPersistenceService.findCommentsByAnnotationId(fileId, legalBasisChange.getId().getAnnotationId(), false) + .forEach(comment -> commentPersistenceService.softDelete(comment.getId(), softDeletedTime)); + }); viewedPagesPersistenceService.deleteForFile(fileId); indexingService.addToIndexingQueue(IndexMessageType.UPDATE, null, dossierId, fileId, 2); @@ -170,43 +176,49 @@ public class FileService { public void hardDeleteFile(String dossierId, String fileId) { - Arrays.stream(FileType.values()).forEach(fileType -> { - try { - fileManagementStorageService.deleteObject(dossierId, fileId, fileType); - } catch (Exception e) { - log.warn("Failed to physically delete file: {} with type {}", fileId, fileType); - } - }); + Arrays.stream(FileType.values()) + .forEach(fileType -> { + try { + fileManagementStorageService.deleteObject(dossierId, fileId, fileType); + } catch (Exception e) { + log.warn("Failed to physically delete file: {} with type {}", fileId, fileType); + } + }); - forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> { - forceRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) - .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); - }); + forceRedactionPersistenceService.findForceRedactions(fileId, true) + .forEach(annotation -> { + forceRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); + }); - removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> { - removeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) - .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); - }); + removeRedactionPersistenceService.findRemoveRedactions(fileId, true) + .forEach(annotation -> { + removeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); + }); - addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> { - addRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) - .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); - }); + addRedactionPersistenceService.findAddRedactions(fileId, true) + .forEach(annotation -> { + addRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); + }); - recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> { - recategorizationPersistenceService.hardDelete(fileId, recatigorization.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true) - .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); - }); + recategorizationPersistenceService.findRecategorizations(fileId, true) + .forEach(recatigorization -> { + recategorizationPersistenceService.hardDelete(fileId, recatigorization.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true) + .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); + }); - resizeRedactionPersistenceService.findResizeRedactions(fileId, true).forEach(annotation -> { - resizeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) - .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); - }); + resizeRedactionPersistenceService.findResizeRedactions(fileId, true) + .forEach(annotation -> { + resizeRedactionPersistenceService.hardDelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> commentPersistenceService.hardDelete(comment.getId())); + }); indexingService.addToDeleteFromIndexQueue(dossierId, fileId, 2); } @@ -232,75 +244,95 @@ public class FileService { public void undeleteFile(String dossierTemplateId, String dossierId, String fileId, OffsetDateTime softDeletedTime) { - forceRedactionPersistenceService.findForceRedactions(fileId, true).forEach(annotation -> { - if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { - forceRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + forceRedactionPersistenceService.findForceRedactions(fileId, true) + .forEach(annotation -> { + if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { + forceRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); - removeRedactionPersistenceService.findRemoveRedactions(fileId, true).forEach(annotation -> { - if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { - removeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + removeRedactionPersistenceService.findRemoveRedactions(fileId, true) + .forEach(annotation -> { + if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { + removeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); - addRedactionPersistenceService.findAddRedactions(fileId, true).forEach(annotation -> { - if (annotation != null && annotation.getSoftDeletedTime() != null && (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime() - .isAfter(softDeletedTime))) { - addRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + addRedactionPersistenceService.findAddRedactions(fileId, true) + .forEach(annotation -> { + if (annotation != null && annotation.getSoftDeletedTime() != null && (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime() + .isAfter(softDeletedTime))) { + addRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); - recategorizationPersistenceService.findRecategorizations(fileId, true).forEach(recatigorization -> { - if (recatigorization.getSoftDeletedTime().equals(softDeletedTime) || recatigorization.getSoftDeletedTime().isAfter(softDeletedTime)) { - recategorizationPersistenceService.undelete(fileId, recatigorization.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + recategorizationPersistenceService.findRecategorizations(fileId, true) + .forEach(recatigorization -> { + if (recatigorization.getSoftDeletedTime().equals(softDeletedTime) || recatigorization.getSoftDeletedTime().isAfter(softDeletedTime)) { + recategorizationPersistenceService.undelete(fileId, recatigorization.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, recatigorization.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); - resizeRedactionPersistenceService.findResizeRedactions(fileId, true).forEach(annotation -> { - if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { - resizeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + resizeRedactionPersistenceService.findResizeRedactions(fileId, true) + .forEach(annotation -> { + if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { + resizeRedactionPersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); - legalBasisChangePersistenceService.findLegalBasisChanges(fileId, true).forEach(annotation -> { - if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { - legalBasisChangePersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); - commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true).forEach(comment -> { - if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { - commentPersistenceService.undelete(comment.getId()); + legalBasisChangePersistenceService.findLegalBasisChanges(fileId, true) + .forEach(annotation -> { + if (annotation.getSoftDeletedTime().equals(softDeletedTime) || annotation.getSoftDeletedTime().isAfter(softDeletedTime)) { + legalBasisChangePersistenceService.undelete(fileId, annotation.getId().getAnnotationId()); + commentPersistenceService.findCommentsByAnnotationId(fileId, annotation.getId().getAnnotationId(), true) + .forEach(comment -> { + if (comment.getSoftDeletedTime().equals(softDeletedTime) || comment.getSoftDeletedTime().isAfter(softDeletedTime)) { + commentPersistenceService.undelete(comment.getId()); + } + }); } }); - } - }); indexingService.addToIndexingQueue(IndexMessageType.UPDATE, dossierTemplateId, dossierId, fileId, 2); } + + public void deleteViewerDocument(String dossierId, String fileId) { + + if (fileManagementStorageService.objectExists(dossierId, fileId, FileType.VIEWER_DOCUMENT)) { + fileManagementStorageService.deleteObject(dossierId, fileId, FileType.VIEWER_DOCUMENT); + } + } + } -- 2.47.2