Tweaked the updateTask method to only send notification emails if the assignee has changed (Explorer client always sends all properties on an update) and added check for null start task just in case!

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29945 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2011-08-22 12:22:16 +00:00
parent 3d050b6033
commit a9229b3ed6

View File

@@ -699,31 +699,40 @@ public class WorkflowServiceImpl implements WorkflowService
{ {
String engineId = BPMEngineRegistry.getEngineId(taskId); String engineId = BPMEngineRegistry.getEngineId(taskId);
TaskComponent component = getTaskComponent(engineId); TaskComponent component = getTaskComponent(engineId);
// get the current assignee before updating the task
String originalAsignee = (String)component.getTaskById(taskId).getProperties().get(ContentModel.PROP_OWNER);
WorkflowTask task = component.updateTask(taskId, properties, add, remove); WorkflowTask task = component.updateTask(taskId, properties, add, remove);
if(add!=null && add.containsKey(WorkflowModel.ASSOC_PACKAGE)) if (add != null && add.containsKey(WorkflowModel.ASSOC_PACKAGE))
{ {
WorkflowInstance instance = task.getPath().getInstance(); WorkflowInstance instance = task.getPath().getInstance();
workflowPackageComponent.setWorkflowForPackage(instance); workflowPackageComponent.setWorkflowForPackage(instance);
} }
// Get the start task
String instanceId = task.getPath().getInstance().getId();
WorkflowTask startTask = component.getStartTask(instanceId);
// Get the email notification flag
Boolean sendEMailNotification = (Boolean) startTask.getProperties().get(WorkflowModel.PROP_SEND_EMAIL_NOTIFICATIONS);
// Get the 'new' assignee // Get the 'new' assignee
String assignee = (String)properties.get(ContentModel.PROP_OWNER); String assignee = (String)properties.get(ContentModel.PROP_OWNER);
if (assignee != null && assignee.length() != 0 && if (assignee != null && assignee.length() != 0)
Boolean.TRUE.equals(sendEMailNotification) == true)
{ {
// Send the notification // if the assignee has changed get the start task
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail( if (!assignee.equals(originalAsignee))
services, {
taskId, String instanceId = task.getPath().getInstance().getId();
assignee, WorkflowTask startTask = component.getStartTask(instanceId);
false);
if (startTask != null)
{
// Get the email notification flag
Boolean sendEMailNotification = (Boolean) startTask.getProperties().get(WorkflowModel.PROP_SEND_EMAIL_NOTIFICATIONS);
if (Boolean.TRUE.equals(sendEMailNotification) == true)
{
// Send the notification
WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
services,
taskId,
assignee,
false);
}
}
}
} }
return task; return task;