Search in sources :

Example 1 with TaskNotification

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);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with TaskNotification

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);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 3 with TaskNotification

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;
}
Also used : Logger(org.slf4j.Logger) Task(org.kie.api.task.model.Task) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) LoggerFactory(org.slf4j.LoggerFactory) I18NText(org.kie.api.task.model.I18NText) TaskModelProvider(org.kie.internal.task.api.TaskModelProvider) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Collectors(java.util.stream.Collectors) Language(org.kie.internal.task.api.model.Language) ArrayList(java.util.ArrayList) TaskNotificationImpl(org.jbpm.kie.services.impl.admin.TaskNotificationImpl) UserGroupCallbackTaskCommand(org.jbpm.services.task.commands.UserGroupCallbackTaskCommand) List(java.util.List) Context(org.kie.api.runtime.Context) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskModelFactory(org.kie.internal.task.api.TaskModelFactory) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) Deadlines(org.kie.internal.task.api.model.Deadlines) Notification(org.kie.internal.task.api.model.Notification) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) TaskContext(org.jbpm.services.task.commands.TaskContext) EmailNotificationHeader(org.kie.internal.task.api.model.EmailNotificationHeader) InternalTask(org.kie.internal.task.api.model.InternalTask) ArrayList(java.util.ArrayList) EmailNotification(org.kie.internal.task.api.model.EmailNotification) TaskNotification(org.jbpm.services.api.admin.TaskNotification) EmailNotification(org.kie.internal.task.api.model.EmailNotification) Notification(org.kie.internal.task.api.model.Notification) TaskNotificationImpl(org.jbpm.kie.services.impl.admin.TaskNotificationImpl) Deadlines(org.kie.internal.task.api.model.Deadlines) Language(org.kie.internal.task.api.model.Language) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskNotification(org.jbpm.services.api.admin.TaskNotification)

Aggregations

ArrayList (java.util.ArrayList)3 TaskNotification (org.jbpm.services.api.admin.TaskNotification)3 EmailNotification (org.kie.internal.task.api.model.EmailNotification)3 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 Test (org.junit.Test)2 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)2 TaskSummary (org.kie.api.task.model.TaskSummary)2 QueryFilter (org.kie.internal.query.QueryFilter)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 TaskNotificationImpl (org.jbpm.kie.services.impl.admin.TaskNotificationImpl)1 TaskContext (org.jbpm.services.task.commands.TaskContext)1 UserGroupCallbackTaskCommand (org.jbpm.services.task.commands.UserGroupCallbackTaskCommand)1 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)1 Context (org.kie.api.runtime.Context)1 I18NText (org.kie.api.task.model.I18NText)1 Task (org.kie.api.task.model.Task)1 TaskModelFactory (org.kie.internal.task.api.TaskModelFactory)1 TaskModelProvider (org.kie.internal.task.api.TaskModelProvider)1