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

The following examples show how to use org.activiti.engine.runtime.ProcessInstance#getId() . 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: ProcessConnectorImpl.java    From lemon with Apache License 2.0 6 votes vote down vote up
public String startProcess(String userId, String businessKey,
        String processDefinitionId, Map<String, Object> processParameters) {
    // 先设置登录用户
    IdentityService identityService = processEngine.getIdentityService();
    identityService.setAuthenticatedUserId(userId);
    processParameters.put("_starter", userId);
    logger.info("businessKey : {}", businessKey);

    ProcessInstance processInstance = processEngine.getRuntimeService()
            .startProcessInstanceById(processDefinitionId, businessKey,
                    processParameters);

    /*
     * // {流程标题:title}-{发起人:startUser}-{发起时间:startTime} String processDefinitionName =
     * processEngine.getRepositoryService() .createProcessDefinitionQuery()
     * .processDefinitionId(processDefinitionId).singleResult() .getName(); String processInstanceName =
     * processDefinitionName + "-" + userConnector.findById(userId).getDisplayName() + "-" + new
     * SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
     * processEngine.getRuntimeService().setProcessInstanceName( processInstance.getId(), processInstanceName);
     */
    return processInstance.getId();
}
 
Example 2
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存请假实体并启动流程
 */
public ProcessInstance startWorkflow(Leave entity, String userId, Map<String, Object> variables) {
    if (entity.getId() == null) {
        entity.setApplyTime(new Date());
        entity.setUserId(userId);
    }
    leaveManager.save(entity);
    String businessKey = entity.getId().toString();

    // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
    identityService.setAuthenticatedUserId(userId);

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave", businessKey, variables);
    String processInstanceId = processInstance.getId();
    entity.setProcessInstanceId(processInstanceId);
    logger.debug("start process of {key={}, bkey={}, pid={}, variables={}}", new Object[]{"leave", businessKey, processInstanceId, variables});
    leaveManager.save(entity);
    return processInstance;
}
 
Example 3
Source File: PurchaseApplyUserInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 6 votes vote down vote up
/**
     * 启动流程
     *
     * @return
     */
    public PurchaseApplyDto startProcess(@RequestBody PurchaseApplyDto purchaseApplyDto) {
        //将信息加入map,以便传入流程中
        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("purchaseApplyDto", purchaseApplyDto);
        variables.put("nextAuditStaffId",purchaseApplyDto.getStaffId());
        variables.put("userId", purchaseApplyDto.getCurrentUserId());
        //开启流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("resourceEntry", purchaseApplyDto.getApplyOrderId(), variables);
//        //将得到的实例流程id值赋给之前设置的变量
        String processInstanceId = processInstance.getId();
//        // System.out.println("流程开启成功.......实例流程id:" + processInstanceId);
//
        purchaseApplyDto.setProcessInstanceId(processInstanceId);
        autoFinishFirstTask(purchaseApplyDto);
        return purchaseApplyDto;
    }
 
Example 4
Source File: LeaveWorkflowService.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 保存请假实体并启动流程
 */
public ProcessInstance startWorkflow(Leave entity, String userId, Map<String, Object> variables) {
    if (entity.getId() == null) {
        entity.setApplyTime(new Date());
        entity.setUserId(userId);
    }
    leaveManager.save(entity);
    String businessKey = entity.getId().toString();

    // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
    identityService.setAuthenticatedUserId(userId);

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave", businessKey, variables);
    String processInstanceId = processInstance.getId();
    entity.setProcessInstanceId(processInstanceId);
    logger.debug("start process of {key={}, bkey={}, pid={}, variables={}}", new Object[]{"leave", businessKey, processInstanceId, variables});
    leaveManager.save(entity);
    return processInstance;
}
 
Example 5
Source File: ProcessUIController.java    From easyweb with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/start/{processDefinitionId}")
    public String start(@PathVariable("processDefinitionId") String processDefinitionId, HttpServletRequest request) throws Exception {

        try {
            // 定义map用于往工作流数据库中传值。
            Map<String, String> formProperties = new HashMap<String, String>();
            //启动流程-何静媛-2015年5月24日--processDefinitionId,
            ProcessInstance processInstance = formService
                    .submitStartFormData(processDefinitionId,
                            formProperties);
            // 返回到显示用户信息的controller
            _log.debug("开始流程", processInstance);
            return "redirect:/workflow/processui/get-form/task/" + processInstance.getId();

        } catch (Exception e) {
            throw e;
        } finally {
//            identityService.setAuthenticatedUserId(null);
        }
    }
 
