Search in sources :

Example 16 with Deadlines

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));
}
Also used : Deadlines(org.kie.internal.task.api.model.Deadlines) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) WorkItem(org.drools.core.process.instance.WorkItem) Reassignment(org.kie.internal.task.api.model.Reassignment) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 17 with Deadlines

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);
            }
        }
    }
}
Also used : Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) InternalTask(org.kie.internal.task.api.model.InternalTask) DeadlineSummary(org.kie.internal.task.api.model.DeadlineSummary) Deadline(org.kie.internal.task.api.model.Deadline) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) ScheduledFuture(java.util.concurrent.ScheduledFuture) JobHandle(org.drools.core.time.JobHandle) Deadlines(org.kie.internal.task.api.model.Deadlines) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 18 with Deadlines

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;
}
Also used : Deadlines(org.kie.internal.task.api.model.Deadlines) Deadline(org.kie.internal.task.api.model.Deadline) ArrayList(java.util.ArrayList)

Aggregations

Deadlines (org.kie.internal.task.api.model.Deadlines)18 WorkItem (org.drools.core.process.instance.WorkItem)10 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)10 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)10 Test (org.junit.Test)10 Reassignment (org.kie.internal.task.api.model.Reassignment)7 Task (org.kie.api.task.model.Task)6 InternalTask (org.kie.internal.task.api.model.InternalTask)6 EmailNotification (org.kie.internal.task.api.model.EmailNotification)5 EmailNotificationHeader (org.kie.internal.task.api.model.EmailNotificationHeader)5 Language (org.kie.internal.task.api.model.Language)5 Notification (org.kie.internal.task.api.model.Notification)5 TaskContext (org.jbpm.services.task.commands.TaskContext)4 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)3 Context (org.kie.api.runtime.Context)3 Deadline (org.kie.internal.task.api.model.Deadline)3 Logger (org.slf4j.Logger)3