Java Code Examples for org.activiti.engine.runtime.ProcessInstance#getProcessInstanceId()

The following examples show how to use org.activiti.engine.runtime.ProcessInstance#getProcessInstanceId() . 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: BxlcTaskListeningImpl.java    From gem with MIT License 5 votes vote down vote up
/**
 * @Description:填写申请的表单
 * @param rmb 报销金额
 * @param key 流程的key
 * @author: Ryan
 * @date 2018年11月18日
 */
public String saveBxlcForm(String rmb, String key) {
	Map<String, Object> variables = new HashMap<String, Object>();
	variables.put("rmb", rmb);
	ProcessInstance startProcessInstanceByKey = runtimeService.startProcessInstanceByKey(key, variables);
	String processInstanceId = startProcessInstanceByKey.getProcessInstanceId();
	return processInstanceId;
}
 
Example 2
Source File: ProcessScopeTestEngine.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private StatefulObject run() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("customerId", customerId);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("component-waiter", vars);

  Map<String, Object> runtimeVars = runtimeService.getVariables(processInstance.getId());

  String statefulObjectVariableKey = keyForObjectType(runtimeVars, StatefulObject.class);

  assertTrue(!runtimeVars.isEmpty());
  assertTrue(StringUtils.hasText(statefulObjectVariableKey));

  StatefulObject scopedObject = (StatefulObject) runtimeService.getVariable(processInstance.getId(), statefulObjectVariableKey);
  assertNotNull(scopedObject);
  assertTrue(StringUtils.hasText(scopedObject.getName()));
  assertEquals(2, scopedObject.getVisitedCount());

  // the process has paused
  String procId = processInstance.getProcessInstanceId();

  List<Task> tasks = taskService.createTaskQuery().executionId(procId).list();
  assertEquals(1, tasks.size());

  Task t = tasks.iterator().next();
  this.taskService.claim(t.getId(), "me");
  this.taskService.complete(t.getId());

  scopedObject = (StatefulObject) runtimeService.getVariable(processInstance.getId(), statefulObjectVariableKey);
  assertEquals(3, scopedObject.getVisitedCount());

  assertEquals(customerId, scopedObject.getCustomerId());
  return scopedObject;
}
 
Example 3
Source File: ProcessScopeTestEngine.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private StatefulObject run() {
  Map<String, Object> vars = new HashMap<String, Object>();
  vars.put("customerId", customerId);

  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("component-waiter", vars);

  Map<String, Object> runtimeVars = runtimeService.getVariables(processInstance.getId());

  String statefulObjectVariableKey = keyForObjectType(runtimeVars, StatefulObject.class);

  assertTrue(!runtimeVars.isEmpty());
  assertTrue(StringUtils.hasText(statefulObjectVariableKey));

  StatefulObject scopedObject = (StatefulObject) runtimeService.getVariable(processInstance.getId(), statefulObjectVariableKey);
  assertNotNull(scopedObject);
  assertTrue(StringUtils.hasText(scopedObject.getName()));
  assertEquals(2, scopedObject.getVisitedCount());

  // the process has paused
  String procId = processInstance.getProcessInstanceId();

  List<Task> tasks = taskService.createTaskQuery().executionId(procId).list();
  assertEquals(1, tasks.size());

  Task t = tasks.iterator().next();
  this.taskService.claim(t.getId(), "me");
  this.taskService.complete(t.getId());

  scopedObject = (StatefulObject) runtimeService.getVariable(processInstance.getId(), statefulObjectVariableKey);
  assertEquals(3, scopedObject.getVisitedCount());

  assertEquals(customerId, scopedObject.getCustomerId());
  return scopedObject;
}
 
