Search in sources :

Example 6 with ColumnFilter

use of org.dashbuilder.dataset.filter.ColumnFilter in project jbpm by kiegroup.

the class PotOwnerTasksPreprocessor method preprocess.

@SuppressWarnings("rawtypes")
@Override
public void preprocess(DataSetLookup lookup) {
    if (identityProvider == null) {
        return;
    }
    final List<Comparable> orgEntities = new ArrayList<Comparable>(identityProvider.getRoles());
    orgEntities.add(identityProvider.getName());
    final ColumnFilter myGroupFilter = AND(equalsTo(COLUMN_ORGANIZATIONAL_ENTITY, orgEntities), OR(equalsTo(COLUMN_ACTUALOWNER, ""), isNull(COLUMN_ACTUALOWNER)));
    final ColumnFilter columnFilter = AND(OR(isNull(COLUMN_EXCLUDED_OWNER), notEqualsTo(COLUMN_EXCLUDED_OWNER, identityProvider.getName())), OR(myGroupFilter, equalsTo(COLUMN_ACTUALOWNER, identityProvider.getName())));
    LOGGER.debug("Adding column filter: {}", columnFilter);
    if (lookup.getFirstFilterOp() != null) {
        lookup.getFirstFilterOp().addFilterColumn(columnFilter);
    } else {
        DataSetFilter filter = new DataSetFilter();
        filter.addFilterColumn(columnFilter);
        lookup.addOperation(filter);
    }
    super.preprocess(lookup);
}
Also used : ArrayList(java.util.ArrayList) DataSetFilter(org.dashbuilder.dataset.filter.DataSetFilter) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter)

Example 7 with ColumnFilter

use of org.dashbuilder.dataset.filter.ColumnFilter 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 8 with ColumnFilter

use of org.dashbuilder.dataset.filter.ColumnFilter in project jbpm by kiegroup.

the class UserTaskPotOwnerQueryBuilder method build.

@Override
public ColumnFilter build() {
    // return null if it was already invoked
    if (built) {
        return null;
    }
    String columnName = "potOwner";
    UserGroupCallback userGroupCallback = UserDataServiceProvider.getUserGroupCallback();
    List<String> potOwners = (List<String>) parameters.get(columnName);
    List<String> potOwnersList = new ArrayList<String>();
    for (String potOwner : potOwners) {
        potOwnersList.add(potOwner);
        List<String> groups = userGroupCallback.getGroupsForUser(potOwner);
        if (groups != null) {
            potOwnersList.addAll(groups);
        }
    }
    ColumnFilter filter = FilterFactory.AND(FilterFactory.in(columnName, potOwnersList));
    filter.setColumnId(columnName);
    built = true;
    return filter;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ColumnFilter(org.dashbuilder.dataset.filter.ColumnFilter) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Aggregations

ColumnFilter (org.dashbuilder.dataset.filter.ColumnFilter)8 ArrayList (java.util.ArrayList)4 DataSetFilter (org.dashbuilder.dataset.filter.DataSetFilter)3 List (java.util.List)2 LogicalExprFilter (org.dashbuilder.dataset.filter.LogicalExprFilter)2 QueryParam (org.jbpm.services.api.query.model.QueryParam)2 DataSet (org.dashbuilder.dataset.DataSet)1 DataSetLookup (org.dashbuilder.dataset.DataSetLookup)1 DataSetMetadata (org.dashbuilder.dataset.DataSetMetadata)1 CoreFunctionFilter (org.dashbuilder.dataset.filter.CoreFunctionFilter)1 CoreFunctionType (org.dashbuilder.dataset.filter.CoreFunctionType)1 FilterFactory.equalsTo (org.dashbuilder.dataset.filter.FilterFactory.equalsTo)1 LogicalExprType (org.dashbuilder.dataset.filter.LogicalExprType)1 AggregateFunctionType (org.dashbuilder.dataset.group.AggregateFunctionType)1 AbstractDataSetLookupBuilder (org.dashbuilder.dataset.impl.AbstractDataSetLookupBuilder)1 QueryNotFoundException (org.jbpm.services.api.query.QueryNotFoundException)1 COLUMN_ORGANIZATIONAL_ENTITY (org.jbpm.services.api.query.QueryResultMapper.COLUMN_ORGANIZATIONAL_ENTITY)1 Test (org.junit.Test)1 AdvancedQueryContext (org.kie.api.runtime.query.AdvancedQueryContext)1 UserGroupCallback (org.kie.api.task.UserGroupCallback)1