From a9229b3ed6cfb8645eeb50cb569dc97ee2c80702 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Mon, 22 Aug 2011 12:22:16 +0000 Subject: [PATCH] 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 --- .../repo/workflow/WorkflowServiceImpl.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/source/java/org/alfresco/repo/workflow/WorkflowServiceImpl.java b/source/java/org/alfresco/repo/workflow/WorkflowServiceImpl.java index 55d14aa976..dd2df6ef5f 100644 --- a/source/java/org/alfresco/repo/workflow/WorkflowServiceImpl.java +++ b/source/java/org/alfresco/repo/workflow/WorkflowServiceImpl.java @@ -699,31 +699,40 @@ public class WorkflowServiceImpl implements WorkflowService { String engineId = BPMEngineRegistry.getEngineId(taskId); 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); - if(add!=null && add.containsKey(WorkflowModel.ASSOC_PACKAGE)) + if (add != null && add.containsKey(WorkflowModel.ASSOC_PACKAGE)) { WorkflowInstance instance = task.getPath().getInstance(); 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 String assignee = (String)properties.get(ContentModel.PROP_OWNER); - if (assignee != null && assignee.length() != 0 && - Boolean.TRUE.equals(sendEMailNotification) == true) + if (assignee != null && assignee.length() != 0) { - // Send the notification - WorkflowNotificationUtils.sendWorkflowAssignedNotificationEMail( - services, - taskId, - assignee, - false); + // if the assignee has changed get the start task + if (!assignee.equals(originalAsignee)) + { + String instanceId = task.getPath().getInstance().getId(); + WorkflowTask startTask = component.getStartTask(instanceId); + + 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;