Search in sources :

Example 26 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class ValueFilterProcessor method processRight.

private <TQ extends FlexibleRelationalPathBase<TR>, TR> RightHandProcessor processRight(ItemPath path) throws RepositoryException {
    if (path.size() == 1) {
        QName itemName = path.firstToQName();
        RightHandProcessor filterProcessor = mapping.itemMapper(itemName).createRightHandProcessor(context);
        if (filterProcessor == null) {
            throw new QueryException("Filtering on " + path + " is not supported.");
        // this should not even happen, we can't even create a Query that would cause this
        }
        return filterProcessor;
    } else {
        // noinspection DuplicatedCode
        ItemRelationResolver.ResolutionResult<TQ, TR> resolution = mapping.<TQ, TR>relationResolver(path).resolve(context);
        SqlQueryContext<?, TQ, TR> subcontext = resolution.context;
        ValueFilterProcessor<TQ, TR> nestedProcessor = new ValueFilterProcessor<>(subcontext, resolution.mapping);
        if (resolution.subquery) {
            throw new RepositoryException("Right path " + path + "is not single value");
        }
        return nestedProcessor.processRight(path.rest());
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QName(javax.xml.namespace.QName) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) ItemValueFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.ItemValueFilterProcessor) ItemRelationResolver(com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)

Example 27 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class ValueFilterProcessor method process.

private <TQ extends FlexibleRelationalPathBase<TR>, TR> Predicate process(ItemPath path, ValueFilter<?, ?> filter, RightHandProcessor right) throws RepositoryException {
    // isSingleName/asSingleName or firstName don't work for T_ID (OID)
    if (path.size() == 1) {
        QName itemName = path.firstToQName();
        ItemValueFilterProcessor<ValueFilter<?, ?>> filterProcessor = mapping.itemMapper(itemName).createFilterProcessor(context);
        if (filterProcessor == null) {
            throw new QueryException("Filtering on " + path + " is not supported.");
        // this should not even happen, we can't even create a Query that would cause this
        }
        if (right != null) {
            return filterProcessor.process(filter, right);
        }
        return filterProcessor.process(filter);
    } else {
        // noinspection DuplicatedCode
        ItemRelationResolver.ResolutionResult<TQ, TR> resolution = mapping.<TQ, TR>relationResolver(path).resolve(context);
        SqlQueryContext<?, TQ, TR> subcontext = resolution.context;
        ValueFilterProcessor<TQ, TR> nestedProcessor = new ValueFilterProcessor<>(subcontext, resolution.mapping);
        Predicate predicate = nestedProcessor.process(path.rest(), filter, right);
        if (resolution.subquery) {
            return subcontext.sqlQuery().where(predicate).exists();
        } else {
            return predicate;
        }
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QName(javax.xml.namespace.QName) ValueFilter(com.evolveum.midpoint.prism.query.ValueFilter) ItemValueFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.ItemValueFilterProcessor) ItemRelationResolver(com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver) Predicate(com.querydsl.core.types.Predicate)

Example 28 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class DetailTableItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<String> filter) throws RepositoryException {
    SqlQueryContext<?, DQ, DR> subcontext = context.subquery(detailQueryType);
    SQLQuery<?> subquery = subcontext.sqlQuery();
    subquery.where(joinOnPredicate.apply(context.path(), subcontext.path()));
    FilterProcessor<ValueFilter<?, ?>> filterProcessor = nestedItemMapper.createFilterProcessor(subcontext);
    if (filterProcessor == null) {
        throw new QueryException("Filtering on " + filter.getPath() + " is not supported.");
    // this should not even happen, we can't even create a Query that would cause this
    }
    Predicate predicate = filterProcessor.process(filter);
    if (predicate instanceof Operation && ((Operation<?>) predicate).getOperator().equals(Ops.IS_NULL)) {
        return subquery.notExists();
    } else {
        return subquery.where(predicate).exists();
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) ValueFilter(com.evolveum.midpoint.prism.query.ValueFilter) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) Operation(com.querydsl.core.types.Operation) Predicate(com.querydsl.core.types.Predicate)