Example 6
Source File: ListenerTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"diagrams/chapter7/listener/listener.bpmn"})
public void testListener() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("endListener", new ProcessEndExecutionListener());
    variables.put("assignmentDelegate", new TaskAssigneeListener());
    variables.put("name", "Henry Yan");

    identityService.setAuthenticatedUserId("henryyan");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("listener", variables);

    // 校验是否执行了启动监听
    String processInstanceId = processInstance.getId();
    assertTrue((Boolean) runtimeService.getVariable(processInstanceId, "setInStartListener"));

    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).taskAssignee("jenny").singleResult();
    String setInTaskCreate = (String) taskService.getVariable(task.getId(), "setInTaskCreate");
    assertEquals("create, Hello, Henry Yan", setInTaskCreate);
    taskService.complete(task.getId());

    // 流程结束后查询变量
    List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
    boolean hasVariableOfEndListener = false;
    for (HistoricVariableInstance variableInstance : list) {
        if (variableInstance.getVariableName().equals("setInEndListener")) {
            hasVariableOfEndListener = true;
        }
    }
    assertTrue(hasVariableOfEndListener);
}
 
Example 7
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 8
Source File: ProcessInstanceResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected ProcessInstanceResponse activateProcessInstance(ProcessInstance processInstance) {
  if (!processInstance.isSuspended()) {
    throw new ActivitiConflictException("Process instance with id '" + processInstance.getId() + "' is already active.");
  }
  runtimeService.activateProcessInstanceById(processInstance.getId());

  ProcessInstanceResponse response = restResponseFactory.createProcessInstanceResponse(processInstance);

  // No need to re-fetch the instance, just alter the suspended state of
  // the result-object
  response.setSuspended(false);
  return response;
}
 
Example 9
Source File: ActivitiSpringTransactionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testSmoke() throws Exception
{
    assertNotNull(runtime);

    ProcessInstance instance = runtime.startProcessInstanceByKey(PROC_DEF_KEY);
    assertNotNull(instance);
    
    String instanceId = instance.getId();
    ProcessInstance instanceInDb = findProcessInstance(instanceId);
    assertNotNull(instanceInDb);
    runtime.deleteProcessInstance(instance.getId(), "");
    assertNotNull(instance);
}
 
Example 10
Source File: ActivitiSmokeTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testDeploy() throws Exception
    {
        ProcessEngine engine = buildProcessEngine();

        RepositoryService repoService = engine.getRepositoryService();

        Deployment deployment = deployDefinition(repoService);

        assertNotNull(deployment);

        RuntimeService runtimeService = engine.getRuntimeService();
        try
        {
            ProcessInstance instance = runtimeService.startProcessInstanceByKey("testTask");
            assertNotNull(instance);
            
            String instanceId = instance.getId();
            ProcessInstance instanceInDb = findProcessInstance(runtimeService, instanceId);
            assertNotNull(instanceInDb);
            runtimeService.deleteProcessInstance(instanceId, "");
        }
        finally
        {
            
//            List<Deployment> deployments = repoService.createDeploymentQuery().list();
//            for (Deployment deployment2 : deployments)
//            {
//                repoService.deleteDeployment(deployment2.getId());
//            }
            
            repoService.deleteDeployment(deployment.getId());
        }
    }
 
Example 11
Source File: CartController.java    From Spring-MVC-Blueprints with MIT License 5 votes vote down vote up
@RequestMapping("/ocs/order")
public String startOrder(HttpServletRequest req){
	String cartUser = (String)req.getSession().getAttribute("cartUser");
	System.out.println("Cart user" + cartUser);
	
	ProcessInstance processInstance = getRuntimeService().startProcessInstanceByKey("shopping");
	processId = processInstance.getId();
	execAndCompleteTask(processId, cartUser, "start");

	return "order";
}
 
Example 12
Source File: ProcessInstanceCollectionResourceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Test getting a list of process instance, using all tenant filters.
 */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" })
public void testGetProcessInstancesTenant() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
  String id = processInstance.getId();

  // Test without tenant id
  String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true";
  assertResultsPresentInDataResponse(url, id);

  // Update the tenant for the deployment
  managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));

  // Test tenant id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=myTenant";
  assertResultsPresentInDataResponse(url, id);

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=anotherTenant";
  assertResultsPresentInDataResponse(url);

  // Test tenant id like
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%enant");
  assertResultsPresentInDataResponse(url, id);

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%what");
  assertResultsPresentInDataResponse(url);

  // Test without tenant id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true";
  assertResultsPresentInDataResponse(url);
}
 
