Search in sources :

Example 1 with CacheConfigurationManager

use of com.evolveum.midpoint.schema.cache.CacheConfigurationManager in project midpoint by Evolveum.

the class ResourceObjectConverter method searchResourceObjects.

public SearchResultMetadata searchResourceObjects(@NotNull ProvisioningContext ctx, @NotNull ResourceObjectHandler resultHandler, @Nullable ObjectQuery query, boolean fetchAssociations, @Nullable FetchErrorReportingMethodType errorReportingMethod, @NotNull OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    LOGGER.trace("Searching resource objects, query: {}, OC: {}", query, objectDefinition);
    AttributesToReturn attributesToReturn = ProvisioningUtil.createAttributesToReturn(ctx);
    SearchHierarchyConstraints searchHierarchyConstraints = entitlementConverter.determineSearchHierarchyConstraints(ctx, parentResult);
    if (InternalsConfig.consistencyChecks && query != null && query.getFilter() != null) {
        query.getFilter().checkConsistence(true);
    }
    ConnectorInstance connector = ctx.getConnector(ReadCapabilityType.class, parentResult);
    AtomicInteger objectCounter = new AtomicInteger(0);
    UcfFetchErrorReportingMethod ucfErrorReportingMethod;
    if (errorReportingMethod == FetchErrorReportingMethodType.FETCH_RESULT) {
        ucfErrorReportingMethod = UcfFetchErrorReportingMethod.UCF_OBJECT;
    } else {
        ucfErrorReportingMethod = UcfFetchErrorReportingMethod.EXCEPTION;
    }
    SearchResultMetadata metadata;
    try {
        metadata = connector.search(objectDefinition, query, (ucfObject, result) -> {
            ResourceObjectFound objectFound = new ResourceObjectFound(ucfObject, ResourceObjectConverter.this, ctx, fetchAssociations);
            // in order to utilize the cache right from the beginning...
            RepositoryCache.enterLocalCaches(cacheConfigurationManager);
            try {
                int objectNumber = objectCounter.getAndIncrement();
                Task task = ctx.getTask();
                try {
                    OperationResult objResult = result.subresult(OperationConstants.OPERATION_SEARCH_RESULT).setMinor().addParam("number", objectNumber).addArbitraryObjectAsParam("primaryIdentifierValue", ucfObject.getPrimaryIdentifierValue()).addArbitraryObjectAsParam("errorState", ucfObject.getErrorState()).build();
                    try {
                        objectFound.initialize(task, objResult);
                        return resultHandler.handle(objectFound, objResult);
                    } catch (Throwable t) {
                        objResult.recordFatalError(t);
                        throw t;
                    } finally {
                        objResult.computeStatusIfUnknown();
                        // AbstractSummarizingResultHandler [lazyman]
                        if (objResult.isSuccess() && objResult.canBeCleanedUp()) {
                            objResult.getSubresults().clear();
                        }
                        // TODO Reconsider this. It is quite dubious to touch the global result from the inside.
                        result.summarize();
                    }
                } finally {
                    RepositoryCache.exitLocalCaches();
                }
            } catch (RuntimeException e) {
                throw e;
            } catch (Throwable t) {
                throw new TunnelException(t);
            }
        }, attributesToReturn, objectDefinition.getPagedSearches(ctx.getResource()), searchHierarchyConstraints, ucfErrorReportingMethod, ctx.getUcfExecutionContext(), parentResult);
    } catch (GenericFrameworkException e) {
        parentResult.recordFatalError("Generic error in the connector: " + e.getMessage(), e);
        throw new SystemException("Generic error in the connector: " + e.getMessage(), e);
    } catch (CommunicationException ex) {
        parentResult.recordFatalError("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
        throw new CommunicationException("Error communicating with the connector " + connector + ": " + ex.getMessage(), ex);
    } catch (SecurityViolationException ex) {
        parentResult.recordFatalError("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
        throw new SecurityViolationException("Security violation communicating with the connector " + connector + ": " + ex.getMessage(), ex);
    } catch (TunnelException e) {
        Throwable cause = e.getCause();
        parentResult.recordFatalError("Problem while communicating with the connector " + connector + ": " + cause.getMessage(), cause);
        if (cause instanceof SchemaException) {
            throw (SchemaException) cause;
        } else if (cause instanceof CommunicationException) {
            throw (CommunicationException) cause;
        } else if (cause instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) cause;
        } else if (cause instanceof ConfigurationException) {
            throw (ConfigurationException) cause;
        } else if (cause instanceof SecurityViolationException) {
            throw (SecurityViolationException) cause;
        } else if (cause instanceof ExpressionEvaluationException) {
            throw (ExpressionEvaluationException) cause;
        } else if (cause instanceof GenericFrameworkException) {
            throw new GenericConnectorException(cause.getMessage(), cause);
        } else {
            throw new SystemException(cause.getMessage(), cause);
        }
    }
    computeResultStatus(parentResult);
    LOGGER.trace("Searching resource objects done: {}", parentResult.getStatus());
    return metadata;
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UcfAsyncUpdateChangeListener(com.evolveum.midpoint.provisioning.ucf.api.async.UcfAsyncUpdateChangeListener) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) LightweightIdentifierGenerator(com.evolveum.midpoint.task.api.LightweightIdentifierGenerator) Collections.emptyList(java.util.Collections.emptyList) PrismPropertyValue.getRealValue(com.evolveum.midpoint.prism.PrismPropertyValue.getRealValue) Task(com.evolveum.midpoint.task.api.Task) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) com.evolveum.midpoint.xml.ns._public.resource.capabilities_3(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3) ResourceObjectPattern(com.evolveum.midpoint.schema.processor.ResourceObjectPattern) Nullable(org.jetbrains.annotations.Nullable) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) com.evolveum.midpoint.schema.result(com.evolveum.midpoint.schema.result) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Entry(java.util.Map.Entry) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) UcfExecutionContext(com.evolveum.midpoint.provisioning.ucf.api.UcfExecutionContext) com.evolveum.midpoint.provisioning.impl(com.evolveum.midpoint.provisioning.impl) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) com.evolveum.midpoint.util(com.evolveum.midpoint.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) Trace(com.evolveum.midpoint.util.logging.Trace) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) RepositoryCache(com.evolveum.midpoint.repo.cache.RepositoryCache) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) LiveSyncToken(com.evolveum.midpoint.provisioning.api.LiveSyncToken) PrismUtil(com.evolveum.midpoint.prism.util.PrismUtil) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) com.evolveum.midpoint.provisioning.ucf.api(com.evolveum.midpoint.provisioning.ucf.api) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) ProvisioningUtil(com.evolveum.midpoint.provisioning.util.ProvisioningUtil) Tracer(com.evolveum.midpoint.task.api.Tracer) CacheConfigurationManager(com.evolveum.midpoint.schema.cache.CacheConfigurationManager) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) com.evolveum.midpoint.schema.util(com.evolveum.midpoint.schema.util) Task(com.evolveum.midpoint.task.api.Task) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException)

