Search in sources :

Example 1 with TaskDeadlinesService

use of org.kie.internal.task.api.TaskDeadlinesService 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 TaskDeadlinesService

use of org.kie.internal.task.api.TaskDeadlinesService 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)

Example 3 with TaskDeadlinesService

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

the class InitDeadlinesCommand method execute.

@Override
public Void execute(Context context) {
    TaskContext ctx = (TaskContext) context;
    TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
    TaskDeadlinesService deadlineService = ctx.getTaskDeadlinesService();
    try {
        long now = System.currentTimeMillis();
        List<DeadlineSummary> resultList = persistenceContext.queryInTransaction("UnescalatedStartDeadlines", ClassUtil.<List<DeadlineSummary>>castClass(List.class));
        for (DeadlineSummary summary : resultList) {
            long delay = summary.getDate().getTime() - now;
            deadlineService.schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.START);
        }
        resultList = persistenceContext.queryInTransaction("UnescalatedEndDeadlines", ClassUtil.<List<DeadlineSummary>>castClass(List.class));
        for (DeadlineSummary summary : resultList) {
            long delay = summary.getDate().getTime() - now;
            deadlineService.schedule(summary.getTaskId(), summary.getDeadlineId(), delay, DeadlineType.END);
        }
    } catch (Exception e) {
        logger.error("Error when executing deadlines", e);
    }
    return null;
}
Also used : TaskDeadlinesService(org.kie.internal.task.api.TaskDeadlinesService) DeadlineSummary(org.kie.internal.task.api.model.DeadlineSummary) List(java.util.List) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Example 4 with TaskDeadlinesService

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

the class ScheduleTaskDeadlineCommand method execute.

@Override
public Long execute(Context cntxt) {
    TaskContext context = (TaskContext) cntxt;
    Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
    TaskPersistenceContext persistenceContext = context.getPersistenceContext();
    if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
        throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
    }
    logger.debug("About to schedule {} on a task {}", deadline, task);
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    if (type.equals(DeadlineType.START)) {
        deadlines.getStartDeadlines().add(deadline);
    } else {
        deadlines.getEndDeadlines().add(deadline);
    }
    doCallbackOperationForTaskDeadlines(deadlines, context);
    persistenceContext.persistDeadline(deadline);
    persistenceContext.updateTask(task);
    logger.debug("Task updated and deadline stored with id {}", deadline.getId());
    TaskDeadlinesService deadlinesService = context.getTaskDeadlinesService();
    long fireAfterDuration = DateTimeUtils.parseDuration(timeExpression);
    deadline.setDate(new Date(System.currentTimeMillis() + fireAfterDuration));
    logger.debug("Deadline expiration time set to {} and duration {}", deadline.getDate(), fireAfterDuration);
    deadlinesService.schedule(taskId, deadline.getId(), fireAfterDuration, type);
    logger.debug("Deadline on task {} successfully scheduled to fire at {}", task, deadline.getDate());
    return deadline.getId();
}
Also used : 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) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) Date(java.util.Date) TaskPersistenceContext(org.kie.internal.task.api.TaskPersistenceContext)

Aggregations

TaskDeadlinesService (org.kie.internal.task.api.TaskDeadlinesService)4 TaskPersistenceContext (org.kie.internal.task.api.TaskPersistenceContext)4 InternalTask (org.kie.internal.task.api.model.InternalTask)3 TaskContext (org.jbpm.services.task.commands.TaskContext)2 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)2 Task (org.kie.api.task.model.Task)2 Deadlines (org.kie.internal.task.api.model.Deadlines)2 Date (java.util.Date)1 List (java.util.List)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 Context (org.kie.api.runtime.Context)1 DeadlineType (org.kie.internal.task.api.TaskDeadlinesService.DeadlineType)1 TaskQueryService (org.kie.internal.task.api.TaskQueryService)1 Deadline (org.kie.internal.task.api.model.Deadline)1 DeadlineSummary (org.kie.internal.task.api.model.DeadlineSummary)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1