use of org.kie.internal.task.api.model.DeadlineSummary in project jbpm by kiegroup.
the class ExecuteReminderCommand method execute.
@Override
public Void execute(Context context) {
TaskContext ctx = (TaskContext) context;
UserInfo userInfo = (UserInfo) context.get(EnvironmentName.TASK_USER_INFO);
TaskPersistenceContext persistenceContext = ctx.getPersistenceContext();
try {
Task task = persistenceContext.findTask(taskId);
TaskData taskData = task.getTaskData();
List<DeadlineSummary> resultList = null;
resultList = getAlldeadlines(persistenceContext, taskData);
TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
if (resultList == null || resultList.size() == 0) {
if (taskData.getActualOwner() == null)
return null;
if (taskData != null) {
// check if task is still in valid status
if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
taskEventSupport.fireBeforeTaskNotified(task, ctx);
logger.debug("Sending an Email");
Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
Notification notification = buildDefaultNotification(taskData, task);
NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
taskEventSupport.fireAfterTaskNotified(task, ctx);
}
}
} else {
for (DeadlineSummary deadlineSummary : resultList) {
executedeadLine(ctx, persistenceContext, task, deadlineSummary, taskData);
}
}
} catch (Exception e) {
logger.error("Error when executing deadlines", e);
}
return null;
}
use of org.kie.internal.task.api.model.DeadlineSummary 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.model.DeadlineSummary in project jbpm by kiegroup.
the class TaskDeadlinesServiceImpl method unschedule.
public void unschedule(long taskId, 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) {
if (type == DeadlineType.START) {
List<Deadline> startDeadlines = deadlines.getStartDeadlines();
List<DeadlineSummary> resultList = (List<DeadlineSummary>) persistenceContext.queryWithParametersInTransaction("UnescalatedStartDeadlinesByTaskId", persistenceContext.addParametersToMap("taskId", taskId), ClassUtil.<List<DeadlineSummary>>castClass(List.class));
for (DeadlineSummary summary : resultList) {
TaskDeadlineJob deadlineJob = new TaskDeadlineJob(summary.getTaskId(), summary.getDeadlineId(), DeadlineType.START, deploymentId, task.getTaskData().getProcessInstanceId());
logger.debug("unscheduling timer job for deadline {} {} and task {} using timer service {}", deadlineJob.getId(), summary.getDeadlineId(), 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
for (Deadline deadline : startDeadlines) {
if (deadline.getId() == summary.getDeadlineId()) {
deadline.setEscalated(true);
}
}
}
} else if (type == DeadlineType.END) {
List<Deadline> endDeadlines = deadlines.getStartDeadlines();
List<DeadlineSummary> resultList = (List<DeadlineSummary>) persistenceContext.queryWithParametersInTransaction("UnescalatedEndDeadlinesByTaskId", persistenceContext.addParametersToMap("taskId", taskId), ClassUtil.<List<DeadlineSummary>>castClass(List.class));
for (DeadlineSummary summary : resultList) {
TaskDeadlineJob deadlineJob = new TaskDeadlineJob(summary.getTaskId(), summary.getDeadlineId(), DeadlineType.END, deploymentId, task.getTaskData().getProcessInstanceId());
logger.debug("unscheduling timer job for deadline {} and task {} using timer service {}", deadlineJob.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
for (Deadline deadline : endDeadlines) {
if (deadline.getId() == summary.getDeadlineId()) {
deadline.setEscalated(true);
}
}
}
}
} else {
List<ScheduledFuture<ScheduledTaskDeadline>> knownFutures = null;
if (type == DeadlineType.START) {
knownFutures = startScheduledTaskDeadlines.get(taskId);
} else if (type == DeadlineType.END) {
knownFutures = endScheduledTaskDeadlines.get(taskId);
}
if (knownFutures == null) {
return;
}
Iterator<ScheduledFuture<ScheduledTaskDeadline>> it = knownFutures.iterator();
while (it.hasNext()) {
ScheduledFuture<ScheduledTaskDeadline> scheduled = it.next();
try {
if (!scheduled.isDone() && !scheduled.isCancelled()) {
scheduled.cancel(true);
}
} catch (Exception e) {
logger.error("Error while cancelling scheduled deadline task for Task with id {} -> {}", taskId, e);
}
}
}
}
Aggregations