Search in sources :

Example 21 with QueryDefinition

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;
}
Also used : QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) QueryDefinitionEntity(org.jbpm.kie.services.impl.query.persistence.QueryDefinitionEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 22 with QueryDefinition

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());
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) NamedQueryMapper(org.jbpm.services.api.query.NamedQueryMapper) Test(org.junit.Test)

Aggregations

QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)22 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)20 Test (org.junit.Test)20 QueryContext (org.kie.api.runtime.query.QueryContext)20 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)17 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 List (java.util.List)9 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)9 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)4 QueryParam (org.jbpm.services.api.query.model.QueryParam)4 TaskSummary (org.kie.api.task.model.TaskSummary)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 QueryDefinitionEntity (org.jbpm.kie.services.impl.query.persistence.QueryDefinitionEntity)2 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)2 NamedQueryMapper (org.jbpm.services.api.query.NamedQueryMapper)2 PersistDataSetListener (org.jbpm.kie.services.impl.query.persistence.PersistDataSetListener)1 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)1