org.alfresco.service.cmr.workflow.WorkflowInstance Java Examples

The following examples show how to use org.alfresco.service.cmr.workflow.WorkflowInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public WorkflowPath buildCompletedPath(String executionId, String processInstanceId)
{
    WorkflowInstance wfInstance = null;
    ProcessInstance processInstance = activitiUtil.getProcessInstance(processInstanceId);
    if(processInstance != null)
    {
        wfInstance = convert(processInstance);
    } 
    else
    {
        HistoricProcessInstance historicProcessInstance = activitiUtil.getHistoricProcessInstance(processInstanceId);
        if(historicProcessInstance!= null)
            wfInstance = convert(historicProcessInstance);
    }
    if(wfInstance == null)
    {
    	// When workflow is cancelled or deleted, WorkflowPath should not be returned
    	return null;
    }
    WorkflowNode node = null;
    return factory.createPath(executionId, wfInstance, node, false);
}
 
Example #2
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<WorkflowInstance> getWorkflows(WorkflowInstanceQuery workflowInstanceQuery, int maxItems, int skipCount)
{
    LinkedList<WorkflowInstance> results = new LinkedList<WorkflowInstance>();
    if (Boolean.FALSE.equals(workflowInstanceQuery.getActive()) == false)
    {
        //Add active. 
        results.addAll(getWorkflowsInternal(workflowInstanceQuery, true, maxItems, skipCount));
    }
    if (Boolean.TRUE.equals(workflowInstanceQuery.getActive()) == false)
    {
        //Add complete
        results.addAll(getWorkflowsInternal(workflowInstanceQuery, false, maxItems, skipCount));
    }
    
    return results;
}
 
Example #3
Source File: AbstractWorkflowRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkWorkflowInstance(WorkflowInstance wfInstance, JSONObject instance) throws Exception
{
    assertNotNull(instance);
    assertEquals(wfInstance.getId(), instance.getString("id"));
    assertTrue(instance.has("url"));
    assertEquals(wfInstance.getDefinition().getName(), instance.getString("name"));
    assertEquals(wfInstance.getDefinition().getTitle(), instance.getString("title"));
    assertEquals(wfInstance.getDefinition().getDescription(), instance.getString("description"));
    assertEquals(wfInstance.isActive(), instance.getBoolean("isActive"));
    assertTrue(instance.has("startDate"));

    JSONObject initiator = instance.getJSONObject("initiator");

    assertEquals(USER1, initiator.getString("userName"));
    assertEquals(personManager.getFirstName(USER1), initiator.getString("firstName"));
    assertEquals(personManager.getLastName(USER1), initiator.getString("lastName"));
}
 
Example #4
Source File: ActivitiWorkflowServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public WorkflowPath convert(Execution execution, ProcessInstance instance)
{
    if(execution == null)
        return null;
    
    boolean isActive = !execution.isEnded();
    
    // Convert workflow and collect variables
    Map<String, Object> workflowInstanceVariables = new HashMap<String, Object>();
    WorkflowInstance wfInstance = convertAndSetVariables(instance, workflowInstanceVariables);
    
    WorkflowNode node = null;
    // Get active node on execution
    List<String> nodeIds = runtimeService.getActiveActivityIds(execution.getId());

    if (nodeIds != null && nodeIds.size() >= 1)
    {
        ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(instance.getProcessDefinitionId());
        PvmActivity activity = procDef.findActivity(nodeIds.get(0));
        node = convert(activity);
    }

    return factory.createPath(execution.getId(), wfInstance, node, isActive);
}
 
Example #6
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* {@inheritDoc}
*/
@Override
public List<WorkflowInstance> getCompletedWorkflows()
{
    try
    {
        return getWorkflows(new WorkflowInstanceQuery(false));
    }
    catch(ActivitiException ae) 
    {
        String message = messageService.getMessage(ERR_GET_COMPLETED_WORKFLOW_INSTS, "");
        if(logger.isDebugEnabled())
        {
        	logger.debug(message, ae);
        }
        throw new WorkflowException(message, ae);
    }
}
 
