use of org.kie.internal.task.api.model.Deadline in project jbpm by kiegroup.
the class UserGroupCallbackTaskCommand method doCallbackOperationForTaskDeadlines.
protected void doCallbackOperationForTaskDeadlines(Deadlines deadlines, TaskContext context) {
if (deadlines != null) {
if (deadlines.getStartDeadlines() != null) {
List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
for (Deadline startDeadline : startDeadlines) {
List<? extends Escalation> escalations = startDeadline.getEscalations();
if (escalations != null) {
for (Escalation escalation : escalations) {
List<? extends Notification> notifications = escalation.getNotifications();
List<? extends Reassignment> ressignments = escalation.getReassignments();
if (notifications != null) {
for (Notification notification : notifications) {
List<? extends OrganizationalEntity> recipients = notification.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
doCallbackUserOperation(recipient.getId(), context);
}
if (recipient instanceof Group) {
doCallbackGroupOperation(recipient.getId(), context);
}
}
}
List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
if (administrators != null) {
for (OrganizationalEntity administrator : administrators) {
if (administrator instanceof User) {
doCallbackUserOperation(administrator.getId(), context);
}
if (administrator instanceof Group) {
doCallbackGroupOperation(administrator.getId(), context);
}
}
}
}
}
if (ressignments != null) {
for (Reassignment reassignment : ressignments) {
List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity potentialOwner : potentialOwners) {
if (potentialOwner instanceof User) {
doCallbackUserOperation(potentialOwner.getId(), context);
}
if (potentialOwner instanceof Group) {
doCallbackGroupOperation(potentialOwner.getId(), context);
}
}
}
}
}
}
}
}
}
if (deadlines.getEndDeadlines() != null) {
List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
for (Deadline endDeadline : endDeadlines) {
List<? extends Escalation> escalations = endDeadline.getEscalations();
if (escalations != null) {
for (Escalation escalation : escalations) {
List<? extends Notification> notifications = escalation.getNotifications();
List<? extends Reassignment> ressignments = escalation.getReassignments();
if (notifications != null) {
for (Notification notification : notifications) {
List<? extends OrganizationalEntity> recipients = notification.getRecipients();
if (recipients != null) {
for (OrganizationalEntity recipient : recipients) {
if (recipient instanceof User) {
doCallbackUserOperation(recipient.getId(), context);
}
if (recipient instanceof Group) {
doCallbackGroupOperation(recipient.getId(), context);
}
}
}
List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
if (administrators != null) {
for (OrganizationalEntity administrator : administrators) {
if (administrator instanceof User) {
doCallbackUserOperation(administrator.getId(), context);
}
if (administrator instanceof Group) {
doCallbackGroupOperation(administrator.getId(), context);
}
}
}
}
}
if (ressignments != null) {
for (Reassignment reassignment : ressignments) {
List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
if (potentialOwners != null) {
for (OrganizationalEntity potentialOwner : potentialOwners) {
if (potentialOwner instanceof User) {
doCallbackUserOperation(potentialOwner.getId(), context);
}
if (potentialOwner instanceof Group) {
doCallbackGroupOperation(potentialOwner.getId(), context);
}
}
}
}
}
}
}
}
}
}
}
use of org.kie.internal.task.api.model.Deadline in project jbpm by kiegroup.
the class ExecuteReminderCommand method executedeadLine.
private Void executedeadLine(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, DeadlineSummary deadlineSummary, TaskData taskData) {
Deadline deadline = persistenceContext.findDeadline(deadlineSummary.getDeadlineId());
if (task == null || deadline == null) {
return null;
}
if (taskData != null) {
UserInfo userInfo = (UserInfo) ctx.get(EnvironmentName.TASK_USER_INFO);
// check if task is still in valid status
if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
if (deadline == null || deadline.getEscalations() == null) {
return null;
}
TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
taskEventSupport.fireBeforeTaskNotified(task, ctx);
for (Escalation escalation : deadline.getEscalations()) {
for (Notification notification : escalation.getNotifications()) {
if (notification.getNotificationType() == NotificationType.Email) {
logger.debug("Sending an Email");
NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
}
}
}
taskEventSupport.fireAfterTaskNotified(task, ctx);
}
}
return null;
}
use of org.kie.internal.task.api.model.Deadline 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);
}
}
}
}
use of org.kie.internal.task.api.model.Deadline in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method setDeadlines.
public static Deadlines setDeadlines(WorkItem workItem, List<OrganizationalEntity> businessAdministrators, Environment environment) {
String notStartedReassign = (String) workItem.getParameter("NotStartedReassign");
String notStartedNotify = (String) workItem.getParameter("NotStartedNotify");
String notCompletedReassign = (String) workItem.getParameter("NotCompletedReassign");
String notCompletedNotify = (String) workItem.getParameter("NotCompletedNotify");
Deadlines deadlinesTotal = TaskModelProvider.getFactory().newDeadlines();
List<Deadline> startDeadlines = new ArrayList<Deadline>();
startDeadlines.addAll(parseDeadlineString(notStartedNotify, businessAdministrators, environment));
startDeadlines.addAll(parseDeadlineString(notStartedReassign, businessAdministrators, environment));
List<Deadline> endDeadlines = new ArrayList<Deadline>();
endDeadlines.addAll(parseDeadlineString(notCompletedNotify, businessAdministrators, environment));
endDeadlines.addAll(parseDeadlineString(notCompletedReassign, businessAdministrators, environment));
if (!startDeadlines.isEmpty()) {
deadlinesTotal.setStartDeadlines(startDeadlines);
}
if (!endDeadlines.isEmpty()) {
deadlinesTotal.setEndDeadlines(endDeadlines);
}
return deadlinesTotal;
}
use of org.kie.internal.task.api.model.Deadline in project jbpm by kiegroup.
the class HumanTaskHandlerHelper method parseDeadlineString.
protected static List<Deadline> parseDeadlineString(String deadlineInfo, List<OrganizationalEntity> businessAdministrators, Environment environment) {
if (deadlineInfo == null || deadlineInfo.length() == 0) {
return new ArrayList<Deadline>();
}
List<Deadline> deadlines = new ArrayList<Deadline>();
String[] allComponents = deadlineInfo.split(COMPONENT_SEPARATOR);
BusinessCalendar businessCalendar = null;
if (environment != null && environment.get("jbpm.business.calendar") != null) {
businessCalendar = (BusinessCalendar) environment.get("jbpm.business.calendar");
}
for (String component : allComponents) {
String[] mainComponents = component.split(ELEMENT_SEPARATOR);
if (mainComponents != null && mainComponents.length == 2) {
String actionComponent = mainComponents[0].substring(1, mainComponents[0].length() - 1);
String expireComponents = mainComponents[1].substring(1, mainComponents[1].length() - 1);
String[] expireElements = expireComponents.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
Deadline taskDeadline = null;
for (String expiresAt : expireElements) {
logger.debug("Expires at is {}", expiresAt);
taskDeadline = TaskModelProvider.getFactory().newDeadline();
if (businessCalendar != null) {
taskDeadline.setDate(businessCalendar.calculateBusinessTimeAsDate(expiresAt));
} else {
taskDeadline.setDate(new Date(System.currentTimeMillis() + TimeUtils.parseTimeString(expiresAt)));
}
logger.debug("Calculated date of execution is {} and current date {}", taskDeadline.getDate(), new Date());
List<Escalation> escalations = new ArrayList<Escalation>();
Escalation escalation = TaskModelProvider.getFactory().newEscalation();
escalations.add(escalation);
escalation.setName("Default escalation");
taskDeadline.setEscalations(escalations);
escalation.setReassignments(parseReassignment(actionComponent));
escalation.setNotifications(parseNotifications(actionComponent, businessAdministrators));
deadlines.add(taskDeadline);
}
} else {
logger.warn("Incorrect syntax of deadline property {}", deadlineInfo);
}
}
return deadlines;
}
Aggregations