Aggregations

com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 PrismPropertyValue.getRealValue (com.evolveum.midpoint.prism.PrismPropertyValue.getRealValue)1 com.evolveum.midpoint.prism.delta (com.evolveum.midpoint.prism.delta)1 EquivalenceStrategy (com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy)1 MatchingRule (com.evolveum.midpoint.prism.match.MatchingRule)1 MatchingRuleRegistry (com.evolveum.midpoint.prism.match.MatchingRuleRegistry)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 PrismUtil (com.evolveum.midpoint.prism.util.PrismUtil)1 GenericConnectorException (com.evolveum.midpoint.provisioning.api.GenericConnectorException)1 LiveSyncToken (com.evolveum.midpoint.provisioning.api.LiveSyncToken)1 com.evolveum.midpoint.provisioning.impl (com.evolveum.midpoint.provisioning.impl)1 com.evolveum.midpoint.provisioning.ucf.api (com.evolveum.midpoint.provisioning.ucf.api)1 UcfExecutionContext (com.evolveum.midpoint.provisioning.ucf.api.UcfExecutionContext)1 UcfAsyncUpdateChangeListener (com.evolveum.midpoint.provisioning.ucf.api.async.UcfAsyncUpdateChangeListener)1 ProvisioningUtil (com.evolveum.midpoint.provisioning.util.ProvisioningUtil)1 RepositoryCache (com.evolveum.midpoint.repo.cache.RepositoryCache)1 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)1 com.evolveum.midpoint.schema (com.evolveum.midpoint.schema)1