Example #7
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* {@inheritDoc}
*/
public List<WorkflowInstance> getActiveWorkflows()
{
    try
    {
        return getWorkflows(new WorkflowInstanceQuery(true));
    }
    catch(ActivitiException ae) 
    {
        String message = messageService.getMessage(ERR_GET_ACTIVE_WORKFLOW_INSTS, "");
        if(logger.isDebugEnabled())
        {
        	logger.debug(message, ae);
        }
        throw new WorkflowException(message, ae);
    }
}
 
Example #8
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public WorkflowInstance convertToInstanceAndSetVariables(HistoricProcessInstance historicProcessInstance, Map<String, Object> collectedVariables)
{
    String processInstanceId = historicProcessInstance.getId();
    String id = processInstanceId;
    ProcessDefinition procDef = activitiUtil.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
    WorkflowDefinition definition = convert(procDef);
    
    // Set process variables based on historic detail query
    Map<String, Object> variables = propertyConverter.getHistoricProcessVariables(processInstanceId);
    
    Date startDate = historicProcessInstance.getStartTime();
    Date endDate = historicProcessInstance.getEndTime();

    // Copy all variables to map, if not null
    if(collectedVariables != null)
    {
    	collectedVariables.putAll(variables);
    }
    boolean isActive = endDate == null;
    return factory.createInstance(id, definition, variables, isActive, startDate, endDate);
}
 
Example #9
Source File: WorkflowServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<WorkflowInstance> getWorkflowsForContent(NodeRef packageItem, boolean active)
{
    List<String> workflowIds = workflowPackageComponent.getWorkflowIdsForContent(packageItem);
    List<WorkflowInstance> workflowInstances = new ArrayList<WorkflowInstance>(workflowIds.size());
    for (String workflowId : workflowIds)
    {
        try
        {
            String engineId = BPMEngineRegistry.getEngineId(workflowId);
            WorkflowComponent component = getWorkflowComponent(engineId);
            WorkflowInstance instance = component.getWorkflowById(workflowId);
            if (instance != null && instance.isActive() == active)
            {
                workflowInstances.add(instance);
            }
        }
        catch (WorkflowException componentForEngineNotRegistered)
        {
            String message = componentForEngineNotRegistered.getMessage();
            logger.debug(message + ". Ignored workflow on " + packageItem);
        }
    }
    return workflowInstances;
}
 
Example #10
Source File: JscriptWorkflowDefinition.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get active workflow instances this node belongs to
 * 
 * @return the active workflow instances this node belongs to
 */
public Scriptable getActiveWorkflows()
{
    if (this.activeWorkflows == null)
    {
        WorkflowService workflowService = this.services.getWorkflowService();
        
        List<WorkflowInstance> workflowInstances = workflowService.getWorkflowsForContent(this.nodeRef, true);
        Object[] jsWorkflowInstances = new Object[workflowInstances.size()];
        int index = 0;
        for (WorkflowInstance workflowInstance : workflowInstances)
        {
            jsWorkflowInstances[index++] = new JscriptWorkflowInstance(workflowInstance, this.services, this.scope);
        }
        this.activeWorkflows = Context.getCurrentContext().newArray(this.scope, jsWorkflowInstances);		
    }

    return this.activeWorkflows;
}
 
Example #12
Source File: WorkflowServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
 */
public WorkflowInstance getWorkflowById(String workflowId)
{
    String engineId = BPMEngineRegistry.getEngineId(workflowId);
    WorkflowComponent component = getWorkflowComponent(engineId);
    return component.getWorkflowById(workflowId);
}
 
Example #13
Source File: WorkflowServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WorkflowPath startWorkflow(String workflowDefinitionId, Map<QName, Serializable> parameters)
{
    String engineId = BPMEngineRegistry.getEngineId(workflowDefinitionId);
    WorkflowComponent component = getWorkflowComponent(engineId);
    WorkflowPath path = component.startWorkflow(workflowDefinitionId, parameters);
    if(path != null && parameters!=null && parameters.containsKey(WorkflowModel.ASSOC_PACKAGE))
    {
        WorkflowInstance instance = path.getInstance();
        workflowPackageComponent.setWorkflowForPackage(instance);
    }
    return path;
}
 
