Search in sources :

Example 1 with RepositoryException

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

the class SqaleAuditService method searchObjects.

@Override
@NotNull
public SearchResultList<AuditEventRecordType> searchObjects(@Nullable ObjectQuery query, @Nullable Collection<SelectorOptions<GetOperationOptions>> options, @NotNull OperationResult parentResult) throws SchemaException {
    OperationResult operationResult = parentResult.subresult(opNamePrefix + OP_SEARCH_OBJECTS).addParam("query", query).build();
    try {
        logSearchInputParameters(AuditEventRecordType.class, query, "Search audit");
        query = simplifyQuery(query);
        if (isNoneQuery(query)) {
            return new SearchResultList<>();
        }
        return executeSearchObjects(query, options, OP_SEARCH_OBJECTS);
    } catch (RepositoryException | RuntimeException e) {
        throw handledGeneralException(e, operationResult);
    } catch (Throwable t) {
        recordFatalError(operationResult, t);
        throw t;
    } finally {
        operationResult.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RepositoryException

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

the class SqaleAuditService method searchObjectsIterative.

@Override
public SearchResultMetadata searchObjectsIterative(@Nullable ObjectQuery query, @NotNull AuditResultHandler handler, @Nullable Collection<SelectorOptions<GetOperationOptions>> options, @NotNull OperationResult parentResult) throws SchemaException {
    Validate.notNull(handler, "Result handler must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    OperationResult operationResult = parentResult.subresult(opNamePrefix + OP_SEARCH_OBJECTS_ITERATIVE).addParam("type", AuditEventRecordType.class.getName()).addParam("query", query).build();
    try {
        logSearchInputParameters(AuditEventRecordType.class, query, "Iterative search audit");
        query = simplifyQuery(query);
        if (isNoneQuery(query)) {
            return new SearchResultMetadata().approxNumberOfAllResults(0);
        }
        return executeSearchObjectsIterative(query, handler, options, operationResult);
    } catch (RepositoryException | RuntimeException e) {
        throw handledGeneralException(e, operationResult);
    } catch (Throwable t) {
        recordFatalError(operationResult, t);
        throw t;
    } finally {
        operationResult.computeStatusIfUnknown();
    }
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException)

Example 3 with RepositoryException

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

the class SqaleAuditService method executeSearchObjectsIterative.

/*
    TODO: We should try to unify iterative search for repo and audit.
     There are some obvious differences - like the provider of the page results - the differences need to be
     captured before the common functionality.
     Then there are little nuances in filter/ordering:
     In repo there is no potential collision between provided filter/ordering and additional "technical" one for OID.
     In audit these can collide, but perhaps not every situation needs to be optimized and we can let DB do the work
     (e.g. superfluous timestamp conditions).
     See also iterativeSearchCondition() comment and ideas there.
     */
private SearchResultMetadata executeSearchObjectsIterative(ObjectQuery originalQuery, AuditResultHandler handler, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult operationResult) throws SchemaException, RepositoryException {
    try {
        ObjectPaging originalPaging = originalQuery != null ? originalQuery.getPaging() : null;
        // this is total requested size of the search
        Integer maxSize = originalPaging != null ? originalPaging.getMaxSize() : null;
        List<? extends ObjectOrdering> providedOrdering = originalPaging != null ? originalPaging.getOrderingInstructions() : null;
        if (providedOrdering != null && providedOrdering.size() > 1) {
            throw new RepositoryException("searchObjectsIterative() does not support ordering" + " by multiple paths (yet): " + providedOrdering);
        }
        ObjectQuery pagedQuery = prismContext().queryFactory().createQuery();
        ObjectPaging paging = prismContext().queryFactory().createPaging();
        if (originalPaging != null && originalPaging.getOrderingInstructions() != null) {
            originalPaging.getOrderingInstructions().forEach(o -> paging.addOrderingInstruction(o.getOrderBy(), o.getDirection()));
        }
        // TODO check of provided ordering
        paging.addOrderingInstruction(AuditEventRecordType.F_REPO_ID, OrderDirection.ASCENDING);
        pagedQuery.setPaging(paging);
        int pageSize = Math.min(repositoryConfiguration().getIterativeSearchByPagingBatchSize(), defaultIfNull(maxSize, Integer.MAX_VALUE));
        pagedQuery.getPaging().setMaxSize(pageSize);
        AuditEventRecordType lastProcessedObject = null;
        int handledObjectsTotal = 0;
        while (true) {
            if (maxSize != null && maxSize - handledObjectsTotal < pageSize) {
                // relevant only for the last page
                pagedQuery.getPaging().setMaxSize(maxSize - handledObjectsTotal);
            }
            // filterAnd() is quite null safe, even for both nulls
            ObjectFilter originalFilter = originalQuery != null ? originalQuery.getFilter() : null;
            pagedQuery.setFilter(ObjectQueryUtil.filterAndImmutable(originalFilter, iterativeSearchCondition(lastProcessedObject, providedOrdering)));
            // we don't call public searchObject to avoid subresults and query simplification
            logSearchInputParameters(AuditEventRecordType.class, pagedQuery, "Search audit iterative page");
            List<AuditEventRecordType> resultPage = executeSearchObjects(pagedQuery, options, OP_SEARCH_OBJECTS_ITERATIVE_PAGE);
            // process page results
            for (AuditEventRecordType auditEvent : resultPage) {
                lastProcessedObject = auditEvent;
                if (!handler.handle(auditEvent, operationResult)) {
                    return new SearchResultMetadata().approxNumberOfAllResults(handledObjectsTotal + 1).pagingCookie(lastProcessedObject.getRepoId().toString()).partialResults(true);
                }
                handledObjectsTotal += 1;
                if (maxSize != null && handledObjectsTotal >= maxSize) {
                    return new SearchResultMetadata().approxNumberOfAllResults(handledObjectsTotal).pagingCookie(lastProcessedObject.getRepoId().toString());
                }
            }
            if (resultPage.isEmpty() || resultPage.size() < pageSize) {
                return new SearchResultMetadata().approxNumberOfAllResults(handledObjectsTotal).pagingCookie(lastProcessedObject != null ? lastProcessedObject.getRepoId().toString() : null);
            }
        }
    } finally {
        // This just counts the operation and adds zero/minimal time not to confuse user
        // with what could be possibly very long duration.
        registerOperationFinish(registerOperationStart(OP_SEARCH_OBJECTS_ITERATIVE));
    }
}
Also used : AuditEventRecordType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException)

Example 4 with RepositoryException

use of com.evolveum.midpoint.repo.sqlbase.RepositoryException 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 5 with RepositoryException

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

RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)6 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)3 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)2 SqlQueryContext (com.evolveum.midpoint.repo.sqlbase.SqlQueryContext)2 SinglePathItemFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor)2 FlexibleRelationalPathBase (com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 AuditEventRecordType (com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType)2 Predicate (com.querydsl.core.types.Predicate)2 List (java.util.List)2 Function (java.util.function.Function)2 NotNull (org.jetbrains.annotations.NotNull)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 JsonbPath (com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath)1 JSONB_POLY_NORM_KEY (com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_NORM_KEY)1 JSONB_POLY_ORIG_KEY (com.evolveum.midpoint.repo.sqale.jsonb.JsonbUtils.JSONB_POLY_ORIG_KEY)1 ValueFilterValues (com.evolveum.midpoint.repo.sqlbase.filtering.ValueFilterValues)1 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)1 ItemValueFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.ItemValueFilterProcessor)1