Example 13
Source File: ActivitiWorkflowComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testSignal() throws Exception
{
    WorkflowDefinition def = deployTestSignallingDefinition();
    ProcessInstance processInstance = runtime.startProcessInstanceById(BPMEngineRegistry.getLocalId(def.getId()));
    
    String procId = processInstance.getId();
    List<String> nodeIds = runtime.getActiveActivityIds(procId);
    assertEquals(1, nodeIds.size());
    assertEquals("task1", nodeIds.get(0));
    
    String pathId = BPMEngineRegistry.createGlobalId(ActivitiConstants.ENGINE_ID, procId);
    WorkflowPath path = workflowEngine.signal(pathId, null);
    assertEquals(pathId, path.getId());
    assertEquals("task2", path.getNode().getName());
    assertEquals(pathId, path.getInstance().getId());
    assertTrue(path.isActive());
    
    nodeIds = runtime.getActiveActivityIds(procId);
    assertEquals(1, nodeIds.size());
    assertEquals("task2", nodeIds.get(0));

    // Should end the WorkflowInstance
    path = workflowEngine.signal(pathId, null);
    assertEquals(pathId, path.getId());
    assertNull(path.getNode());
    assertEquals(pathId, path.getInstance().getId());
    assertFalse(path.isActive());
}
 
Example 14
Source File: ListenerTest.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {"diagrams/chapter7/listener/listener.bpmn"})
public void testListener() {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("endListener", new ProcessEndExecutionListener());
    variables.put("assignmentDelegate", new TaskAssigneeListener());
    variables.put("name", "Henry Yan");

    identityService.setAuthenticatedUserId("henryyan");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("listener", variables);

    // 校验是否执行了启动监听
    String processInstanceId = processInstance.getId();
    assertTrue((Boolean) runtimeService.getVariable(processInstanceId, "setInStartListener"));

    Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).taskAssignee("jenny").singleResult();
    String setInTaskCreate = (String) taskService.getVariable(task.getId(), "setInTaskCreate");
    assertEquals("create, Hello, Henry Yan", setInTaskCreate);
    taskService.complete(task.getId());

    // 流程结束后查询变量
    List<HistoricVariableInstance> list = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
    boolean hasVariableOfEndListener = false;
    for (HistoricVariableInstance variableInstance : list) {
        if (variableInstance.getVariableName().equals("setInEndListener")) {
            hasVariableOfEndListener = true;
        }
    }
    assertTrue(hasVariableOfEndListener);
}
 
Example 15
Source File: ActivitiController.java    From acitviti6.0 with MIT License 5 votes vote down vote up
@RequestMapping("exclusiveGateway")  
public void exclusiveGateway() {  
	
	//根据bpmn文件部署流程  
	repositoryService.createDeployment().addClasspathResource("exclusiveGateway.bpmn").deploy();
	// 设置User Task1受理人变量
	Map<String, Object> variables = new HashMap<>();
	variables.put("user1", "007");
	//采用key来启动流程定义并设置流程变量,返回流程实例  
	ProcessInstance pi = runtimeService.startProcessInstanceByKey("exclusiveGatewayAndTimerBoundaryEventProcess", variables);  
	String processId = pi.getId();  
	System.out.println("流程创建成功,当前流程实例ID:"+processId);
	
	// 注意 这里需要拿007来查询,key-value需要拿value来获取任务
	List<Task> list = taskService.createTaskQuery().taskAssignee("007").list();
	Map<String, Object> variables1 = new HashMap<>();
	variables1.put("user2", "lili"); // 设置User Task2的受理人变量
	variables1.put("operate", ""); // 设置用户的操作 为空 表示走flow3的默认路线
	taskService.complete(list.get(0).getId(), variables1);
	System.out.println("User Task1被完成了,此时流程已流转到User Task2");
	
	List<Task> list1 = taskService.createTaskQuery().taskAssignee("lili").list();
	Map<String, Object> variables2 = new HashMap<>();
	variables2.put("user4", "bobo");
	variables2.put("startTime", "2018-6-11T14:22:00"); // 设置定时边界任务的触发时间 注意:后面的时间必须是ISO 8601时间格式的字符串!!!
	taskService.complete(list1.get(0).getId(), variables2);
	
	List<Task> list2 = taskService.createTaskQuery().taskAssignee("bobo").list();
	if(list2!=null && list2.size()>0){ 
           for(org.activiti.engine.task.Task task:list2){  
               System.out.println("任务ID:"+task.getId());  
               System.out.println("任务的办理人:"+task.getAssignee());  
               System.out.println("任务名称:"+task.getName());  
               System.out.println("任务的创建时间:"+task.getCreateTime());  
               System.out.println("流程实例ID:"+task.getProcessInstanceId());  
               System.out.println("#######################################");
           }
       }
}
 
