Search in sources :

Example 11 with WorkflowService

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;
}
Also used : Serializable(java.io.Serializable) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) ArrayList(java.util.ArrayList) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) Scriptable(org.mozilla.javascript.Scriptable) ValueConverter(org.alfresco.repo.jscript.ValueConverter)

Example 12 with WorkflowService

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);
}
Also used : Serializable(java.io.Serializable) ScriptableObject(org.mozilla.javascript.ScriptableObject) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) QName(org.alfresco.service.namespace.QName) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath)

Example 13 with WorkflowService

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;
}
Also used : WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with WorkflowService

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) QName(org.alfresco.service.namespace.QName) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WorkflowService (org.alfresco.service.cmr.workflow.WorkflowService)14 Serializable (java.io.Serializable)7 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)5 ArrayList (java.util.ArrayList)4 Scriptable (org.mozilla.javascript.Scriptable)4 HashMap (java.util.HashMap)3 ValueConverter (org.alfresco.repo.jscript.ValueConverter)3 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)3 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)3 QName (org.alfresco.service.namespace.QName)3 Map (java.util.Map)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 PersonService (org.alfresco.service.cmr.security.PersonService)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ScriptableObject (org.mozilla.javascript.ScriptableObject)2 OutputStream (java.io.OutputStream)1 List (java.util.List)1 Properties (java.util.Properties)1 ResourceBundle (java.util.ResourceBundle)1