Search in sources :

Example 1 with ProcessInstanceBuilder

use of org.activiti.engine.runtime.ProcessInstanceBuilder in project Activiti by Activiti.

the class HistoricProcessInstanceTest method testHistoricProcessInstanceName.

@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.processInstanceName(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());
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ProcessInstanceBuilder

use of org.activiti.engine.runtime.ProcessInstanceBuilder in project Activiti by Activiti.

the class RuntimeServiceTest method testStartProcessInstanceByProcessInstanceBuilder.

@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").addVariable("var", "value").processInstanceName("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").addVariable("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").processInstanceName("processName2").start();
    assertNotNull(processInstance);
    assertEquals(5, runtimeService.createProcessInstanceQuery().processDefinitionKey("oneTaskProcess").count());
    assertEquals("processName2", processInstance.getName());
    assertEquals("101124", processInstance.getBusinessKey());
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with ProcessInstanceBuilder

use of org.activiti.engine.runtime.ProcessInstanceBuilder in project midpoint by Evolveum.

the class ActivitiInterface method startActivitiProcessInstance.

public void startActivitiProcessInstance(StartProcessCommand spic, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    String owner = spic.getProcessOwner();
    if (owner != null) {
        activitiEngine.getIdentityService().setAuthenticatedUserId(owner);
    }
    RuntimeService rs = activitiEngine.getProcessEngine().getRuntimeService();
    ProcessInstanceBuilder builder = rs.createProcessInstanceBuilder().processDefinitionKey(spic.getProcessName()).processInstanceName(spic.getProcessInstanceName());
    for (Map.Entry<String, Object> varEntry : spic.getVariables().entrySet()) {
        builder.addVariable(varEntry.getKey(), varEntry.getValue());
    }
    ProcessInstance pi = builder.start();
    if (spic.isSendStartConfirmation()) {
        // let us send a reply back (useful for listener-free processes)
        ProcessStartedEvent event = new ProcessStartedEvent(pi.getProcessInstanceId(), // a bit of hack...
        ((ExecutionEntity) pi).getVariables(), processInterfaceFinder);
        event.setRunning(!pi.isEnded());
        LOGGER.trace("Event to be sent to IDM: {}", event);
        wfTaskController.onProcessEvent(event, task, result);
    }
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ProcessInstanceBuilder

use of org.activiti.engine.runtime.ProcessInstanceBuilder in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowProcessInstanceService method startProcess.

@Override
@Transactional
public ProcessInstance startProcess(String definitionKey, String objectType, String applicant, String objectIdentifier, Map<String, Object> variables) {
    Assert.hasText(definitionKey, "Definition key cannot be null!");
    UUID implementerId = securityService.getCurrentId();
    IdmIdentityDto applicantIdentity = null;
    if (applicant != null) {
        applicantIdentity = identityService.getByUsername(applicant);
    }
    ProcessInstanceBuilder builder = runtimeService.createProcessInstanceBuilder().processDefinitionKey(// 
    definitionKey).addVariable(WorkflowProcessInstanceService.OBJECT_TYPE, objectType).addVariable(WorkflowProcessInstanceService.ACTIVITI_SKIP_EXPRESSION_ENABLED, // Allow skip expression on user task
    Boolean.TRUE).addVariable(WorkflowProcessInstanceService.OBJECT_IDENTIFIER, objectIdentifier).addVariable(WorkflowProcessInstanceService.IMPLEMENTER_IDENTIFIER, implementerId == null ? null : implementerId.toString()).addVariable(WorkflowProcessInstanceService.APPLICANT_USERNAME, applicant).addVariable(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER, applicantIdentity != null ? applicantIdentity.getId() : null);
    if (variables != null) {
        for (Entry<String, Object> entry : variables.entrySet()) {
            builder.addVariable(entry.getKey(), entry.getValue());
        }
    }
    ProcessInstance instance = builder.start();
    if (!instance.isEnded()) {
        // must explicit check null, else throw org.activiti.engine.ActivitiIllegalArgumentException: userId and groupId cannot both be null
        if (applicantIdentity != null) {
            // Set applicant as owner of process
            runtimeService.addUserIdentityLink(instance.getId(), applicantIdentity.getId().toString(), IdentityLinkType.OWNER);
        }
        if (implementerId != null) {
            // Set current logged user (implementer) as starter of process
            runtimeService.addUserIdentityLink(instance.getId(), implementerId.toString(), IdentityLinkType.STARTER);
        }
    }
    return instance;
}
Also used : ProcessInstanceBuilder(org.activiti.engine.runtime.ProcessInstanceBuilder) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProcessInstance (org.activiti.engine.runtime.ProcessInstance)4 ProcessInstanceBuilder (org.activiti.engine.runtime.ProcessInstanceBuilder)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)2 Deployment (org.activiti.engine.test.Deployment)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 RuntimeService (org.activiti.engine.RuntimeService)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 Transactional (org.springframework.transaction.annotation.Transactional)1