Search in sources :

Example 31 with QueryException

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

the class JsonbPolysPathItemFilterProcessor method processPolyStringBoth.

private Predicate processPolyStringBoth(ValueFilterValues<?, ?> values) throws QueryException {
    Object value = values.singleValueRaw();
    // empty values treated in main process()
    assert value != null;
    if (!(value instanceof PolyString)) {
        throw new QueryException("PolyString value must be provided to match both orig and norm values, was: " + value + " (type " + value.getClass() + ")");
    }
    // must be Poly here
    PolyString poly = (PolyString) value;
    return predicateWithNotTreated(path, booleanTemplate("{0} @> {1}::jsonb", path, String.format("[{\"" + JSONB_POLY_ORIG_KEY + "\":\"%s\",\"" + JSONB_POLY_NORM_KEY + "\":\"%s\"}]", poly.getOrig(), poly.getNorm())));
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 32 with QueryException

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

the class AuditCustomColumnItemFilterProcessor method createPredicate.

private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
    FilterOperation operation = operation(filter);
    Path<?> path = context.path().getPath(customColumnPropertyType.getName());
    if (customColumnPropertyType.getValue() == null) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)

Example 33 with QueryException

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

the class OrgFilterProcessor method process.

@Override
public Predicate process(OrgFilter filter) throws QueryException {
    // necessary for lazy refresh of org closure
    context.markContainsOrgFilter();
    FlexibleRelationalPathBase<?> path = context.root();
    if (!(path instanceof QObject)) {
        throw new QueryException("Org filter can only be used for objects," + " not for path " + path + " of type " + path.getClass());
    }
    QObject<?> objectPath = (QObject<?>) path;
    if (filter.isRoot()) {
        QObjectReference<MObject> ref = getNewRefAlias();
        return subQuery(ref).where(ref.ownerOid.eq(objectPath.oid)).notExists();
    }
    if (filter.getOrgRef() == null) {
        throw new QueryException("No organization reference defined in the search query.");
    }
    String oidParam = filter.getOrgRef().getOid();
    if (oidParam == null) {
        throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
    }
    QName relation = filter.getOrgRef().getRelation();
    // null means ANY (not "default") here, so we only search/normalize non-nulls
    Integer relationId = relation != null ? context.repositoryContext().searchCachedRelationId(relation) : null;
    if (filter.getScope() == OrgFilter.Scope.ONE_LEVEL) {
        QObjectReference<MObject> ref = getNewRefAlias();
        SQLQuery<?> subQuery = subQuery(ref).where(ref.ownerOid.eq(objectPath.oid).and(ref.targetOid.eq(UUID.fromString(oidParam))));
        if (relationId != null) {
            subQuery.where(ref.relationId.eq(relationId));
        }
        return subQuery.exists();
    } else if (filter.getScope() == OrgFilter.Scope.SUBTREE) {
        QObjectReference<MObject> ref = getNewRefAlias();
        QOrgClosure oc = getNewClosureAlias();
        SQLQuery<?> subQuery = subQuery(ref).join(oc).on(oc.descendantOid.eq(ref.targetOid)).where(ref.ownerOid.eq(objectPath.oid).and(oc.ancestorOid.eq(UUID.fromString(oidParam))));
        if (relationId != null) {
            subQuery.where(ref.relationId.eq(relationId));
        }
        return subQuery.exists();
    } else if (filter.getScope() == OrgFilter.Scope.ANCESTORS) {
        QOrgClosure oc = getNewClosureAlias();
        return subQuery(oc).where(oc.ancestorOid.eq(objectPath.oid).and(oc.descendantOid.eq(UUID.fromString(oidParam))).and(oc.ancestorOid.ne(oc.descendantOid))).exists();
    } else {
        throw new QueryException("Unknown scope if org filter: " + filter);
    }
}
Also used : QName(javax.xml.namespace.QName) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) SQLQuery(com.querydsl.sql.SQLQuery) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) QOrgClosure(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference)

Example 34 with QueryException

use of com.evolveum.midpoint.repo.sqlbase.QueryException 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)

Example 35 with QueryException

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

the class ObjectRetriever method executeQueryDiagnosticsRequest.

public RepositoryQueryDiagResponse executeQueryDiagnosticsRequest(RepositoryQueryDiagRequest request, OperationResult result) {
    LOGGER_PERFORMANCE.debug("> execute query diagnostics {}", request);
    Session session = null;
    try {
        // beware, not all databases support read-only transactions!
        session = baseHelper.beginReadOnlyTransaction();
        final String implementationLevelQuery;
        final Map<String, RepositoryQueryDiagResponse.ParameterValue> implementationLevelQueryParameters;
        final Query<?> query;
        final boolean isMidpointQuery = request.getImplementationLevelQuery() == null;
        if (isMidpointQuery) {
            QueryEngine engine = new QueryEngine(getConfiguration(), extItemDictionary, prismContext, relationRegistry);
            RQueryImpl rQuery = (RQueryImpl) engine.interpret(request.getQuery(), request.getType(), request.getOptions(), false, session);
            query = rQuery.getQuery();
            implementationLevelQuery = query.getQueryString();
            implementationLevelQueryParameters = new HashMap<>();
            for (Map.Entry<String, QueryParameterValue> entry : rQuery.getQuerySource().getParameters().entrySet()) {
                implementationLevelQueryParameters.put(entry.getKey(), new RepositoryQueryDiagResponse.ParameterValue(entry.getValue().getValue(), entry.getValue().toString()));
            }
        } else {
            implementationLevelQuery = (String) request.getImplementationLevelQuery();
            implementationLevelQueryParameters = new HashMap<>();
            query = session.createQuery(implementationLevelQuery);
        }
        List<?> objects = request.isTranslateOnly() ? null : query.list();
        if (isMidpointQuery && objects != null) {
            // raw GetObjectResult instances are useless outside repo-sql-impl module, so we'll convert them to objects
            @SuppressWarnings("unchecked") List<GetObjectResult> listOfGetObjectResults = (List<GetObjectResult>) objects;
            objects = queryResultToPrismObjects(listOfGetObjectResults, request.getType(), null, session, result);
        }
        RepositoryQueryDiagResponse response = new RepositoryQueryDiagResponse(objects, implementationLevelQuery, implementationLevelQueryParameters);
        session.getTransaction().rollback();
        return response;
    } catch (SchemaException | QueryException | RuntimeException ex) {
        baseHelper.handleGeneralException(ex, session, result);
        throw new IllegalStateException("shouldn't get here");
    } finally {
        baseHelper.cleanupSessionAndResult(session, result);
    }
}
Also used : QueryParameterValue(com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QueryParameterValue(com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue) QueryEngine(com.evolveum.midpoint.repo.sql.query.QueryEngine) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl)

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