Search in sources :

Example 6 with Notification

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

the class CollectionUtils method readNotificationList.

public static List<Notification> readNotificationList(ObjectInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    List<Notification> list = new ArrayList<Notification>(size);
    for (int i = 0; i < size; i++) {
        Notification item = null;
        switch(NotificationType.valueOf(in.readUTF())) {
            case Default:
                {
                    item = new NotificationImpl();
                    break;
                }
            case Email:
                {
                    item = new EmailNotificationImpl();
                    break;
                }
        }
        item.readExternal(in);
        list.add(item);
    }
    return list;
}
Also used : EmailNotificationImpl(org.jbpm.services.task.impl.model.EmailNotificationImpl) NotificationImpl(org.jbpm.services.task.impl.model.NotificationImpl) ArrayList(java.util.ArrayList) EmailNotificationImpl(org.jbpm.services.task.impl.model.EmailNotificationImpl) Notification(org.kie.internal.task.api.model.Notification)

Example 7 with Notification

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

the class CollectionUtils method writeNotificationList.

public static void writeNotificationList(List<Notification> list, ObjectOutput out) throws IOException {
    out.writeInt(list.size());
    for (Notification item : list) {
        // item.getNotificationType().toString() is never null
        out.writeUTF(item.getNotificationType().toString());
        item.writeExternal(out);
    }
}
Also used : Notification(org.kie.internal.task.api.model.Notification)

Example 8 with Notification

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

the class UserGroupCallbackTaskCommand method doCallbackOperationForTaskDeadlines.

