use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class QueryServiceImpl method getQueries.
@Override
public List<QueryDefinition> getQueries(QueryContext queryContext) {
List<QueryDefinition> result = new ArrayList<QueryDefinition>();
Map<String, Object> params = new HashMap<String, Object>();
applyQueryContext(params, queryContext);
List<QueryDefinitionEntity> queries = commandService.execute(new QueryNameCommand<List<QueryDefinitionEntity>>("getQueryDefinitions", params));
for (QueryDefinitionEntity entity : queries) {
QueryDefinition definition = entity.toQueryDefinition();
result.add(definition);
}
return result;
}
use of org.jbpm.services.api.query.model.QueryDefinition in project jbpm by kiegroup.
the class QueryServiceEJBIntegrationTest method testGetProcessInstances.
@Test
public void testGetProcessInstances() {
query = new SqlQueryDefinition("getAllProcessInstances", "java:jboss/datasources/ExampleDS");
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());
Collection<ProcessInstanceDesc> instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(1, (int) instances.iterator().next().getState());
// search using named mapper to refer to query mappers by name
instances = queryService.query(query.getName(), new NamedQueryMapper<Collection<ProcessInstanceDesc>>("ProcessInstances"), new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(1, (int) instances.iterator().next().getState());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(COLUMN_PROCESSNAME, false));
assertNotNull(instances);
assertEquals(1, instances.size());
assertEquals(3, (int) instances.iterator().next().getState());
}
Aggregations