mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
REST API fixes based on mobile testing + new Activiti version
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55132 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -30,7 +30,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.activiti.engine.form.StartFormData;
|
||||
import org.activiti.engine.impl.form.StartFormHandler;
|
||||
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
||||
import org.activiti.engine.repository.ProcessDefinitionQuery;
|
||||
import org.alfresco.repo.i18n.MessageService;
|
||||
@@ -385,31 +384,12 @@ public class ProcessDefinitionsImpl extends WorkflowRestImpl implements ProcessD
|
||||
{
|
||||
try
|
||||
{
|
||||
StartFormData startFormData = null;
|
||||
ProcessDefinitionEntity definitionEntity = getCachedProcessDefinition(processDefinition.getId());
|
||||
if (definitionEntity != null)
|
||||
{
|
||||
StartFormHandler startFormHandler = definitionEntity.getStartFormHandler();
|
||||
if (startFormHandler == null) {
|
||||
throw new ApiException("No start form defined for " + processDefinition.getId());
|
||||
}
|
||||
|
||||
startFormData = startFormHandler.createStartFormData(definitionEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinition.getId());
|
||||
}
|
||||
|
||||
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinition.getId());
|
||||
if (startFormData != null)
|
||||
{
|
||||
processDefinitionRest.setStartFormResourceKey(startFormData.getFormKey());
|
||||
}
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ApiException("Error while retrieving start form key");
|
||||
|
@@ -100,13 +100,14 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
protected static String PROCESS_STATUS_ANY = "any";
|
||||
protected static String PROCESS_STATUS_ACTIVE = "active";
|
||||
protected static String PROCESS_STATUS_COMPLETED = "completed";
|
||||
protected static String PROCESS_STATUS_DELETED = "deleted";
|
||||
|
||||
protected static final Set<String> PROCESS_STATUS_LIST = new HashSet<String>(Arrays.asList(
|
||||
PROCESS_STATUS_ANY, PROCESS_STATUS_ACTIVE, PROCESS_STATUS_COMPLETED
|
||||
PROCESS_STATUS_ANY, PROCESS_STATUS_ACTIVE, PROCESS_STATUS_COMPLETED, PROCESS_STATUS_DELETED
|
||||
));
|
||||
|
||||
protected static final Set<String> PROCESS_COLLECTION_EQUALS_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
|
||||
"processDefinitionId", "businessKey", "processDefinitionKey", "startUserId", "status"
|
||||
"processDefinitionId", "businessKey", "processDefinitionKey", "startUserId", "status", "includeVariables"
|
||||
));
|
||||
|
||||
protected static final Set<String> PROCESS_COLLECTION_GREATERTHAN_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
|
||||
@@ -289,6 +290,7 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
|
||||
Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
|
||||
Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
|
||||
Boolean includeVariables = propertyWalker.getProperty("includeVariables", WhereClauseParser.EQUALS, Boolean.class);
|
||||
|
||||
if (status != null && PROCESS_STATUS_LIST.contains(status) == false)
|
||||
{
|
||||
@@ -343,6 +345,15 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
else if (PROCESS_STATUS_COMPLETED.equals(status))
|
||||
{
|
||||
query.finished();
|
||||
query.notDeleted();
|
||||
}
|
||||
else if (PROCESS_STATUS_DELETED.equals(status))
|
||||
{
|
||||
query.deleted();
|
||||
}
|
||||
|
||||
if (includeVariables != null && includeVariables) {
|
||||
query.includeProcessVariables();
|
||||
}
|
||||
|
||||
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
|
||||
@@ -457,9 +468,31 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
int totalCount = (int) query.count();
|
||||
|
||||
List<ProcessInfo> page = new ArrayList<ProcessInfo>(processInstances.size());
|
||||
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
|
||||
for (HistoricProcessInstance processInstance: processInstances)
|
||||
{
|
||||
page.add(createProcessInfo(processInstance));
|
||||
ProcessInfo processInfo = createProcessInfo(processInstance);
|
||||
if (includeVariables != null && includeVariables)
|
||||
{
|
||||
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId()) == false)
|
||||
{
|
||||
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processInfo.getProcessDefinitionId());
|
||||
if (startFormData != null)
|
||||
{
|
||||
String formKey = startFormData.getFormKey();
|
||||
definitionTypeMap.put(processInfo.getProcessDefinitionId(), workflowFactory.getTaskFullTypeDefinition(formKey, true));
|
||||
}
|
||||
}
|
||||
|
||||
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId()))
|
||||
{
|
||||
// Convert raw variables to Variable objects
|
||||
List<Variable> resultingVariables = restVariableHelper.getVariables(
|
||||
processInstance.getProcessVariables(), definitionTypeMap.get(processInfo.getProcessDefinitionId()));
|
||||
processInfo.setProcessVariables(resultingVariables);
|
||||
}
|
||||
}
|
||||
page.add(processInfo);
|
||||
}
|
||||
|
||||
return CollectionWithPagingInfo.asPaged(paging, page, page.size() != totalCount, totalCount);
|
||||
@@ -732,6 +765,17 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
public void deleteProcess(String id)
|
||||
{
|
||||
validateIfUserAllowedToWorkWithProcess(id);
|
||||
|
||||
ProcessInstance processInstance = activitiProcessEngine.getRuntimeService()
|
||||
.createProcessInstanceQuery()
|
||||
.processInstanceId(id)
|
||||
.singleResult();
|
||||
|
||||
if (processInstance == null)
|
||||
{
|
||||
throw new EntityNotFoundException(id);
|
||||
}
|
||||
|
||||
activitiProcessEngine.getRuntimeService().deleteProcessInstance(id, "deleted through REST API call");
|
||||
}
|
||||
|
||||
@@ -1056,11 +1100,8 @@ public class ProcessesImpl extends WorkflowRestImpl implements Processes
|
||||
protected ProcessInfo createProcessInfo(HistoricProcessInstance processInstance)
|
||||
{
|
||||
ProcessInfo processInfo = new ProcessInfo(processInstance);
|
||||
ProcessDefinition definitionEntity = getCachedProcessDefinition(processInstance.getProcessDefinitionId());
|
||||
if (definitionEntity == null)
|
||||
{
|
||||
definitionEntity = activitiProcessEngine.getRepositoryService().getProcessDefinition(processInstance.getProcessDefinitionId());
|
||||
}
|
||||
ProcessDefinition definitionEntity = activitiProcessEngine.getRepositoryService()
|
||||
.getProcessDefinition(processInstance.getProcessDefinitionId());
|
||||
processInfo.setProcessDefinitionKey(getLocalProcessDefinitionKey(definitionEntity.getKey()));
|
||||
return processInfo;
|
||||
}
|
||||
|
@@ -80,18 +80,19 @@ public class RestVariableHelper
|
||||
* @param typeDefinition the typê definition for this task, used to extract types.
|
||||
* @return list of {@link TaskVariable}, representing the given raw variables
|
||||
*/
|
||||
public List<TaskVariable> getTaskVariables(Map<String, Object> localVariables, Map<String, Object> globalVariables, TypeDefinition typeDefinition)
|
||||
public List<TaskVariable> getTaskVariables(Map<String, Object> localVariables, Map<String, Object> globalVariables,
|
||||
TypeDefinition startFormTypeDefinition, TypeDefinition taskTypeDefinition)
|
||||
{
|
||||
List<TaskVariable> result = new ArrayList<TaskVariable>();
|
||||
TypeDefinitionContext context = new TypeDefinitionContext(typeDefinition);
|
||||
|
||||
if (localVariables != null)
|
||||
{
|
||||
TypeDefinitionContext context = new TypeDefinitionContext(taskTypeDefinition);
|
||||
addTaskVariables(result, localVariables, context, VariableScope.LOCAL);
|
||||
}
|
||||
|
||||
if (globalVariables != null)
|
||||
{
|
||||
TypeDefinitionContext context = new TypeDefinitionContext(startFormTypeDefinition);
|
||||
addTaskVariables(result, globalVariables, context, VariableScope.GLOBAL);
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ public class RestVariableHelper
|
||||
/**
|
||||
* Converts the raw variables to {@link TaskVariable}s and adds them to the given result-list.
|
||||
*/
|
||||
protected void addTaskVariables(List<TaskVariable> result, Map<String, Object> variables,
|
||||
public void addTaskVariables(List<TaskVariable> result, Map<String, Object> variables,
|
||||
TypeDefinitionContext context, VariableScope scope)
|
||||
{
|
||||
TaskVariable variable = null;
|
||||
|
@@ -28,11 +28,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.activiti.engine.ActivitiTaskAlreadyClaimedException;
|
||||
import org.activiti.engine.form.StartFormData;
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.history.HistoricTaskInstanceQuery;
|
||||
import org.activiti.engine.history.HistoricVariableInstance;
|
||||
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
||||
import org.activiti.engine.impl.task.TaskDefinition;
|
||||
import org.activiti.engine.task.DelegationState;
|
||||
import org.activiti.engine.task.IdentityLink;
|
||||
import org.activiti.engine.task.IdentityLinkType;
|
||||
@@ -88,7 +87,8 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
|
||||
private static final Set<String> TASK_COLLECTION_EQUALS_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
|
||||
"status", "assignee", "owner", "candidateUser", "candidateGroup", "name", "description", "priority", "processId",
|
||||
"processBusinessKey", "activityDefinitionId", "processDefinitionId", "processDefinitionName", "startedAt", "endedAt", "dueAt"
|
||||
"processBusinessKey", "activityDefinitionId", "processDefinitionId", "processDefinitionName", "startedAt", "endedAt", "dueAt",
|
||||
"includeTaskVariables", "includeProcessVariables"
|
||||
));
|
||||
|
||||
private static final Set<String> TASK_COLLECTION_MATCHES_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
|
||||
@@ -183,6 +183,8 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
Date dueAt = propertyWalker.getProperty("dueAt", WhereClauseParser.EQUALS, Date.class);
|
||||
Date dueAtGreaterThan = propertyWalker.getProperty("dueAt", WhereClauseParser.GREATERTHAN, Date.class);
|
||||
Date dueAtLessThan = propertyWalker.getProperty("dueAt", WhereClauseParser.LESSTHAN, Date.class);
|
||||
Boolean includeProcessVariables = propertyWalker.getProperty("includeProcessVariables", WhereClauseParser.EQUALS, Boolean.class);
|
||||
Boolean includeTaskVariables = propertyWalker.getProperty("includeTaskVariables", WhereClauseParser.EQUALS, Boolean.class);
|
||||
|
||||
List<SortColumn> sortList = parameters.getSorting();
|
||||
SortColumn sortColumn = null;
|
||||
@@ -254,6 +256,14 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
if (startedAtGreaterThan != null) query.taskCreatedAfter(startedAtGreaterThan);
|
||||
if (startedAtLessThan != null) query.taskCreatedBefore(startedAtLessThan);
|
||||
|
||||
if (includeProcessVariables != null && includeProcessVariables) {
|
||||
query.includeProcessVariables();
|
||||
}
|
||||
|
||||
if (includeTaskVariables != null && includeTaskVariables) {
|
||||
query.includeTaskLocalVariables();
|
||||
}
|
||||
|
||||
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
|
||||
if (variableProperties != null)
|
||||
{
|
||||
@@ -305,7 +315,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
}
|
||||
|
||||
// Add involvment filtering if user is not admin
|
||||
if(!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
|
||||
if(processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
|
||||
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
|
||||
@@ -315,10 +325,16 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
totalCount = (int) query.count();
|
||||
|
||||
page = new ArrayList<Task>(tasks.size());
|
||||
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
|
||||
for (org.activiti.engine.task.Task taskInstance: tasks)
|
||||
{
|
||||
Task task = new Task(taskInstance);
|
||||
task.setFormResourceKey(getFormResourceKey(taskInstance));
|
||||
if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables))
|
||||
{
|
||||
addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(),
|
||||
taskInstance.getTaskLocalVariables(), definitionTypeMap);
|
||||
}
|
||||
page.add(task);
|
||||
}
|
||||
}
|
||||
@@ -368,6 +384,14 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
if (endedAtGreaterThan != null) query.taskCompletedAfter(endedAtGreaterThan);
|
||||
if (endedAtLessThan != null) query.taskCompletedBefore(endedAtLessThan);
|
||||
|
||||
if (includeProcessVariables != null && includeProcessVariables) {
|
||||
query.includeProcessVariables();
|
||||
}
|
||||
|
||||
if (includeTaskVariables != null && includeTaskVariables) {
|
||||
query.includeTaskLocalVariables();
|
||||
}
|
||||
|
||||
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
|
||||
if (variableProperties != null)
|
||||
{
|
||||
@@ -420,7 +444,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
}
|
||||
|
||||
// Add involvment filtering if user is not admin
|
||||
if(!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser()))
|
||||
if(processInstanceId == null && !authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser()))
|
||||
{
|
||||
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
@@ -431,9 +455,15 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
totalCount = (int) query.count();
|
||||
|
||||
page = new ArrayList<Task>(tasks.size());
|
||||
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
|
||||
for (HistoricTaskInstance taskInstance: tasks)
|
||||
{
|
||||
Task task = new Task(taskInstance);
|
||||
if ((includeProcessVariables != null && includeProcessVariables) || (includeTaskVariables != null && includeTaskVariables))
|
||||
{
|
||||
addVariables(task, includeProcessVariables, includeTaskVariables, taskInstance.getProcessVariables(),
|
||||
taskInstance.getTaskLocalVariables(), definitionTypeMap);
|
||||
}
|
||||
page.add(task);
|
||||
}
|
||||
}
|
||||
@@ -445,6 +475,39 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
return CollectionWithPagingInfo.asPaged(paging, page, page.size() != totalCount, totalCount);
|
||||
}
|
||||
|
||||
protected void addVariables(Task task, Boolean includeProcessVariables, Boolean includeTaskVariables,
|
||||
Map<String, Object> processVariables, Map<String, Object> taskVariables, Map<String, TypeDefinition> definitionTypeMap)
|
||||
{
|
||||
TypeDefinition startFormTypeDefinition = null;
|
||||
if (includeProcessVariables != null && includeProcessVariables)
|
||||
{
|
||||
if (definitionTypeMap.containsKey(task.getProcessDefinitionId()) == false)
|
||||
{
|
||||
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(task.getProcessDefinitionId());
|
||||
if (startFormData != null)
|
||||
{
|
||||
String formKey = startFormData.getFormKey();
|
||||
definitionTypeMap.put(task.getProcessDefinitionId(), workflowFactory.getTaskFullTypeDefinition(formKey, true));
|
||||
}
|
||||
}
|
||||
|
||||
if (definitionTypeMap.containsKey(task.getProcessDefinitionId()))
|
||||
{
|
||||
startFormTypeDefinition = definitionTypeMap.get(task.getProcessDefinitionId());
|
||||
}
|
||||
}
|
||||
|
||||
TypeDefinition taskTypeDefinition = null;
|
||||
if (includeTaskVariables != null && includeTaskVariables)
|
||||
{
|
||||
taskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(task.getFormResourceKey(), false);
|
||||
}
|
||||
|
||||
List<TaskVariable> variables = restVariableHelper.getTaskVariables(taskVariables, processVariables,
|
||||
startFormTypeDefinition, taskTypeDefinition);
|
||||
task.setVariables(variables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Task> getTasks(String processId, Parameters parameters)
|
||||
{
|
||||
@@ -501,11 +564,6 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
|
||||
}
|
||||
|
||||
// Add involvment filtering if user is not admin
|
||||
if(!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
|
||||
query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
|
||||
setSorting(query, sortColumn);
|
||||
|
||||
List<HistoricTaskInstance> tasks = query.listPage(paging.getSkipCount(), paging.getMaxItems());
|
||||
@@ -642,8 +700,29 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
else
|
||||
{
|
||||
// Perform actions associated to state transition
|
||||
if (taskAction != null) {
|
||||
switch (taskAction) {
|
||||
if (taskAction != null)
|
||||
{
|
||||
// look for variables submitted with task action
|
||||
Map<String, Object> globalVariables = new HashMap<String, Object>();
|
||||
Map<String, Object> localVariables = new HashMap<String, Object>();
|
||||
if (selectedProperties.contains("variables") && task.getVariables() != null && task.getVariables().size() > 0)
|
||||
{
|
||||
for (TaskVariable taskVariable : task.getVariables())
|
||||
{
|
||||
taskVariable = convertToTypedVariable(taskVariable, taskInstance);
|
||||
if (taskVariable.getVariableScope() == VariableScope.GLOBAL)
|
||||
{
|
||||
globalVariables.put(taskVariable.getName(), taskVariable.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
localVariables.put(taskVariable.getName(), taskVariable.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (taskAction)
|
||||
{
|
||||
case CLAIMED:
|
||||
try
|
||||
{
|
||||
@@ -655,7 +734,19 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
}
|
||||
break;
|
||||
case COMPLETED:
|
||||
activitiProcessEngine.getTaskService().complete(taskId);
|
||||
if (localVariables.size() > 0)
|
||||
{
|
||||
activitiProcessEngine.getTaskService().setVariablesLocal(taskId, localVariables);
|
||||
}
|
||||
if (globalVariables.size() > 0)
|
||||
{
|
||||
activitiProcessEngine.getTaskService().complete(taskId, globalVariables);
|
||||
}
|
||||
else
|
||||
{
|
||||
activitiProcessEngine.getTaskService().complete(taskId);
|
||||
}
|
||||
|
||||
break;
|
||||
case DELEGATED:
|
||||
if(selectedProperties.contains("assignee") && task.getAssignee() != null)
|
||||
@@ -673,7 +764,18 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
}
|
||||
break;
|
||||
case RESOLVED:
|
||||
activitiProcessEngine.getTaskService().resolveTask(taskId);
|
||||
if (localVariables.size() > 0)
|
||||
{
|
||||
activitiProcessEngine.getTaskService().setVariablesLocal(taskId, localVariables);
|
||||
}
|
||||
if (globalVariables.size() > 0)
|
||||
{
|
||||
activitiProcessEngine.getTaskService().resolveTask(taskId, globalVariables);
|
||||
}
|
||||
else
|
||||
{
|
||||
activitiProcessEngine.getTaskService().resolveTask(taskId);
|
||||
}
|
||||
break;
|
||||
|
||||
case UNCLAIMED:
|
||||
@@ -771,7 +873,20 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
}
|
||||
|
||||
// Convert raw variables to TaskVariables
|
||||
List<TaskVariable> page = restVariableHelper.getTaskVariables(taskvariables, processVariables, getWorkflowFactory().getTaskFullTypeDefinition(formKey, false));
|
||||
TypeDefinition taskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, false);
|
||||
TypeDefinition startFormTypeDefinition = null;
|
||||
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(taskInstance.getProcessDefinitionId());
|
||||
if (startFormData != null)
|
||||
{
|
||||
startFormTypeDefinition = workflowFactory.getTaskFullTypeDefinition(startFormData.getFormKey(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// fall back
|
||||
startFormTypeDefinition = taskTypeDefinition;
|
||||
}
|
||||
List<TaskVariable> page = restVariableHelper.getTaskVariables(taskvariables, processVariables,
|
||||
startFormTypeDefinition, taskTypeDefinition);
|
||||
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
|
||||
}
|
||||
|
||||
@@ -779,7 +894,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
public TaskVariable updateTaskVariable(String taskId, TaskVariable taskVariable)
|
||||
{
|
||||
org.activiti.engine.task.Task taskInstance = getValidTask(taskId);
|
||||
return updateVariableInTask(taskId, taskInstance, taskVariable);
|
||||
return updateVariableInTask(taskInstance, taskVariable);
|
||||
}
|
||||
|
||||
public List<TaskVariable> updateTaskVariables(String taskId, List<TaskVariable> variables)
|
||||
@@ -790,20 +905,44 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
{
|
||||
for (TaskVariable variable : variables)
|
||||
{
|
||||
updatedVariables.add(updateVariableInTask(taskId, taskInstance, variable));
|
||||
updatedVariables.add(updateVariableInTask(taskInstance, variable));
|
||||
}
|
||||
}
|
||||
return updatedVariables;
|
||||
}
|
||||
|
||||
protected TaskVariable updateVariableInTask(String taskId, org.activiti.engine.task.Task taskInstance, TaskVariable taskVariable)
|
||||
protected TaskVariable updateVariableInTask(org.activiti.engine.task.Task taskInstance, TaskVariable taskVariable)
|
||||
{
|
||||
taskVariable = convertToTypedVariable(taskVariable, taskInstance);
|
||||
|
||||
if (VariableScope.LOCAL.equals(taskVariable.getVariableScope()))
|
||||
{
|
||||
activitiProcessEngine.getTaskService().setVariableLocal(taskInstance.getId(), taskVariable.getName(), taskVariable.getValue());
|
||||
}
|
||||
else if(VariableScope.GLOBAL.equals(taskVariable.getVariableScope()))
|
||||
{
|
||||
if(taskInstance.getExecutionId() != null)
|
||||
{
|
||||
activitiProcessEngine.getRuntimeService().setVariable(taskInstance.getExecutionId(), taskVariable.getName(), taskVariable.getValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException("Cannot set global variables on a task that is not part of a process.");
|
||||
}
|
||||
}
|
||||
|
||||
return taskVariable;
|
||||
}
|
||||
|
||||
protected TaskVariable convertToTypedVariable(TaskVariable taskVariable, org.activiti.engine.task.Task taskInstance)
|
||||
{
|
||||
if (taskVariable.getName() == null)
|
||||
{
|
||||
throw new InvalidArgumentException("Variable name is required.");
|
||||
}
|
||||
|
||||
if (taskVariable.getVariableScope() == null || taskVariable.getVariableScope() == VariableScope.ANY)
|
||||
if (taskVariable.getVariableScope() == null || (taskVariable.getVariableScope() != VariableScope.GLOBAL &&
|
||||
taskVariable.getVariableScope() != VariableScope.LOCAL))
|
||||
{
|
||||
throw new InvalidArgumentException("Variable scope is required and can only be 'local' or 'global'.");
|
||||
}
|
||||
@@ -872,26 +1011,12 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
{
|
||||
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, taskVariable.getValue());
|
||||
}
|
||||
taskVariable.setValue(actualValue);
|
||||
|
||||
if (VariableScope.LOCAL.equals(taskVariable.getVariableScope()))
|
||||
{
|
||||
activitiProcessEngine.getTaskService().setVariableLocal(taskId, taskVariable.getName(), actualValue);
|
||||
}
|
||||
else if(VariableScope.GLOBAL.equals(taskVariable.getVariableScope()))
|
||||
{
|
||||
if(taskInstance.getExecutionId() != null)
|
||||
{
|
||||
activitiProcessEngine.getRuntimeService().setVariable(taskInstance.getExecutionId(), taskVariable.getName(), actualValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidArgumentException("Cannot set global variables on a task that is not part of a process.");
|
||||
}
|
||||
}
|
||||
taskVariable.setValue(actualValue);
|
||||
|
||||
// Set type so it's returned in case it was left empty
|
||||
taskVariable.setType(dataTypeDefinition.getName().toPrefixString(namespaceService));
|
||||
|
||||
return taskVariable;
|
||||
}
|
||||
|
||||
@@ -987,22 +1112,7 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
|
||||
{
|
||||
if (task.getProcessDefinitionId() != null)
|
||||
{
|
||||
ProcessDefinitionEntity definitionEntity = getCachedProcessDefinition(task.getProcessDefinitionId());
|
||||
|
||||
String formKey = null;
|
||||
if (definitionEntity != null)
|
||||
{
|
||||
TaskDefinition taskDefinition = definitionEntity.getTaskDefinitions().get(task.getTaskDefinitionKey());
|
||||
if (taskDefinition != null)
|
||||
{
|
||||
formKey = taskDefinition.getTaskFormHandler().getFormKey().getExpressionText();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
formKey = activitiProcessEngine.getFormService().getTaskFormKey(task.getProcessDefinitionId(), task.getTaskDefinitionKey());
|
||||
}
|
||||
|
||||
String formKey = activitiProcessEngine.getFormService().getTaskFormKey(task.getProcessDefinitionId(), task.getTaskDefinitionKey());
|
||||
return formKey;
|
||||
}
|
||||
else
|
||||
|
@@ -17,13 +17,6 @@ import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.history.HistoricTaskInstanceQuery;
|
||||
import org.activiti.engine.history.HistoricVariableInstance;
|
||||
import org.activiti.engine.impl.ProcessEngineImpl;
|
||||
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
|
||||
import org.activiti.engine.impl.context.Context;
|
||||
import org.activiti.engine.impl.interceptor.Command;
|
||||
import org.activiti.engine.impl.interceptor.CommandContext;
|
||||
import org.activiti.engine.impl.persistence.deploy.DeploymentCache;
|
||||
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -326,32 +319,6 @@ public class WorkflowRestImpl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the process definition from the cache if available
|
||||
*
|
||||
* @param processDefinitionId the unique id identifier of the process definition
|
||||
*/
|
||||
public ProcessDefinitionEntity getCachedProcessDefinition(final String processDefinitionId)
|
||||
{
|
||||
ProcessEngineConfigurationImpl processConfig = (ProcessEngineConfigurationImpl) ((ProcessEngineImpl) activitiProcessEngine).getProcessEngineConfiguration();
|
||||
ProcessDefinitionEntity definitionEntity = processConfig.getCommandExecutorTxRequired().execute(new Command<ProcessDefinitionEntity>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public ProcessDefinitionEntity execute(CommandContext commandContext)
|
||||
{
|
||||
DeploymentCache<ProcessDefinitionEntity> cache = Context
|
||||
.getProcessEngineConfiguration()
|
||||
.getDeploymentManager()
|
||||
.getProcessDefinitionCache();
|
||||
|
||||
return cache.get(processDefinitionId);
|
||||
}
|
||||
|
||||
});
|
||||
return definitionEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first parameter value, converted to the requested type.
|
||||
* @param parameters used to extract parameter value from
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.rest.workflow.api.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -42,6 +43,7 @@ public class ProcessInfo
|
||||
boolean completed;
|
||||
|
||||
Map<String, Object> variables;
|
||||
List<Variable> processVariables;
|
||||
Set<String> items;
|
||||
|
||||
public ProcessInfo()
|
||||
@@ -204,6 +206,16 @@ public class ProcessInfo
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public List<Variable> getProcessVariables()
|
||||
{
|
||||
return processVariables;
|
||||
}
|
||||
|
||||
public void setProcessVariables(List<Variable> processVariables)
|
||||
{
|
||||
this.processVariables = processVariables;
|
||||
}
|
||||
|
||||
public Set<String> getItems()
|
||||
{
|
||||
return items;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.rest.workflow.api.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.task.DelegationState;
|
||||
@@ -40,6 +41,7 @@ public class Task
|
||||
String assignee;
|
||||
String formResourceKey;
|
||||
String state;
|
||||
List<TaskVariable> variables;
|
||||
|
||||
public Task()
|
||||
{
|
||||
@@ -255,4 +257,14 @@ public class Task
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public List<TaskVariable> getVariables()
|
||||
{
|
||||
return variables;
|
||||
}
|
||||
|
||||
public void setVariables(List<TaskVariable> variables)
|
||||
{
|
||||
this.variables = variables;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user