Merged DEV/V4.0-BUGFIX into HEAD:

36275 ALF-14029: Updating single-valued association (no List<NodeRef>) fixed.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@36279 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2012-05-11 10:57:47 +00:00
parent dbb11a5ce2
commit 2a00f36241
2 changed files with 72 additions and 27 deletions

View File

@@ -721,6 +721,7 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
QName propQname = QName.createQName("testProp"); QName propQname = QName.createQName("testProp");
QName nodeRefPropQname = QName.createQName("testAssoc"); QName nodeRefPropQname = QName.createQName("testAssoc");
QName singleNodeRefPropQname = QName.createQName("testAssocSingleValue");
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>(); HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
// Start the workflow-path // Start the workflow-path
@@ -740,6 +741,7 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
// Test altering plain properties // Test altering plain properties
props = new HashMap<QName, Serializable>(); props = new HashMap<QName, Serializable>();
props.put(propQname, "54321"); props.put(propQname, "54321");
props.put(singleNodeRefPropQname, nodeRef);
workflowEngine.updateTask(task.getId(), props, null, null); workflowEngine.updateTask(task.getId(), props, null, null);
tasks = workflowEngine.queryTasks(taskQuery); tasks = workflowEngine.queryTasks(taskQuery);
@@ -766,6 +768,31 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
task = tasks.get(0); task = tasks.get(0);
assertEquals(1, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).size()); assertEquals(1, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).size());
assertEquals(anotherRef, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).get(0)); assertEquals(anotherRef, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).get(0));
// Test changing single-valued association
toAdd = new HashMap<QName, List<NodeRef>>();
toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(singleNodeRefPropQname, Arrays.asList(nodeRef));
toAdd.put(singleNodeRefPropQname, Arrays.asList(anotherRef));
workflowEngine.updateTask(task.getId(), null, toAdd, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(anotherRef, task.getProperties().get(singleNodeRefPropQname));
// Test clearing single-valued association
toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(singleNodeRefPropQname, Arrays.asList(anotherRef));
workflowEngine.updateTask(task.getId(), null, null, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
// Association value should be empty now
assertNull(task.getProperties().get(singleNodeRefPropQname));
} }
private void checkTaskVariableTaskPresent(WorkflowTaskState state, private void checkTaskVariableTaskPresent(WorkflowTaskState state,

View File

@@ -684,29 +684,38 @@ public class ActivitiPropertyConverter
// add new associations // add new associations
for (Entry<QName, List<NodeRef>> toAdd : add.entrySet()) for (Entry<QName, List<NodeRef>> toAdd : add.entrySet())
{ {
// retrieve existing list of noderefs for // Retrieve existing list of noderefs for association OR single nodeRef
// association Serializable existingAdd = newProperties.get(toAdd.getKey());
List<NodeRef> existingAdd = (List<NodeRef>) newProperties.get(toAdd.getKey());
if (existingAdd == null) if (existingAdd == null)
{ {
existingAdd = (List<NodeRef>) existingProperties.get(toAdd.getKey()); // Get the property values from the existing values, if any
existingAdd = existingProperties.get(toAdd.getKey());
newProperties.put(toAdd.getKey(), (Serializable) existingAdd); newProperties.put(toAdd.getKey(), (Serializable) existingAdd);
} }
// make the additions // Add property values, if nessesairy
if (existingAdd == null) if (existingAdd == null)
{ {
newProperties.put(toAdd.getKey(), (Serializable) toAdd.getValue()); newProperties.put(toAdd.getKey(), (Serializable) toAdd.getValue());
} }
else else
{ {
for (NodeRef nodeRef : toAdd.getValue()) if(existingAdd instanceof List<?>) {
{ List<NodeRef> existingList = (List<NodeRef>) existingAdd;
if (!(existingAdd.contains(nodeRef)))
{ for (NodeRef nodeRef : toAdd.getValue())
existingAdd.add(nodeRef); {
} if (!(existingList.contains(nodeRef)))
} {
existingList.add(nodeRef);
}
}
} else {
// Single valued property, add first value
if(toAdd.getValue().size() > 0) {
newProperties.put(toAdd.getKey(), (Serializable) toAdd.getValue().get(0));
}
}
} }
} }
} }
@@ -718,23 +727,32 @@ public class ActivitiPropertyConverter
{ {
// retrieve existing list of noderefs for // retrieve existing list of noderefs for
// association // association
List<NodeRef> existingRemove = (List<NodeRef>) newProperties.get(toRemove.getKey()); Serializable existingRemove = (Serializable) newProperties.get(toRemove.getKey());
boolean isAlreadyNewProperty = existingRemove != null;
if (existingRemove == null) if (existingRemove == null)
{ {
existingRemove = (List<NodeRef>) existingProperties.get(toRemove.getKey()); existingRemove = (Serializable) existingProperties.get(toRemove.getKey());
if(existingRemove != null) {
existingRemove = new ArrayList<NodeRef>(existingRemove);
newProperties.put(toRemove.getKey(), (Serializable) existingRemove);
}
} }
// make the subtractions // Only if the current property value is set, remove makes sense
if (existingRemove != null) if(existingRemove != null) {
{ if(existingRemove instanceof List<?>) {
for (NodeRef nodeRef : toRemove.getValue()) existingRemove = new ArrayList<NodeRef>((List<NodeRef>)existingRemove);
{
existingRemove.remove(nodeRef); for (NodeRef nodeRef : toRemove.getValue())
} {
((List<NodeRef>)existingRemove).remove(nodeRef);
}
newProperties.put(toRemove.getKey(),existingRemove);
} else {
// It's a single-valued property and an "add" has been done. No need to remove
// previous value, since it's overridden by the new value.
if(!isAlreadyNewProperty) {
// Property is single-valued and should be removed
newProperties.put(toRemove.getKey(), null);
}
}
} }
} }
} }