From 348cc9831f615cd62f5a00d2e72b3d04b62310c8 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Wed, 17 Aug 2011 04:59:49 +0000 Subject: [PATCH] Workflow Notificatoins: * Email notifications sent asynchronously * Activiti pooled tasks now work correctly git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29812 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../workflow/WorkflowNotificationUtils.java | 3 ++ .../tasklistener/TaskCreateListener.java | 41 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java b/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java index ff64182cd6..25b96a4bbf 100644 --- a/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java +++ b/source/java/org/alfresco/repo/workflow/WorkflowNotificationUtils.java @@ -142,6 +142,9 @@ public abstract class WorkflowNotificationUtils { notificationContext.addTo(assignedAuthority); } + + // Indicate that we want to execute the notification asynchronously + notificationContext.setAsyncNotification(true); // Send email notification services.getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext); diff --git a/source/java/org/alfresco/repo/workflow/activiti/tasklistener/TaskCreateListener.java b/source/java/org/alfresco/repo/workflow/activiti/tasklistener/TaskCreateListener.java index b3939fcafc..fd6ba63b11 100644 --- a/source/java/org/alfresco/repo/workflow/activiti/tasklistener/TaskCreateListener.java +++ b/source/java/org/alfresco/repo/workflow/activiti/tasklistener/TaskCreateListener.java @@ -19,11 +19,15 @@ package org.alfresco.repo.workflow.activiti.tasklistener; +import java.util.ArrayList; +import java.util.List; + import org.activiti.engine.delegate.DelegateTask; import org.activiti.engine.delegate.TaskListener; import org.activiti.engine.form.FormData; import org.activiti.engine.impl.form.TaskFormHandler; import org.activiti.engine.impl.persistence.entity.ExecutionEntity; +import org.activiti.engine.impl.persistence.entity.IdentityLinkEntity; import org.activiti.engine.impl.persistence.entity.TaskEntity; import org.alfresco.repo.workflow.WorkflowNotificationUtils; import org.alfresco.repo.workflow.activiti.ActivitiConstants; @@ -73,6 +77,7 @@ public class TaskCreateListener implements TaskListener Boolean value = (Boolean)executionEntity.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS); if (Boolean.TRUE.equals(value) == true) { + // Get the workflow package node NodeRef workflowPackage = null; ActivitiScriptNode scriptNode = (ActivitiScriptNode)executionEntity.getVariable(WorkflowNotificationUtils.PROP_PACKAGE); if (scriptNode != null) @@ -80,6 +85,38 @@ public class TaskCreateListener implements TaskListener workflowPackage = scriptNode.getNodeRef(); } + // Determine whether the task is pooled or not + String[] authorities = null; + boolean isPooled = false; + if (task.getAssignee() == null) + { + // Task is pooled + isPooled = true; + + // Get the pool of user/groups for this task + List identities = ((TaskEntity)task).getIdentityLinks(); + List temp = new ArrayList(identities.size()); + for (IdentityLinkEntity item : identities) + { + String group = item.getGroupId(); + if (group != null) + { + temp.add(group); + } + String user = item.getUserId(); + if (user != null) + { + temp.add(user); + } + } + authorities = temp.toArray(new String[temp.size()]); + } + else + { + // Get the assigned user or group + authorities = new String[]{task.getAssignee()}; + } + // Send email notification WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail( services, @@ -89,8 +126,8 @@ public class TaskCreateListener implements TaskListener task.getDueDate(), Integer.valueOf(task.getPriority()), workflowPackage, - new String[]{task.getAssignee()}, - (task.getAssignee() == null)); + authorities, + isPooled); } }