use of org.alfresco.service.cmr.workflow.WorkflowService in project alfresco-repository by Alfresco.
the class JscriptWorkflowInstance method getPaths.
/**
* Get all paths for the specified workflow instance
*/
public Scriptable getPaths() {
WorkflowService workflowService = serviceRegistry.getWorkflowService();
List<WorkflowPath> cmrPaths = workflowService.getWorkflowPaths(this.id);
ArrayList<Serializable> paths = new ArrayList<Serializable>();
for (WorkflowPath cmrPath : cmrPaths) {
paths.add(new JscriptWorkflowPath(cmrPath, this.serviceRegistry, this.scope));
}
Scriptable pathsScriptable = (Scriptable) new ValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, paths);
return pathsScriptable;
}
use of org.alfresco.service.cmr.workflow.WorkflowService in project alfresco-repository by Alfresco.
the class JscriptWorkflowDefinition method startWorkflow.
/**
* Start workflow instance from workflow definition
*
* @param workflowPackage workflow package node to 'attach' to the new workflow
* instance
* @param properties Associative array of properties used to populate the
* start task properties
* @return the initial workflow path
*/
@SuppressWarnings("unchecked")
public JscriptWorkflowPath startWorkflow(ScriptNode workflowPackage, Object properties) {
WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
// if properties object is a scriptable object, then extract property name/value pairs
// into property Map<QName, Serializable>, otherwise leave property map as null
Map<QName, Serializable> workflowParameters = null;
if (properties instanceof ScriptableObject) {
ScriptableObject scriptableProps = (ScriptableObject) properties;
workflowParameters = new HashMap<QName, Serializable>(scriptableProps.getIds().length);
extractScriptablePropertiesToMap(scriptableProps, workflowParameters);
}
// attach given workflow package node if it is not null
if (workflowPackage != null) {
if (workflowParameters == null) {
workflowParameters = new HashMap<QName, Serializable>(1);
}
workflowParameters.put(WorkflowModel.ASSOC_PACKAGE, getValueConverter().convertValueForRepo(workflowPackage));
}
// provide a default context, if one is not specified
Serializable context = workflowParameters.get(WorkflowModel.PROP_CONTEXT);
if (context == null) {
workflowParameters.put(WorkflowModel.PROP_CONTEXT, workflowPackage.getNodeRef());
}
WorkflowPath cmrWorkflowPath = workflowService.startWorkflow(this.id, workflowParameters);
return new JscriptWorkflowPath(cmrWorkflowPath, this.serviceRegistry, this.scope);
}
use of org.alfresco.service.cmr.workflow.WorkflowService in project alfresco-repository by Alfresco.
the class WorkflowFormProcessorTest method makeWorkflowService.
@SuppressWarnings("unchecked")
private WorkflowService makeWorkflowService() {
WorkflowService service = mock(WorkflowService.class);
when(service.getDefinitionByName(WF_DEF_NAME)).thenReturn(definition);
String instanceId = "foo$instanceId";
newInstance = new WorkflowInstance(instanceId, definition, null, null, null, null, true, null, null);
WorkflowTask startTask = new WorkflowTask("foo$taskId", null, null, null, null, null, null, null);
String pathId = "foo$pathId";
final WorkflowPath path = new WorkflowPath(pathId, newInstance, null, true);
when(service.startWorkflow(eq(definition.getId()), anyMap())).thenAnswer(new Answer<WorkflowPath>() {
public WorkflowPath answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
actualProperties = (Map<QName, Serializable>) arguments[1];
return path;
}
});
when(service.getTasksForWorkflowPath(path.getId())).thenReturn(Collections.singletonList(startTask));
when(service.createPackage(null)).thenReturn(PCKG_NODE);
return service;
}
use of org.alfresco.service.cmr.workflow.WorkflowService in project alfresco-repository by Alfresco.
the class TaskFormProcessorTest method makeWorkflowService.
@SuppressWarnings("unchecked")
private WorkflowService makeWorkflowService() {
WorkflowService service = mock(WorkflowService.class);
when(service.getTaskById(any())).thenAnswer(new Answer<WorkflowTask>() {
public WorkflowTask answer(InvocationOnMock invocation) throws Throwable {
String id = (String) invocation.getArguments()[0];
if (TASK_ID.equals(id))
return task;
else {
// if TaskId is not found then Activity returns null, does not throws WorkflowException
return null;
}
}
});
this.newTask = new WorkflowTask(TASK_ID, null, null, null, null, null, null, null);
when(service.updateTask(any(), anyMap(), anyMap(), anyMap())).thenAnswer(new Answer<WorkflowTask>() {
public WorkflowTask answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
Map<QName, Serializable> props = (Map<QName, Serializable>) args[1];
actualProperties = new HashMap<QName, Serializable>(props);
Map<QName, List<NodeRef>> added = (Map<QName, List<NodeRef>>) args[2];
actualAdded = new HashMap<QName, List<NodeRef>>(added);
Map<QName, List<NodeRef>> removed = (Map<QName, List<NodeRef>>) args[3];
actualRemoved = new HashMap<QName, List<NodeRef>>(removed);
return newTask;
}
});
when(service.endTask(eq(TASK_ID), any())).thenReturn(newTask);
when(service.isTaskEditable((WorkflowTask) any(), any())).thenReturn(true);
return service;
}
Aggregations