Search in sources :

Example 21 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class JscriptWorkflowDefinition method getActiveInstances.

/**
 * Get active workflow instances of this workflow definition
 *
 * @return the active workflow instances spawned from this workflow definition
 */
public synchronized Scriptable getActiveInstances() {
    WorkflowService workflowService = this.serviceRegistry.getWorkflowService();
    List<WorkflowInstance> cmrWorkflowInstances = workflowService.getActiveWorkflows(this.id);
    ArrayList<Serializable> activeInstances = new ArrayList<Serializable>();
    for (WorkflowInstance cmrWorkflowInstance : cmrWorkflowInstances) {
        activeInstances.add(new JscriptWorkflowInstance(cmrWorkflowInstance, this.serviceRegistry, this.scope));
    }
    Scriptable activeInstancesScriptable = (Scriptable) getValueConverter().convertValueForScript(this.serviceRegistry, this.scope, null, activeInstances);
    return activeInstancesScriptable;
}
Also used : Serializable(java.io.Serializable) WorkflowService(org.alfresco.service.cmr.workflow.WorkflowService) ArrayList(java.util.ArrayList) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Scriptable(org.mozilla.javascript.Scriptable)

Example 22 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class WorkflowFormProcessorTest method processPersist.

private void processPersist(String dataKey, String value) {
    FormData data = new FormData();
    data.addFieldData(dataKey, value);
    WorkflowInstance persistedItem = (WorkflowInstance) processor.persist(item, data);
    assertEquals(newInstance, persistedItem);
}
Also used : FormData(org.alfresco.repo.forms.FormData) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 23 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class AbstractWorkflowServiceIntegrationTest method testAssociateWorkflowPackage.

public void testAssociateWorkflowPackage() {
    // create workflow package
    authenticationComponent.setSystemUserAsCurrentUser();
    NodeRef rootNode = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));
    ChildAssociationRef childAssoc = nodeService.createNode(rootNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test"), ContentModel.TYPE_CONTENT, null);
    NodeRef contentNode = childAssoc.getChildRef();
    NodeRef pckgNode = workflowService.createPackage(null);
    assertNotNull(pckgNode);
    assertTrue(nodeService.hasAspect(pckgNode, WorkflowModel.ASPECT_WORKFLOW_PACKAGE));
    List<WorkflowInstance> existingInstances = workflowService.getWorkflowsForContent(contentNode, true);
    assertNotNull(existingInstances);
    assertEquals(0, existingInstances.size());
    existingInstances = workflowService.getWorkflowsForContent(contentNode, false);
    assertNotNull(existingInstances);
    assertEquals(0, existingInstances.size());
    // Add content to the package
    nodeService.addChild(pckgNode, contentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "test123"));
    // start workflow
    WorkflowDefinition workflowDef = deployDefinition(getAdhocDefinitionPath());
    Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
    parameters.put(WorkflowModel.ASSOC_PACKAGE, pckgNode);
    parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    WorkflowPath path = workflowService.startWorkflow(workflowDef.getId(), parameters);
    assertNotNull(path);
    assertTrue(path.isActive());
    assertNotNull(path.getNode());
    assertNotNull(path.getInstance());
    assertEquals(workflowDef.getId(), path.getInstance().getDefinition().getId());
    String workflowDefId = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_ID);
    assertEquals(workflowDefId, workflowDef.getId());
    String workflowDefName = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_DEFINITION_NAME);
    assertEquals(workflowDefName, workflowDef.getName());
    String workflowInstanceId = (String) nodeService.getProperty(pckgNode, WorkflowModel.PROP_WORKFLOW_INSTANCE_ID);
    assertEquals(workflowInstanceId, path.getInstance().getId());
    // get workflows for content
    List<WorkflowInstance> instances = workflowService.getWorkflowsForContent(contentNode, true);
    assertNotNull(instances);
    assertEquals(1, instances.size());
    WorkflowInstance newInstance = instances.get(0);
    assertNotNull(newInstance);
    assertEquals(path.getInstance().getId(), newInstance.getId());
    List<WorkflowInstance> completedInstances = workflowService.getWorkflowsForContent(contentNode, false);
    assertNotNull(completedInstances);
    assertEquals(0, completedInstances.size());
// TODO End the workfow instance and test the completed workflow is returned
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowPath(org.alfresco.service.cmr.workflow.WorkflowPath) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance)

Example 24 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class ActivitiWorkflowServiceIntegrationTest method testBuildWorkflowWithNoUserTasks.

@Test
public void testBuildWorkflowWithNoUserTasks() throws Exception {
    // Deploy a definition containing only a service task
    WorkflowDefinition testDefinition = deployDefinition("activiti/testWorkflowNoUserTasks.bpmn20.xml");
    WorkflowBuilder builder = new WorkflowBuilder(testDefinition, workflowService, nodeService, null);
    // Build a workflow
    WorkflowInstance builtInstance = builder.build();
    assertNotNull(builtInstance);
    // Check that there is no active workflow for the deployed definition(it should have finished already due to absence of user tasks)
    List<WorkflowInstance> activeInstances = workflowService.getActiveWorkflows(testDefinition.getId());
    assertNotNull(activeInstances);
    assertEquals(0, activeInstances.size());
    // Check that there's a historic record of our 'only service task' workflow being run.
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().finishedAfter(builtInstance.getStartDate()).singleResult();
    assertNotNull(historicProcessInstance);
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) WorkflowBuilder(org.alfresco.repo.workflow.WorkflowBuilder) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) AbstractWorkflowServiceIntegrationTest(org.alfresco.repo.workflow.AbstractWorkflowServiceIntegrationTest) Test(org.junit.Test)

Example 25 with WorkflowInstance

use of org.alfresco.service.cmr.workflow.WorkflowInstance in project alfresco-repository by Alfresco.

the class ActivitiWorkflowComponentTest method testCancelWorkflow.

@Test
public void testCancelWorkflow() throws Exception {
    WorkflowDefinition def = deployTestAdhocDefinition();
    ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()));
    // Validate if a workflow exists
    List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(processInstance.getId(), BPMEngineRegistry.getLocalId(instances.get(0).getId()));
    // Call cancel method on component
    WorkflowInstance cancelledWorkflow = workflowEngine.cancelWorkflow(instances.get(0).getId());
    assertFalse(cancelledWorkflow.isActive());
    instances = workflowEngine.getActiveWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    // Histrotic process instance shouldn't be present
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
    if (workflowEngine.activitiUtil.isRetentionHistoricProcessInstanceEnabled() == false) {
        assertNull(historicProcessInstance);
    }
}
Also used : HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) WorkflowDefinition(org.alfresco.service.cmr.workflow.WorkflowDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) Test(org.junit.Test)

Aggregations

WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)56 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)26 HashMap (java.util.HashMap)22 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)19 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)16 QName (org.alfresco.service.namespace.QName)16 Serializable (java.io.Serializable)15 Date (java.util.Date)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)13 Test (org.junit.Test)13 Map (java.util.Map)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 ArrayList (java.util.ArrayList)9 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)7 WorkflowNode (org.alfresco.service.cmr.workflow.WorkflowNode)5 Execution (org.activiti.engine.runtime.Execution)4 List (java.util.List)3 ActivitiException (org.activiti.engine.ActivitiException)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3