Workflow Notification working for Activiti workflows

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29737 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2011-08-15 05:41:15 +00:00
parent 2eca29a4b7
commit 660690bbd8
2 changed files with 118 additions and 59 deletions

View File

@@ -30,45 +30,46 @@ public abstract class WorkflowNotificationUtils
{ {
/** Send EMail notifications property */ /** Send EMail notifications property */
public static final String PROP_SEND_EMAIL_NOTIFICATIONS = "bpm_sendEMailNotifications"; public static final String PROP_SEND_EMAIL_NOTIFICATIONS = "bpm_sendEMailNotifications";
public static final String PROP_PACKAGE = "bpm_package";
/** I18N */ /** I18N */
public static final String MSG_ASSIGNED_TASK = "assigned-task"; public static final String MSG_ASSIGNED_TASK = "assigned-task";
public static final String MSG_NEW_POOLED_TASK = "new-pooled-task"; public static final String MSG_NEW_POOLED_TASK = "new-pooled-task";
/** Args value names */
public static final String ARG_WF_ID = "workflowId";
public static final String ARG_WF_TITLE = "workflowTitle";
public static final String ARG_WF_DESCRIPTION = "workflowDescription";
public static final String ARG_WF_DUEDATE = "workflowDueDate";
public static final String ARG_WF_PRIORITY = "workflowPriority";
public static final String ARG_WF_POOLED = "workflowPooled";
public static final String ARG_WF_DOCUMENTS = "workflowDocuments";
/** Standard workflow assigned template */ /** Standard workflow assigned template */
private static final NodeRef WF_ASSIGNED_TEMPLATE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "wf-email-html-ftl"); private static final NodeRef WF_ASSIGNED_TEMPLATE = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "wf-email-html-ftl");
/** /**
* Send workflow assigned email notification.
* *
* @param services service registry * @param services
* @param taskId workflow global task id * @param taskId
* @param assignedAuthority assigned authority * @param title
* @param pooled true if pooled task, false otherwise * @param description
*/ * @param dueDate
public static void sendWorkflowAssignedNotificationEMail(ServiceRegistry services, * @param priority
String taskId, * @param workflowPackage
String assignedAuthority, * @param assignedAuthorites
boolean pooled) * @param pooled
{
sendWorkflowAssignedNotificationEMail(services, taskId, new String[]{assignedAuthority}, pooled);
}
/**
* Send workflow assigned email notification.
*
* @param services service registry
* @param taskId workflow global task id
* @param assignedAuthorites assigned authorities
* @param pooled true if pooled task, false otherwise
*/ */
public static void sendWorkflowAssignedNotificationEMail(ServiceRegistry services, public static void sendWorkflowAssignedNotificationEMail(ServiceRegistry services,
String taskId, String taskId,
String title,
String description,
Date dueDate,
Integer priority,
NodeRef workflowPackage,
String[] assignedAuthorites, String[] assignedAuthorites,
boolean pooled) boolean pooled)
{ {
WorkflowTask workflowTask = services.getWorkflowService().getTaskById(taskId);
Map<QName, Serializable> props = workflowTask.getProperties();
NotificationContext notificationContext = new NotificationContext(); NotificationContext notificationContext = new NotificationContext();
// Determine the subject of the notification // Determine the subject of the notification
@@ -88,36 +89,24 @@ public abstract class WorkflowNotificationUtils
// Build the template args // Build the template args
Map<String, Serializable>templateArgs = new HashMap<String, Serializable>(7); Map<String, Serializable>templateArgs = new HashMap<String, Serializable>(7);
templateArgs.put("workflowId", workflowTask.getId()); templateArgs.put(ARG_WF_ID, taskId);
templateArgs.put("workflowTitle", workflowTask.getTitle()); templateArgs.put(ARG_WF_TITLE, title);
templateArgs.put(ARG_WF_DESCRIPTION, description);
// Get the description
String description = (String)props.get(WorkflowModel.PROP_DESCRIPTION);
if (description == null)
{
description = workflowTask.getDescription();
}
templateArgs.put("workflowDescription", description);
// Get the due date
Date dueDate = (Date)props.get(WorkflowModel.PROP_DUE_DATE);
if (dueDate != null) if (dueDate != null)
{ {
templateArgs.put("workflowDueDate", dueDate); templateArgs.put(ARG_WF_DUEDATE, dueDate);
} }
// Get the workflow priority
Integer priority = (Integer)props.get(WorkflowModel.PROP_PRIORITY);
if (priority != null) if (priority != null)
{ {
templateArgs.put("workflowPriority", priority); templateArgs.put(ARG_WF_PRIORITY, priority);
} }
// Indicate whether this is a pooled workflow item or not // Indicate whether this is a pooled workflow item or not
templateArgs.put("workflowPooled", pooled); templateArgs.put(ARG_WF_POOLED, pooled);
if (workflowPackage != null)
{
// Add details of associated content // Add details of associated content
NodeRef workflowPackage = workflowTask.getPath().getInstance().getWorkflowPackage();
List<ChildAssociationRef> assocs = services.getNodeService().getChildAssocs(workflowPackage); List<ChildAssociationRef> assocs = services.getNodeService().getChildAssocs(workflowPackage);
NodeRef[] docs = new NodeRef[assocs.size()]; NodeRef[] docs = new NodeRef[assocs.size()];
if (assocs.size() != 0) if (assocs.size() != 0)
@@ -128,7 +117,8 @@ public abstract class WorkflowNotificationUtils
docs[index] = assoc.getChildRef(); docs[index] = assoc.getChildRef();
index++; index++;
} }
templateArgs.put("workflowDocuments", docs); templateArgs.put(ARG_WF_DOCUMENTS, docs);
}
} }
// Set the template args // Set the template args
@@ -143,4 +133,56 @@ public abstract class WorkflowNotificationUtils
// Send email notification // Send email notification
services.getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext); services.getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext);
} }
/**
* Send workflow assigned email notification.
*
* @param services service registry
* @param taskId workflow global task id
* @param assignedAuthorites assigned authorities
* @param pooled true if pooled task, false otherwise
*/
public static void sendWorkflowAssignedNotificationEMail(ServiceRegistry services,
String taskId,
String[] assignedAuthorites,
boolean pooled)
{
// Get the workflow task
WorkflowTask workflowTask = services.getWorkflowService().getTaskById(taskId);
// Get the workflow properties
Map<QName, Serializable> props = workflowTask.getProperties();
// Get the title and description
String title = workflowTask.getTitle();
String description = (String)props.get(WorkflowModel.PROP_DESCRIPTION);
if (description == null)
{
description = workflowTask.getDescription();
}
// Get the duedate, priority and workflow package
Date dueDate = (Date)props.get(WorkflowModel.PROP_DUE_DATE);
Integer priority = (Integer)props.get(WorkflowModel.PROP_PRIORITY);
NodeRef workflowPackage = workflowTask.getPath().getInstance().getWorkflowPackage();
// Send notification
sendWorkflowAssignedNotificationEMail(services, taskId, title, description, dueDate, priority, workflowPackage, assignedAuthorites, pooled);
}
/**
* Send workflow assigned email notification.
*
* @param services service registry
* @param taskId workflow global task id
* @param assignedAuthority assigned authority
* @param pooled true if pooled task, false otherwise
*/
public static void sendWorkflowAssignedNotificationEMail(ServiceRegistry services,
String taskId,
String assignedAuthority,
boolean pooled)
{
sendWorkflowAssignedNotificationEMail(services, taskId, new String[]{assignedAuthority}, pooled);
}
} }

