Merged BRANCHES/V3.4 to HEAD:

24530: ALF-6133 Fixed an issue in JbpmEngine.updateTask() where the added and removed associations were not being handled properly.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@24575 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2010-12-17 11:55:18 +00:00
parent 7d77b7ca63
commit 5612c8ba1b

View File

@@ -23,8 +23,10 @@ import java.io.InputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -1665,11 +1667,7 @@ public class JBPMEngine extends BPMEngine
TaskInstance taskInstance = getTaskInstance(taskSession, taskId); TaskInstance taskInstance = getTaskInstance(taskSession, taskId);
// create properties to set on task instance // create properties to set on task instance
Map<QName, Serializable> newProperties = properties; Map<QName, Serializable> newProperties = properties !=null ? properties : new HashMap<QName, Serializable>(10);
if (newProperties == null && (add != null || remove != null))
{
newProperties = new HashMap<QName, Serializable>(10);
}
if (add != null || remove != null) if (add != null || remove != null)
{ {
@@ -1681,19 +1679,31 @@ public class JBPMEngine extends BPMEngine
for (Entry<QName, List<NodeRef>> toAdd : add.entrySet()) for (Entry<QName, List<NodeRef>> toAdd : add.entrySet())
{ {
// retrieve existing list of noderefs for association // retrieve existing list of noderefs for association
List<NodeRef> existingAdd = (List<NodeRef>)newProperties.get(toAdd.getKey()); QName key = toAdd.getKey();
if (existingAdd == null) Serializable existingValue = newProperties.get(key);
if (existingValue == null)
{ {
existingAdd = (List<NodeRef>)existingProperties.get(toAdd.getKey()); existingValue = existingProperties.get(key);
} }
// make the additions // make the additions
if (existingAdd == null) if (existingValue == null)
{ {
newProperties.put(toAdd.getKey(), (Serializable)toAdd.getValue()); newProperties.put(key, (Serializable)toAdd.getValue());
} }
else else
{ {
List<NodeRef> existingAdd;
if (existingValue instanceof List<?>)
{
existingAdd = (List<NodeRef>) existingValue;
}
else
{
existingAdd = new LinkedList<NodeRef>();
existingAdd.add((NodeRef) existingValue);
}
for (NodeRef nodeRef : toAdd.getValue()) for (NodeRef nodeRef : toAdd.getValue())
{ {
if (!(existingAdd.contains(nodeRef))) if (!(existingAdd.contains(nodeRef)))
@@ -1701,6 +1711,7 @@ public class JBPMEngine extends BPMEngine
existingAdd.add(nodeRef); existingAdd.add(nodeRef);
} }
} }
newProperties.put(key, (Serializable) existingAdd);
} }
} }
} }
@@ -1711,18 +1722,25 @@ public class JBPMEngine extends BPMEngine
for (Entry<QName, List<NodeRef>> toRemove: remove.entrySet()) for (Entry<QName, List<NodeRef>> toRemove: remove.entrySet())
{ {
// retrieve existing list of noderefs for association // retrieve existing list of noderefs for association
List<NodeRef> existingRemove = (List<NodeRef>)newProperties.get(toRemove.getKey()); QName key = toRemove.getKey();
if (existingRemove == null) Serializable existingValue = newProperties.get(key);
if (existingValue == null)
{ {
existingRemove = (List<NodeRef>)existingProperties.get(toRemove.getKey()); existingValue = existingProperties.get(key);
} }
// make the subtractions // make the subtractions
if (existingRemove != null) if (existingValue != null)
{ {
for (NodeRef nodeRef : (List<NodeRef>)toRemove.getValue()) if(existingValue instanceof List<?>)
{ {
existingRemove.remove(nodeRef); List<NodeRef> existingRemove = (List<NodeRef>) existingValue;
existingRemove.removeAll(toRemove.getValue());
newProperties.put(key, (Serializable) existingRemove);
}
else if(toRemove.getValue().contains(existingValue))
{
newProperties.put(key, new LinkedList<NodeRef>());
} }
} }
} }
@@ -1730,7 +1748,7 @@ public class JBPMEngine extends BPMEngine
} }
// update the task // update the task
if (newProperties != null) if (newProperties.isEmpty() == false)
{ {
setTaskProperties(taskInstance, newProperties); setTaskProperties(taskInstance, newProperties);
@@ -2111,7 +2129,8 @@ public class JBPMEngine extends BPMEngine
QName qname = mapNameToQName(key); QName qname = mapNameToQName(key);
// add variable, only if part of task definition or locally defined on task // add variable, only if part of task definition or locally defined on task
if (taskProperties.containsKey(qname) || taskAssocs.containsKey(qname) || instance.hasVariableLocally(key)) boolean isAssoc = taskAssocs.containsKey(qname);
if (taskProperties.containsKey(qname) || isAssoc || instance.hasVariableLocally(key))
{ {
Serializable value = convertValue(entry.getValue()); Serializable value = convertValue(entry.getValue());
properties.put(qname, value); properties.put(qname, value);