Search in sources :

Example 1 with UserTaskPotOwnerQueryBuilderFactory

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

Aggregations

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