View File

@@ -27,8 +27,10 @@ import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity; import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.alfresco.repo.workflow.WorkflowNotificationUtils; import org.alfresco.repo.workflow.WorkflowNotificationUtils;
import org.alfresco.repo.workflow.activiti.ActivitiConstants; import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.repo.workflow.activiti.properties.ActivitiPropertyConverter; import org.alfresco.repo.workflow.activiti.properties.ActivitiPropertyConverter;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
/** /**
* Tasklistener that is notified when a task is created. This will set all * Tasklistener that is notified when a task is created. This will set all
@@ -71,12 +73,27 @@ public class TaskCreateListener implements TaskListener
Boolean value = (Boolean)executionEntity.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS); Boolean value = (Boolean)executionEntity.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS);
if (Boolean.TRUE.equals(value) == true) if (Boolean.TRUE.equals(value) == true)
{ {
NodeRef workflowPackage = null;
ActivitiScriptNode scriptNode = (ActivitiScriptNode)executionEntity.getVariable(WorkflowNotificationUtils.PROP_PACKAGE);
if (scriptNode != null)
{
workflowPackage = scriptNode.getNodeRef();
}
// TODO how do we identify a pooled task?
boolean pooled = false;
// Send email notification // Send email notification
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail( WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
services, services,
"activiti$" + task.getId(), "activiti$" + task.getId(),
task.getAssignee(), task.getName(),
false); task.getDescription(),
task.getDueDate(),
Integer.valueOf(task.getPriority()),
workflowPackage,
new String[]{task.getAssignee()},
pooled);
} }
} }