Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (4.3/Cloud)

74247: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (5.0/Cloud)
      73960: Merged DEV to V4.2-BUG-FIX (4.2.3)
         73719: MNT-11586 : bpm:outcome property is not set when completing a task via the workflow public API
         Added "bpm_outcome" variable to completed and resolved tasks.
         Added checks to tests.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@74881 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Will Abson
2014-06-25 16:32:28 +00:00
parent 3e30eaba81
commit 59a74742cc
2 changed files with 42 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,6 +18,7 @@
*/
package org.alfresco.rest.workflow.api.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -44,6 +45,7 @@ import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.repo.workflow.WorkflowObjectFactory;
import org.alfresco.repo.workflow.WorkflowQNameConverter;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.properties.ActivitiPropertyConverter;
import org.alfresco.rest.antlr.WhereClauseParser;
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
@@ -126,6 +128,12 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
private WorkflowQNameConverter qNameConverter;
private MessageService messageService;
private PersonService personService;
private ActivitiPropertyConverter propertyConverter;
public void setPropertyConverter(ActivitiPropertyConverter propertyConverter)
{
this.propertyConverter = propertyConverter;
}
public void setRestVariableHelper(RestVariableHelper restVariableHelper)
{
@@ -838,7 +846,6 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
}
}
}
switch (taskAction)
{
case CLAIMED:
@@ -852,6 +859,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
}
break;
case COMPLETED:
setOutcome(localVariables, taskId);
if (localVariables.size() > 0)
{
activitiProcessEngine.getTaskService().setVariablesLocal(taskId, localVariables);
@@ -882,6 +890,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
}
break;
case RESOLVED:
setOutcome(localVariables, taskId);
if (localVariables.size() > 0)
{
activitiProcessEngine.getTaskService().setVariablesLocal(taskId, localVariables);
@@ -1702,4 +1711,28 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
}
return workflowFactory;
}
/**
* Set bpm:outcome variable to the local variables of the specified task.
* <br>The variables should be set separately via {@link org.activiti.engine.TaskService}
* @param localVariables The variable, that will be set to the task
* @param taskId The id of the task
*/
private void setOutcome(Map<String, Object> localVariables, String taskId)
{
WorkflowQNameConverter qNameConverter = getQNameConverter();
org.activiti.engine.task.Task task = activitiProcessEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
String outcomeValue = ActivitiConstants.DEFAULT_TRANSITION_NAME;
Map<QName, Serializable> properties = propertyConverter.getTaskProperties(task);
QName outcomePropName = (QName) properties.get(WorkflowModel.PROP_OUTCOME_PROPERTY_NAME);
if (outcomePropName != null)
{
Serializable rawOutcome = properties.get(outcomePropName);
if (rawOutcome != null)
{
outcomeValue = DefaultTypeConverter.INSTANCE.convert(String.class, rawOutcome);
}
}
localVariables.put(qNameConverter.mapQNameToName(WorkflowModel.PROP_OUTCOME), outcomeValue);
}
}

View File

@@ -792,7 +792,7 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
assertEquals(1234, historyTask.getProcessVariables().get("newGlobalVariable"));
assertEquals(5678, historyTask.getTaskLocalVariables().get("newLocalVariable"));
assertNotNull("The outcome should not be null for completed task.", historyTask.getTaskLocalVariables().get("bpm_outcome"));
JSONObject variables = tasksClient.findTaskVariables(withVariablesTask.getId());
assertNotNull(variables);
JSONObject list = (JSONObject) variables.get("list");
@@ -988,6 +988,12 @@ public class TaskWorkflowApiTest extends EnterpriseWorkflowTestApi
task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals(DelegationState.RESOLVED, task.getDelegationState());
assertEquals(initiator, task.getAssignee());
HistoricTaskInstance historyTask = activitiProcessEngine.getHistoryService().createHistoricTaskInstanceQuery()
.taskId(task.getId())
.includeProcessVariables()
.includeTaskLocalVariables()
.singleResult();
assertNotNull("The outcome should not be null for resolved task.", historyTask.getTaskLocalVariables().get("bpm_outcome"));
// Resolving as owner
task.setDelegationState(null);