Skip to content

Commit

Permalink
Merge pull request kitodo#5657 from markusweigelt/task-action-processor
Browse files Browse the repository at this point in the history
Task action processor
  • Loading branch information
solth authored Oct 2, 2023
2 parents 409d5d3 + b7fa835 commit eb3d4df
Show file tree
Hide file tree
Showing 15 changed files with 695 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ public enum TaskEditType {
/**
* Automatic = all kinds of automatic steps.
*/
AUTOMATIC(4, "automatic");
AUTOMATIC(4, "automatic"),

/**
* Queue = all kinds of changes by ActiveMQ.
*/
QUEUE(5, "queue");

private int value;
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.kitodo.data.database.beans.Comment;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Task;
import org.kitodo.data.database.exceptions.DAOException;

public class CommentDAO extends BaseDAO<Comment> {
Expand Down Expand Up @@ -54,6 +55,18 @@ public List<Comment> getAllByProcess(Process process) {
Collections.singletonMap("processId", process.getId()));
}

/**
* Get all comments by task ordered by id ascending.
*
* @param task
* The current task to get the comments for
* @return List of comments
*/
public List<Comment> getAllByTask(Task task) {
return getByQuery("FROM Comment WHERE currentTask_id = :taskId ORDER BY id ASC",
Collections.singletonMap("taskId", task.getId()));
}

/**
* Save list of comments.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ public enum ParameterCore implements ParameterInterface {

ACTIVE_MQ_FINALIZE_STEP_QUEUE(new Parameter<UndefinedParameter>("activeMQ.finalizeStep.queue")),

ACTIVE_MQ_TASK_ACTION_QUEUE(new Parameter<UndefinedParameter>("activeMQ.taskAction.queue")),

ACTIVE_MQ_USER(new Parameter<UndefinedParameter>("activeMQ.user")),

ACTIVE_MQ_RESULTS_TOPIC(new Parameter<UndefinedParameter>("activeMQ.results.topic")),
Expand Down
36 changes: 36 additions & 0 deletions Kitodo/src/main/java/org/kitodo/exceptions/ProcessorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.exceptions;

public class ProcessorException extends Exception {

/**
* Constructor with given exception.
*
* @param exception
* as Exception
*/
public ProcessorException(Exception exception) {
super(exception);
}

/**
* Constructor with given message.
*
* @param message
* the exception message
*/
public ProcessorException(String message) {
super(message);
}

}
31 changes: 26 additions & 5 deletions Kitodo/src/main/java/org/kitodo/production/forms/CommentForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Task;
import org.kitodo.data.database.enums.CommentType;
import org.kitodo.data.database.enums.TaskEditType;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.data.elasticsearch.exceptions.CustomResponseException;
import org.kitodo.data.exceptions.DataException;
Expand Down Expand Up @@ -159,7 +160,7 @@ public String addCommentToAllBatchProcesses() {
*/
private void reportProblem(Comment comment) {
try {
this.workflowControllerService.reportProblem(comment);
this.workflowControllerService.reportProblem(comment, TaskEditType.MANUAL_SINGLE);
} catch (DataException e) {
Helper.setErrorMessage("reportingProblem", logger, e);
}
Expand Down Expand Up @@ -225,11 +226,11 @@ public int getSizeOfPreviousStepsForProblemReporting() {
*/
public String solveProblem(Comment comment) {
try {
this.workflowControllerService.solveProblem(comment);
this.workflowControllerService.solveProblem(comment, TaskEditType.MANUAL_SINGLE);
} catch (DataException | DAOException | IOException e) {
Helper.setErrorMessage("SolveProblem", logger, e);
}
refreshProcess(this.currentTask.getProcess());
refreshProcess(comment.getCurrentTask().getProcess());
return MessageFormat.format(REDIRECT_PATH, "tasks");
}

Expand All @@ -239,15 +240,35 @@ public String solveProblem(Comment comment) {
public String solveProblemForAllBatchProcesses(Comment comment) {
for (Task task : batchHelper.getSteps()) {
for (Comment processComment : ServiceManager.getCommentService().getAllCommentsByProcess(task.getProcess())) {
if (!processComment.isCorrected()
&& processComment.getCorrectionTask().getTitle().equals(comment.getCorrectionTask().getTitle())) {
if (!processComment.isCorrected() && verifyCorrectionTasks(comment.getCorrectionTask(),
processComment.getCorrectionTask())) {
solveProblem(processComment);
}
}
}
return MessageFormat.format(REDIRECT_PATH, "tasks");
}

/**
* Verify whether both correction tasks are null or share identical titles.
*
* @param commentCorrectionTask
* The comment correction task
* @param processCommentCorrectionTask
* The process comment correction task
* @return True if they are null or have equal titles
*/
private static boolean verifyCorrectionTasks(Task commentCorrectionTask, Task processCommentCorrectionTask) {
if (Objects.isNull(commentCorrectionTask) && Objects.isNull(processCommentCorrectionTask)) {
return true;
} else if (Objects.isNull(commentCorrectionTask) && Objects.nonNull(
processCommentCorrectionTask) || Objects.nonNull(commentCorrectionTask) && Objects.isNull(
processCommentCorrectionTask)) {
return false;
}
return processCommentCorrectionTask.getTitle().equals(commentCorrectionTask.getTitle());
}

/**
* refresh the process in the session.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ActiveMQDirector implements Runnable, ServletContextListener {
private static Collection<? extends ActiveMQProcessor> services;

static {
services = Arrays.asList(new FinalizeStepProcessor());
services = Arrays.asList(new FinalizeStepProcessor(), new TaskActionProcessor());
}

private static Connection connection = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.kitodo.data.database.beans.Client;
import org.kitodo.data.database.beans.User;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.exceptions.ProcessorException;
import org.kitodo.production.enums.ReportLevel;
import org.kitodo.production.helper.Helper;
import org.kitodo.production.security.SecurityUserDetails;
Expand Down Expand Up @@ -63,7 +64,7 @@ public abstract class ActiveMQProcessor implements MessageListener {
* an object providing access to the fields of the received map
* message
*/
protected abstract void process(MapMessageObjectReader ticket) throws DAOException, JMSException;
protected abstract void process(MapMessageObjectReader ticket) throws ProcessorException, JMSException;

/**
* Instantiating the class ActiveMQProcessor always requires to pass the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.kitodo.data.database.beans.Property;
import org.kitodo.data.database.enums.CommentType;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.exceptions.ProcessorException;
import org.kitodo.production.forms.CurrentTaskForm;
import org.kitodo.production.services.ServiceManager;

Expand All @@ -44,32 +45,36 @@ public FinalizeStepProcessor() {
}

/**
* This is the main routine processing incoming tickets. It gets an
* CurrentTaskForm object, sets it to the appropriate step which is
* retrieved from the database, appends the message − if any − to the wiki
* field, and executes the form’s the step close function.
* This is the main routine processing incoming tickets. It gets an CurrentTaskForm object, sets it to the
* appropriate step which is retrieved from the database, appends the message − if any − to the wiki field, and
* executes the form’s the step close function.
*
* @param ticket
* the incoming message
* the incoming message
*/
@Override
protected void process(MapMessageObjectReader ticket) throws DAOException, JMSException {
protected void process(MapMessageObjectReader ticket) throws ProcessorException, JMSException {
CurrentTaskForm dialog = new CurrentTaskForm();
Integer stepID = ticket.getMandatoryInteger("id");
dialog.setCurrentTask(ServiceManager.getTaskService().getById(stepID));
if (ticket.hasField("properties")) {
updateProperties(dialog, ticket.getMapOfStringToString("properties"));
}
if (ticket.hasField("message")) {
Comment comment = new Comment();
comment.setProcess(dialog.getCurrentTask().getProcess());
comment.setAuthor(ServiceManager.getUserService().getCurrentUser());
comment.setMessage(ticket.getString("message"));
comment.setType(CommentType.INFO);
comment.setCreationDate(new Date());
ServiceManager.getCommentService().saveToDatabase(comment);
try {
Integer stepID = ticket.getMandatoryInteger("id");
dialog.setCurrentTask(ServiceManager.getTaskService().getById(stepID));

if (ticket.hasField("properties")) {
updateProperties(dialog, ticket.getMapOfStringToString("properties"));
}
if (ticket.hasField("message")) {
Comment comment = new Comment();
comment.setProcess(dialog.getCurrentTask().getProcess());
comment.setMessage(ticket.getString("message"));
comment.setAuthor(ServiceManager.getUserService().getCurrentUser());
comment.setType(CommentType.INFO);
comment.setCreationDate(new Date());
ServiceManager.getCommentService().saveToDatabase(comment);
}
dialog.closeTaskByUser();
} catch (DAOException e) {
throw new ProcessorException(e);
}
dialog.closeTaskByUser();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.interfaces.activemq;

public enum TaskAction {
/**
* Adds a comment to the task.
*/
COMMENT,

/**
* Add an error comment when task status is INWORK and set the task status to LOCKED if the correction id is set.
*/
ERROR_OPEN,

/**
* Set task status of LOCKED (if correction id is set) or INWORK (if correction id is not set) task to OPEN.
*/
ERROR_CLOSE,

/**
* Set task status of open task to INWORK.
*/
PROCESS,

/**
* Close a task.
*/
CLOSE
}
Loading

0 comments on commit eb3d4df

Please sign in to comment.