protected void doCallbackOperationForTaskDeadlines(Deadlines deadlines, TaskContext context) {
    if (deadlines != null) {
        if (deadlines.getStartDeadlines() != null) {
            List<? extends Deadline> startDeadlines = deadlines.getStartDeadlines();
            for (Deadline startDeadline : startDeadlines) {
                List<? extends Escalation> escalations = startDeadline.getEscalations();
                if (escalations != null) {
                    for (Escalation escalation : escalations) {
                        List<? extends Notification> notifications = escalation.getNotifications();
                        List<? extends Reassignment> ressignments = escalation.getReassignments();
                        if (notifications != null) {
                            for (Notification notification : notifications) {
                                List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                                if (recipients != null) {
                                    for (OrganizationalEntity recipient : recipients) {
                                        if (recipient instanceof User) {
                                            doCallbackUserOperation(recipient.getId(), context);
                                        }
                                        if (recipient instanceof Group) {
                                            doCallbackGroupOperation(recipient.getId(), context);
                                        }
                                    }
                                }
                                List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
                                if (administrators != null) {
                                    for (OrganizationalEntity administrator : administrators) {
                                        if (administrator instanceof User) {
                                            doCallbackUserOperation(administrator.getId(), context);
                                        }
                                        if (administrator instanceof Group) {
                                            doCallbackGroupOperation(administrator.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                        if (ressignments != null) {
                            for (Reassignment reassignment : ressignments) {
                                List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
                                if (potentialOwners != null) {
                                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                                        if (potentialOwner instanceof User) {
                                            doCallbackUserOperation(potentialOwner.getId(), context);
                                        }
                                        if (potentialOwner instanceof Group) {
                                            doCallbackGroupOperation(potentialOwner.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (deadlines.getEndDeadlines() != null) {
            List<? extends Deadline> endDeadlines = deadlines.getEndDeadlines();
            for (Deadline endDeadline : endDeadlines) {
                List<? extends Escalation> escalations = endDeadline.getEscalations();
                if (escalations != null) {
                    for (Escalation escalation : escalations) {
                        List<? extends Notification> notifications = escalation.getNotifications();
                        List<? extends Reassignment> ressignments = escalation.getReassignments();
                        if (notifications != null) {
                            for (Notification notification : notifications) {
                                List<? extends OrganizationalEntity> recipients = notification.getRecipients();
                                if (recipients != null) {
                                    for (OrganizationalEntity recipient : recipients) {
                                        if (recipient instanceof User) {
                                            doCallbackUserOperation(recipient.getId(), context);
                                        }
                                        if (recipient instanceof Group) {
                                            doCallbackGroupOperation(recipient.getId(), context);
                                        }
                                    }
                                }
                                List<? extends OrganizationalEntity> administrators = notification.getBusinessAdministrators();
                                if (administrators != null) {
                                    for (OrganizationalEntity administrator : administrators) {
                                        if (administrator instanceof User) {
                                            doCallbackUserOperation(administrator.getId(), context);
                                        }
                                        if (administrator instanceof Group) {
                                            doCallbackGroupOperation(administrator.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                        if (ressignments != null) {
                            for (Reassignment reassignment : ressignments) {
                                List<? extends OrganizationalEntity> potentialOwners = reassignment.getPotentialOwners();
                                if (potentialOwners != null) {
                                    for (OrganizationalEntity potentialOwner : potentialOwners) {
                                        if (potentialOwner instanceof User) {
                                            doCallbackUserOperation(potentialOwner.getId(), context);
                                        }
                                        if (potentialOwner instanceof Group) {
                                            doCallbackGroupOperation(potentialOwner.getId(), context);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Group(org.kie.api.task.model.Group) User(org.kie.api.task.model.User) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) Reassignment(org.kie.internal.task.api.model.Reassignment) Notification(org.kie.internal.task.api.model.Notification)

Example 9 with Notification

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

the class ExecuteReminderCommand method executedeadLine.

private Void executedeadLine(TaskContext ctx, TaskPersistenceContext persistenceContext, Task task, DeadlineSummary deadlineSummary, TaskData taskData) {
    Deadline deadline = persistenceContext.findDeadline(deadlineSummary.getDeadlineId());
    if (task == null || deadline == null) {
        return null;
    }
    if (taskData != null) {
        UserInfo userInfo = (UserInfo) ctx.get(EnvironmentName.TASK_USER_INFO);
        // check if task is still in valid status
        if (DeadlineType.START.isValidStatus(taskData.getStatus()) || DeadlineType.END.isValidStatus(taskData.getStatus())) {
            Map<String, Object> variables = getVariables(ctx, persistenceContext, task, taskData);
            if (deadline == null || deadline.getEscalations() == null) {
                return null;
            }
            TaskEventSupport taskEventSupport = ctx.getTaskEventSupport();
            taskEventSupport.fireBeforeTaskNotified(task, ctx);
            for (Escalation escalation : deadline.getEscalations()) {
                for (Notification notification : escalation.getNotifications()) {
                    if (notification.getNotificationType() == NotificationType.Email) {
                        logger.debug("Sending an Email");
                        NotificationListenerManager.get().broadcast(new NotificationEvent(notification, task, variables), userInfo);
                    }
                }
            }
            taskEventSupport.fireAfterTaskNotified(task, ctx);
        }
    }
    return null;
}
Also used : Deadline(org.kie.internal.task.api.model.Deadline) Escalation(org.kie.internal.task.api.model.Escalation) UserInfo(org.kie.internal.task.api.UserInfo) NotificationEvent(org.kie.internal.task.api.model.NotificationEvent) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) Notification(org.kie.internal.task.api.model.Notification) EmailNotification(org.kie.internal.task.api.model.EmailNotification)

Example 10 with Notification

use of org.kie.internal.task.api.model.Notification 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:&lt;html&gt;" + "&lt;body&gt;" + "Reason {s}&lt;br/&gt;" + "body of notification:&lt;br/&gt;" + "work item id - ${workItemId}&lt;br/&gt;" + "process instance id - ${processInstanceId}&lt;br/&gt;" + "task id - ${taskId}&lt;br/&gt;" + "http://localhost:8080/taskserver-url" + "expiration time - ${doc['Deadlines'][0].expires}&lt;br/&gt;" + "&lt;/body&gt;" + "&lt;/html&gt;]@[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)

Aggregations

Notification (org.kie.internal.task.api.model.Notification)13 EmailNotification (org.kie.internal.task.api.model.EmailNotification)9 EmailNotificationHeader (org.kie.internal.task.api.model.EmailNotificationHeader)6 Language (org.kie.internal.task.api.model.Language)6 ArrayList (java.util.ArrayList)5 Deadlines (org.kie.internal.task.api.model.Deadlines)5 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 Deadline (org.kie.internal.task.api.model.Deadline)4 Escalation (org.kie.internal.task.api.model.Escalation)4 TaskEventSupport (org.jbpm.services.task.events.TaskEventSupport)3 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)3 Task (org.kie.api.task.model.Task)3 UserInfo (org.kie.internal.task.api.UserInfo)3 NotificationEvent (org.kie.internal.task.api.model.NotificationEvent)3 HashMap (java.util.HashMap)2 TaskNotification (org.jbpm.services.api.admin.TaskNotification)2 Group (org.kie.api.task.model.Group)2