Search in sources :

Example 61 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowDeltaComputer method processAttributes.

private void processAttributes(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, PrismObject<ShadowType> resourceObject, ObjectDelta<ShadowType> resourceObjectDelta, CachingStategyType cachingStrategy, Collection<QName> incompleteCacheableAttributes, ObjectDelta<ShadowType> computedShadowDelta) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException {
    PrismContainer<Containerable> resourceObjectAttributes = resourceObject.findContainer(ShadowType.F_ATTRIBUTES);
    PrismContainer<Containerable> repoShadowAttributes = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    ResourceObjectDefinition ocDef = ctx.computeCompositeObjectDefinition(resourceObject);
    for (Item<?, ?> currentResourceAttrItem : resourceObjectAttributes.getValue().getItems()) {
        if (currentResourceAttrItem instanceof PrismProperty<?>) {
            // noinspection unchecked
            PrismProperty<Object> currentResourceAttrProperty = (PrismProperty<Object>) currentResourceAttrItem;
            ResourceAttributeDefinition<?> attrDef = ocDef.findAttributeDefinitionRequired(currentResourceAttrProperty.getElementName());
            if (ProvisioningUtil.shouldStoreAttributeInShadow(ocDef, attrDef.getItemName(), cachingStrategy)) {
                if (!currentResourceAttrItem.isIncomplete()) {
                    processResourceAttribute(computedShadowDelta, repoShadowAttributes, currentResourceAttrProperty, attrDef);
                } else {
                    incompleteCacheableAttributes.add(attrDef.getItemName());
                    if (resourceObjectDelta != null) {
                        LOGGER.trace("Resource attribute {} is incomplete but a delta does exist: we'll update the shadow " + "using the delta", attrDef.getItemName());
                    } else {
                        LOGGER.trace("Resource attribute {} is incomplete and object delta is not present: will not update the" + " shadow with its content", attrDef.getItemName());
                    }
                }
            } else {
                LOGGER.trace("Skipping resource attribute because it's not going to be stored in shadow: {}", attrDef.getItemName());
            }
        } else {
            LOGGER.warn("Skipping resource attribute because it's not a PrismProperty (huh?): {}", currentResourceAttrItem);
        }
    }
    for (Item<?, ?> oldRepoItem : repoShadowAttributes.getValue().getItems()) {
        if (oldRepoItem instanceof PrismProperty<?>) {
            // noinspection unchecked
            PrismProperty<Object> oldRepoAttrProperty = (PrismProperty<Object>) oldRepoItem;
            ResourceAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(oldRepoAttrProperty.getElementName());
            PrismProperty<Object> currentAttribute = resourceObjectAttributes.findProperty(oldRepoAttrProperty.getElementName());
            // note: incomplete attributes with no values are not here: they are found in resourceObjectAttributes container
            if (attrDef == null || !ProvisioningUtil.shouldStoreAttributeInShadow(ocDef, attrDef.getItemName(), cachingStrategy) || currentAttribute == null) {
                // No definition for this property it should not be there or no current value: remove it from the shadow
                PropertyDelta<Object> oldRepoAttrPropDelta = oldRepoAttrProperty.createDelta();
                oldRepoAttrPropDelta.addValuesToDelete(PrismValueCollectionsUtil.cloneCollection(oldRepoAttrProperty.getValues()));
                computedShadowDelta.addModification(oldRepoAttrPropDelta);
            }
        } else {
            LOGGER.warn("Skipping repo shadow attribute because it's not a PrismProperty (huh?): {}", oldRepoItem);
        }
    }
    if (resourceObjectDelta != null && !incompleteCacheableAttributes.isEmpty()) {
        LOGGER.trace("Found incomplete cacheable attributes: {} while resource object delta is known. " + "We'll update them using the delta.", incompleteCacheableAttributes);
        for (ItemDelta<?, ?> modification : resourceObjectDelta.getModifications()) {
            if (modification.getPath().startsWith(ShadowType.F_ATTRIBUTES)) {
                if (QNameUtil.contains(incompleteCacheableAttributes, modification.getElementName())) {
                    LOGGER.trace(" - using: {}", modification);
                    computedShadowDelta.addModification(modification.clone());
                }
            }
        }
        // So we are OK regarding this. We can update caching timestamp.
        incompleteCacheableAttributes.clear();
    }
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)

Example 62 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowFinder method createQueryBySelectedIds.

