Search in sources :

Example 11 with QueryDefinition

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

the class QueryServiceImplTest method testGetTaskInstancesAsExcludedOwner.

@Test
public void testGetTaskInstancesAsExcludedOwner() {
    final String potentialOwner = "maciej";
    final String excludedOwner = "kris";
    final List<String> roles = Arrays.asList("admins");
    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());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.ExcludedOwner", new HashMap<String, Object>());
    assertNotNull(processInstanceId);
    identityProvider.setName(potentialOwner);
    identityProvider.setRoles(roles);
    List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(1, taskInstanceLogs.size());
    identityProvider.setName(excludedOwner);
    identityProvider.setRoles(roles);
    taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
    assertNotNull(taskInstanceLogs);
    assertEquals(0, taskInstanceLogs.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) 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 12 with QueryDefinition

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

the class QueryServiceImplTest method testGetProcessInstancesCountAndGroup.

@Test
public void testGetProcessInstancesCountAndGroup() {
    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());
    QueryParam[] parameters = QueryParam.getBuilder().append(QueryParam.groupBy(COLUMN_PROCESSNAME)).append(QueryParam.count(COLUMN_PROCESSINSTANCEID)).get();
    Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
    assertNotNull(instances);
    assertEquals(0, instances.size());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jboss.qa.bpms.HumanTask");
    instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
    assertNotNull(instances);
    assertEquals(2, instances.size());
    // write document process
    List<Object> result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(2, result.size());
    assertTrue(result.get(1) instanceof Number);
    assertEquals(1, ((Number) result.get(1)).intValue());
    // org.jboss.qa.bpms.HumanTask task process
    result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(2, result.size());
    assertTrue(result.get(1) instanceof Number);
    assertEquals(1, ((Number) result.get(1)).intValue());
    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) QueryParam(org.jbpm.services.api.query.model.QueryParam) 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 13 with QueryDefinition

use of org.jbpm.services.api.query.model.QueryDefinition 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 14 with QueryDefinition

use of org.jbpm.services.api.query.model.QueryDefinition 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 15 with QueryDefinition

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

Aggregations

QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)22 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)20 Test (org.junit.Test)20 QueryContext (org.kie.api.runtime.query.QueryContext)20 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)17 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)15 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 List (java.util.List)9 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)9 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)4 QueryParam (org.jbpm.services.api.query.model.QueryParam)4 TaskSummary (org.kie.api.task.model.TaskSummary)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 QueryDefinitionEntity (org.jbpm.kie.services.impl.query.persistence.QueryDefinitionEntity)2 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)2 NamedQueryMapper (org.jbpm.services.api.query.NamedQueryMapper)2 PersistDataSetListener (org.jbpm.kie.services.impl.query.persistence.PersistDataSetListener)1 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)1