use of org.kie.internal.task.api.model.InternalTask 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.InternalTask 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;
}
use of org.kie.internal.task.api.model.InternalTask 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.InternalTask 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.InternalTask 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