Search in sources :

Example 1 with MatchingRuleRegistry

use of com.evolveum.midpoint.prism.match.MatchingRuleRegistry in project midpoint by Evolveum.

the class ImportProducerWorker method processStream.

private void processStream(InputStream input) throws IOException {
    ApplicationContext appContext = context.getApplicationContext();
    PrismContext prismContext = appContext.getBean(PrismContext.class);
    MatchingRuleRegistry matchingRuleRegistry = appContext.getBean(MatchingRuleRegistry.class);
    EventHandler<T> handler = new EventHandler<>() {

        @Override
        public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) {
            currentOid = objectElement.getAttribute("oid");
            return EventResult.cont();
        }

        @Override
        public EventResult postMarshall(T object, Element objectElement, OperationResult objectResult) {
            try {
                if (filter != null) {
                    boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry);
                    if (!match) {
                        operation.incrementSkipped();
                        return EventResult.skipObject("Object doesn't match filter");
                    }
                }
                if (!matchSelectedType(object.getClass())) {
                    operation.incrementSkipped();
                    return EventResult.skipObject("Type doesn't match");
                }
                queue.put(object);
            } catch (Exception ex) {
                throw new NinjaException(getErrorMessage() + ", reason: " + ex.getMessage(), ex);
            }
            currentOid = null;
            return stopAfterFound ? EventResult.skipObject() : EventResult.cont();
        }

        @Override
        public void handleGlobalError(OperationResult currentResult, Exception cause) {
            // This should not
            // Should we log error?
            operation.incrementError();
            String message = getErrorMessage();
            if (continueOnInputError) {
                if (context.isVerbose()) {
                    context.getLog().error(message, cause);
                } else {
                    context.getLog().error(message + ", reason: {}", cause.getMessage());
                }
            } else {
                // We need to throw runtime exception in order to stop validator, otherwise validator will continue
                // fill queue and this may result in deadlock
                operation.finish();
                throw new NinjaException(message + ", reason: " + cause.getMessage(), cause);
            }
        }
    };
    // FIXME: MID-5151: If validateSchema is false we are not validating unknown attributes on import
    LegacyValidator<?> validator = new LegacyValidator<>(prismContext, handler);
    validator.setValidateSchema(false);
    OperationResult result = operation.getResult();
    Charset charset = context.getCharset();
    Reader reader = new InputStreamReader(input, charset);
    validator.validate(new ReaderInputStream(reader, charset), result, result.getOperation());
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) EventHandler(com.evolveum.midpoint.common.validator.EventHandler) Charset(java.nio.charset.Charset) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NinjaException(com.evolveum.midpoint.ninja.impl.NinjaException) ApplicationContext(org.springframework.context.ApplicationContext) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) LegacyValidator(com.evolveum.midpoint.common.validator.LegacyValidator) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry)

Example 2 with MatchingRuleRegistry

use of com.evolveum.midpoint.prism.match.MatchingRuleRegistry in project midpoint by Evolveum.

the class ProvisioningUtil method narrowPropertyDelta.

public static <T> PropertyDelta<T> narrowPropertyDelta(PropertyDelta<T> propertyDelta, PrismObject<ShadowType> currentShadow, QName overridingMatchingRuleQName, MatchingRuleRegistry matchingRuleRegistry) throws SchemaException {
    ItemDefinition propertyDef = propertyDelta.getDefinition();
    QName matchingRuleQName;
    if (overridingMatchingRuleQName != null) {
        matchingRuleQName = overridingMatchingRuleQName;
    } else if (propertyDef instanceof ResourceAttributeDefinition) {
        matchingRuleQName = ((ResourceAttributeDefinition<?>) propertyDef).getMatchingRuleQName();
    } else {
        matchingRuleQName = null;
    }
    MatchingRule<T> matchingRule;
    if (matchingRuleQName != null && propertyDef != null) {
        matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, propertyDef.getTypeName());
    } else {
        matchingRule = null;
    }
    LOGGER.trace("Narrowing attr def={}, matchingRule={} ({})", propertyDef, matchingRule, matchingRuleQName);
    Comparator<PrismPropertyValue<T>> comparator = (o1, o2) -> {
        if (o1.equals(o2, EquivalenceStrategy.REAL_VALUE, matchingRule)) {
            return 0;
        } else {
            return 1;
        }
    };
    // We can safely narrow delta using real values, because we are not interested in value metadata here.
    // Because we are dealing with properties, container IDs are also out of questions, and operational items
    // as well.
    // MID-5280
    PropertyDelta<T> filteredDelta = propertyDelta.narrow(currentShadow, comparator, comparator, true);
    if (filteredDelta == null || !filteredDelta.equals(propertyDelta)) {
        LOGGER.trace("Narrowed delta: {}", DebugUtil.debugDumpLazily(filteredDelta));
    }
    return filteredDelta;
}
Also used : ExecuteScriptArgument(com.evolveum.midpoint.provisioning.ucf.api.ExecuteScriptArgument) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) DOMUtil(com.evolveum.midpoint.util.DOMUtil) QNameUtil(com.evolveum.midpoint.util.QNameUtil) Duration(javax.xml.datatype.Duration) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) Collectors(java.util.stream.Collectors) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) ResourceObjectPattern(com.evolveum.midpoint.schema.processor.ResourceObjectPattern) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) StaticExpressionUtil(com.evolveum.midpoint.common.StaticExpressionUtil) CryptoUtil(com.evolveum.midpoint.common.crypto.CryptoUtil) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) CredentialsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) CloneUtil(com.evolveum.midpoint.prism.util.CloneUtil) AttributesToReturn(com.evolveum.midpoint.provisioning.ucf.api.AttributesToReturn) ProvisioningOperationState(com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState) ExecuteProvisioningScriptOperation(com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) S_ItemEntry(com.evolveum.midpoint.prism.delta.builder.S_ItemEntry) ResourceAssociationDefinition(com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ItemName(com.evolveum.midpoint.prism.path.ItemName) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) Comparator(java.util.Comparator) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ChangeTypeType(com.evolveum.prism.xml.ns._public.types_3.ChangeTypeType) QName(javax.xml.namespace.QName)

Aggregations

MatchingRuleRegistry (com.evolveum.midpoint.prism.match.MatchingRuleRegistry)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 StaticExpressionUtil (com.evolveum.midpoint.common.StaticExpressionUtil)1 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)1 LegacyValidator (com.evolveum.midpoint.common.validator.LegacyValidator)1 NinjaException (com.evolveum.midpoint.ninja.impl.NinjaException)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 S_ItemEntry (com.evolveum.midpoint.prism.delta.builder.S_ItemEntry)1 EquivalenceStrategy (com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy)1 MatchingRule (com.evolveum.midpoint.prism.match.MatchingRule)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 CloneUtil (com.evolveum.midpoint.prism.util.CloneUtil)1 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)1 ProvisioningOperationOptions (com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)1