Search in sources :

Example 1 with TaskReassignmentImpl

use of org.jbpm.kie.services.impl.admin.TaskReassignmentImpl in project jbpm by kiegroup.

the class ListTaskReassignmentsCommand method execute.

@Override
public List<TaskReassignment> execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    List<TaskReassignment> reassignmantsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> reassignmantsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getReassignments().isEmpty()).map(d -> {
        Reassignment r = d.getEscalations().get(0).getReassignments().get(0);
        return new TaskReassignmentImpl(d.getId(), get(r.getDocumentation()), d.getDate(), r.getPotentialOwners(), !d.isEscalated());
    }).collect(Collectors.toList());
    List<TaskReassignment> result = new ArrayList<>();
    result.addAll(reassignmantsNotStarted);
    result.addAll(reassignmantsNotCompleted);
    if (activeOnly) {
        logger.debug("Removing already completed deadlines from the result");
        result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
    }
    return result;
}
Also used : Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) I18NText(org.kie.api.task.model.I18NText) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) Collectors(java.util.stream.Collectors) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) List(java.util.List) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) Reassignment(org.kie.internal.task.api.model.Reassignment) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) ArrayList(java.util.ArrayList) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskReassignmentImpl(org.jbpm.kie.services.impl.admin.TaskReassignmentImpl) TaskReassignment(org.jbpm.services.api.admin.TaskReassignment) Reassignment(org.kie.internal.task.api.model.Reassignment)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TaskReassignmentImpl (org.jbpm.kie.services.impl.admin.TaskReassignmentImpl)1 TaskReassignment (org.jbpm.services.api.admin.TaskReassignment)1 TaskContext (org.jbpm.services.task.commands.TaskContext)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 Context (org.kie.api.runtime.Context)1 I18NText (org.kie.api.task.model.I18NText)1 Task (org.kie.api.task.model.Task)1 Deadlines (org.kie.internal.task.api.model.Deadlines)1 InternalTask (org.kie.internal.task.api.model.InternalTask)1 Reassignment (org.kie.internal.task.api.model.Reassignment)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1