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();
}
}
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();
}
}
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));
}
}
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());
}
}
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 + "'.");
}
}
Aggregations