ALF-13640: fix merged from V4.0-BUGFIX branch

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@35257 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Frederik Heremans
2012-04-16 10:06:16 +00:00
parent 556377ea3b
commit 21b5d8a41f
4 changed files with 82 additions and 9 deletions

View File

@@ -226,7 +226,7 @@ public class WorkflowObjectFactory
String processKey = getProcessKey(defName) + ".task." + name; String processKey = getProcessKey(defName) + ".task." + name;
TypeDefinition metadata = taskDef.getMetadata(); TypeDefinition metadata = taskDef.getMetadata();
String title = getLabel(processKey, TITLE_LABEL, metadata.getTitle(), defaultTitle, name); String title = getLabel(processKey, TITLE_LABEL, metadata.getTitle(), defaultTitle, name);
String description = getLabel(processKey, DESC_LABEL, metadata.getDescription(), title, defaultDescription); String description = getLabel(processKey, DESC_LABEL, metadata.getDescription(), defaultDescription, title);
return new WorkflowTask(actualId, return new WorkflowTask(actualId,
taskDef, name, title, description, taskDef, name, title, description,
state, path, properties); state, path, properties);

View File

@@ -389,6 +389,17 @@ public class AbstractActivitiComponentTest
return (String) arg; return (String) arg;
} }
}); });
when(tenantService.getName(anyString())).thenAnswer(new Answer<String>()
{
public String answer(InvocationOnMock invocation) throws Throwable
{
Object arg= invocation.getArguments()[0];
return (String) arg;
}
});
when(tenantService.getCurrentUserDomain()).thenReturn("");
} }
@After @After

View File

