org.activiti.engine.runtime.ProcessInstanceBuilder Java Examples

The following examples show how to use org.activiti.engine.runtime.ProcessInstanceBuilder. 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: ProcessInstanceBuilderImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceBuilder variable(String variableName, Object value) {
  if (this.variables == null) {
    this.variables = new HashMap<String, Object>();
  }
  this.variables.put(variableName, value);
  return this;
}
 
Example #2
Source File: ProcessInstanceBuilderImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessInstanceBuilder transientVariable(String variableName, Object value) {
    if (this.transientVariables == null) {
        this.transientVariables = new HashMap<>();
    }
    this.transientVariables.put(variableName, value);
    return this;
}
 
Example #3
Source File: ProcessInstanceBuilderImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessInstanceBuilder variable(String variableName, Object value) {
    if (this.variables == null) {
        this.variables = new HashMap<>();
    }
    this.variables.put(variableName, value);
    return this;
}
 
Example #4
Source File: DefaultFlowable5CompatibilityHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessInstance startProcessInstanceByMessage(String messageName, Map<String, Object> variables,
                                                     Map<String, Object> transientVariables, String businessKey, String tenantId) {

    try {

        ProcessInstanceBuilder processInstanceBuilder = getProcessEngine().getRuntimeService().createProcessInstanceBuilder();
        if (messageName != null) {
            processInstanceBuilder.messageName(messageName);
        }
        if (variables != null) {
            processInstanceBuilder.variables(variables);
        }
        if (transientVariables != null) {
            processInstanceBuilder.transientVariables(transientVariables);
        }
        if (businessKey != null) {
            processInstanceBuilder.businessKey(businessKey);
        }
        if (tenantId != null) {
            processInstanceBuilder.tenantId(tenantId);
        }

        org.activiti.engine.runtime.ProcessInstance activiti5ProcessInstance = processInstanceBuilder.start();
        return new Flowable5ProcessInstanceWrapper(activiti5ProcessInstance);

    } catch (org.activiti.engine.ActivitiException e) {
        handleActivitiException(e);
        return null;
    }
}
 
Example #5
Source File: DefaultFlowable5CompatibilityHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public ProcessInstance startProcessInstance(String processDefinitionKey, String processDefinitionId,
                                            Map<String, Object> variables, Map<String, Object> transientVariables, String businessKey, String tenantId, String processInstanceName) {

    org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(Authentication.getAuthenticatedUserId());

    try {

        ProcessInstanceBuilder processInstanceBuilder = getProcessEngine().getRuntimeService().createProcessInstanceBuilder();
        if (processDefinitionKey != null) {
            processInstanceBuilder.processDefinitionKey(processDefinitionKey);
        }
        if (processDefinitionId != null) {
            processInstanceBuilder.processDefinitionId(processDefinitionId);
        }
        if (variables != null) {
            processInstanceBuilder.variables(variables);
        }
        if (transientVariables != null) {
            processInstanceBuilder.transientVariables(transientVariables);
        }
        if (businessKey != null) {
            processInstanceBuilder.businessKey(businessKey);
        }
        if (tenantId != null) {
            processInstanceBuilder.tenantId(tenantId);
        }
        if (processInstanceName != null) {
            processInstanceBuilder.name(processInstanceName);
        }

        org.activiti.engine.runtime.ProcessInstance activiti5ProcessInstance = processInstanceBuilder.start();
        return new Flowable5ProcessInstanceWrapper(activiti5ProcessInstance);

    } catch (org.activiti.engine.ActivitiException e) {
        handleActivitiException(e);
        return null;
    }
}
 
Example #6
Source File: FormLeaveController.java    From my_curd with Apache License 2.0 5 votes vote down vote up
/**
 * 新增 action
 */
@TxConfig(ActivitiConfig.DATASOURCE_NAME)
@Before(Tx.class)
public void addAction() {
    // 保存业务表
    FormLeave formLeave = getBean(FormLeave.class, "");
    formLeave.setId(IdUtils.id())
            .setCreater(WebUtils.getSessionUsername(this))
            .setCreateTime(new Date());
    formLeave.save();

    //发起流程
    String businessFormInfoId = getPara("businessFormInfoId");
    if (StringUtils.isEmpty(businessFormInfoId)) {
        renderFail("businessFormInfoId 参数为空");
        return;
    }
    BusinessFormInfo info = BusinessFormInfo.dao.findById(businessFormInfoId);
    if (info == null) {
        renderFail("businessFormInfoId 参数错误");
        return;
    }
    SysUser sysUser = WebUtils.getSysUser(this);
    String processInstanceName = info.getName() + "-( " + sysUser.getRealName()
            + new DateTime(formLeave.getCreateTime()).toString(" yyyy/MM/dd HH:mm )");
    Authentication.setAuthenticatedUserId(WebUtils.getSessionUsername(this));
    ProcessInstanceBuilder builder = ActivitiKit.getRuntimeService().createProcessInstanceBuilder()
            .processDefinitionKey(info.getProcessKey())
            .businessKey(formLeave.getId())
            .processInstanceName(processInstanceName)
            .addVariable("businessForm", info.getFormName());
    builder.start();

    renderSuccess(NEW_PROCESS_SUCCESS);
}
 