private ObjectQuery createQueryBySelectedIds(ProvisioningContext ctx, Collection<ResourceAttribute<?>> identifiers, boolean primaryIdentifiersOnly) throws SchemaException, ConfigurationException {
    boolean identifierFound = false;
    S_AtomicFilterEntry q = prismContext.queryFor(ShadowType.class);
    ResourceObjectDefinition objectClassDefinition = ctx.getObjectDefinition();
    for (PrismProperty<?> identifier : identifiers) {
        ResourceAttributeDefinition<?> rAttrDef;
        PrismPropertyValue<?> identifierValue = identifier.getValue();
        if (objectClassDefinition == null) {
            // If there is no specific object class definition then the identifier definition
            // must be the same in all object classes and that means that we can use
            // definition from any of them.
            ResourceObjectTypeDefinition anyDefinition = ctx.getResourceSchema().getObjectTypeDefinitions().iterator().next();
            rAttrDef = anyDefinition.findAttributeDefinition(identifier.getElementName());
            if (primaryIdentifiersOnly && !anyDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
        } else {
            if (primaryIdentifiersOnly && !objectClassDefinition.isPrimaryIdentifier(identifier.getElementName())) {
                continue;
            }
            rAttrDef = objectClassDefinition.findAttributeDefinition(identifier.getElementName());
        }
        if (rAttrDef == null) {
            throw new SchemaException("No definition for " + identifier.getElementName());
        }
        String normalizedIdentifierValue = (String) helper.getNormalizedAttributeValue(identifierValue, rAttrDef);
        // noinspection unchecked
        PrismPropertyDefinition<String> def = (PrismPropertyDefinition<String>) identifier.getDefinition();
        q = q.itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getItemName()).eq(normalizedIdentifierValue).and();
        identifierFound = true;
    }
    if (!identifierFound) {
        throw new SchemaException("Identifiers not found. Cannot create search query by identifier.");
    }
    if (objectClassDefinition != null) {
        q = q.item(ShadowType.F_OBJECT_CLASS).eq(objectClassDefinition.getTypeName()).and();
    }
    return q.item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition) S_AtomicFilterEntry(com.evolveum.midpoint.prism.query.builder.S_AtomicFilterEntry)

Example 63 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ShadowedObjectConstruction method copyAttributes.

private void copyAttributes(OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    resultingShadowedObject.removeContainer(ShadowType.F_ATTRIBUTES);
    ResourceAttributeContainer resultAttributes = resourceObjectAttributes.clone();
    ResourceObjectDefinition compositeObjectClassDef = computeCompositeObjectClassDefinition();
    localBeans.accessChecker.filterGetAttributes(resultAttributes, compositeObjectClassDef, result);
    resultingShadowedObject.add(resultAttributes);
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)

Example 64 with ResourceObjectDefinition

use of com.evolveum.midpoint.schema.processor.ResourceObjectDefinition in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.

/**
 * Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (identifiers == null) {
        return null;
    }
    ResourceObjectDefinition objDef = ctx.getObjectDefinitionRequired();
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, objDef);
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIds(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        return null;
    }
    shadowsFacade.applyDefinition(repoShadow, ctx.getTask(), result);
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        return null;
    }
    Collection primaryIdentifiers = new ArrayList<>();
    for (PrismProperty property : attributesContainer.getValue().getProperties()) {
        if (objDef.isPrimaryIdentifier(property.getElementName())) {
            ResourceAttributeDefinition<?> attrDef = objDef.findAttributeDefinition(property.getElementName());
            if (attrDef == null) {
                throw new IllegalStateException("No definition for attribute " + property);
            }
            ResourceAttribute primaryIdentifier = attrDef.instantiate();
            primaryIdentifier.setRealValue(property.getRealValue());
            primaryIdentifiers.add(primaryIdentifier);
        }
    }
    LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, objDef);
    return primaryIdentifiers;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

ResourceObjectDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectDefinition)64 QName (javax.xml.namespace.QName)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 ArrayList (java.util.ArrayList)14 Task (com.evolveum.midpoint.task.api.Task)12 Test (org.testng.annotations.Test)12 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)8 NotNull (org.jetbrains.annotations.NotNull)8 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 ResourceAssociationDefinition (com.evolveum.midpoint.schema.processor.ResourceAssociationDefinition)5 Collection (java.util.Collection)5 Nullable (org.jetbrains.annotations.Nullable)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)4 ResourceObjectTypeDefinition (com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)4 AutoCompleteQNamePanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel)3 AutoCompleteTextPanel (com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)2