use of org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstancesWithVariables.
@Test
public void testGetTaskInstancesWithVariables() {
query = new SqlQueryDefinition("getAllTaskInputInstancesWithVariables", dataSourceJNDIname);
query.setExpression("select ti.*, tv.name tvname, tv.value tvvalue from AuditTaskImpl ti " + "inner join (select tv.taskId, tv.name, tv.value from TaskVariableImpl tv where tv.type = 0 ) tv " + "on (tv.taskId = ti.taskId)");
queryService.registerQuery(query);
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
params.put("approval_translatedDocument", "translated content");
params.put("approval_reviewComment", "reviewed content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
UserTaskInstanceWithVarsDesc instance = taskInstanceLogs.get(0);
assertEquals(3, instance.getVariables().size());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Write a Document"));
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
instance = taskInstanceLogs.get(0);
assertEquals(1, instance.getVariables().size());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Wrong Comment"));
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc in project jbpm by kiegroup.
the class QueryServiceEJBIntegrationTest method testGetTaskInstancesWithVariables.
@Test
public void testGetTaskInstancesWithVariables() {
query = new SqlQueryDefinition("getAllTaskInputInstancesWithVariables", "java:jboss/datasources/ExampleDS");
query.setExpression("select ti.*, tv.name tvname, tv.value tvvalue from AuditTaskImpl ti " + "inner join (select tv.taskId, tv.name, tv.value from TaskVariableImpl tv where tv.type = 0 ) tv " + "on (tv.taskId = ti.taskId)");
queryService.registerQuery(query);
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
params.put("approval_translatedDocument", "translated content");
params.put("approval_reviewComment", "reviewed content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
List<UserTaskInstanceWithVarsDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
UserTaskInstanceWithVarsDesc instance = taskInstanceLogs.get(0);
assertEquals(5, instance.getVariables().size());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Write a Document"));
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
instance = taskInstanceLogs.get(0);
assertEquals(1, instance.getVariables().size());
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_TASK_VAR_NAME, "Comment"), QueryParam.equalsTo(COLUMN_TASK_VAR_VALUE, "Wrong Comment"));
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc 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.jbpm.services.api.model.UserTaskInstanceWithVarsDesc 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());
}
use of org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc in project jbpm by kiegroup.
the class UserTaskInstanceWithVarsQueryMapper method map.
@Override
public List<UserTaskInstanceWithVarsDesc> map(Object result) {
if (result instanceof DataSet) {
DataSet dataSetResult = (DataSet) result;
List<UserTaskInstanceWithVarsDesc> mappedResult = new ArrayList<UserTaskInstanceWithVarsDesc>();
if (dataSetResult != null) {
Map<Long, UserTaskInstanceWithVarsDesc> tmp = new HashMap<Long, UserTaskInstanceWithVarsDesc>();
for (int i = 0; i < dataSetResult.getRowCount(); i++) {
Long taskId = getColumnLongValue(dataSetResult, COLUMN_TASKID, i);
UserTaskInstanceWithVarsDesc ut = tmp.get(taskId);
if (ut == null) {
ut = buildInstance(dataSetResult, i);
mappedResult.add(ut);
tmp.put(taskId, ut);
}
// now add variable
String varName = getColumnStringValue(dataSetResult, COLUMN_TASK_VAR_NAME, i);
String varValue = getColumnStringValue(dataSetResult, COLUMN_TASK_VAR_VALUE, i);
((org.jbpm.kie.services.impl.model.UserTaskInstanceWithVarsDesc) ut).addVariable(varName, varValue);
}
}
return mappedResult;
}
throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Aggregations