Search in sources :

Example 1 with QueryParamBuilderFactory

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

the class UserTaskInstanceWithPotOwnerTest method testSearchTaskByPotOwnerQueryParamBuilder.

@Test
public void testSearchTaskByPotOwnerQueryParamBuilder() {
    query = new SqlQueryDefinition("jbpmHumanTasksPO", dataSourceJNDIname);
    query.setExpression("select t.actualowner_id as actualowner, t.CREATEDBY_ID as createdby, t.CREATEDON as CREATEDON, t.EXPIRATIONTIME as expirationDate, " + "t.id as TASKID, t.name as NAME, t.priority as PRIORITY, t.PROCESSINSTANCEID as PROCESSINSTANCEID, t.PROCESSID as PROCESSID, t.STATUS as STATUS,  " + "po.entity_id as POTOWNER, t.FORMNAME AS FORMNAME, p.processinstancedescription as PROCESSINSTANCEDESCRIPTION, t.subject as SUBJECT, t.deploymentid as DEPLOYMENTID " + "from TASK t " + "inner join PEOPLEASSIGNMENTS_POTOWNERS po on t.id=po.task_id " + "inner join PROCESSINSTANCELOG p on t.processinstanceid = p.processinstanceid");
    queryService.registerQuery(query);
    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);
    List<UserTaskInstanceWithPotOwnerDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    assertNotNull(taskInstanceLogs.get(0).getProcessInstanceDescription());
    QueryParamBuilderFactory qbFactory = new UserTaskPotOwnerQueryBuilderFactory();
    assertTrue(qbFactory.accept("potOwnerBuilder"));
    List<String> potOwners = new ArrayList<String>();
    potOwners.add("salaboy");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("potOwner", potOwners);
    QueryParamBuilder<?> paramBuilder = qbFactory.newInstance(parameters);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    potOwners = new ArrayList<String>();
    potOwners.add("wrongPotOwner");
    parameters = new HashMap<String, Object>();
    parameters.put("potOwner", potOwners);
    paramBuilder = qbFactory.newInstance(parameters);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceWithPotOwnerQueryMapper.get(), new QueryContext(), paramBuilder);
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : UserTaskPotOwnerQueryBuilderFactory(org.jbpm.kie.services.impl.query.builder.UserTaskPotOwnerQueryBuilderFactory) UserTaskInstanceWithPotOwnerDesc(org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryContext(org.kie.api.runtime.query.QueryContext) QueryParamBuilderFactory(org.jbpm.services.api.query.QueryParamBuilderFactory) SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 2 with QueryParamBuilderFactory

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

Aggregations

HashMap (java.util.HashMap)2 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 QueryParamBuilderFactory (org.jbpm.services.api.query.QueryParamBuilderFactory)2 Test (org.junit.Test)2 QueryContext (org.kie.api.runtime.query.QueryContext)2 ArrayList (java.util.ArrayList)1 UserTaskPotOwnerQueryBuilderFactory (org.jbpm.kie.services.impl.query.builder.UserTaskPotOwnerQueryBuilderFactory)1 TestQueryParamBuilderFactory (org.jbpm.kie.services.test.objects.TestQueryParamBuilderFactory)1 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)1 UserTaskInstanceWithPotOwnerDesc (org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc)1 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)1