use of org.jbpm.services.api.admin.TaskNotification in project jbpm by kiegroup.
the class UserTaskAdminServiceImplTest method testNotifyNotCompleted.
@Test(timeout = 10000)
public void testNotifyNotCompleted() 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);
Collection<TaskNotification> notifications = userTaskAdminService.getTaskNotifications(task.getId(), false);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(0);
userTaskService.start(task.getId(), "salaboy");
List<OrganizationalEntity> recipients = new ArrayList<>();
recipients.add(factory.newUser("john"));
EmailNotification emailNotification = userTaskAdminService.buildEmailNotification("test", recipients, "Simple body", "Administrator", "");
userTaskAdminService.notifyWhenNotCompleted(task.getId(), "2s", emailNotification);
notifications = userTaskAdminService.getTaskNotifications(task.getId(), false);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(1);
CountDownListenerFactory.getExistingTask("userTaskAdminService").waitTillCompleted();
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
Assertions.assertThat(tasks).hasSize(1);
notifications = userTaskAdminService.getTaskNotifications(task.getId(), true);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(0);
notifications = userTaskAdminService.getTaskNotifications(task.getId(), false);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(1);
}
use of org.jbpm.services.api.admin.TaskNotification in project jbpm by kiegroup.
the class UserTaskAdminServiceImplTest method testNotifyNotStartedAndCancel.
@Test(timeout = 10000)
public void testNotifyNotStartedAndCancel() 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);
Collection<TaskNotification> notifications = userTaskAdminService.getTaskNotifications(task.getId(), false);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(0);
List<OrganizationalEntity> recipients = new ArrayList<>();
recipients.add(factory.newUser("john"));
EmailNotification emailNotification = userTaskAdminService.buildEmailNotification("test", recipients, "Simple body", "Administrator", "");
long notificationId = userTaskAdminService.notifyWhenNotStarted(task.getId(), "2s", emailNotification);
notifications = userTaskAdminService.getTaskNotifications(task.getId(), true);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(1);
userTaskAdminService.cancelNotification(task.getId(), notificationId);
notifications = userTaskAdminService.getTaskNotifications(task.getId(), true);
Assertions.assertThat(notifications).isNotNull();
Assertions.assertThat(notifications).hasSize(0);
}
use of org.jbpm.services.api.admin.TaskNotification 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;
}
Aggregations