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;
}
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);
}
}
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);
}
}
}
}
}
}
}
}
}
}
}
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;
}
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:<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));
}
Aggregations