Skip to content

Commit

Permalink
Merge pull request kitodo#6155 from effective-webwork/correction-comm…
Browse files Browse the repository at this point in the history
…ent-state

Correction comment state
  • Loading branch information
solth authored Aug 1, 2024
2 parents 45b9930 + 6f295a2 commit 1f5499d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -398,13 +405,13 @@ 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()));
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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}

0 comments on commit 1f5499d

Please sign in to comment.