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;
}
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;
}
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;
}
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();
}
Aggregations