use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.
the class HumanTaskHandlerHelperTest method testSetDeadlinesNotStartedReassign.
@Test
public void testSetDeadlinesNotStartedReassign() {
WorkItem workItem = new WorkItemImpl();
workItem.setParameter("NotStartedReassign", "[users:john]@[4h]");
@SuppressWarnings("unchecked") Deadlines deadlines = HumanTaskHandlerHelper.setDeadlines(workItem, Collections.EMPTY_LIST, null);
assertNotNull(deadlines);
assertEquals(1, deadlines.getStartDeadlines().size());
assertEquals(0, deadlines.getEndDeadlines().size());
assertEquals(1, deadlines.getStartDeadlines().get(0).getEscalations().size());
assertEquals(1, deadlines.getStartDeadlines().get(0).getEscalations().get(0).getReassignments().size());
assertEquals(0, deadlines.getStartDeadlines().get(0).getEscalations().get(0).getNotifications().size());
// verify reassignment
Reassignment reassignment = deadlines.getStartDeadlines().get(0).getEscalations().get(0).getReassignments().get(0);
assertEquals(1, reassignment.getPotentialOwners().size());
assertEquals("john", reassignment.getPotentialOwners().get(0).getId());
// check deadline expiration time
assertNotNull(deadlines.getStartDeadlines().get(0).getDate());
long expirationTime = deadlines.getStartDeadlines().get(0).getDate().getTime() - System.currentTimeMillis();
assertEquals(4, roundExpirationTime(expirationTime));
}
use of org.kie.internal.task.api.model.Deadlines 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.Deadlines 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;
}
Aggregations