use of org.kie.internal.task.api.model.Deadlines 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.model.Deadlines in project jbpm by kiegroup.
the class TaskDeadlinesServiceImpl method unschedule.
public void unschedule(long taskId, Deadline deadline, DeadlineType type) {
Task task = persistenceContext.findTask(taskId);
String deploymentId = task.getTaskData().getDeploymentId();
Deadlines deadlines = ((InternalTask) task).getDeadlines();
TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null && timerService instanceof GlobalTimerService) {
TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId());
logger.debug("unscheduling timer job for deadline {} {} and task {} using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService);
JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
if (jobHandle == null) {
jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
}
timerService.removeJob(jobHandle);
// mark the deadlines so they won't be rescheduled again
deadline.setEscalated(true);
}
}
use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.
the class ListTaskNotificationsCommand method execute.
@Override
public List<TaskNotification> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Language lang = factory.newLanguage();
lang.setMapkey("en-UK");
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<TaskNotification> notificationsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> notificationsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> result = new ArrayList<>();
result.addAll(notificationsNotStarted);
result.addAll(notificationsNotCompleted);
if (activeOnly) {
logger.debug("Removing already completed deadlines from the result");
result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
}
return result;
}
use of org.kie.internal.task.api.model.Deadlines 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;
}
use of org.kie.internal.task.api.model.Deadlines 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