Search in sources :

Example 1 with NamedQueryMapper

use of org.jbpm.services.api.query.NamedQueryMapper in project jbpm by kiegroup.

the class QueryServiceImplTest method testGetProcessInstances.

@Test
public void testGetProcessInstances() {
    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());
    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) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) NamedQueryMapper(org.jbpm.services.api.query.NamedQueryMapper) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with NamedQueryMapper

use of org.jbpm.services.api.query.NamedQueryMapper 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

SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)2 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)2 NamedQueryMapper (org.jbpm.services.api.query.NamedQueryMapper)2 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)2 Test (org.junit.Test)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)1 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)1