Example 29 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class FullTextFilterProcessor method process.

@Override
public Predicate process(FullTextFilter filter) throws QueryException {
    if (filter.getValues().size() != 1) {
        throw new QueryException("FullText filter currently supports only a single string");
    }
    String text = filter.getValues().iterator().next();
    String normalized = PrismContext.get().getDefaultPolyStringNormalizer().normalize(text);
    String[] words = StringUtils.split(normalized);
    if (words.length == 0) {
        // no condition, matches everything
        return null;
    }
    Predicate predicate = null;
    for (String word : words) {
        // and() is null safe on both sides
        predicate = ExpressionUtils.and(predicate, // We know it's object context, so we can risk the cast.
        ((QObject<?>) context.root()).fullTextInfo.contains(word));
    }
    return predicate;
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) Predicate(com.querydsl.core.types.Predicate)

Example 30 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException in project midpoint by Evolveum.

the class JsonbPolysPathItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<T> filter) throws RepositoryException {
    String matchingRule = filter.getMatchingRule() != null ? filter.getMatchingRule().getLocalPart() : null;
    if (!(filter instanceof EqualFilter) || STRICT_IGNORE_CASE.equals(matchingRule) || ORIG_IGNORE_CASE.equals(matchingRule) || NORM_IGNORE_CASE.equals(matchingRule)) {
        throw new QueryException("Can't translate filter '" + filter + "' to operation." + " JSONB stored poly strings support only equals with no IC matching rule.");
    }
    List<?> filterValues = filter.getValues();
    if (filterValues == null || filterValues.isEmpty()) {
        return path.isNull();
    }
    ValueFilterValues<?, ?> values = ValueFilterValues.from(filter);
    if (Strings.isNullOrEmpty(matchingRule) || DEFAULT.equals(matchingRule) || STRICT.equals(matchingRule)) {
        // The value here should be poly-string, otherwise it never matches both orig and norm.
        return processPolyStringBoth(values);
    } else if (ORIG.equals(matchingRule)) {
        return processPolyStringComponent(convertPolyValuesToString(values, filter, p -> p.getOrig()), JSONB_POLY_ORIG_KEY);
    } else if (NORM.equals(matchingRule)) {
        return processPolyStringComponent(convertPolyValuesToString(values, filter, p -> p.getNorm()), JSONB_POLY_NORM_KEY);
    } else {
        throw new QueryException("Unknown matching rule '" + matchingRule + "'.");
    }
}
Also used : Expressions.booleanTemplate(com.querydsl.core.types.dsl.Expressions.booleanTemplate) FlexibleRelationalPathBase(com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase) JSONB_POLY_ORIG_KEY(com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_ORIG_KEY) SqlQueryContext(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext) JSONB_POLY_NORM_KEY(com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_NORM_KEY) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) JsonbPath(com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath) Function(java.util.function.Function) PolyStringItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.PolyStringItemFilterProcessor) Strings(com.google.common.base.Strings) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) List(java.util.List) ValueFilterValues(com.evolveum.midpoint.repo.sqlbase.filtering.ValueFilterValues) SinglePathItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor) Predicate(com.querydsl.core.types.Predicate) NotNull(org.jetbrains.annotations.NotNull) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)46 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 QName (javax.xml.namespace.QName)9 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)8 Predicate (com.querydsl.core.types.Predicate)8 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)6 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)5 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Condition (com.evolveum.midpoint.repo.sql.query.hqm.condition.Condition)4 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 RPolyString (com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString)3 HqlDataInstance (com.evolveum.midpoint.repo.sql.query.resolution.HqlDataInstance)3 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)3 ItemRelationResolver (com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver)3 NotNull (org.jetbrains.annotations.NotNull)3 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)2 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)2 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)2