Java Code Examples for org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition#findActivity()

The following examples show how to use org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition#findActivity() . 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: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private WorkflowTask getTaskForTimer(Job job, ProcessInstance processInstance, Execution jobExecution) 
{
    if (job instanceof TimerEntity) 
    {
        ReadOnlyProcessDefinition def = activitiUtil.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
        List<String> activeActivityIds = runtimeService.getActiveActivityIds(jobExecution.getId());
        
        if(activeActivityIds.size() == 1)
        {
            PvmActivity targetActivity = def.findActivity(activeActivityIds.get(0));
            if(targetActivity != null)
            {
                // Only get tasks of active activity is a user-task 
                String activityType = (String) targetActivity.getProperty(ActivitiConstants.NODE_TYPE);
                if(ActivitiConstants.USER_TASK_NODE_TYPE.equals(activityType))
                {
                    Task task = taskService.createTaskQuery().executionId(job.getExecutionId()).singleResult();
                    return typeConverter.convert(task);
                }
            }
        }
    }
    return null;
}
 
Example 2
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 3
Source File: ActivitiWorkflowEngine.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WorkflowTask endStartTask(String localTaskId)
{
    // We don't end a task, we set a variable on the process-instance 
    // to indicate that it's started
    String processInstanceId = localTaskId.replace(ActivitiConstants.START_TASK_PREFIX, "");
    if(false == typeConverter.isStartTaskActive(processInstanceId))
    {
        return typeConverter.getVirtualStartTask(processInstanceId, false);
    }
    
    // Set start task end date on the process
    runtimeService.setVariable(processInstanceId, ActivitiConstants.PROP_START_TASK_END_DATE, new Date());
    
    // Check if the current activity is a signalTask and the first activity in the process,
    // this is a workaround for processes without any task/waitstates that should otherwise end
    // when they are started.
    ProcessInstance processInstance = activitiUtil.getProcessInstance(processInstanceId);
    String currentActivity = ((ExecutionEntity)processInstance).getActivityId();
    
    ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
    PvmActivity activity = procDef.findActivity(currentActivity);
    if(isReceiveTask(activity) && isFirstActivity(activity, procDef)) 
    {
        // Signal the process to start flowing, beginning from the recieve task
        runtimeService.signal(processInstanceId);
        
        // It's possible the process has ended after signalling the receive task
    }
    // Return virtual start task for the execution, it's safe to use the
    // processInstanceId
    return typeConverter.getVirtualStartTask(processInstanceId, false);
}
 
Example 4
Source File: ProcessDefinitionPersistenceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void testProcessDefinitionIntrospection() {
    String deploymentId = repositoryService
            .createDeployment()
            .addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy()
            .getId();

    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessEngineConfigurationImpl activiti5ProcessEngineConfig = (ProcessEngineConfigurationImpl) processEngineConfiguration.getFlowable5CompatibilityHandler().getRawProcessConfiguration();
    ReadOnlyProcessDefinition processDefinition = ((RepositoryServiceImpl) activiti5ProcessEngineConfig.getRepositoryService()).getDeployedProcessDefinition(procDefId);

    assertEquals(procDefId, processDefinition.getId());
    assertEquals("Process One", processDefinition.getName());
    assertEquals("the first process", processDefinition.getProperty("documentation"));

    PvmActivity start = processDefinition.findActivity("start");
    assertNotNull(start);
    assertEquals("start", start.getId());
    assertEquals("S t a r t", start.getProperty("name"));
    assertEquals("the start event", start.getProperty("documentation"));
    assertEquals(Collections.EMPTY_LIST, start.getActivities());
    List<PvmTransition> outgoingTransitions = start.getOutgoingTransitions();
    assertEquals(1, outgoingTransitions.size());
    assertEquals("${a == b}", outgoingTransitions.get(0).getProperty(BpmnParse.PROPERTYNAME_CONDITION_TEXT));

    PvmActivity end = processDefinition.findActivity("end");
    assertNotNull(end);
    assertEquals("end", end.getId());

    PvmTransition transition = outgoingTransitions.get(0);
    assertEquals("flow1", transition.getId());
    assertEquals("Flow One", transition.getProperty("name"));
    assertEquals("The only transitions in the process", transition.getProperty("documentation"));
    assertSame(start, transition.getSource());
    assertSame(end, transition.getDestination());

    repositoryService.deleteDeployment(deploymentId);
}
 
Example 5
Source File: ActivitiTypeConverter.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private WorkflowNode buildHistoricTaskWorkflowNode(HistoricTaskInstance historicTaskInstance) 
   {
   	ReadOnlyProcessDefinition procDef = activitiUtil.getDeployedProcessDefinition(historicTaskInstance.getProcessDefinitionId());
   	PvmActivity taskActivity = procDef.findActivity(historicTaskInstance.getTaskDefinitionKey());
	return convert(taskActivity);
}