Search in sources :

Example 1 with QueryParam

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

the class CoreFunctionQueryParamBuilder method build.

@Override
public Object build() {
    if (filterParams.length == 0 || filterParams.length <= index) {
        return null;
    }
    QueryParam param = filterParams[index];
    index++;
    if ("group".equalsIgnoreCase(param.getOperator())) {
        // if operator is group consider it as group functions
        if (param.getValue().size() > 1) {
            return new GroupColumnFilter(param.getColumn(), (String) param.getValue().get(0), (String) param.getValue().get(1), (Integer) param.getValue().get(2));
        } else {
            return new GroupColumnFilter(param.getColumn(), (String) param.getValue().get(0), null, -1);
        }
    }
    // check core functions
    CoreFunctionType type = CoreFunctionType.getByName(param.getOperator());
    if (type != null) {
        return new CoreFunctionFilter(param.getColumn(), type, param.getValue());
    }
    LogicalExprType logicalExprType = LogicalExprType.getByName(param.getOperator());
    if (logicalExprType != null) {
        return new LogicalExprFilter(param.getColumn(), logicalExprType, (List<ColumnFilter>) param.getValue());
    }
    // check aggregate functions
    AggregateFunctionType aggregationType = AggregateFunctionType.getByName(param.getOperator());
    if (aggregationType != null) {
        return new AggregateColumnFilter(aggregationType, param.getColumn(), (String) param.getValue().get(0));
    }
    return new ExtraColumnFilter(param.getColumn(), (String) param.getValue().get(0));
}
Also used : CoreFunctionFilter(org.dashbuilder.dataset.filter.CoreFunctionFilter) AggregateFunctionType(org.dashbuilder.dataset.group.AggregateFunctionType) QueryParam(org.jbpm.services.api.query.model.QueryParam) LogicalExprType(org.dashbuilder.dataset.filter.LogicalExprType) CoreFunctionType(org.dashbuilder.dataset.filter.CoreFunctionType) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) LogicalExprFilter(org.dashbuilder.dataset.filter.LogicalExprFilter)

Example 2 with QueryParam

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

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

the class QueryServiceImplTest method testGetProcessInstancesGroupWithoutInterval.

@Test
public void testGetProcessInstancesGroupWithoutInterval() {
    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_START)).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");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
    // expected date is day when processes started
    String expectedDate = sdf.format(new Date());
    instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
    assertNotNull(instances);
    assertEquals(1, instances.size());
    // write document process
    List<Object> result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedDate, result.get(0));
    processService.abortProcessInstance(processInstanceId2);
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) Date(java.util.Date) 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) SimpleDateFormat(java.text.SimpleDateFormat) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 4 with QueryParam

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

the class QueryServiceImplTest method testGetProcessInstancesGroupWithInterval.

@Test
public void testGetProcessInstancesGroupWithInterval() {
    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_START, QueryParam.DAY, 30)).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");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    // expected date is day when processes started
    String expectedDate = sdf.format(new Date());
    instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), parameters);
    assertNotNull(instances);
    assertEquals(1, instances.size());
    // write document process
    List<Object> result = instances.iterator().next();
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(expectedDate, result.get(0));
    processService.abortProcessInstance(processInstanceId2);
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) QueryContext(org.kie.api.runtime.query.QueryContext) Date(java.util.Date) 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) SimpleDateFormat(java.text.SimpleDateFormat) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 5 with QueryParam

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

the class CoreFunctionQueryParamBuilderTest method testLogicalExprPassedAsQueryParam.

@Test
public void testLogicalExprPassedAsQueryParam() {
    ArrayList values = new ArrayList();
    values.add("value1");
    values.add("value2");
    final ColumnFilter filter1 = likeTo(COLUMN_PROCESSNAME, "%processName%");
    final ColumnFilter filter2 = likeTo(COLUMN_PROCESSID, "%processName%");
    ArrayList terms = new ArrayList();
    terms.add(filter1);
    terms.add(filter2);
    QueryParam queryParam = new QueryParam("", LogicalExprType.OR.toString(), terms);
    ArrayList queryParams = new ArrayList();
    queryParams.add(queryParam);
    coreFunctionQueryParamBuilder = new CoreFunctionQueryParamBuilder(queryParam);
    Object builded = coreFunctionQueryParamBuilder.build();
    assertTrue(builded instanceof LogicalExprFilter);
    assertEquals("(" + COLUMN_PROCESSNAME + " like %processName%, true OR " + COLUMN_PROCESSID + " like %processName%, true)", builded.toString());
}
Also used : QueryParam(org.jbpm.services.api.query.model.QueryParam) ArrayList(java.util.ArrayList) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) LogicalExprFilter(org.dashbuilder.dataset.filter.LogicalExprFilter) Test(org.junit.Test)

Aggregations

QueryParam (org.jbpm.services.api.query.model.QueryParam)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 List (java.util.List)4 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)4 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)4 QueryDefinition (org.jbpm.services.api.query.model.QueryDefinition)4 QueryContext (org.kie.api.runtime.query.QueryContext)4 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ColumnFilter (org.dashbuilder.dataset.filter.ColumnFilter)2 LogicalExprFilter (org.dashbuilder.dataset.filter.LogicalExprFilter)2 HashMap (java.util.HashMap)1 CoreFunctionFilter (org.dashbuilder.dataset.filter.CoreFunctionFilter)1 CoreFunctionType (org.dashbuilder.dataset.filter.CoreFunctionType)1 LogicalExprType (org.dashbuilder.dataset.filter.LogicalExprType)1 AggregateFunctionType (org.dashbuilder.dataset.group.AggregateFunctionType)1 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)1 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)1