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