Search in sources :

Example 26 with SqlQueryDefinition

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

the class QueryServiceImplTest method testGetProcessInstancesWithRawMapperMultipleRows.

@Test
public void testGetProcessInstancesWithRawMapperMultipleRows() {
    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<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext());
    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);
    instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext());
    assertNotNull(instances);
    assertEquals(2, instances.size());
    List<Object> firstRow = instances.get(0);
    assertNotNull(firstRow);
    assertEquals(18, firstRow.size());
    List<Object> secondRow = instances.get(1);
    assertNotNull(secondRow);
    assertEquals(18, secondRow.size());
    Assert.assertNotEquals(firstRow, secondRow);
    processService.abortProcessInstance(processInstanceId2);
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
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) List(java.util.List) ArrayList(java.util.ArrayList) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 27 with SqlQueryDefinition

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

the class QueryServiceImplTest method testGetProcessInstancesWithQueryParamBuilder.

@Test
public void testGetProcessInstancesWithQueryParamBuilder() {
    query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
    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);
    QueryParamBuilderFactory qbFactory = new TestQueryParamBuilderFactory();
    assertTrue(qbFactory.accept("test"));
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("min", processInstanceId);
    parameters.put("max", processInstanceId + 2);
    QueryParamBuilder<?> paramBuilder = qbFactory.newInstance(parameters);
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(instances);
    assertEquals(1, instances.size());
    parameters = new HashMap<String, Object>();
    parameters.put("min", processInstanceId + 2);
    parameters.put("max", 0l);
    paramBuilder = qbFactory.newInstance(parameters);
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(instances);
    assertEquals(0, instances.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : TestQueryParamBuilderFactory(org.jbpm.kie.services.test.objects.TestQueryParamBuilderFactory) QueryParamBuilderFactory(org.jbpm.services.api.query.QueryParamBuilderFactory) HashMap(java.util.HashMap) 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) TestQueryParamBuilderFactory(org.jbpm.kie.services.test.objects.TestQueryParamBuilderFactory) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 28 with SqlQueryDefinition

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

the class QueryServiceImplTest method testGetTaskInstancesAsPotOwners.

@Test
public void testGetTaskInstancesAsPotOwners() {
    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());
    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("notvalid");
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    identityProvider.setName("salaboy");
    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());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) QueryDefinition(org.jbpm.services.api.query.model.QueryDefinition) HashMap(java.util.HashMap) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) TaskSummary(org.kie.api.task.model.TaskSummary) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 29 with SqlQueryDefinition

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

the class QueryServiceImplTest method testGetProcessInstancesCount.

@Test
public void testGetProcessInstancesCount() {
    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());
    Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), QueryParam.count(COLUMN_PROCESSINSTANCEID));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    List<Object> result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(1, result.size());
    assertTrue(result.get(0) instanceof Number);
    assertEquals(0, ((Number) result.get(0)).intValue());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), QueryParam.count(COLUMN_PROCESSINSTANCEID));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(1, result.size());
    assertTrue(result.get(0) instanceof Number);
    assertEquals(1, ((Number) result.get(0)).intValue());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
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) List(java.util.List) ArrayList(java.util.ArrayList) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 30 with SqlQueryDefinition

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

the class QueryServiceImplTest method testGetProcessInstancesWithCustomVariables.

@Test
public void testGetProcessInstancesWithCustomVariables() throws Exception {
    deploymentService.deploy(deploymentUnitJPA);
    units.add(deploymentUnitJPA);
    query = new SqlQueryDefinition("getAllProcessInstancesWithCustomVariables", dataSourceJNDIname);
    query.setExpression("select pi.*,  c.firstname, c.lastname, c.age, c.customerId from ProcessInstanceLog pi " + "inner join (select mv.map_var_id, mv.processInstanceId from MappedVariable mv) mv " + "on (mv.processInstanceId = pi.processinstanceId) " + "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<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    ProcessInstanceWithVarsDesc instance = processInstanceLogs.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;
}
Also used : InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) ProcessInstanceWithVarsDesc(org.jbpm.services.api.model.ProcessInstanceWithVarsDesc) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) 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