Search in sources :

Example 36 with DataSet

use of org.dashbuilder.dataset.DataSet in project jbpm by kiegroup.

the class QueryServiceImpl method query.

@Override
public <T> T query(String queryName, QueryResultMapper<T> mapper, QueryContext queryContext, QueryParamBuilder<?> paramBuilder) throws QueryNotFoundException {
    if (dataSetDefRegistry.getDataSetDef(queryName) == null) {
        throw new QueryNotFoundException("Query " + queryName + " not found");
    }
    logger.debug("About to query using {} definition with number of rows {} and starting at {} offset", queryName, queryContext.getCount(), queryContext.getOffset());
    DataSetLookupBuilder<?> builder = DataSetLookupFactory.newDataSetLookupBuilder().dataset(queryName).rowNumber(queryContext.getCount()).rowOffset(queryContext.getOffset());
    Object filter = paramBuilder.build();
    while (filter != null) {
        if (filter instanceof ColumnFilter) {
            // add filter
            builder.filter((ColumnFilter) filter);
        } else if (filter instanceof AggregateColumnFilter) {
            // add aggregate function
            builder.column(((AggregateColumnFilter) filter).getColumnId(), ((AggregateColumnFilter) filter).getType(), ((AggregateColumnFilter) filter).getColumnId());
        } else if (filter instanceof GroupColumnFilter) {
            GroupColumnFilter groupFilter = ((GroupColumnFilter) filter);
            // add group function
            builder.group(((GroupColumnFilter) filter).getColumnId(), ((GroupColumnFilter) filter).getNewColumnId());
            if (groupFilter.getIntervalSize() != null) {
                ((AbstractDataSetLookupBuilder<?>) builder).dynamic(groupFilter.getMaxIntervals(), DateIntervalType.valueOf(groupFilter.getIntervalSize()), true);
            }
        } else if (filter instanceof ExtraColumnFilter) {
            // add extra column
            builder.column(((ExtraColumnFilter) filter).getColumnId(), ((ExtraColumnFilter) filter).getNewColumnId());
        } else {
            logger.warn("Unsupported filter '{}' generated by '{}'", filter, paramBuilder);
        }
        // call builder again in case more parameters are available
        filter = paramBuilder.build();
    }
    // if advanced ordering is used process the ORDER BY clause into order by and sort order pairs
    if (queryContext instanceof AdvancedQueryContext && ((AdvancedQueryContext) queryContext).getOrderByClause() != null && !((AdvancedQueryContext) queryContext).getOrderByClause().isEmpty()) {
        String[] orderBySortOrderItems = ((AdvancedQueryContext) queryContext).getOrderByClause().split(",");
        for (String orderBySortOrderItem : orderBySortOrderItems) {
            String[] orderBySortOrder = orderBySortOrderItem.trim().split(" ");
            // check that sort order is given.  default to 'asc'.
            String sortOrder = orderBySortOrder.length == 1 ? "asc" : orderBySortOrder[1].trim();
            logger.debug("Applying order by clause '{}' with {}ending sort order", orderBySortOrder[0].trim(), sortOrder);
            builder.sort(orderBySortOrder[0].trim(), sortOrder);
        }
    } else {
        // use default simple ordering
        if (queryContext.getOrderBy() != null) {
            String[] oderByItems = queryContext.getOrderBy().split(",");
            for (String orderBy : oderByItems) {
                logger.debug("Applying order by {} and ascending {}", orderBy, queryContext.isAscending());
                builder.sort(orderBy.trim(), queryContext.isAscending() ? "asc" : "desc");
            }
        }
    }
    DataSet result = dataSetManager.lookupDataSet(builder.buildLookup());
    logger.debug("Query result is {}", result);
    T mappedResult = mapper.map(result);
    logger.debug("Mapped result is {}", mappedResult);
    return mappedResult;
}
Also used : AbstractDataSetLookupBuilder(org.dashbuilder.dataset.impl.AbstractDataSetLookupBuilder) DataSet(org.dashbuilder.dataset.DataSet) AdvancedQueryContext(org.kie.api.runtime.query.AdvancedQueryContext) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException)

