mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged BRANCHES/DEV/WF-NOTIFICATION to HEAD:
29508: Workflow Notification - First Cut * Notification service to consolidate sending of user notifications (kinds of notifications are provided by Sprung in notification providers) * EMail notification provider implementation (uses standard Email action to send email) * Frist cut workflow email template (still needs lots of details added) * AMP, etc for email template * Hook point within Activit and JBMP implementations * Property added to model (startTask) indicating whether email notifications should be sent * Hook points sensitive to property * Wf forms updated to show property 29703: Workflow Notification: * Remove AMP and replace with exploded XMl and template (easier to maintain) * Bootstrap updated * Patch added * Refactored hooks to use generic workflowTask object (tidies up helper methods) * I18n'ed messages * Task and work package information placed in template model * Email template built with reference to Lintons wire's (still needs some polish!) * Added Notification Servcice to Service Registry git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29705 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -86,5 +86,7 @@ public interface WorkflowModel
|
||||
static final QName PROP_WORKFLOW_DEF_ENGINE_ID = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "engineId");
|
||||
static final QName PROP_WORKFLOW_DEF_NAME = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "definitionName");
|
||||
static final QName PROP_WORKFLOW_DEF_DEPLOYED = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "definitionDeployed");
|
||||
|
||||
static final QName PROP_SEND_EMAIL_NOTIFICATIONS = QName.createQName(NamespaceService.BPM_MODEL_1_0_URI, "sendEMailNotifications");
|
||||
|
||||
}
|
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.workflow;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.notification.EMailNotificationProvider;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.notification.NotificationContext;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowTask;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Utility class containing methods to help when sending workflow notifications.
|
||||
*
|
||||
* TODO? Move to workflow serivce??
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class WorkflowNotificationUtils
|
||||
{
|
||||
/** Send EMail notifications property */
|
||||
public static final String PROP_SEND_EMAIL_NOTIFICATIONS = "bpm_sendEMailNotifications";
|
||||
|
||||
/** I18N */
|
||||
public static final String MSG_ASSIGNED_TASK = "assigned-task";
|
||||
public static final String MSG_NEW_POOLED_TASK = "new-pooled-task";
|
||||
|
||||
/** Standard workflow assigned template */
|
||||
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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
WorkflowTask workflowTask = services.getWorkflowService().getTaskById(taskId);
|
||||
Map<QName, Serializable> props = workflowTask.getProperties();
|
||||
NotificationContext notificationContext = new NotificationContext();
|
||||
|
||||
// Determine the subject of the notification
|
||||
String subject = null;
|
||||
if (pooled == false)
|
||||
{
|
||||
subject = I18NUtil.getMessage(MSG_ASSIGNED_TASK);
|
||||
}
|
||||
else
|
||||
{
|
||||
subject = I18NUtil.getMessage(MSG_NEW_POOLED_TASK);
|
||||
}
|
||||
notificationContext.setSubject(subject);
|
||||
|
||||
// Set the email template
|
||||
notificationContext.setBodyTemplate(WF_ASSIGNED_TEMPLATE);
|
||||
|
||||
// Build the template args
|
||||
Map<String, Serializable>templateArgs = new HashMap<String, Serializable>(7);
|
||||
templateArgs.put("workflowId", workflowTask.getId());
|
||||
templateArgs.put("workflowTitle", workflowTask.getTitle());
|
||||
|
||||
// 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)
|
||||
{
|
||||
templateArgs.put("workflowDueDate", dueDate);
|
||||
}
|
||||
|
||||
// Get the workflow priority
|
||||
Integer priority = (Integer)props.get(WorkflowModel.PROP_PRIORITY);
|
||||
if (priority != null)
|
||||
{
|
||||
templateArgs.put("workflowPriority", priority);
|
||||
}
|
||||
|
||||
// Indicate whether this is a pooled workflow item or not
|
||||
templateArgs.put("workflowPooled", pooled);
|
||||
|
||||
// Add details of associated content
|
||||
NodeRef workflowPackage = workflowTask.getPath().getInstance().getWorkflowPackage();
|
||||
List<ChildAssociationRef> assocs = services.getNodeService().getChildAssocs(workflowPackage);
|
||||
NodeRef[] docs = new NodeRef[assocs.size()];
|
||||
if (assocs.size() != 0)
|
||||
{
|
||||
int index = 0;
|
||||
for (ChildAssociationRef assoc : assocs)
|
||||
{
|
||||
docs[index] = assoc.getChildRef();
|
||||
index++;
|
||||
}
|
||||
templateArgs.put("workflowDocuments", docs);
|
||||
}
|
||||
|
||||
// Set the template args
|
||||
notificationContext.setTemplateArgs(templateArgs);
|
||||
|
||||
// Set the notification recipients
|
||||
for (String assignedAuthority : assignedAuthorites)
|
||||
{
|
||||
notificationContext.addTo(assignedAuthority);
|
||||
}
|
||||
|
||||
// Send email notification
|
||||
services.getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext);
|
||||
}
|
||||
}
|
@@ -23,9 +23,12 @@ 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.TaskEntity;
|
||||
import org.alfresco.repo.workflow.WorkflowNotificationUtils;
|
||||
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
|
||||
import org.alfresco.repo.workflow.activiti.properties.ActivitiPropertyConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Tasklistener that is notified when a task is created. This will set all
|
||||
@@ -38,6 +41,17 @@ public class TaskCreateListener implements TaskListener
|
||||
{
|
||||
private ActivitiPropertyConverter propertyConverter;
|
||||
|
||||
/** Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* @param services the service registry
|
||||
*/
|
||||
public void setServices(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notify(DelegateTask task)
|
||||
{
|
||||
@@ -51,6 +65,19 @@ public class TaskCreateListener implements TaskListener
|
||||
{
|
||||
task.setVariableLocal(ActivitiConstants.PROP_TASK_FORM_KEY, taskFormKey);
|
||||
}
|
||||
|
||||
// Determine whether we need to send the workflow notification or not
|
||||
ExecutionEntity executionEntity = ((ExecutionEntity)task.getExecution()).getProcessInstance();
|
||||
Boolean value = (Boolean)executionEntity.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS);
|
||||
if (Boolean.TRUE.equals(value) == true)
|
||||
{
|
||||
// Send email notification
|
||||
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
|
||||
services,
|
||||
"activiti$" + task.getId(),
|
||||
task.getAssignee(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFormKey(DelegateTask task)
|
||||
|
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.jscript.ScriptNode;
|
||||
import org.alfresco.repo.security.authority.AuthorityDAO;
|
||||
import org.alfresco.repo.workflow.WorkflowNotificationUtils;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowException;
|
||||
@@ -195,17 +196,41 @@ public class AlfrescoAssignment extends JBPMSpringAssignmentHandler
|
||||
}
|
||||
}
|
||||
|
||||
//Determine whether we need to send email notifications of not
|
||||
Boolean sendEMailNotification = (Boolean)executionContext.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS);
|
||||
|
||||
//
|
||||
// make the assignment
|
||||
//
|
||||
if (assignedActor != null)
|
||||
{
|
||||
assignable.setActorId(assignedActor);
|
||||
|
||||
if (Boolean.TRUE.equals(sendEMailNotification) == true)
|
||||
{
|
||||
// Send the notification
|
||||
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
|
||||
services,
|
||||
JBPMEngine.ENGINE_ID + "$" + executionContext.getTaskInstance().getId(),
|
||||
assignedActor,
|
||||
false);
|
||||
}
|
||||
|
||||
}
|
||||
if (assignedPooledActors != null)
|
||||
{
|
||||
assignable.setPooledActors(assignedPooledActors);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(sendEMailNotification) == true)
|
||||
{
|
||||
// Send the notification
|
||||
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
|
||||
services,
|
||||
JBPMEngine.ENGINE_ID + "$" + executionContext.getTaskInstance().getId(),
|
||||
assignedPooledActors,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user