Search in sources :

Example 1 with HookRegistry

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;
}
Also used : GetOperationOptions.createReadOnlyCollection(com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) CaseManager(com.evolveum.midpoint.cases.api.CaseManager) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager) ChangeType(com.evolveum.midpoint.prism.delta.ChangeType) AuthorizationConstants(com.evolveum.midpoint.security.api.AuthorizationConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) DiffUtil(com.evolveum.midpoint.prism.delta.DiffUtil) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) Collections.singletonList(java.util.Collections.singletonList) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) QNameUtil(com.evolveum.midpoint.util.QNameUtil) TaskActivityManager(com.evolveum.midpoint.repo.common.activity.TaskActivityManager) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) ScriptingExpressionEvaluator(com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator) AuditHelper(com.evolveum.midpoint.model.common.util.AuditHelper) OperationResultRunner(com.evolveum.midpoint.schema.result.OperationResultRunner) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collections.emptyList(java.util.Collections.emptyList) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) DebugUtil.lazy(com.evolveum.midpoint.util.DebugUtil.lazy) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) ObjectImporter(com.evolveum.midpoint.model.impl.importer.ObjectImporter) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) EvaluationTimeType(com.evolveum.prism.xml.ns._public.types_3.EvaluationTimeType) java.util(java.util) CompareResultType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.CompareResultType) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ObjectTypeUtil.hasArchetype(com.evolveum.midpoint.schema.util.ObjectTypeUtil.hasArchetype) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) TaskManager(com.evolveum.midpoint.task.api.TaskManager) DebugUtil(com.evolveum.midpoint.util.DebugUtil) LocalizationService(com.evolveum.midpoint.common.LocalizationService) EventDispatcher(com.evolveum.midpoint.provisioning.api.EventDispatcher) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) ModelImplUtils(com.evolveum.midpoint.model.impl.util.ModelImplUtils) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) CorrelationCaseManager(com.evolveum.midpoint.model.impl.correlator.CorrelationCaseManager) RepositoryCache(com.evolveum.midpoint.repo.cache.RepositoryCache) ReadHook(com.evolveum.midpoint.model.api.hooks.ReadHook) com.evolveum.midpoint.model.api(com.evolveum.midpoint.model.api) HookRegistry(com.evolveum.midpoint.model.api.hooks.HookRegistry) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) Qualifier(org.springframework.beans.factory.annotation.Qualifier) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ApprovalUtils(com.evolveum.midpoint.schema.util.cases.ApprovalUtils) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ImportFromResourceLauncher(com.evolveum.midpoint.model.impl.sync.tasks.imp.ImportFromResourceLauncher) com.evolveum.midpoint.model.impl.lens(com.evolveum.midpoint.model.impl.lens) GuiProfiledPrincipalManager(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipalManager) AuthorizationParameters(com.evolveum.midpoint.security.enforcer.api.AuthorizationParameters) SecurityEnforcer(com.evolveum.midpoint.security.enforcer.api.SecurityEnforcer) ExternalResourceEvent(com.evolveum.midpoint.provisioning.api.ExternalResourceEvent) CertificationManager(com.evolveum.midpoint.certification.api.CertificationManager) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) WorkItemId(com.evolveum.midpoint.schema.util.WorkItemId) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) Component(org.springframework.stereotype.Component) RepoAddOptions(com.evolveum.midpoint.repo.api.RepoAddOptions) ItemName(com.evolveum.midpoint.prism.path.ItemName) java.io(java.io) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) ModelObjectResolver(com.evolveum.midpoint.model.impl.ModelObjectResolver) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ReadHook(com.evolveum.midpoint.model.api.hooks.ReadHook) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes)

Aggregations

AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)1 CaseManager (com.evolveum.midpoint.cases.api.CaseManager)1 CertificationManager (com.evolveum.midpoint.certification.api.CertificationManager)1 LocalizationService (com.evolveum.midpoint.common.LocalizationService)1 com.evolveum.midpoint.model.api (com.evolveum.midpoint.model.api)1 GuiProfiledPrincipalManager (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipalManager)1 HookRegistry (com.evolveum.midpoint.model.api.hooks.HookRegistry)1 ReadHook (com.evolveum.midpoint.model.api.hooks.ReadHook)1 SystemObjectCache (com.evolveum.midpoint.model.common.SystemObjectCache)1 AuditHelper (com.evolveum.midpoint.model.common.util.AuditHelper)1 ModelObjectResolver (com.evolveum.midpoint.model.impl.ModelObjectResolver)1 CorrelationCaseManager (com.evolveum.midpoint.model.impl.correlator.CorrelationCaseManager)1 ObjectImporter (com.evolveum.midpoint.model.impl.importer.ObjectImporter)1 com.evolveum.midpoint.model.impl.lens (com.evolveum.midpoint.model.impl.lens)1 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)1 ScriptingExpressionEvaluator (com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator)1 ImportFromResourceLauncher (com.evolveum.midpoint.model.impl.sync.tasks.imp.ImportFromResourceLauncher)1 ModelImplUtils (com.evolveum.midpoint.model.impl.util.ModelImplUtils)1