Search in sources :

Example 1 with TaskQueryService

use of org.kie.internal.task.api.TaskQueryService in project jbpm by kiegroup.

the class CancelDeadlineCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskDeadlinesService deadlineService = context.getTaskDeadlinesService();
    TaskQueryService queryService = context.getTaskQueryService();
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    InternalTask task = (InternalTask) queryService.getTaskInstanceById(taskId);
    if (task == null || task.getDeadlines() == null) {
        return null;
    }
    Iterator<? extends Deadline> it = null;
    if (removeStart) {
        if (task.getDeadlines().getStartDeadlines() != null) {
            deadlineService.unschedule(taskId, DeadlineType.START);
            it = task.getDeadlines().getStartDeadlines().iterator();
            while (it.hasNext()) {
                persistenceContext.removeDeadline(it.next());
                it.remove();
            }
        }
    }
    if (removeEnd) {
        if (task.getDeadlines().getEndDeadlines() != null) {
            deadlineService.unschedule(taskId, DeadlineType.END);
            it = task.getDeadlines().getEndDeadlines().iterator();
            while (it.hasNext()) {
                persistenceContext.removeDeadline(it.next());
                it.remove();
            }
        }
    }
    return null;
}
Also used : TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskQueryService(org.kie.internal.task.api.TaskQueryService) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 2 with TaskQueryService

use of org.kie.internal.task.api.TaskQueryService in project jbpm by kiegroup.

the class ProcessSubTaskCommand method execute.

@Override
public Void execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    TaskInstanceService instanceService = context.getTaskInstanceService();
    TaskQueryService queryService = context.getTaskQueryService();
    Task task = queryService.getTaskInstanceById(taskId);
    if (task == null) {
        return null;
    }
    Task parentTask = null;
    if (task.getTaskData().getParentId() != -1) {
        parentTask = queryService.getTaskInstanceById(task.getTaskData().getParentId());
    }
    if (parentTask != null) {
        if (((InternalTask) parentTask).getSubTaskStrategy() != null && ((InternalTask) parentTask).getSubTaskStrategy().equals(SubTasksStrategy.EndParentOnAllSubTasksEnd)) {
            List<TaskSummary> subTasks = queryService.getSubTasksByParent(parentTask.getId());
            // If there are no more sub tasks or if the last sub task is the one that we are completing now
            if (subTasks.isEmpty() || (subTasks.size() == 1 && subTasks.get(0).getId().equals(taskId))) {
                // Completing parent task if all the sub task has being completed, including the one that we are completing now
                instanceService.complete(parentTask.getId(), "Administrator", data);
            }
        }
    }
    if (((InternalTask) task).getSubTaskStrategy() != null && ((InternalTask) task).getSubTaskStrategy().equals(SubTasksStrategy.SkipAllSubTasksOnParentSkip)) {
        List<TaskSummary> subTasks = queryService.getSubTasksByParent(task.getId());
        for (TaskSummary taskSummary : subTasks) {
            Task subTask = queryService.getTaskInstanceById(taskSummary.getId());
            // Exit each sub task because the parent task was aborted
            instanceService.skip(subTask.getId(), "Administrator");
        }
    }
    return null;
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskInstanceService(org.kie.internal.task.api.TaskInstanceService) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskSummary(org.kie.api.task.model.TaskSummary) TaskQueryService(org.kie.internal.task.api.TaskQueryService)

Aggregations

TaskQueryService (org.kie.internal.task.api.TaskQueryService)2 InternalTask (org.kie.internal.task.api.model.InternalTask)2 Task (org.kie.api.task.model.Task)1 TaskSummary (org.kie.api.task.model.TaskSummary)1 TaskDeadlinesService (org.kie.internal.task.api.TaskDeadlinesService)1 TaskInstanceService (org.kie.internal.task.api.TaskInstanceService)1 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)1