use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetFilteredTaskInstancesAsPotOwners.
@Test
public void testGetFilteredTaskInstancesAsPotOwners() {
// let's grant managers role so process can be started
List<String> roles = new ArrayList<String>();
roles.add("managers");
identityProvider.setRoles(roles);
query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.FILTERED_PO_TASK);
query.setExpression(PO_TASK_QUERY);
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
identityProvider.setName("salaboy");
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(1, taskSummaries.size());
// let's now change the roles so user should not see instances
roles.clear();
roles.add("employees");
identityProvider.setRoles(roles);
identityProvider.setName("anotherUser");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(0, taskSummaries.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesWithOrderByClause.
/*
* JBPM-5468 adding support for full ORDER BY clause with QueryService. This test
* selects 3 processes and verifies sorting criteria specified by the ORDER BY clause.
*/
@Test
public void testGetProcessInstancesWithOrderByClause() {
query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
query.setExpression("select * from processinstancelog");
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queries.get(0);
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
List<ProcessInstanceDesc> instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new AdvancedQueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId2);
Long processInstanceId3 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jboss.qa.bpms.HumanTask");
assertNotNull(processInstanceId3);
String orderByClause = "processId asc, processInstanceId desc";
instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new AdvancedQueryContext(orderByClause));
assertNotNull(instances);
assertEquals(3, instances.size());
// Check that sorting criteria for processInstanceId is descending
assertTrue("Testing ORDER BY clause with descending sort order on processInstanceId failed", instances.get(2).getId() < instances.get(1).getId());
processService.abortProcessInstance(processInstanceId2);
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition 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.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstancesAsExcludedOwner.
@Test
public void testGetTaskInstancesAsExcludedOwner() {
final String potentialOwner = "maciej";
final String excludedOwner = "kris";
final List<String> roles = Arrays.asList("admins");
query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK);
query.setExpression(PO_TASK_QUERY);
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queries.get(0);
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>());
assertNotNull(processInstanceId);
identityProvider.setName(potentialOwner);
identityProvider.setRoles(roles);
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
identityProvider.setName(excludedOwner);
identityProvider.setRoles(roles);
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesCountAndGroup.
@Test
public void testGetProcessInstancesCountAndGroup() {
query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
query.setExpression("select * from processinstancelog");
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_PROCESSNAME)).append(QueryParam.count(COLUMN_PROCESSINSTANCEID)).get();
Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jboss.qa.bpms.HumanTask");
instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
assertNotNull(instances);
assertEquals(2, instances.size());
// write document process
List<Object> result = instances.iterator().next();
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.get(1) instanceof Number);
assertEquals(1, ((Number) result.get(1)).intValue());
// org.jboss.qa.bpms.HumanTask task process
result = instances.iterator().next();
assertNotNull(result);
assertEquals(2, result.size());
assertTrue(result.get(1) instanceof Number);
assertEquals(1, ((Number) result.get(1)).intValue());
processService.abortProcessInstance(processInstanceId2);
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
Aggregations