@@ -448,13 +448,13 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
// Test query by process-name // Test query by process-name
taskQuery = createWorkflowTaskQuery(WorkflowTaskState.IN_PROGRESS); taskQuery = createWorkflowTaskQuery(WorkflowTaskState.IN_PROGRESS);
taskQuery.setProcessName(QName.createQName("testTask")); taskQuery.setWorkflowDefinitionName("testTask");
tasks = workflowEngine.queryTasks(taskQuery); tasks = workflowEngine.queryTasks(taskQuery);
Assert.assertNotNull(tasks); Assert.assertNotNull(tasks);
Assert.assertEquals(1, tasks.size()); Assert.assertEquals(1, tasks.size());
taskQuery.setProcessName(QName.createQName("unexistingTaskName")); taskQuery.setWorkflowDefinitionName("unexistingTaskName");
tasks = workflowEngine.queryTasks(taskQuery); tasks = workflowEngine.queryTasks(taskQuery);
Assert.assertNotNull(tasks); Assert.assertNotNull(tasks);
Assert.assertEquals(0, tasks.size()); Assert.assertEquals(0, tasks.size());
@@ -635,14 +635,14 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
// Test query by process-name // Test query by process-name
taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED); taskQuery = createWorkflowTaskQuery(WorkflowTaskState.COMPLETED);
taskQuery.setProcessName(QName.createQName("testTask")); taskQuery.setWorkflowDefinitionName("testTask");
taskQuery.setActive(Boolean.FALSE); taskQuery.setActive(Boolean.FALSE);
tasks = workflowEngine.queryTasks(taskQuery); tasks = workflowEngine.queryTasks(taskQuery);
Assert.assertNotNull(tasks); Assert.assertNotNull(tasks);
Assert.assertEquals(1, tasks.size()); Assert.assertEquals(1, tasks.size());
taskQuery.setProcessName(QName.createQName("unexistingTaskName")); taskQuery.setWorkflowDefinitionName("unexistingTaskName");
tasks = workflowEngine.queryTasks(taskQuery); tasks = workflowEngine.queryTasks(taskQuery);
Assert.assertNotNull(tasks); Assert.assertNotNull(tasks);
Assert.assertEquals(0, tasks.size()); Assert.assertEquals(0, tasks.size());
@@ -704,6 +704,61 @@ public class ActivitiTaskComponentTest extends AbstractActivitiComponentTest
assertEquals(1, tasks.size()); assertEquals(1, tasks.size());
} }
@SuppressWarnings("unchecked")
@Test
public void testUpdateTask() {
NodeRef nodeRef = new NodeRef("workspace:///someRef");
NodeRef anotherRef = new NodeRef("workspace:///anotherRef");
QName propQname = QName.createQName("testProp");
QName nodeRefPropQname = QName.createQName("testAssoc");
HashMap<QName, Serializable> props = new HashMap<QName, Serializable>();
// Start the workflow-path
WorkflowPath path = workflowEngine.startWorkflow(workflowDef.getId(), props);
WorkflowTask startTask = workflowEngine.getStartTask(path.getInstance().getId());
// End the start-task
workflowEngine.endTask(startTask.getId(), null);
// Get the task to update
WorkflowTaskQuery taskQuery = createWorkflowTaskQuery(WorkflowTaskState.IN_PROGRESS);
taskQuery.setProcessId(path.getInstance().getId());
List<WorkflowTask> tasks = workflowEngine.queryTasks(taskQuery);
WorkflowTask task = tasks.get(0);
// Test altering plain properties
props = new HashMap<QName, Serializable>();
props.put(propQname, "54321");
workflowEngine.updateTask(task.getId(), props, null, null);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals("54321", task.getProperties().get(propQname));
// Test adding association
HashMap<QName, List<NodeRef>> toAdd = new HashMap<QName, List<NodeRef>>();
toAdd.put(nodeRefPropQname, Arrays.asList(anotherRef, nodeRef));
workflowEngine.updateTask(task.getId(), null, toAdd, null);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(2, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).size());
// Test removing association
HashMap<QName, List<NodeRef>> toRemove = new HashMap<QName, List<NodeRef>>();
toRemove.put(nodeRefPropQname, Arrays.asList(nodeRef));
workflowEngine.updateTask(task.getId(), null, null, toRemove);
tasks = workflowEngine.queryTasks(taskQuery);
task = tasks.get(0);
assertEquals(1, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).size());
assertEquals(anotherRef, ((List<NodeRef>)task.getProperties().get(nodeRefPropQname)).get(0));
}
private void checkTaskVariableTaskPresent(WorkflowTaskState state, private void checkTaskVariableTaskPresent(WorkflowTaskState state,
QName varName, Object varValue, String expectedTask) QName varName, Object varValue, String expectedTask)
{ {

View File

@@ -385,11 +385,13 @@ public class ActivitiPropertyConverter
Serializable existingValue = existingValues.get(WorkflowModel.PROP_PRIORITY); Serializable existingValue = existingValues.get(WorkflowModel.PROP_PRIORITY);
try try
{ {
if(priorDef != null) {
for (ConstraintDefinition constraintDef : priorDef.getConstraints()) for (ConstraintDefinition constraintDef : priorDef.getConstraints())
{ {
constraintDef.getConstraint().evaluate(existingValue); constraintDef.getConstraint().evaluate(existingValue);
} }
} }
}
catch (ConstraintException ce) catch (ConstraintException ce)
{ {
Integer defaultVal = Integer.valueOf(priorDef.getDefaultValue()); Integer defaultVal = Integer.valueOf(priorDef.getDefaultValue());
@@ -687,6 +689,7 @@ public class ActivitiPropertyConverter
if (existingAdd == null) if (existingAdd == null)
{ {
existingAdd = (List<NodeRef>) existingProperties.get(toAdd.getKey()); existingAdd = (List<NodeRef>) existingProperties.get(toAdd.getKey());
newProperties.put(toAdd.getKey(), (Serializable) existingAdd);
} }
// make the additions // make the additions
@@ -718,6 +721,10 @@ public class ActivitiPropertyConverter
if (existingRemove == null) if (existingRemove == null)
{ {
existingRemove = (List<NodeRef>) existingProperties.get(toRemove.getKey()); existingRemove = (List<NodeRef>) existingProperties.get(toRemove.getKey());
if(existingRemove != null) {
existingRemove = new ArrayList<NodeRef>(existingRemove);
newProperties.put(toRemove.getKey(), (Serializable) existingRemove);
}
} }
// make the subtractions // make the subtractions