Example 16
Source File: ResourceEntryStoreInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 启动流程
 *
 * @return
 */
public ResourceOrderDto startProcess(@RequestBody ResourceOrderDto resourceOrderDto) {
    //将信息加入map,以便传入流程中
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("resourceOrderDto", resourceOrderDto);
    //开启流程
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("resourceEntry", variables);
    //将得到的实例流程id值赋给之前设置的变量
    String processInstanceId = processInstance.getId();
    // System.out.println("流程开启成功.......实例流程id:" + processInstanceId);

    resourceOrderDto.setProcessInstanceId(processInstanceId);

    return resourceOrderDto;
}
 
Example 17
Source File: ExecutionCollectionResourceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
/**
 * Test getting a list of executions, using all possible filters.
 */
@Deployment(resources = { "org/activiti/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" })
public void testGetExecutions() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey");
  String id = processInstance.getId();
  runtimeService.addUserIdentityLink(id, "kermit", "whatever");

  Execution childExecutionInTask = runtimeService.createExecutionQuery().activityId("processTask").singleResult();
  assertNotNull(childExecutionInTask);
  
  Execution childExecutionInSubProcess = runtimeService.createExecutionQuery().activityId("subProcess").singleResult();
  assertNotNull(childExecutionInSubProcess);

  // Test without any parameters
  String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION);
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  // Process instance id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=" + id;
  assertResultsPresentInDataResponse(url, id);

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=anotherId";
  assertResultsPresentInDataResponse(url);

  // Process instance business key
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=myBusinessKey";
  assertResultsPresentInDataResponse(url, id);

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=anotherBusinessKey";
  assertResultsPresentInDataResponse(url);

  // Process definition key
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processOne";
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processTwo";
  assertResultsPresentInDataResponse(url);

  // Process definition id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId();
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=anotherId";
  assertResultsPresentInDataResponse(url);

  // Parent id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=" + id;
  assertResultsPresentInDataResponse(url, childExecutionInSubProcess.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=anotherId";
  assertResultsPresentInDataResponse(url);

  // Activity id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=processTask";
  assertResultsPresentInDataResponse(url, childExecutionInTask.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=anotherId";
  assertResultsPresentInDataResponse(url);

  // Without tenant ID, before tenant is set
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  // Update the tenant for the deployment
  managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));

  // Without tenant ID, after tenant is set
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true";
  assertResultsPresentInDataResponse(url);

  // Tenant id
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant";
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant2";
  assertResultsPresentInDataResponse(url);

  // Tenant id like
  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%enant");
  assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId());

  url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%whatever");
  assertResultsPresentInDataResponse(url);
}
 
Example 18
Source File: ProcessDefinitionCacheTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void testStartProcessInstanceByIdAfterReboot() {

    // In case this test is run in a test suite, previous engines might
    // have been initialized and cached. First we close the
    // existing process engines to make sure that the db is clean
    // and that there are no existing process engines involved.
    ProcessEngines.destroy();

    // Creating the DB schema (without building a process engine)
    ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration();
    processEngineConfiguration.setProcessEngineName("reboot-test-schema");
    processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000");
    ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine();

    // Create process engine and deploy test process
    ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    processEngine.getRepositoryService().createDeployment().addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml").deploy();

    // verify existence of process definition
    List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();

    assertEquals(1, processDefinitions.size());

    // Start a new Process instance
    ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    String processInstanceId = processInstance.getId();
    assertNotNull(processInstance);

    // Close the process engine
    processEngine.close();
    assertNotNull(processEngine.getRuntimeService());

    // Reboot the process engine
    processEngine = new StandaloneProcessEngineConfiguration().setProcessEngineName("reboot-test").setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
        .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine();

    // Check if the existing process instance is still alive
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNotNull(processInstance);

    // Complete the task. That will end the process instance
    TaskService taskService = processEngine.getTaskService();
    Task task = taskService.createTaskQuery().list().get(0);
    taskService.complete(task.getId());

    // Check if the process instance has really ended. This means that the
    // process definition has
    // re-loaded into the process definition cache
    processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    assertNull(processInstance);

    // Extra check to see if a new process instance can be started as well
    processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId());
    assertNotNull(processInstance);

    // close the process engine
    processEngine.close();

    // Cleanup schema
    schemaProcessEngine.close();
  }
 