Example #14
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
*/
public WorkflowInstance deleteWorkflow(String workflowId)
{
    String localId = createLocalId(workflowId);
    try
    {
        // Delete the runtime process instance if still running, this calls the end-listeners if any
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(localId).singleResult();
        if(processInstance != null) 
        {
            runtimeService.deleteProcessInstance(processInstance.getId(), ActivitiConstants.DELETE_REASON_DELETED);
        }
        
        // Convert historic process instance
        HistoricProcessInstance deletedInstance = historyService.createHistoricProcessInstanceQuery()
            .processInstanceId(localId)
            .singleResult();
        
        if(deletedInstance == null) {
            throw new WorkflowException(messageService.getMessage(ERR_DELETE_UNEXISTING_WORKFLOW, localId));
        }
        
        WorkflowInstance result =  typeConverter.convert(deletedInstance);
        
        // Delete the historic process instance
        historyService.deleteHistoricProcessInstance(deletedInstance.getId());
        
        return result;
    } 
    catch(ActivitiException ae) 
    {
        String msg = messageService.getMessage(ERR_DELETE_WORKFLOW);
        if(logger.isDebugEnabled())
        {
        	logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
 
Example #15
Source File: ActivitiWorkflowComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testGetCompletedWorkflows() throws Exception 
{
    WorkflowDefinition def = deployTestAdhocDefinition();
    String activitiProcessDefinitionId = BPMEngineRegistry.getLocalId(def.getId());
    
    runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance completedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance cancelledInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance deletedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    
    // Complete completedProcessInstance.
    String completedId = completedInstance.getId();
    boolean isActive = true;
    while (isActive)
    {
        Execution execution = runtime.createExecutionQuery()
        .processInstanceId(completedId)
        .singleResult();
        runtime.signal(execution.getId());
        ProcessInstance instance = runtime.createProcessInstanceQuery()
        .processInstanceId(completedId)
        .singleResult();
        isActive = instance != null;
    }
    
    // Deleted and canceled instances shouldn't be returned
    workflowEngine.cancelWorkflow(workflowEngine.createGlobalId(cancelledInstance.getId()));
    workflowEngine.deleteWorkflow(workflowEngine.createGlobalId(deletedInstance.getId()));
    
    // Validate if a workflow exists
    List<WorkflowInstance> instances = workflowEngine.getCompletedWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(1, instances.size());
    String instanceId = instances.get(0).getId();
    assertEquals(completedId, BPMEngineRegistry.getLocalId(instanceId));
}
 
Example #16
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
*/
public WorkflowInstance cancelWorkflow(String workflowId)
{
    String localId = createLocalId(workflowId);
    try
    {
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(localId).singleResult();
        if (processInstance == null)
        {
            throw new WorkflowException(messageService.getMessage(ERR_CANCEL_UNEXISTING_WORKFLOW));
        }

        // TODO: Cancel VS delete?
        // Delete the process instance
        runtimeService.deleteProcessInstance(processInstance.getId(), WorkflowConstants.PROP_CANCELLED);

        // Convert historic process instance
        HistoricProcessInstance deletedInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId())
                .singleResult();
        WorkflowInstance result = typeConverter.convert(deletedInstance);

        // Delete the historic process instance
        // MNT-15498
        if (!activitiUtil.isRetentionHistoricProcessInstanceEnabled())
        {
            historyService.deleteHistoricProcessInstance(deletedInstance.getId());
        }

        return result;
    }
    catch (ActivitiException ae)
    {
        String msg = messageService.getMessage(ERR_CANCEL_WORKFLOW);
        if (logger.isDebugEnabled())
        {
            logger.debug(msg, ae);
        }
        throw new WorkflowException(msg, ae);
    }
}
 
Example #17
Source File: WorkflowInstancesGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int compare(WorkflowInstance o1, WorkflowInstance o2)
{
    Date date1 = o1.getDueDate();
    Date date2 = o2.getDueDate();
    
    long time1 = date1 == null ? Long.MAX_VALUE : date1.getTime();
    long time2 = date2 == null ? Long.MAX_VALUE : date2.getTime();
    
    long result = time1 - time2;
    
    return (result > 0) ? 1 : (result < 0 ? -1 : 0);
}
 
Example #18
Source File: AbstractWorkflowRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testWorkflowInstanceDeleteAsAdministrator() throws Exception
{
    //Start workflow as USER1 
    personManager.setUser(USER1);
    WorkflowDefinition adhocDef = workflowService.getDefinitionByName(getAdhocWorkflowDefinitionName());
    Map<QName, Serializable> params = new HashMap<QName, Serializable>();
    params.put(WorkflowModel.ASSOC_ASSIGNEE, personManager.get(USER2));
    Date dueDate = new Date();
    params.put(WorkflowModel.PROP_DUE_DATE, dueDate);
    params.put(WorkflowModel.PROP_PRIORITY, 1);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    params.put(WorkflowModel.PROP_CONTEXT, packageRef);

    WorkflowPath adhocPath = workflowService.startWorkflow(adhocDef.getId(), params);
    WorkflowTask startTask = workflowService.getTasksForWorkflowPath(adhocPath.getId()).get(0);
    startTask = workflowService.endTask(startTask.getId(), null);

    WorkflowInstance adhocInstance = startTask.getPath().getInstance();
    
    // Run next request as admin
    String admin = authenticationComponent.getDefaultAdministratorUserNames().iterator().next();
    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    
    sendRequest(new DeleteRequest(URL_WORKFLOW_INSTANCES + "/" + adhocInstance.getId()), Status.STATUS_OK);

    WorkflowInstance instance = workflowService.getWorkflowById(adhocInstance.getId());
    if (instance != null)
    {
        assertFalse("The deleted workflow is still active!", instance.isActive());
    }
    
    List<WorkflowInstance> instances = workflowService.getActiveWorkflows(adhocInstance.getDefinition().getId());
    for (WorkflowInstance activeInstance : instances)
    {
        assertFalse(adhocInstance.getId().equals(activeInstance.getId()));
    }
}
 
Example #19
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<WorkflowInstance> cancelWorkflows(List<String> workflowIds)
{
    List<WorkflowInstance> result = new ArrayList<WorkflowInstance>(workflowIds.size());
    for (String workflowId : workflowIds)
    {
        result.add(cancelWorkflow(workflowId));
    }
    return result;
}
 
Example #20
Source File: ActivitiWorkflowComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testGetActiveWorkflows() throws Exception 
{
    WorkflowDefinition def = deployTestAdhocDefinition();
    String activitiProcessDefinitionId = BPMEngineRegistry.getLocalId(def.getId());
    
    ProcessInstance activeInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance completedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance cancelledInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    ProcessInstance deletedInstance = runtime.startProcessInstanceById(activitiProcessDefinitionId);
    
    // Complete completedProcessInstance.
    String completedId = completedInstance.getId();
    boolean isActive = true;
    while (isActive)
    {
        Execution execution = runtime.createExecutionQuery()
            .processInstanceId(completedId)
            .singleResult();
        runtime.signal(execution.getId());
        ProcessInstance instance = runtime.createProcessInstanceQuery()
            .processInstanceId(completedId)
            .singleResult();
        isActive = instance != null;
    }
    
    // Deleted and canceled instances shouldn't be returned
    workflowEngine.cancelWorkflow(workflowEngine.createGlobalId(cancelledInstance.getId()));
    workflowEngine.deleteWorkflow(workflowEngine.createGlobalId(deletedInstance.getId()));
    
    // Validate if a workflow exists
    List<WorkflowInstance> instances = workflowEngine.getActiveWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(1, instances.size());
    String instanceId = instances.get(0).getId();
    assertEquals(activeInstance.getId(), BPMEngineRegistry.getLocalId(instanceId));
}
 
Example #21
Source File: ActivitiWorkflowComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testDeleteWorkflow() 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 delete method on component
    workflowEngine.deleteWorkflow(instances.get(0).getId());
    
    instances = workflowEngine.getActiveWorkflows(def.getId());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    
    // Historic process instance shouldn't be present
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
        .processInstanceId(processInstance.getProcessInstanceId())
        .singleResult();
    
    assertNull(historicProcessInstance);
}
 
Example #22
Source File: WorkflowModelBuilderTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WorkflowPath makePath()
{
    String id = "pathId$1";
    Date startDate = new Date();
    WorkflowDefinition definition = new WorkflowDefinition(
            "The Id", "The Name", "1", "The Title", "The Description", null);
    WorkflowInstance instance = new WorkflowInstance("",
                definition, null, null, null,
                workflowPackage, true, startDate, null);
    return new WorkflowPath(id, instance, null, true);
}
 
Example #23
Source File: WorkflowModelBuilderTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WorkflowInstance makeWorkflowInstance(WorkflowTaskDefinition taskDefinition)
{
    String id = "The id";
    boolean active = true;
    Date startDate = new Date();
    Date endDate = new Date();
    NodeRef initiator = person;
    WorkflowDefinition definition = new WorkflowDefinition(
                "The Id", "The Name", "The Version", "The Title", "The Description", taskDefinition);
    return new WorkflowInstance(id,
                definition, "", initiator, workflowPackage,
                workflowPackage, active, startDate, endDate);
}
 
Example #24
Source File: WorkflowServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<WorkflowInstance> cancelWorkflows(List<String> workflowIds)
{
    if (workflowIds == null)
    {
        workflowIds = Collections.emptyList();
    }
    
    if (logger.isTraceEnabled()) { logger.trace("Cancelling " + workflowIds.size() + " workflowIds..."); }
    
    List<WorkflowInstance> result = new ArrayList<WorkflowInstance>(workflowIds.size());
    
    // Batch the workflow IDs by engine ID
    Map<String, List<String>> workflows = batchByEngineId(workflowIds);
    
    // Process each engine's batch
    for (Map.Entry<String, List<String>> entry : workflows.entrySet())
    {
        String engineId = entry.getKey();
        WorkflowComponent component = getWorkflowComponent(engineId);
        List<WorkflowInstance> instances = component.cancelWorkflows(entry.getValue());
        for (WorkflowInstance instance : instances)
        {
            // NOTE: Delete workflow package after cancelling workflow, so it's
            // still available
            // in process-end events of workflow definition
            workflowPackageComponent.deletePackage(instance.getWorkflowPackage());
            result.add(instance);
        }
    }        
    return result;
}
 
Example #25
Source File: AbstractWorkflowServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkWorkflowsContains(List<WorkflowInstance> workflows, String... expectedIds)
{
    List<String> expIds = Arrays.asList(expectedIds);
    List<String> workflowIds = CollectionUtils.transform(workflows, new Function<WorkflowInstance, String>()
    {
        public String apply(WorkflowInstance workflow)
        {
            return workflow.getId();
        }
    });
    assertTrue(workflowIds.containsAll(expIds));
}
 
Example #26
Source File: AbstractWorkflowServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkWorkflows(List<WorkflowInstance> workflows, String... expectedIds)
{
    assertEquals(expectedIds.length, workflows.size());
    List<String> expIds = Arrays.asList(expectedIds);
    for (WorkflowInstance workflow : workflows)
    {
        String workflowId = workflow.getId();
        assertTrue("The id: "+workflowId +" was not expected! Expected Ids: "+expIds, expIds.contains(workflowId));
    }
}
 
Example #27
Source File: JscriptWorkflowInstance.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance of <code>WorkflowInstance</code> from a
 * WorkflowInstance object from the CMR workflow object model
 *
 * @param cmrWorkflowInstance CMR workflow instance
 * @param serviceRegistry Service Registry instance 
 * @param scope the root scripting scope for this object 
 */
public JscriptWorkflowInstance(final WorkflowInstance
		cmrWorkflowInstance, final ServiceRegistry serviceRegistry, final Scriptable scope)
{
	this.id = cmrWorkflowInstance.id;
	this.description = cmrWorkflowInstance.description;
	this.active = cmrWorkflowInstance.active;
	this.startDate = cmrWorkflowInstance.startDate;
	this.endDate = cmrWorkflowInstance.endDate;
	this.serviceRegistry = serviceRegistry;
	this.scope = scope;
}
 
Example #28
Source File: WorkflowFormProcessorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #29
Source File: WorkflowFormProcessorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #30
Source File: WorkflowBuilder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WorkflowInstance build()
{
    NodeRef packageRef = packageMgr.create(packageNode);
    params.put(WorkflowModel.ASSOC_PACKAGE, packageRef);
    WorkflowPath path = workflowService.startWorkflow(definition.getId(), params);
    if (path.isActive()){
        signalStartTask(path);
    }
    return path.getInstance();
}