Search in sources :

Example 6 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter 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)

Example 7 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter in project midpoint by Evolveum.

the class UuidItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<Object> filter) throws RepositoryException {
    // This is adapted version of ItemValueFilterProcessor#createBinaryCondition.
    // Because conversion is different for various operations, we don't use ValueFilterValues.
    FilterOperation operation = operation(filter);
    if (filter.getValues() == null || filter.getValues().isEmpty()) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    if (filter.getValues().size() > 1) {
        if (operation.isAnyEqualOperation()) {
            List<UUID> oids = filter.getValues().stream().map(s -> UUID.fromString(uuidString(s.getValue()))).collect(Collectors.toList());
            return ExpressionUtils.predicate(Ops.IN, operation.treatPathForIn(path), ConstantImpl.create(oids));
        } else {
            throw new QueryException("Multi-value for other than EQUAL filter: " + filter);
        }
    }
    // noinspection ConstantConditions
    String oid = uuidString(filter.getSingleValue().getValue());
    if (oid.length() < OID_MIN.length()) {
        // operator is enough, ignore case doesn't play any role for UUID type
        return processIncompleteOid(oid, operation.operator, filter);
    } else {
        // singleValuePredicate() treatment is not necessary, let's just create the predicate
        return ExpressionUtils.predicate(operation.operator, path, ConstantImpl.create(UUID.fromString(oid)));
    }
}
Also used : FlexibleRelationalPathBase(com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase) SqlQueryContext(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext) ExpressionUtils(com.querydsl.core.types.ExpressionUtils) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) Ops(com.querydsl.core.types.Ops) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) UUID(java.util.UUID) UuidPath(com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) List(java.util.List) SinglePathItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor) ConstantImpl(com.querydsl.core.types.ConstantImpl) Predicate(com.querydsl.core.types.Predicate) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) SimpleItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SimpleItemFilterProcessor) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) UUID(java.util.UUID)

Aggregations

PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)7 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)5 Predicate (com.querydsl.core.types.Predicate)3 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)2 SqlQueryContext (com.evolveum.midpoint.repo.sqlbase.SqlQueryContext)2 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)2 SinglePathItemFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor)2 FlexibleRelationalPathBase (com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase)2 List (java.util.List)2 Function (java.util.function.Function)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)1 ProvisioningContext (com.evolveum.midpoint.provisioning.impl.ProvisioningContext)1 ProvisioningContextFactory (com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory)1