Search in sources :

Example 6 with Deadlines

use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.

the class HumanTaskHandlerHelperTest method testSetDeadlinesNotStartedReassignTwoTimes.

@Test
public void testSetDeadlinesNotStartedReassignTwoTimes() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedReassign", "[users:john]@[4h,6h]");
    @SuppressWarnings("unchecked") Deadlines deadlines = HumanTaskHandlerHelper.setDeadlines(workItem, Collections.EMPTY_LIST, null);
    assertNotNull(deadlines);
    assertEquals(2, 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());
    assertEquals(1, deadlines.getStartDeadlines().get(1).getEscalations().size());
    assertEquals(1, deadlines.getStartDeadlines().get(1).getEscalations().get(0).getReassignments().size());
    assertEquals(0, deadlines.getStartDeadlines().get(1).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));
    // verify reassignment
    reassignment = deadlines.getStartDeadlines().get(1).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(1).getDate());
    expirationTime = deadlines.getStartDeadlines().get(1).getDate().getTime() - System.currentTimeMillis();
    assertEquals(6, 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 7 with Deadlines

use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.

the class HumanTaskHandlerHelperTest method testNotStartedNotifyMinimalMultipleExpirations.

@Test
public void testNotStartedNotifyMinimalMultipleExpirations() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedNotify", "[tousers:john|subject:Test of notification|body:And here is the body]@[4h,6h]");
    @SuppressWarnings("unchecked") Deadlines deadlines = HumanTaskHandlerHelper.setDeadlines(workItem, Collections.EMPTY_LIST, null);
    assertNotNull(deadlines);
    assertEquals(2, 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).getNotifications().size());
    assertEquals(0, deadlines.getStartDeadlines().get(0).getEscalations().get(0).getReassignments().size());
    // verify notification
    Notification notification = deadlines.getStartDeadlines().get(0).getEscalations().get(0).getNotifications().get(0);
    assertNotNull(notification);
    assertEquals(1, notification.getRecipients().size());
    assertEquals("john", notification.getRecipients().get(0).getId());
    assertEquals(1, notification.getSubjects().size());
    assertEquals("Test of notification", notification.getSubjects().get(0).getText());
    EmailNotification emailNotification = (EmailNotification) notification;
    assertEquals(1, emailNotification.getEmailHeaders().size());
    Language lang = TaskModelProvider.getFactory().newLanguage();
    lang.setMapkey("en-UK");
    EmailNotificationHeader header = emailNotification.getEmailHeaders().get(lang);
    assertNotNull(header);
    assertEquals("Test of notification", header.getSubject());
    assertEquals("And here is the body", header.getBody());
    // check deadline expiration time
    assertNotNull(deadlines.getStartDeadlines().get(0).getDate());
    long expirationTime = deadlines.getStartDeadlines().get(0).getDate().getTime() - System.currentTimeMillis();
    assertEquals(4, roundExpirationTime(expirationTime));
    // verify notification
    notification = deadlines.getStartDeadlines().get(1).getEscalations().get(0).getNotifications().get(0);
    assertNotNull(notification);
    assertEquals(1, notification.getRecipients().size());
    assertEquals("john", notification.getRecipients().get(0).getId());
    assertEquals(1, notification.getSubjects().size());
    assertEquals("Test of notification", notification.getSubjects().get(0).getText());
    emailNotification = (EmailNotification) notification;
    assertEquals(1, emailNotification.getEmailHeaders().size());
    lang = TaskModelProvider.getFactory().newLanguage();
    lang.setMapkey("en-UK");
    header = emailNotification.getEmailHeaders().get(lang);
    assertNotNull(header);
    assertEquals("Test of notification", header.getSubject());
    assertEquals("And here is the body", header.getBody());
    // check deadline expiration time
    assertNotNull(deadlines.getStartDeadlines().get(1).getDate());
    expirationTime = deadlines.getStartDeadlines().get(1).getDate().getTime() - System.currentTimeMillis();
    assertEquals(6, roundExpirationTime(expirationTime));
}
Also used : Deadlines(org.kie.internal.task.api.model.Deadlines) Language(org.kie.internal.task.api.model.Language) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) EmailNotification(org.kie.internal.task.api.model.EmailNotification) WorkItem(org.drools.core.process.instance.WorkItem) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Notification(org.kie.internal.task.api.model.Notification) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 8 with Deadlines

use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.

the class HumanTaskHandlerHelperTest method testSetDeadlinesNotStartedReassignWithGroups.

@Test
public void testSetDeadlinesNotStartedReassignWithGroups() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedReassign", "[users:john|groups:sales]@[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(2, reassignment.getPotentialOwners().size());
    assertEquals("john", reassignment.getPotentialOwners().get(0).getId());
    assertEquals("sales", reassignment.getPotentialOwners().get(1).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 9 with Deadlines

use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.

the class AddTaskCommand method scheduleDeadlinesForTask.

private void scheduleDeadlinesForTask(final InternalTask task, TaskDeadlinesService deadlineService) {
    final long now = System.currentTimeMillis();
    Deadlines deadlines = task.getDeadlines();
    if (deadlines != null) {
        final List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
        if (startDeadlines != null) {
            scheduleDeadlines(startDeadlines, now, task.getId(), DeadlineType.START, deadlineService);
        }
        final List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
        if (endDeadlines != null) {
            scheduleDeadlines(endDeadlines, now, task.getId(), DeadlineType.END, deadlineService);
        }
    }
}
Also used : Deadlines(org.kie.internal.task.api.model.Deadlines)

Example 10 with Deadlines

use of org.kie.internal.task.api.model.Deadlines in project jbpm by kiegroup.

the class HumanTaskHandlerHelperTest method testSetDeadlinesNotCompletedReassignWithGroups.

// JBPM-4291
@Test
public void testSetDeadlinesNotCompletedReassignWithGroups() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotCompletedReassign", "[users:john|groups:sales]@[4h]");
    @SuppressWarnings("unchecked") Deadlines deadlines = HumanTaskHandlerHelper.setDeadlines(workItem, Collections.EMPTY_LIST, null);
    assertNotNull(deadlines);
    assertEquals(1, deadlines.getEndDeadlines().size());
    assertEquals(0, deadlines.getStartDeadlines().size());
    assertEquals(1, deadlines.getEndDeadlines().get(0).getEscalations().size());
    assertEquals(1, deadlines.getEndDeadlines().get(0).getEscalations().get(0).getReassignments().size());
    assertEquals(0, deadlines.getEndDeadlines().get(0).getEscalations().get(0).getNotifications().size());
    // verify reassignment
    Reassignment reassignment = deadlines.getEndDeadlines().get(0).getEscalations().get(0).getReassignments().get(0);
    assertEquals(2, reassignment.getPotentialOwners().size());
    assertEquals("john", reassignment.getPotentialOwners().get(0).getId());
    assertEquals("sales", reassignment.getPotentialOwners().get(1).getId());
    // check deadline expiration time
    assertNotNull(deadlines.getEndDeadlines().get(0).getDate());
    long expirationTime = deadlines.getEndDeadlines().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)

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