Example 37 with DataSet

use of org.dashbuilder.dataset.DataSet in project jbpm by kiegroup.

the class ExecutionErrorQueryMapper method map.

@Override
public List<ExecutionError> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<ExecutionError> mappedResult = new ArrayList<ExecutionError>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                ExecutionError pi = buildInstance(dataSetResult, i);
                mappedResult.add(pi);
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : ExecutionError(org.kie.internal.runtime.error.ExecutionError) DataSet(org.dashbuilder.dataset.DataSet) ArrayList(java.util.ArrayList)

Example 38 with DataSet

use of org.dashbuilder.dataset.DataSet in project jbpm by kiegroup.

the class ProcessInstanceQueryMapper method map.

@Override
public List<ProcessInstanceDesc> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<ProcessInstanceDesc> mappedResult = new ArrayList<ProcessInstanceDesc>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                ProcessInstanceDesc pi = buildInstance(dataSetResult, i);
                mappedResult.add(pi);
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) ArrayList(java.util.ArrayList) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc)

Example 39 with DataSet

use of org.dashbuilder.dataset.DataSet in project jbpm by kiegroup.

the class RawListQueryMapper method map.

@Override
public List<List<Object>> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<List<Object>> mappedResult = new ArrayList<List<Object>>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                List<Object> row = buildInstance(dataSetResult, i);
                mappedResult.add(row);
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 40 with DataSet

use of org.dashbuilder.dataset.DataSet in project jbpm by kiegroup.

the class TaskSummaryQueryMapper method map.

@Override
public List<TaskSummary> map(Object result) {
    if (result instanceof DataSet) {
        DataSet dataSetResult = (DataSet) result;
        List<TaskSummary> mappedResult = new ArrayList<TaskSummary>();
        if (dataSetResult != null) {
            for (int i = 0; i < dataSetResult.getRowCount(); i++) {
                TaskSummary ut = buildInstance(dataSetResult, i);
                mappedResult.add(ut);
            }
        }
        return mappedResult;
    }
    throw new IllegalArgumentException("Unsupported result for mapping " + result);
}
Also used : DataSet(org.dashbuilder.dataset.DataSet) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList)

Aggregations

DataSet (org.dashbuilder.dataset.DataSet)41 Test (org.junit.Test)27 AbstractDisplayerTest (org.dashbuilder.displayer.client.AbstractDisplayerTest)25 AbstractDisplayer (org.dashbuilder.displayer.client.AbstractDisplayer)17 Displayer (org.dashbuilder.displayer.client.Displayer)13 ArrayList (java.util.ArrayList)12 RawDataSet (org.dashbuilder.dataset.RawDataSet)11 HashMap (java.util.HashMap)6 SelectorDisplayer (org.dashbuilder.renderer.client.selector.SelectorDisplayer)6 DataColumn (org.dashbuilder.dataset.DataColumn)3 DataSetLookup (org.dashbuilder.dataset.DataSetLookup)2 ProcessInstanceWithVarsDesc (org.jbpm.services.api.model.ProcessInstanceWithVarsDesc)2 UserTaskInstanceWithPotOwnerDesc (org.jbpm.services.api.model.UserTaskInstanceWithPotOwnerDesc)2 UserTaskInstanceWithVarsDesc (org.jbpm.services.api.model.UserTaskInstanceWithVarsDesc)2 Date (java.util.Date)1 List (java.util.List)1 DataSetBuilder (org.dashbuilder.dataset.DataSetBuilder)1 DataSetMetadata (org.dashbuilder.dataset.DataSetMetadata)1 DataColumnDef (org.dashbuilder.dataset.def.DataColumnDef)1 DataSetDef (org.dashbuilder.dataset.def.DataSetDef)1