From f172d9d335007e2193863f3b8b330bbd7888cace Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 30 Jul 2024 15:06:19 +0200 Subject: [PATCH 1/3] Add test for 'getCorrectionCommentStatus' --- .../workflow/WorkflowControllerServiceIT.java | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java index c4855a3a7d1..f3d4181feda 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/workflow/WorkflowControllerServiceIT.java @@ -38,9 +38,11 @@ import org.kitodo.data.database.beans.Task; import org.kitodo.data.database.beans.WorkflowCondition; import org.kitodo.data.database.enums.CommentType; +import org.kitodo.data.database.enums.CorrectionComments; import org.kitodo.data.database.enums.TaskEditType; import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.data.elasticsearch.index.converter.ProcessConverter; import org.kitodo.data.exceptions.DataException; import org.kitodo.production.services.ServiceManager; import org.kitodo.production.services.data.TaskService; @@ -420,20 +422,10 @@ public void shouldReportProblem() throws Exception { @Test public void shouldSolveProblem() throws Exception { - Task currentTask = taskService.getById(8); - Task correctionTask = taskService.getById(6); - - Comment correctionComment = new Comment(); - correctionComment.setMessage("Fix it!"); - correctionComment.setAuthor(ServiceManager.getUserService().getById(1)); - correctionComment.setCurrentTask(currentTask); - correctionComment.setCorrectionTask(correctionTask); - correctionComment.setProcess(currentTask.getProcess()); - correctionComment.setType(CommentType.ERROR); - correctionComment.setCorrected(Boolean.FALSE); - correctionComment.setCreationDate(new Date()); - ServiceManager.getCommentService().saveToDatabase(correctionComment); + Comment correctionComment = prepareCorrectionComment(); + Task currentTask = correctionComment.getCurrentTask(); + Task correctionTask = correctionComment.getCorrectionTask(); workflowService.reportProblem(correctionComment, TaskEditType.MANUAL_SINGLE); workflowService.solveProblem(correctionComment, TaskEditType.MANUAL_SINGLE); @@ -454,4 +446,34 @@ public void shouldSolveProblem() throws Exception { assertEquals(TaskStatus.OPEN, correctionComment.getCurrentTask().getProcessingStatus(), "Solving reported problem was unsuccessful - current task '" + currentTask.getTitle() + "' was not set to processing status 'OPEN'!"); } + + @Test + public void shouldGetCorrectCommentStatus() throws DAOException, DataException, IOException { + Comment correctionComment = prepareCorrectionComment(); + workflowService.reportProblem(correctionComment, TaskEditType.MANUAL_SINGLE); + assertEquals(CorrectionComments.OPEN_CORRECTION_COMMENTS, ProcessConverter + .getCorrectionCommentStatus(correctionComment.getProcess())); + workflowService.solveProblem(correctionComment, TaskEditType.MANUAL_SINGLE); + assertEquals(CorrectionComments.NO_OPEN_CORRECTION_COMMENTS, ProcessConverter + .getCorrectionCommentStatus(correctionComment.getProcess())); + } + + private Comment prepareCorrectionComment() throws DAOException { + Task currentTask = taskService.getById(8); + Task correctionTask = taskService.getById(6); + + Comment correctionComment = new Comment(); + correctionComment.setMessage("Fix it!"); + correctionComment.setAuthor(ServiceManager.getUserService().getById(1)); + correctionComment.setCurrentTask(currentTask); + correctionComment.setCorrectionTask(correctionTask); + correctionComment.setProcess(currentTask.getProcess()); + correctionComment.setType(CommentType.ERROR); + correctionComment.setCorrected(Boolean.FALSE); + correctionComment.setCreationDate(new Date()); + + ServiceManager.getCommentService().saveToDatabase(correctionComment); + + return correctionComment; + } } From e7d15d5477304032d9411c15d7e2855a72b258db Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 30 Jul 2024 13:38:28 +0200 Subject: [PATCH 2/3] Save correction comment state to database before re-determining process state --- .../workflow/WorkflowControllerService.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java b/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java index 032a0611810..8f6d4c2fbf0 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java @@ -386,6 +386,13 @@ public void reportProblem(Comment comment, TaskEditType taskEditType) throws Dat */ public void solveProblem(Comment comment, TaskEditType taskEditType) throws DataException, DAOException, IOException { + comment.setCorrected(Boolean.TRUE); + comment.setCorrectionDate(new Date()); + try { + ServiceManager.getCommentService().saveToDatabase(comment); + } catch (DAOException e) { + Helper.setErrorMessage("errorSaving", new Object[] {"comment"}, logger, e); + } if (Objects.nonNull(comment.getCorrectionTask())) { closeTaskByUser(comment.getCorrectionTask()); comment.setCorrectionTask(ServiceManager.getTaskService().getById(comment.getCorrectionTask().getId())); @@ -399,12 +406,8 @@ public void solveProblem(Comment comment, TaskEditType taskEditType) taskService.save(currentTask); } comment.setCurrentTask(ServiceManager.getTaskService().getById(comment.getCurrentTask().getId())); - comment.setCorrected(Boolean.TRUE); - comment.setCorrectionDate(new Date()); - try { - ServiceManager.getCommentService().saveToDatabase(comment); - } catch (DAOException e) { - Helper.setErrorMessage("errorSaving", new Object[] {"comment"}, logger, e); + if (Objects.nonNull(comment.getProcess())) { + comment.setProcess(ServiceManager.getProcessService().getById(comment.getProcess().getId())); } } From 6f295a24df9a37017ff6ca2d9fd5d958467be2fe Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Thu, 1 Aug 2024 11:04:54 +0200 Subject: [PATCH 3/3] Add 'TODO' to suggest further refactoring in the future --- .../services/workflow/WorkflowControllerService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java b/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java index 8f6d4c2fbf0..5575caa251e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/workflow/WorkflowControllerService.java @@ -405,6 +405,10 @@ public void solveProblem(Comment comment, TaskEditType taskEditType) taskService.replaceProcessingUser(currentTask, getCurrentUser()); taskService.save(currentTask); } + // "currentTask" and "process" are re-added to the comment object without saving it to database, again, because + // comment is further used in calling method, hence we make use of a side effect here (without requiring to save + // the comment again, because process ID and current task ID remain the same) + // TODO: refactor to improve readability and maintainability comment.setCurrentTask(ServiceManager.getTaskService().getById(comment.getCurrentTask().getId())); if (Objects.nonNull(comment.getProcess())) { comment.setProcess(ServiceManager.getProcessService().getById(comment.getProcess().getId()));