use of com.evolveum.midpoint.model.api.hooks.HookRegistry in project midpoint by Evolveum.
the class ModelController method searchObjectsIterative.
@Override
public <T extends ObjectType> SearchResultMetadata searchObjectsIterative(Class<T> type, ObjectQuery origQuery, ResultHandler<T> handler, Collection<SelectorOptions<GetOperationOptions>> rawOptions, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Validate.notNull(type, "Object type must not be null.");
Validate.notNull(parentResult, "Result type must not be null.");
ObjectQuery query = origQuery != null ? origQuery.clone() : null;
if (query != null) {
ModelImplUtils.validatePaging(query.getPaging());
}
OP_LOGGER.trace("MODEL OP enter searchObjectsIterative({},{},{})", type.getSimpleName(), query, rawOptions);
final OperationResult result = parentResult.createSubresult(SEARCH_OBJECTS);
result.addParam(OperationResult.PARAM_QUERY, query);
final Collection<SelectorOptions<GetOperationOptions>> options = preProcessOptionsSecurity(rawOptions, task, result);
final GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
ObjectTypes.ObjectManager searchProvider = ObjectTypes.getObjectManagerForClass(type);
if (searchProvider == null || searchProvider == ObjectTypes.ObjectManager.MODEL || GetOperationOptions.isRaw(rootOptions)) {
searchProvider = ObjectTypes.ObjectManager.REPOSITORY;
}
result.addArbitraryObjectAsParam("searchProvider", searchProvider);
// see MID-6115
ObjectQuery processedQuery = preProcessQuerySecurity(type, query, rootOptions, task, result);
if (isFilterNone(processedQuery, result)) {
LOGGER.trace("Skipping search because filter is NONE");
return null;
}
ResultHandler<T> internalHandler = (object, parentResult1) -> {
try {
object = object.cloneIfImmutable();
if (hookRegistry != null) {
for (ReadHook hook : hookRegistry.getAllReadHooks()) {
// TODO result or parentResult??? [med]
hook.invoke(object, options, task, result);
}
}
executeResolveOptions(object.asObjectable(), options, task, result);
schemaTransformer.applySchemasAndSecurity(object, rootOptions, options, null, task, parentResult1);
} catch (SchemaException | ObjectNotFoundException | SecurityViolationException | ExpressionEvaluationException | CommunicationException | ConfigurationException ex) {
parentResult1.recordFatalError(ex);
throw new SystemException(ex.getMessage(), ex);
}
OP_LOGGER.debug("MODEL OP handle searchObjects({},{},{}): {}", type.getSimpleName(), query, rawOptions, object);
if (OP_LOGGER.isTraceEnabled()) {
OP_LOGGER.trace("MODEL OP handle searchObjects({},{},{}):\n{}", type.getSimpleName(), query, rawOptions, object.debugDump(1));
}
return handler.handle(object, parentResult1);
};
SearchResultMetadata metadata;
try {
// skip using cache to avoid potentially many objects there (MID-4615, MID-4959)
enterModelMethodNoRepoCache();
logQuery(processedQuery);
try {
switch(searchProvider) {
case REPOSITORY:
metadata = cacheRepositoryService.searchObjectsIterative(type, processedQuery, internalHandler, options, true, result);
break;
case PROVISIONING:
metadata = provisioning.searchObjectsIterative(type, processedQuery, options, internalHandler, task, result);
break;
case TASK_MANAGER:
metadata = taskManager.searchObjectsIterative(type, processedQuery, options, internalHandler, result);
break;
default:
throw new AssertionError("Unexpected search provider: " + searchProvider);
}
result.computeStatusIfUnknown();
result.cleanupResult();
} catch (CommunicationException | ConfigurationException | ObjectNotFoundException | SchemaException | SecurityViolationException | ExpressionEvaluationException | RuntimeException | Error e) {
processSearchException(e, searchProvider, result);
throw e;
} finally {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(result.dump(false));
}
}
} finally {
exitModelMethodNoRepoCache();
}
if (OP_LOGGER.isDebugEnabled()) {
OP_LOGGER.debug("MODEL OP exit searchObjects({},{},{}): {}", type.getSimpleName(), query, rawOptions, metadata);
}
return metadata;
}
Aggregations