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());
}
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());
}
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);
}
}
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;
}
Aggregations