Search in sources :

Example 36 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetProcessInstancesByProcessId.

@Test
public void testGetProcessInstancesByProcessId() {
    query = new SqlQueryDefinition("getAllProcessInstances", "java:jboss/datasources/ExampleDS");
    query.setExpression("select * from processinstancelog");
    queryService.registerQuery(query);
    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(), QueryParam.likeTo(COLUMN_PROCESSID, true, "org.jbpm%"));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Example 37 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition 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)

Example 38 with SqlQueryDefinition

use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetProcessInstancesWithVariables.

@Test
public void testGetProcessInstancesWithVariables() {
    query = new SqlQueryDefinition("getAllProcessInstancesWithVariables", "java:jboss/datasources/ExampleDS");
    query.setExpression("select pil.*, v.variableId, v.value " + "from ProcessInstanceLog pil " + "inner join (select vil.processInstanceId ,vil.variableId, MAX(vil.ID) maxvilid  FROM VariableInstanceLog vil " + "GROUP BY vil.processInstanceId, vil.variableId ORDER BY vil.processInstanceId)  x " + "ON (v.variableId = x.variableId  AND v.id = x.maxvilid )" + "INNER JOIN VariableInstanceLog v " + "ON (v.processInstanceId = pil.processInstanceId)");
    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<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
    assertEquals(3, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "approval_document"));
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    instance = processInstanceLogs.get(0);
    assertEquals(1, instance.getVariables().size());
    processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithVarsQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_VAR_NAME, "not existing"));
    assertNotNull(processInstanceLogs);
    assertEquals(0, processInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Aggregations

SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)38 Test (org.junit.Test)37 QueryContext (org.kie.api.runtime.query.QueryContext)37 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)29 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)23 HashMap (java.util.HashMap)22 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)20 ArrayList (java.util.ArrayList)11 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)11 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)9 List (java.util.List)7 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)4 QueryParam (org.jbpm.services.api.query.model.QueryParam)4 Date (java.util.Date)3 ProcessInstanceWithVarsDesc (org.jbpm.services.api.model.ProcessInstanceWithVarsDesc)3 UserTaskInstanceWithPotOwnerDesc (org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)3 SimpleDateFormat (java.text.SimpleDateFormat)2