use of org.kie.api.runtime.manager.RuntimeManager 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.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class ProcessTest method testEvaluationProcess.
@Test
public void testEvaluationProcess() {
RuntimeManager manager = createRuntimeManager("Evaluation.bpmn");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
KieRuntimeLogger log = KieServices.Factory.get().getLoggers().newThreadedFileLogger(ksession, "test", 1000);
TaskService taskService = engine.getTaskService();
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("employee", "krisv");
params.put("reason", "Yearly performance evaluation");
ProcessInstance processInstance = ksession.startProcess("com.sample.evaluation", params);
System.out.println("Process started ...");
// complete Self Evaluation
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
System.out.println("'krisv' completing task " + task.getName() + ": " + task.getDescription());
taskService.start(task.getId(), "krisv");
Map<String, Object> results = new HashMap<String, Object>();
results.put("performance", "exceeding");
taskService.complete(task.getId(), "krisv", results);
// john from HR
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
task = tasks.get(0);
System.out.println("'john' completing task " + task.getName() + ": " + task.getDescription());
taskService.claim(task.getId(), "john");
taskService.start(task.getId(), "john");
results = new HashMap<String, Object>();
results.put("performance", "acceptable");
taskService.complete(task.getId(), "john", results);
// mary from PM
tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, tasks.size());
task = tasks.get(0);
System.out.println("'mary' completing task " + task.getName() + ": " + task.getDescription());
taskService.claim(task.getId(), "mary");
taskService.start(task.getId(), "mary");
results = new HashMap<String, Object>();
results.put("performance", "outstanding");
taskService.complete(task.getId(), "mary", results);
assertProcessInstanceNotActive(processInstance.getId(), ksession);
System.out.println("Process instance completed");
log.close();
manager.disposeRuntimeEngine(engine);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstancesWithCustomVariables.
@Test
public void testGetTaskInstancesWithCustomVariables() throws Exception {
deploymentService.deploy(deploymentUnitJPA);
units.add(deploymentUnitJPA);
query = new SqlQueryDefinition("getAllTaskInstancesWithCustomVariables", dataSourceJNDIname);
query.setExpression("select ti.*, c.firstname, c.lastname, c.age, c.customerId from AuditTaskImpl ti " + "inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + "on (mv.taskid = ti.taskId) " + "inner join Customer c " + "on (c.id = mv.map_var_id)");
queryService.registerQuery(query);
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitJPA.getIdentifier());
assertNotNull(manager);
Class<?> clazz = Class.forName("org.jbpm.test.Customer", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object cinstance = clazz.newInstance();
// set fields
setFieldValue(cinstance, "firstName", "john");
setFieldValue(cinstance, "lastName", "doe");
setFieldValue(cinstance, "age", new Integer(45));
setFieldValue(cinstance, "customerId", new Long(1234));
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", cinstance);
processInstanceId = processService.startProcess(deploymentUnitJPA.getIdentifier(), "persistence-test.customer-evaluation", params);
assertNotNull(processInstanceId);
Map<String, String> variableMap = new HashMap<String, String>();
variableMap.put("FIRSTNAME", "string");
variableMap.put("LASTNAME", "string");
variableMap.put("AGE", "integer");
variableMap.put("CUSTOMERID", "long");
List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
UserTaskInstanceWithVarsDesc instance = taskInstanceLogs.get(0);
assertEquals(4, instance.getVariables().size());
assertTrue(instance.getVariables().containsKey("FIRSTNAME"));
assertTrue(instance.getVariables().containsKey("LASTNAME"));
assertTrue(instance.getVariables().containsKey("AGE"));
assertTrue(instance.getVariables().containsKey("CUSTOMERID"));
assertEquals("john", instance.getVariables().get("FIRSTNAME"));
assertEquals("doe", instance.getVariables().get("LASTNAME"));
assertEquals(45, instance.getVariables().get("AGE"));
assertEquals(1234l, instance.getVariables().get("CUSTOMERID"));
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesWithCustomVariables.
@Test
public void testGetProcessInstancesWithCustomVariables() throws Exception {
deploymentService.deploy(deploymentUnitJPA);
units.add(deploymentUnitJPA);
query = new SqlQueryDefinition("getAllProcessInstancesWithCustomVariables", dataSourceJNDIname);
query.setExpression("select pi.*, c.firstname, c.lastname, c.age, c.customerId from ProcessInstanceLog pi " + "inner join (select mv.map_var_id, mv.processInstanceId from MappedVariable mv) mv " + "on (mv.processInstanceId = pi.processinstanceId) " + "inner join Customer c " + "on (c.id = mv.map_var_id)");
queryService.registerQuery(query);
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitJPA.getIdentifier());
assertNotNull(manager);
Class<?> clazz = Class.forName("org.jbpm.test.Customer", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object cinstance = clazz.newInstance();
// set fields
setFieldValue(cinstance, "firstName", "john");
setFieldValue(cinstance, "lastName", "doe");
setFieldValue(cinstance, "age", new Integer(45));
setFieldValue(cinstance, "customerId", new Long(1234));
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", cinstance);
processInstanceId = processService.startProcess(deploymentUnitJPA.getIdentifier(), "persistence-test.customer-evaluation", params);
assertNotNull(processInstanceId);
Map<String, String> variableMap = new HashMap<String, String>();
variableMap.put("FIRSTNAME", "string");
variableMap.put("LASTNAME", "string");
variableMap.put("AGE", "integer");
variableMap.put("CUSTOMERID", "long");
List<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
assertNotNull(processInstanceLogs);
assertEquals(1, processInstanceLogs.size());
ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
assertEquals(4, instance.getVariables().size());
assertTrue(instance.getVariables().containsKey("FIRSTNAME"));
assertTrue(instance.getVariables().containsKey("LASTNAME"));
assertTrue(instance.getVariables().containsKey("AGE"));
assertTrue(instance.getVariables().containsKey("CUSTOMERID"));
assertEquals("john", instance.getVariables().get("FIRSTNAME"));
assertEquals("doe", instance.getVariables().get("LASTNAME"));
assertEquals(45, instance.getVariables().get("AGE"));
assertEquals(1234l, instance.getVariables().get("CUSTOMERID"));
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentOfProcessWithDescriptorWitSecurityManager.
@Test(expected = SecurityException.class)
public void testDeploymentOfProcessWithDescriptorWitSecurityManager() {
assertNotNull(deploymentService);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION);
List<String> processes = new ArrayList<String>();
processes.add("repo/processes/general/customtask.bpmn");
processes.add("repo/processes/general/humanTask.bpmn");
processes.add("repo/processes/general/import.bpmn");
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addWorkItemHandler(new NamedObjectModel("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler")).addRequiredRole("experts");
Map<String, String> resources = new HashMap<String, String>();
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
File pom = new File("target/kmodule", "pom.xml");
pom.getParentFile().mkdir();
try {
FileOutputStream fs = new FileOutputStream(pom);
fs.write(getPom(releaseId).getBytes());
fs.close();
} catch (Exception e) {
}
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, pom);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployedGeneral);
assertNotNull(deployedGeneral.getDeploymentUnit());
assertNotNull(deployedGeneral.getRuntimeManager());
DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(0, descriptor.getMarshallingStrategies().size());
assertEquals(0, descriptor.getConfiguration().size());
assertEquals(0, descriptor.getEnvironmentEntries().size());
assertEquals(0, descriptor.getEventListeners().size());
assertEquals(0, descriptor.getGlobals().size());
assertEquals(0, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(1, descriptor.getRequiredRoles().size());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
manager.getRuntimeEngine(EmptyContext.get());
checkFormsDeployment(deploymentUnit.getIdentifier());
}
Aggregations