Search in sources :

Example 11 with Deadlines

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

the class HumanTaskHandlerHelperTest method testNotStartedNotifyMinimalWithHtml.

@Test
public void testNotStartedNotifyMinimalWithHtml() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedNotify", "[tousers:john|subject:Test of notification|body:<html>" + "<body>" + "Reason {s}<br/>" + "body of notification:<br/>" + "work item id - ${workItemId}<br/>" + "process instance id - ${processInstanceId}<br/>" + "task id - ${taskId}<br/>" + "http://localhost:8080/taskserver-url" + "expiration time - ${doc['Deadlines'][0].expires}<br/>" + "</body>" + "</html>]@[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).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());
    assertTrue((header.getBody().indexOf("http://localhost:8080/taskserver-url") != -1));
    // 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) 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 12 with Deadlines

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

the class HumanTaskHandlerHelperTest method testSetDeadlinesNotCompletedReassignTwoTimes.

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

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

the class HumanTaskHandlerHelperTest method testNotStartedNotifyMinimal.

@Test
public void testNotStartedNotifyMinimal() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedNotify", "[tousers:john|subject:Test of notification|body:And here is the body]@[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).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));
}
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 14 with Deadlines

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

the class HumanTaskHandlerHelperTest method testSetDeadlinesNotCompletedReassign.

@Test
public void testSetDeadlinesNotCompletedReassign() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotCompletedReassign", "[users:john]@[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(1, reassignment.getPotentialOwners().size());
    assertEquals("john", reassignment.getPotentialOwners().get(0).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)

Example 15 with Deadlines

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

the class HumanTaskHandlerHelperTest method testNotStartedNotifyAllElements.

@Test
public void testNotStartedNotifyAllElements() {
    WorkItem workItem = new WorkItemImpl();
    workItem.setParameter("NotStartedNotify", "[from:mike|tousers:john,mary|togroups:sales,hr|replyto:mike|subject:Test of notification|body:And here is the body]@[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).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(4, notification.getRecipients().size());
    assertEquals("john", notification.getRecipients().get(0).getId());
    assertEquals("mary", notification.getRecipients().get(1).getId());
    assertEquals("sales", notification.getRecipients().get(2).getId());
    assertEquals("hr", notification.getRecipients().get(3).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());
    assertEquals("mike", header.getFrom());
    assertEquals("mike", header.getReplyTo());
    // 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) 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)

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