Search in sources :

Example 6 with Language

use of org.kie.internal.task.api.model.Language 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 7 with Language

use of org.kie.internal.task.api.model.Language 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 8 with Language

use of org.kie.internal.task.api.model.Language 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)

Example 9 with Language

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

the class HumanTaskHandlerHelper method parseNotifications.

protected static List<Notification> parseNotifications(String notificationString, List<OrganizationalEntity> businessAdministrators) {
    List<Notification> notifications = new ArrayList<Notification>();
    Map<String, String> parameters = asMap(notificationString);
    if (parameters.containsKey("tousers") || parameters.containsKey("togroups")) {
        String locale = parameters.get("locale");
        if (locale == null) {
            locale = "en-UK";
        }
        EmailNotification emailNotification = TaskModelProvider.getFactory().newEmialNotification();
        notifications.add(emailNotification);
        emailNotification.setBusinessAdministrators(businessAdministrators);
        Map<Language, EmailNotificationHeader> emailHeaders = new HashMap<Language, EmailNotificationHeader>();
        List<I18NText> subjects = new ArrayList<I18NText>();
        List<I18NText> names = new ArrayList<I18NText>();
        List<OrganizationalEntity> notificationRecipients = new ArrayList<OrganizationalEntity>();
        EmailNotificationHeader emailHeader = TaskModelProvider.getFactory().newEmailNotificationHeader();
        emailHeader.setBody(parameters.get("body"));
        emailHeader.setFrom(parameters.get("from"));
        emailHeader.setReplyTo(parameters.get("replyto"));
        emailHeader.setLanguage(locale);
        emailHeader.setSubject(parameters.get("subject"));
        Language lang = TaskModelProvider.getFactory().newLanguage();
        lang.setMapkey(locale);
        emailHeaders.put(lang, emailHeader);
        I18NText subject = TaskModelProvider.getFactory().newI18NText();
        ((InternalI18NText) subject).setLanguage(locale);
        ((InternalI18NText) subject).setText(emailHeader.getSubject());
        ;
        subjects.add(subject);
        names.add(subject);
        String recipients = parameters.get("tousers");
        if (recipients != null && recipients.trim().length() > 0) {
            String[] recipientsIds = recipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
            for (String id : recipientsIds) {
                User user = TaskModelProvider.getFactory().newUser();
                ((InternalOrganizationalEntity) user).setId(id.trim());
                notificationRecipients.add(user);
            }
        }
        String groupRecipients = parameters.get("togroups");
        if (groupRecipients != null && groupRecipients.trim().length() > 0) {
            String[] groupRecipientsIds = groupRecipients.split(ATTRIBUTES_ELEMENTS_SEPARATOR);
            for (String id : groupRecipientsIds) {
                Group group = TaskModelProvider.getFactory().newGroup();
                ((InternalOrganizationalEntity) group).setId(id.trim());
                notificationRecipients.add(group);
            }
        }
        emailNotification.setEmailHeaders(emailHeaders);
        emailNotification.setNames(names);
        emailNotification.setRecipients(notificationRecipients);
        emailNotification.setSubjects(subjects);
    }
    return notifications;
}
Also used : Group(org.kie.api.task.model.Group) I18NText(org.kie.api.task.model.I18NText) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) User(org.kie.api.task.model.User) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) HashMap(java.util.HashMap) InternalI18NText(org.kie.internal.task.api.model.InternalI18NText) ArrayList(java.util.ArrayList) EmailNotification(org.kie.internal.task.api.model.EmailNotification) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Language(org.kie.internal.task.api.model.Language)

Aggregations

EmailNotification (org.kie.internal.task.api.model.EmailNotification)9 EmailNotificationHeader (org.kie.internal.task.api.model.EmailNotificationHeader)9 Language (org.kie.internal.task.api.model.Language)9 Notification (org.kie.internal.task.api.model.Notification)6 ArrayList (java.util.ArrayList)5 Deadlines (org.kie.internal.task.api.model.Deadlines)5 HashMap (java.util.HashMap)4 WorkItem (org.drools.core.process.instance.WorkItem)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 Test (org.junit.Test)4 I18NText (org.kie.api.task.model.I18NText)3 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 List (java.util.List)2 Group (org.kie.api.task.model.Group)2 Task (org.kie.api.task.model.Task)2 User (org.kie.api.task.model.User)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1