Search in sources :

Example 26 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowCache method applyDefinition.

private void applyDefinition(final ProvisioningContext ctx, final ObjectQuery query) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (query == null) {
        return;
    }
    ObjectFilter filter = query.getFilter();
    if (filter == null) {
        return;
    }
    final RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    final ItemPath attributesPath = new ItemPath(ShadowType.F_ATTRIBUTES);
    com.evolveum.midpoint.prism.query.Visitor visitor = subfilter -> {
        if (subfilter instanceof PropertyValueFilter) {
            PropertyValueFilter<?> valueFilter = (PropertyValueFilter<?>) subfilter;
            ItemDefinition definition = valueFilter.getDefinition();
            if (definition instanceof ResourceAttributeDefinition) {
                return;
            }
            if (!attributesPath.equivalent(valueFilter.getParentPath())) {
                return;
            }
            QName attributeName = valueFilter.getElementName();
            ResourceAttributeDefinition attributeDefinition = objectClassDefinition.findAttributeDefinition(attributeName);
            if (attributeDefinition == null) {
                throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query));
            }
            valueFilter.setDefinition(attributeDefinition);
        }
    };
    try {
        filter.accept(visitor);
    } catch (TunnelException te) {
        SchemaException e = (SchemaException) te.getCause();
        throw e;
    }
}
Also used : FailedOperation(com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler.FailedOperation) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) StringUtils(org.apache.commons.lang.StringUtils) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) Autowired(org.springframework.beans.factory.annotation.Autowired) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) QNameUtil(com.evolveum.midpoint.util.QNameUtil) Duration(javax.xml.datatype.Duration) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) com.evolveum.midpoint.provisioning.api(com.evolveum.midpoint.provisioning.api) DatatypeConstants(javax.xml.datatype.DatatypeConstants) CountObjectsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CountObjectsCapabilityType) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) Holder(com.evolveum.midpoint.util.Holder) Collection(java.util.Collection) ResourceTypeUtil(com.evolveum.midpoint.schema.util.ResourceTypeUtil) Task(com.evolveum.midpoint.task.api.Task) MatchingRuleRegistry(com.evolveum.midpoint.prism.match.MatchingRuleRegistry) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) List(java.util.List) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ReadCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ReadCapabilityType) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) QName(javax.xml.namespace.QName) Clock(com.evolveum.midpoint.common.Clock) Validate(org.apache.commons.lang.Validate) ErrorHandlerFactory(com.evolveum.midpoint.provisioning.consistency.impl.ErrorHandlerFactory) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) ResultHandler(com.evolveum.midpoint.provisioning.ucf.api.ResultHandler) 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) 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) ArrayList(java.util.ArrayList) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) ErrorHandler(com.evolveum.midpoint.provisioning.consistency.api.ErrorHandler) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) Change(com.evolveum.midpoint.provisioning.ucf.api.Change) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) com.evolveum.midpoint.schema.processor(com.evolveum.midpoint.schema.processor) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) CountObjectsSimulateType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CountObjectsSimulateType) ProvisioningUtil(com.evolveum.midpoint.provisioning.util.ProvisioningUtil) ShadowUtil(com.evolveum.midpoint.schema.util.ShadowUtil) Collections(java.util.Collections) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) QName(javax.xml.namespace.QName) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 27 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowCache method reapplyDefinitions.

/**
	 * Reapplies definition to the shadow if needed. The definition needs to be
	 * reapplied e.g. if the shadow has auxiliary object classes, it if subclass
	 * of the object class that was originally requested, etc.
	 */
