use of org.kie.internal.task.api.model.EmailNotification 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));
}
use of org.kie.internal.task.api.model.EmailNotification 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;
}
Aggregations