Example 19
Source File: HistoricProcessInstanceQueryTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment
public void testLocalization() throws Exception {
  ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("historicProcessLocalization");
  String processInstanceId = processInstance.getId();
  Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
  taskService.complete(task.getId());

  if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
    List<HistoricProcessInstance> processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list();
    assertEquals(1, processes.size());
    assertNull(processes.get(0).getName());
    assertNull(processes.get(0).getDescription());

    ObjectNode infoNode = dynamicBpmnService.changeLocalizationName("en-GB", "historicProcessLocalization", "Historic Process Name 'en-GB'");
    dynamicBpmnService.changeLocalizationDescription("en-GB", "historicProcessLocalization", "Historic Process Description 'en-GB'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);

    dynamicBpmnService.changeLocalizationName("en", "historicProcessLocalization", "Historic Process Name 'en'", infoNode);
    dynamicBpmnService.changeLocalizationDescription("en", "historicProcessLocalization", "Historic Process Description 'en'", infoNode);
    dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);

    processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list();
    assertEquals(1, processes.size());
    assertNull(processes.get(0).getName());
    assertNull(processes.get(0).getDescription());

    processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").list();
    assertEquals(1, processes.size());
    assertEquals("Historic Process Name 'en-GB'", processes.get(0).getName());
    assertEquals("Historic Process Description 'en-GB'", processes.get(0).getDescription());
    
    processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).listPage(0,10);
    assertEquals(1, processes.size());
    assertNull(processes.get(0).getName());
    assertNull(processes.get(0).getDescription());

    processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").listPage(0,10);
    assertEquals(1, processes.size());
    assertEquals("Historic Process Name 'en-GB'", processes.get(0).getName());
    assertEquals("Historic Process Description 'en-GB'", processes.get(0).getDescription());

    HistoricProcessInstance process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
    assertNull(process.getName());
    assertNull(process.getDescription());

    process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").singleResult();
    assertEquals("Historic Process Name 'en-GB'", process.getName());
    assertEquals("Historic Process Description 'en-GB'", process.getDescription());
    
    process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en").singleResult();
    assertEquals("Historic Process Name 'en'", process.getName());
    assertEquals("Historic Process Description 'en'", process.getDescription());
    
    process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-AU").withLocalizationFallback().singleResult();
    assertEquals("Historic Process Name 'en'", process.getName());
    assertEquals("Historic Process Description 'en'", process.getDescription());
  }
}
 
Example 20
Source File: AbstractProcessEngineTest.java    From openwebflow with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * 测试加签功能的持久化
 */
@Test
public void testInsertTasksWithPersistence() throws Exception
{
	ProcessInstance instance = _processEngine.getRuntimeService().startProcessInstanceByKey("test2");
	String processInstanceId = instance.getId();
	TaskService taskService = _processEngine.getTaskService();
	TaskFlowControlService tfcs = _taskFlowControlServiceFactory.create(instance.getId());
	//到了step2
	//在前面加两个节点
	Authentication.setAuthenticatedUserId("kermit");
	ActivityImpl[] as = tfcs.insertTasksAfter("step2", "bluejoe", "alex");
	//应该执行到了第一个节点
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());

	//此时模拟服务器重启
	ProcessEngine oldProcessEngine = _processEngine;
	rebuildApplicationContext();
	Assert.assertNotSame(oldProcessEngine, _processEngine);

	//重新构造以上对象
	instance = _processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId)
			.singleResult();
	taskService = _processEngine.getTaskService();
	tfcs = _taskFlowControlServiceFactory.create(instance.getId());

	//应该到了下一个节点
	Assert.assertEquals("bluejoe", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals(as[2].getId(), taskService.createTaskQuery().singleResult().getTaskDefinitionKey());
	Assert.assertEquals("alex", taskService.createTaskQuery().singleResult().getAssignee());
	//完成该节点
	taskService.complete(taskService.createTaskQuery().singleResult().getId());
	//应该到了下一个节点
	Assert.assertEquals("step3", taskService.createTaskQuery().singleResult().getTaskDefinitionKey());

	//确认历史轨迹里已保存
	//step1,step2,step2,step2-1,step2-2,step3
	List<HistoricActivityInstance> activities = _processEngine.getHistoryService()
			.createHistoricActivityInstanceQuery().processInstanceId(instance.getId()).list();
	Assert.assertEquals(6, activities.size());

	//删掉流程
	_processEngine.getRuntimeService().deleteProcessInstance(instance.getId(), "test");
}