private ProvisioningContext reapplyDefinitions(ProvisioningContext ctx, PrismObject<ShadowType> rawResourceShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ShadowType rawResourceShadowType = rawResourceShadow.asObjectable();
    QName objectClassQName = rawResourceShadowType.getObjectClass();
    List<QName> auxiliaryObjectClassQNames = rawResourceShadowType.getAuxiliaryObjectClass();
    if (auxiliaryObjectClassQNames.isEmpty() && objectClassQName.equals(ctx.getObjectClassDefinition().getTypeName())) {
        // shortcut, no need to reapply anything
        return ctx;
    }
    ProvisioningContext shadowCtx = ctx.spawn(rawResourceShadow);
    shadowCtx.assertDefinition();
    RefinedObjectClassDefinition shadowDef = shadowCtx.getObjectClassDefinition();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(rawResourceShadow);
    attributesContainer.applyDefinition(shadowDef.toResourceAttributeContainerDefinition());
    return shadowCtx;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) QName(javax.xml.namespace.QName)

Example 28 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowCache method applyAttributesDefinition.

private ProvisioningContext applyAttributesDefinition(ProvisioningContext ctx, PrismObject<ShadowType> shadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ProvisioningContext subctx = ctx.spawn(shadow);
    subctx.assertDefinition();
    RefinedObjectClassDefinition objectClassDefinition = subctx.getObjectClassDefinition();
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer != null) {
        if (attributesContainer instanceof ResourceAttributeContainer) {
            if (attributesContainer.getDefinition() == null) {
                attributesContainer.applyDefinition(objectClassDefinition.toResourceAttributeContainerDefinition());
            }
        } else {
            try {
                // We need to convert <attributes> to
                // ResourceAttributeContainer
                ResourceAttributeContainer convertedContainer = ResourceAttributeContainer.convertFromContainer(attributesContainer, objectClassDefinition);
                shadow.getValue().replace(attributesContainer, convertedContainer);
            } catch (SchemaException e) {
                throw new SchemaException(e.getMessage() + " in " + shadow, e);
            }
        }
    }
    // We also need to replace the entire object definition to inject
    // correct object class definition here
    // If we don't do this then the patch (delta.applyTo) will not work
    // correctly because it will not be able to
    // create the attribute container if needed.
    PrismObjectDefinition<ShadowType> objectDefinition = shadow.getDefinition();
    PrismContainerDefinition<ShadowAttributesType> origAttrContainerDef = objectDefinition.findContainerDefinition(ShadowType.F_ATTRIBUTES);
    if (origAttrContainerDef == null || !(origAttrContainerDef instanceof ResourceAttributeContainerDefinition)) {
        PrismObjectDefinition<ShadowType> clonedDefinition = objectDefinition.cloneWithReplacedDefinition(ShadowType.F_ATTRIBUTES, objectClassDefinition.toResourceAttributeContainerDefinition());
        shadow.setDefinition(clonedDefinition);
    }
    return subctx;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)

Example 29 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowCache method modifyShadow.

