use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testUnDeploymentWithActiveProcesses.
@Test
public void testUnDeploymentWithActiveProcesses() {
assertNotNull(deploymentService);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployedGeneral);
assertNotNull(deployedGeneral.getDeploymentUnit());
assertNotNull(deployedGeneral.getRuntimeManager());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("org.jbpm.writedocument", params);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
try {
// undeploy should fail due to active process instances
deploymentService.undeploy(deploymentUnit);
fail("Should fail due to active process instance");
} catch (IllegalStateException e) {
}
engine.getKieSession().abortProcessInstance(processInstance.getId());
checkFormsDeployment(deploymentUnit.getIdentifier());
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentOfProcessesOnDefaultKbaseAndKsession.
@Test
public void testDeploymentOfProcessesOnDefaultKbaseAndKsession() {
assertNotNull(deploymentService);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertNull(deployed.getDeployedAssetLocation("customtask"));
assertEquals(GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION, deployed.getDeploymentUnit().getIdentifier());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(3, processes.size());
processes = runtimeDataService.getProcessesByFilter("custom", new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
processes = runtimeDataService.getProcessesByDeploymentId(deploymentUnit.getIdentifier(), new QueryContext());
assertNotNull(processes);
assertEquals(3, processes.size());
ProcessDefinition process = runtimeDataService.getProcessesByDeploymentIdProcessId(deploymentUnit.getIdentifier(), "customtask");
assertNotNull(process);
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
params.put("id", "test");
ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
checkFormsDeployment(deploymentUnit.getIdentifier());
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class KModuleDeploymentServiceTest method testDeploymentAndExecutionOfProcessWithImports.
@Test
public void testDeploymentAndExecutionOfProcessWithImports() {
assertNotNull(deploymentService);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployedGeneral);
assertNotNull(deployedGeneral.getDeploymentUnit());
assertNotNull(deployedGeneral.getRuntimeManager());
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("Import", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
checkFormsDeployment(deploymentUnit.getIdentifier());
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class PostDeploymentServiceTest method testDeploymentOfProcesses.
@Test
public void testDeploymentOfProcesses() {
assertNotNull(deploymentService);
DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
assertNotNull(deployed);
assertNotNull(deployed.getDeploymentUnit());
assertNotNull(deployed.getRuntimeManager());
assertNotNull(runtimeDataService);
Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
assertNotNull(processes);
assertEquals(5, processes.size());
processes = runtimeDataService.getProcessesByFilter("custom", new QueryContext());
assertNotNull(processes);
assertEquals(1, processes.size());
processes = runtimeDataService.getProcessesByDeploymentId(deploymentUnit.getIdentifier(), new QueryContext());
assertNotNull(processes);
assertEquals(5, processes.size());
ProcessDefinition process = runtimeDataService.getProcessesByDeploymentIdProcessId(deploymentUnit.getIdentifier(), "customtask");
assertNotNull(process);
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
params.put("id", "test");
ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class TaskVariablesQueryServiceTest method testTaskVariableQueryOnBigTaskSetAsJPA.
@Test
public void testTaskVariableQueryOnBigTaskSetAsJPA() throws Exception {
Map<String, String> variableMap = new HashMap<String, String>();
variableMap.put("COUNTRY", "string");
variableMap.put("PRODUCTCODE", "string");
variableMap.put("QUANTITY", "integer");
variableMap.put("PRICE", "double");
variableMap.put("SALEDATE", "date");
SqlQueryDefinition query = new SqlQueryDefinition("getAllTaskInstancesWithCustomVariables", "jdbc/testDS1");
query.setExpression("select ti.*, c.country, c.productCode, c.quantity, c.price, c.saleDate " + "from AuditTaskImpl ti " + " inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + " on (mv.taskid = ti.taskId) " + " inner join ProductSale c " + " on (c.id = mv.map_var_id)");
queryService.registerQuery(query);
SqlQueryDefinition queryTPO = new SqlQueryDefinition("getMyTaskInstancesWithCustomVariables", "jdbc/testDS1", Target.PO_TASK);
queryTPO.setExpression("select ti.*, c.country, c.productCode, c.quantity, c.price, c.saleDate, oe.id oeid " + "from AuditTaskImpl ti " + " inner join (select mv.map_var_id, mv.taskid from MappedVariable mv) mv " + " on (mv.taskid = ti.taskId) " + " inner join ProductSale c " + " on (c.id = mv.map_var_id), " + " PeopleAssignments_PotOwners po, OrganizationalEntity oe " + " where ti.taskId = po.task_id and po.entity_id = oe.id");
queryService.registerQuery(queryTPO);
queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
long currentTime = System.currentTimeMillis();
Calendar cal = Calendar.getInstance();
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitSalesId);
assertNotNull(manager);
Class<?> clazz = Class.forName("org.jbpm.test.ProductSale", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Random random = new Random();
int i = 0;
for (i = 0; i < 10000; i++) {
cal.setTimeInMillis(currentTime);
// add random number of days
cal.add(Calendar.DAY_OF_YEAR, random.nextInt(60));
Object product = clazz.newInstance();
// set fields
setFieldValue(product, "country", countries.get(random.nextInt(9)));
setFieldValue(product, "productCode", productCodes.get(random.nextInt(9)));
setFieldValue(product, "quantity", random.nextInt(50));
setFieldValue(product, "price", (random.nextDouble() * 1000));
setFieldValue(product, "saleDate", cal.getTime());
Map<String, Object> params = new HashMap<String, Object>();
params.put("product", product);
params.put("sales", "john,actor" + i);
params.put("salesGroup", "Crusaders");
logger.debug("Params : " + params);
processService.startProcess(deploymentUnitSalesId, "product-sale.sale-product", params);
}
logger.info("Generated {} process instances... doing searches now", i);
logger.info("let's find tasks for product EAP only");
long timestamp = System.currentTimeMillis();
List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP or Wildfly");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.in("productCode", Arrays.asList("EAP", "WILDFLY")));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP and country Brazil");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product BPMS and BRMS by using wildcard search");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "B%"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product Weblogic or WebSphere by wildcard and country Canada");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.equalsTo("country", "Canada"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP and country Brazil and tasks with status Ready and Reserved");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"), QueryParam.in("status", Arrays.asList(Status.Ready.toString(), Status.Reserved.toString())));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product Weblogic or WebSphere by wildcard where quantity is bigger than 20");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.greaterOrEqualTo("quantity", 20));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP where sale was put in one month from now");
cal.setTimeInMillis(currentTime);
Date from = cal.getTime();
cal.add(Calendar.MONTH, 1);
Date to = cal.getTime();
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.between("saleDate", from, to));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
// now same queries but with user/group filtering
logger.info("################################################");
logger.info("Task with user/group filtering");
logger.info("################################################");
identityProvider.setName("john");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP or Wildfly");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.in("productCode", Arrays.asList("EAP", "WILDFLY")));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP and country Brazil");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product BPMS and BRMS by using wildcard search");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "B%"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product Weblogic or WebSphere by wildcard and country Canada");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.equalsTo("country", "Canada"));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP and country Brazil and tasks with status Ready and Reserved");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.equalsTo("country", "Brazil"), QueryParam.in("status", Arrays.asList(Status.Ready.toString(), Status.Reserved.toString())));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product Weblogic or WebSphere by wildcard where quantity is bigger than 20");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.likeTo("productCode", false, "WEB%"), QueryParam.greaterOrEqualTo("quantity", 20));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
logger.info("let's find tasks for product EAP where sale was put in one month from now");
timestamp = System.currentTimeMillis();
taskInstanceLogs = queryService.query(queryTPO.getName(), UserTaskInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext(), QueryParam.equalsTo("productCode", "EAP"), QueryParam.between("saleDate", from, to));
logger.info("Task query by variable took {} ms with result size {}", (System.currentTimeMillis() - timestamp), taskInstanceLogs.size());
}
Aggregations