From 559a0b5e5693ca209bc17c0fe296a44a2baafb39 Mon Sep 17 00:00:00 2001 From: Andrei Isvoran Date: Tue, 10 Oct 2023 15:33:43 +0300 Subject: [PATCH] RED-7738 - Fix rollback issue and treat non-manual redaction removal in a Transactional block --- .../service/ManualRedactionService.java | 92 ++++++++++--------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/ManualRedactionService.java b/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/ManualRedactionService.java index 9f0b15eb6..e8a4d7af6 100644 --- a/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/ManualRedactionService.java +++ b/persistence-service-v1/persistence-service-server-v1/src/main/java/com/iqser/red/service/peristence/v1/server/service/ManualRedactionService.java @@ -61,6 +61,7 @@ import com.iqser.red.service.persistence.service.v1.api.model.annotations.Remove import com.iqser.red.service.persistence.service.v1.api.model.annotations.ResizeRedactionRequest; import com.iqser.red.service.persistence.service.v1.api.model.annotations.entitymapped.IdRemoval; import com.iqser.red.service.persistence.service.v1.api.model.annotations.entitymapped.ManualRedactionEntry; +import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.ProcessingStatus; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.WorkflowStatus; import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.type.DictionaryEntryType; @@ -184,7 +185,6 @@ public class ManualRedactionService { } - @Transactional public List addRemoveRedaction(String dossierId, String fileId, List removeRedactionRequests) { RedactionLog redactionLog = null; @@ -200,46 +200,7 @@ public class ManualRedactionService { log.info("hard delete ManualRedactions for file {} and annotation {}", fileId, removeRedactionRequest.getAnnotationId()); manualRedactionProviderService.hardDeleteManualRedactions(fileId, removeRedactionRequest.getAnnotationId()); } else { - - log.info("add removeRedaction for file {} and annotation {}", fileId, removeRedactionRequest.getAnnotationId()); - var idRemoval = convert(removeRedactionPersistenceService.insert(fileId, removeRedactionRequest), IdRemoval.class); - - if (redactionLog == null) { - redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), fileId); - } - - Long commentId = null; - if (removeRedactionRequest.getComment() != null) { - commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), removeRedactionRequest.getComment(), removeRedactionRequest.getUser()).getId(); - } - - if (!removeRedactionRequest.isRemoveFromDictionary() && AnnotationStatus.APPROVED.equals(removeRedactionRequest.getStatus())) { - Optional redactionLogEntryOptional = redactionLog.getRedactionLogEntry() - .stream() - .filter(entry -> entry.getId().equals(removeRedactionRequest.getAnnotationId())) - .findFirst(); - var requiresAnalysis = redactionLogEntryOptional.isPresent() && redactionLogEntryOptional.get().isHint(); - actionPerformed = actionPerformed || requiresAnalysis; - if (!requiresAnalysis && idRemoval.isApproved()) { - removeRedactionPersistenceService.markAsProcessed(idRemoval); - } - } - - var removedFromDictionary = handleRemoveFromDictionary(redactionLog, - dossier, - fileId, - removeRedactionRequest.getAnnotationId(), - removeRedactionRequest.getStatus(), - removeRedactionRequest.isRemoveFromDictionary(), - false); - - if (!removedFromDictionary && idRemoval.isApproved()) { - removeRedactionPersistenceService.markAsProcessed(idRemoval); - } - - actionPerformed = actionPerformed || removedFromDictionary; - - response.add(ManualAddResponse.builder().annotationId(removeRedactionRequest.getAnnotationId()).commentId(commentId).build()); + actionPerformed = removeNonManualRedaction(redactionLog, fileId, removeRedactionRequest, dossier, actionPerformed, response); } } @@ -252,6 +213,55 @@ public class ManualRedactionService { return response; } + @Transactional + private boolean removeNonManualRedaction(RedactionLog redactionLog, String fileId, RemoveRedactionRequest removeRedactionRequest, DossierEntity dossier, boolean actionPerformed, + List response) { + + log.info("add removeRedaction for file {} and annotation {}", fileId, removeRedactionRequest.getAnnotationId()); + + Long commentId = null; + String comment = removeRedactionRequest.getComment(); + if (comment != null) { + commentId = addComment(fileId, removeRedactionRequest.getAnnotationId(), comment, removeRedactionRequest.getUser()).getId(); + } + + var idRemoval = convert(removeRedactionPersistenceService.insert(fileId, removeRedactionRequest), IdRemoval.class); + + if (redactionLog == null) { + redactionLog = fileManagementStorageService.getRedactionLog(dossier.getId(), fileId); + } + + if (!removeRedactionRequest.isRemoveFromDictionary() && AnnotationStatus.APPROVED.equals(removeRedactionRequest.getStatus())) { + Optional redactionLogEntryOptional = redactionLog.getRedactionLogEntry() + .stream() + .filter(entry -> entry.getId().equals(removeRedactionRequest.getAnnotationId())) + .findFirst(); + var requiresAnalysis = redactionLogEntryOptional.isPresent() && redactionLogEntryOptional.get().isHint(); + actionPerformed = actionPerformed || requiresAnalysis; + if (!requiresAnalysis && idRemoval.isApproved()) { + removeRedactionPersistenceService.markAsProcessed(idRemoval); + } + } + + var removedFromDictionary = handleRemoveFromDictionary(redactionLog, + dossier, + fileId, + removeRedactionRequest.getAnnotationId(), + removeRedactionRequest.getStatus(), + removeRedactionRequest.isRemoveFromDictionary(), + false); + + if (!removedFromDictionary && idRemoval.isApproved()) { + removeRedactionPersistenceService.markAsProcessed(idRemoval); + } + + actionPerformed = actionPerformed || removedFromDictionary; + + response.add(ManualAddResponse.builder().annotationId(removeRedactionRequest.getAnnotationId()).commentId(commentId).build()); + + return actionPerformed; + } + @Transactional public List addForceRedaction(String dossierId, String fileId, List forceRedactionRequests) { -- 2.47.2