Search in sources :

Example 26 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class AsyncStartProcessCommand method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResults execute(CommandContext ctx) throws Exception {
    String deploymentId = getDeploymentId(ctx);
    String processId = (String) getData("ProcessId", ctx);
    String correlationKey = (String) getData("CorrelationKey", ctx);
    Map<String, Object> variables = (Map<String, Object>) getData("Variables", ctx);
    if (deploymentId == null || processId == null) {
        throw new IllegalArgumentException("Deployment id and process id is required");
    }
    RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(deploymentId);
    if (runtimeManager == null) {
        throw new IllegalArgumentException("No runtime manager found for deployment id " + deploymentId);
    }
    RuntimeEngine engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get());
    try {
        if (correlationKey == null || correlationKey.isEmpty()) {
            engine.getKieSession().startProcess(processId, variables);
        } else {
            String[] correlationKeyProperties = correlationKey.split(",");
            CorrelationKey ck = correlationKeyFactory.newCorrelationKey(Arrays.asList(correlationKeyProperties));
            ((CorrelationAwareProcessRuntime) engine.getKieSession()).startProcess(processId, ck, variables);
        }
        return new ExecutionResults();
    } finally {
        runtimeManager.disposeRuntimeEngine(engine);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) CorrelationKey(org.kie.internal.process.CorrelationKey) ExecutionResults(org.kie.api.executor.ExecutionResults) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Map(java.util.Map)

Example 27 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class ProcessServiceImplWithoutAuditTest method testStartProcessWithCorrelationKey.

@Test
public void testStartProcessWithCorrelationKey() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "customtask", key);
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(deploymentUnit.getIdentifier(), key);
    assertNull(pi);
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 28 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class RuntimeDataServiceImplTest method testGetProcessInstancesByCorrelationKey.

@Test
public void testGetProcessInstancesByCorrelationKey() {
    Collection<ProcessInstanceDesc> instances = runtimeDataService.getProcessInstances(new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", key);
    assertNotNull(processInstanceId);
    Collection<ProcessInstanceDesc> keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(key, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    ProcessInstanceDesc instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("my business key", instance.getCorrelationKey());
    List<UserTaskInstanceDesc> tasks = instance.getActiveTasks();
    assertNull(tasks);
    processService.abortProcessInstance(processInstanceId);
    instance = runtimeDataService.getProcessInstanceByCorrelationKey(key);
    processInstanceId = null;
    assertNull(instance);
    keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(key, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    instance = keyedInstances.iterator().next();
    assertEquals(3, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("my business key", instance.getCorrelationKey());
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 29 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class RuntimeDataServiceImplTest method testGetProcessInstancesByPartialCorrelationKey.

@Test
public void testGetProcessInstancesByPartialCorrelationKey() {
    Collection<ProcessInstanceDesc> instances = runtimeDataService.getProcessInstances(new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    List<String> props = new ArrayList<String>();
    props.add("first");
    props.add("second");
    props.add("third");
    List<String> partial1props = new ArrayList<String>();
    partial1props.add("first");
    partial1props.add("second");
    List<String> partial2props = new ArrayList<String>();
    partial2props.add("first");
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(props);
    CorrelationKey partialKey1 = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(partial1props);
    CorrelationKey partialKey2 = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey(partial2props);
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", key);
    assertNotNull(processInstanceId);
    Collection<ProcessInstanceDesc> keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(key, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    ProcessInstanceDesc instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    List<UserTaskInstanceDesc> tasks = instance.getActiveTasks();
    assertNull(tasks);
    // search by partial key 1
    keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(partialKey1, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    // search by partial key 2
    keyedInstances = runtimeDataService.getProcessInstancesByCorrelationKey(partialKey2, new QueryContext());
    assertNotNull(keyedInstances);
    assertEquals(1, keyedInstances.size());
    instance = keyedInstances.iterator().next();
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    assertEquals("first:second:third", instance.getCorrelationKey());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : CorrelationKey(org.kie.internal.process.CorrelationKey) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 30 with CorrelationKey

use of org.kie.internal.process.CorrelationKey in project jbpm by kiegroup.

the class ProcessServiceImplTest method testStartProcessWithParmsWithCorrelationKey.

@Test
public void testStartProcessWithParmsWithCorrelationKey() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", "test");
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "customtask", key, params);
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(key);
    assertNull(pi);
}
Also used : HashMap(java.util.HashMap) CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

CorrelationKey (org.kie.internal.process.CorrelationKey)38 Test (org.junit.Test)27 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)12 QueryContext (org.kie.api.runtime.query.QueryContext)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)8 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)6 KieSession (org.kie.api.runtime.KieSession)6 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)5 Collection (java.util.Collection)4 List (java.util.List)4 Map (java.util.Map)4 Collectors.toList (java.util.stream.Collectors.toList)4 RegistryContext (org.drools.core.command.impl.RegistryContext)4 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)4 RuntimeDataService (org.jbpm.services.api.RuntimeDataService)4