Example #7
Source File: HistoricProcessInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {"org/activiti5/engine/test/history/oneTaskProcess.bpmn20.xml"})
public void testHistoricProcessInstanceName() {
 String piName = "Customized Process Instance Name";
 ProcessInstanceBuilder builder = runtimeService.createProcessInstanceBuilder();
 builder.processDefinitionKey("oneTaskProcess");
 builder.name(piName);
 ProcessInstance processInstance1 = builder.start();
	
 HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance1.getProcessInstanceId()).singleResult();
 assertEquals(piName, historicProcessInstance.getName());
 assertEquals(1, historyService.createHistoricProcessInstanceQuery().processInstanceName(piName).list().size());
}
 
Example #8
Source File: HistoricProcessInstanceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/history/oneTaskProcess.bpmn20.xml" })
public void testHistoricProcessInstanceName() {
  String piName = "Customized Process Instance Name";
  ProcessInstanceBuilder builder = runtimeService.createProcessInstanceBuilder();
  builder.processDefinitionKey("oneTaskProcess");
  builder.name(piName);
  ProcessInstance processInstance1 = builder.start();

  HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance1.getProcessInstanceId()).singleResult();
  assertEquals(piName, historicProcessInstance.getName());
  assertEquals(1, historyService.createHistoricProcessInstanceQuery().processInstanceName(piName).list().size());
}
 
Example #9
Source File: ProcessInstanceBuilderImpl.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceBuilder transientVariable(String variableName, Object value) {
  if (this.transientVariables == null) {
    this.transientVariables = new HashMap<String, Object>();
  }
  this.transientVariables.put(variableName, value);
  return this;
}
 
Example #10
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources={"org/activiti5/engine/test/api/oneTaskProcess.bpmn20.xml"})
public void testStartProcessInstanceByProcessInstanceBuilder() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
  
  ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  
  // by key
  ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("123").start();
  assertNotNull(processInstance);
  assertEquals("123", processInstance.getBusinessKey());
  assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  
  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  
  // by key, with processInstance name with variables
  processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("456").variable("var", "value")
      .name("processName1").start();
  assertNotNull(processInstance);
  assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("processName1", processInstance.getName());
  assertEquals("456", processInstance.getBusinessKey());
  assertEquals("value", runtimeService.getVariable(processInstance.getId(), "var"));
  
  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  
  // by id
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("789").start();
  assertNotNull(processInstance);
  assertEquals(3, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("789", processInstance.getBusinessKey());
  
  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  // by id with variables
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101123")
      .variable("var", "value2").start();
  assertNotNull(processInstance);
  assertEquals(4, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "var"));
  assertEquals("101123", processInstance.getBusinessKey());
  
  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  // by id and processInstance name
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101124")
      .name("processName2").start();
  assertNotNull(processInstance);
  assertEquals(5, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("processName2", processInstance.getName());
  assertEquals("101124", processInstance.getBusinessKey());
}
 
Example #11
Source File: RuntimeServiceTest.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testStartProcessInstanceByProcessInstanceBuilder() {
  ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();

  ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();

  // by key
  ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("123").start();
  assertNotNull(processInstance);
  assertEquals("123", processInstance.getBusinessKey());
  assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());

  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();

  // by key, with processInstance name with variables
  processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").businessKey("456").variable("var", "value").name("processName1").start();
  assertNotNull(processInstance);
  assertEquals(2, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("processName1", processInstance.getName());
  assertEquals("456", processInstance.getBusinessKey());
  assertEquals("value", runtimeService.getVariable(processInstance.getId(), "var"));

  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();

  // by id
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("789").start();
  assertNotNull(processInstance);
  assertEquals(3, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("789", processInstance.getBusinessKey());

  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  // by id with variables
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101123").variable("var", "value2").start();
  assertNotNull(processInstance);
  assertEquals(4, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("value2", runtimeService.getVariable(processInstance.getId(), "var"));
  assertEquals("101123", processInstance.getBusinessKey());

  processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
  // by id and processInstance name
  processInstance = processInstanceBuilder.processDefinitionId(processDefinition.getId()).businessKey("101124").name("processName2").start();
  assertNotNull(processInstance);
  assertEquals(5, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
  assertEquals("processName2", processInstance.getName());
  assertEquals("101124", processInstance.getBusinessKey());
}
 
Example #12
Source File: RuntimeServiceImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceBuilder createProcessInstanceBuilder() {
  return new ProcessInstanceBuilderImpl(this);
}
 
Example #13
Source File: ProcessInstanceBuilderImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceBuilder name(String processInstanceName) {
    this.processInstanceName = processInstanceName;
    return this;
}
 
Example #14
Source File: ProcessInstanceBuilderImpl.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstanceBuilder name(String processInstanceName) {
  this.processInstanceName = processInstanceName;
  return this;
}
 
Example #15
Source File: RuntimeServiceImpl.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessInstanceBuilder createProcessInstanceBuilder() {
    return new ProcessInstanceBuilderImpl(this);
}
 
Example #16
Source File: RuntimeService.java    From activiti6-boot2 with Apache License 2.0 2 votes vote down vote up
/** 
 * Create a {@link ProcessInstanceBuilder}, that allows to set various options for starting a process instance,
 * as an alternative to the various startProcessInstanceByXX methods. 
 */
ProcessInstanceBuilder createProcessInstanceBuilder();
 
Example #17
Source File: RuntimeService.java    From flowable-engine with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link ProcessInstanceBuilder}, that allows to set various options for starting a process instance, as an alternative to the various startProcessInstanceByXX methods.
 */
ProcessInstanceBuilder createProcessInstanceBuilder();