use of org.kie.internal.task.api.model.EmailNotification in project jbpm by kiegroup.
the class UserTaskAdminServiceImplTest method testNotifyNotStarted.
@Test(timeout = 10000)
public void testNotifyNotStarted() throws Exception {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
Assertions.assertThat(processInstanceId).isNotNull();
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
Assertions.assertThat(tasks).hasSize(1);
TaskSummary task = tasks.get(0);
List<OrganizationalEntity> recipients = new ArrayList<>();
recipients.add(factory.newUser("john"));
EmailNotification emailNotification = userTaskAdminService.buildEmailNotification("test", recipients, "Simple body", "Administrator", "");
userTaskAdminService.notifyWhenNotStarted(task.getId(), "2s", emailNotification);
CountDownListenerFactory.getExistingTask("userTaskAdminService").waitTillCompleted();
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
Assertions.assertThat(tasks).hasSize(1);
}
use of org.kie.internal.task.api.model.EmailNotification in project jbpm by kiegroup.
the class ListTaskNotificationsCommand method execute.
@Override
public List<TaskNotification> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
Language lang = factory.newLanguage();
lang.setMapkey("en-UK");
Task task = context.getTaskQueryService().getTaskInstanceById(taskId);
if (!isBusinessAdmin(userId, task.getPeopleAssignments().getBusinessAdministrators(), context)) {
throw new PermissionDeniedException("User " + userId + " is not business admin of task " + taskId);
}
Deadlines deadlines = ((InternalTask) task).getDeadlines();
List<TaskNotification> notificationsNotStarted = deadlines.getStartDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> notificationsNotCompleted = deadlines.getEndDeadlines().stream().filter(d -> !d.getEscalations().isEmpty() && !d.getEscalations().get(0).getNotifications().isEmpty()).map(d -> {
Notification n = d.getEscalations().get(0).getNotifications().get(0);
EmailNotificationHeader email = ((EmailNotification) n).getEmailHeaders().get(lang);
return new TaskNotificationImpl(d.getId(), get(n.getNames()), email.getSubject(), email.getBody(), d.getDate(), n.getRecipients(), n.getBusinessAdministrators(), !d.isEscalated());
}).collect(Collectors.toList());
List<TaskNotification> result = new ArrayList<>();
result.addAll(notificationsNotStarted);
result.addAll(notificationsNotCompleted);
if (activeOnly) {
logger.debug("Removing already completed deadlines from the result");
result = result.stream().filter(t -> t.isActive()).collect(Collectors.toList());
}
return result;
}
use of org.kie.internal.task.api.model.EmailNotification 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));
}
use of org.kie.internal.task.api.model.EmailNotification 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));
}
use of org.kie.internal.task.api.model.EmailNotification 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));
}
Aggregations