public String modifyShadow(PrismObject<ShadowType> repoShadow, String oid, Collection<? extends ItemDelta> modifications, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(repoShadow, "Object to modify must not be null.");
    Validate.notNull(oid, "OID must not be null.");
    Validate.notNull(modifications, "Object modification must not be null.");
    InternalMonitor.recordShadowChangeOperation();
    Collection<QName> additionalAuxiliaryObjectClassQNames = new ArrayList<>();
    ItemPath auxPath = new ItemPath(ShadowType.F_AUXILIARY_OBJECT_CLASS);
    for (ItemDelta modification : modifications) {
        if (auxPath.equals(modification.getPath())) {
            PropertyDelta<QName> auxDelta = (PropertyDelta<QName>) modification;
            for (PrismPropertyValue<QName> pval : auxDelta.getValues(QName.class)) {
                additionalAuxiliaryObjectClassQNames.add(pval.getValue());
            }
        }
    }
    ProvisioningContext ctx = ctxFactory.create(repoShadow, additionalAuxiliaryObjectClassQNames, task, parentResult);
    AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>> asyncReturnValue;
    try {
        ctx.assertDefinition();
        RefinedObjectClassDefinition rOCDef = ctx.getObjectClassDefinition();
        applyAttributesDefinition(ctx, repoShadow);
        accessChecker.checkModify(ctx.getResource(), repoShadow, modifications, ctx.getObjectClassDefinition(), parentResult);
        modifications = beforeModifyOnResource(repoShadow, options, modifications);
        preprocessEntitlements(ctx, modifications, "delta for shadow " + oid, parentResult);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Applying change: {}", DebugUtil.debugDump(modifications));
        }
        asyncReturnValue = resouceObjectConverter.modifyResourceObject(ctx, repoShadow, scripts, modifications, parentResult);
    } catch (Exception ex) {
        LOGGER.debug("Provisioning exception: {}:{}, attempting to handle it", new Object[] { ex.getClass(), ex.getMessage(), ex });
        try {
            repoShadow = handleError(ctx, ex, repoShadow, FailedOperation.MODIFY, modifications, isDoDiscovery(ctx.getResource(), options), isCompensate(options), parentResult);
            parentResult.computeStatus();
        } catch (ObjectAlreadyExistsException e) {
            parentResult.recordFatalError("While compensating communication problem for modify operation got: " + ex.getMessage(), ex);
            throw new SystemException(e);
        }
        return repoShadow.getOid();
    }
    Collection<PropertyDelta<PrismPropertyValue>> sideEffectChanges = asyncReturnValue.getReturnValue();
    if (sideEffectChanges != null) {
        ItemDelta.addAll(modifications, sideEffectChanges);
    }
    afterModifyOnResource(ctx, repoShadow, modifications, asyncReturnValue.getOperationResult(), parentResult);
    ObjectDelta<ShadowType> delta = ObjectDelta.createModifyDelta(repoShadow.getOid(), modifications, repoShadow.getCompileTimeClass(), prismContext);
    ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, repoShadow, delta, parentResult);
    if (asyncReturnValue.isInProgress()) {
        operationListener.notifyInProgress(operationDescription, task, parentResult);
        parentResult.recordInProgress();
        parentResult.setAsynchronousOperationReference(asyncReturnValue.getOperationResult().getAsynchronousOperationReference());
    } else {
        operationListener.notifySuccess(operationDescription, task, parentResult);
        parentResult.recordSuccess();
    }
    return oid;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) Collection(java.util.Collection) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 30 with RefinedObjectClassDefinition

use of com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition in project midpoint by Evolveum.

the class ShadowManager method extractRepoShadowChanges.

@SuppressWarnings("rawtypes")
private Collection<? extends ItemDelta> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    Collection<ItemDelta> repoChanges = new ArrayList<ItemDelta>();
    for (ItemDelta itemDelta : objectChange) {
        if (new ItemPath(ShadowType.F_ATTRIBUTES).equivalent(itemDelta.getParentPath())) {
            QName attrName = itemDelta.getElementName();
            if (objectClassDefinition.isSecondaryIdentifier(attrName)) {
                // Change of secondary identifier means object rename. We also need to change $shadow/name
                // TODO: change this to displayName attribute later
                String newName = null;
                if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
                } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
                    newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
                }
                PropertyDelta<PolyString> nameDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
                repoChanges.add(nameDelta);
            }
            if (!ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrName, cachingStrategy)) {
                continue;
            }
        } else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getParentPath())) {
            if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
                continue;
            }
        } else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getPath())) {
            // should not occur, but for completeness...
            for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
                ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
            }
            for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
                ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
            }
        } else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            continue;
        }
        normalizeDelta(itemDelta, objectClassDefinition);
        repoChanges.add(itemDelta);
    }
    return repoChanges;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)72 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)33 QName (javax.xml.namespace.QName)28 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)20 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 ArrayList (java.util.ArrayList)13 Test (org.testng.annotations.Test)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 Task (com.evolveum.midpoint.task.api.Task)8 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 Collection (java.util.Collection)7 RefinedAssociationDefinition (com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)6