Search in sources :

Example 1 with DeadlineType

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

the class CancelTaskDeadlineCommand method execute.

@Override
public Void 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);
    }
    logger.debug("About to cancel deadline {} on a task {}", deadlineId, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    DeadlineType type = DeadlineType.START;
    Deadline deadline = deadlines.getStartDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
    if (deadline == null) {
        deadline = deadlines.getEndDeadlines().stream().filter(d -> deadlineId.equals(d.getId())).findFirst().orElse(null);
        type = DeadlineType.END;
    }
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    deadlinesService.unschedule(taskId, deadline, type);
    persistenceContext.removeDeadline(deadline);
    return null;
}
Also used : DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) LoggerFactory(org.slf4j.LoggerFactory) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext) Deadline(org.kie.internal.task.api.model.Deadline) Deadlines(org.kie.internal.task.api.model.Deadlines) DeadlineType(org.kie.internal.task.api.TaskDeadlinesService.DeadlineType) 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) TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) Deadline(org.kie.internal.task.api.model.Deadline) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Aggregations

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 Task (org.kie.api.task.model.Task)1 TaskDeadlinesService (org.kie.internal.task.api.TaskDeadlinesService)1 DeadlineType (org.kie.internal.task.api.TaskDeadlinesService.DeadlineType)1 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)1 Deadline (org.kie.internal.task.api.model.Deadline)1 Deadlines (org.kie.internal.task.api.model.Deadlines)1 InternalTask (org.kie.internal.task.api.model.InternalTask)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1