Example 4
Source File: JobServiceTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobActiveJobWithMultipleSubProcesses() throws Exception
{
    // Create and persist a test job definition.
    executeJdbcTestHelper
        .prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, ACTIVITI_XML_TEST_MULTIPLE_SUB_PROCESSES);

    try
    {
        // Get the job definition entity and ensure it exists.
        JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
        assertNotNull(jobDefinitionEntity);

        // Get the process definition id.
        String processDefinitionId = jobDefinitionEntity.getActivitiId();

        // Build the parameters map.
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("counter", 0);

        // Start the job.
        ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, parameters);
        assertNotNull(processInstance);

        // Get the process instance id for this job.
        String processInstanceId = processInstance.getProcessInstanceId();

        // Wait for all processes to become active - we expect to have the main process along with 800 sub-processes.
        waitUntilActiveProcessesThreshold(processDefinitionId, 801);

        // Get the job and validate that it is RUNNING.
        Job getJobResponse = jobService.getJob(processInstanceId, true);
        assertNotNull(getJobResponse);
        assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());

        // Delete the job and validate the response.
        Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON));
        assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
        assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());

        // Validate the historic process instance.
        HistoricProcessInstance historicProcessInstance =
            activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        assertNotNull(historicProcessInstance);
        assertEquals(ACTIVITI_JOB_DELETE_REASON, historicProcessInstance.getDeleteReason());
    }
    finally
    {
        // Clean up the Herd database.
        executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);

        // Clean up the Activiti.
        deleteActivitiDeployments();
    }
}
 
Example 5
Source File: JobServiceTest.java    From herd with Apache License 2.0 4 votes vote down vote up
@Test
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void testDeleteJobSuspendedJobWithMultipleSubProcesses() throws Exception
{
    // Create and persist a test job definition.
    executeJdbcTestHelper
        .prepareHerdDatabaseForExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, ACTIVITI_XML_TEST_MULTIPLE_SUB_PROCESSES);

    try
    {
        // Get the job definition entity and ensure it exists.
        JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);
        assertNotNull(jobDefinitionEntity);

        // Get the process definition id.
        String processDefinitionId = jobDefinitionEntity.getActivitiId();

        // Build the parameters map.
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("counter", 0);

        // Start the job.
        ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, parameters);
        assertNotNull(processInstance);

        // Get the process instance id for this job.
        String processInstanceId = processInstance.getProcessInstanceId();

        // Wait for all processes to become active - we expect to have the main process along with 800 sub-processes.
        waitUntilActiveProcessesThreshold(processDefinitionId, 801);

        // Get the job and validate that it is RUNNING.
        Job getJobResponse = jobService.getJob(processInstanceId, true);
        assertNotNull(getJobResponse);
        assertEquals(JobStatusEnum.RUNNING, getJobResponse.getStatus());

        // Suspend the job.
        jobService.updateJob(processInstanceId, new JobUpdateRequest(JobActionEnum.SUSPEND));

        // Get the job again and validate that it is now SUSPENDED.
        getJobResponse = jobService.getJob(processInstanceId, true);
        assertNotNull(getJobResponse);
        assertEquals(JobStatusEnum.SUSPENDED, getJobResponse.getStatus());

        // Delete the job in suspended state and validate the response.
        Job deleteJobResponse = jobService.deleteJob(processInstanceId, new JobDeleteRequest(ACTIVITI_JOB_DELETE_REASON));
        assertEquals(JobStatusEnum.COMPLETED, deleteJobResponse.getStatus());
        assertEquals(ACTIVITI_JOB_DELETE_REASON, deleteJobResponse.getDeleteReason());

        // Validate the historic process instance.
        HistoricProcessInstance historicProcessInstance =
            activitiHistoryService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        assertNotNull(historicProcessInstance);
        assertEquals(ACTIVITI_JOB_DELETE_REASON, historicProcessInstance.getDeleteReason());
    }
    finally
    {
        // Clean up the Herd database.
        executeJdbcTestHelper.cleanUpHerdDatabaseAfterExecuteJdbcWithReceiveTaskTest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME);

        // Clean up the Activiti.
        deleteActivitiDeployments();
    }
}