Search in sources :

Example 36 with ResourceObjectDefinition

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

the class SynchronizationContext method getIntent.

public String getIntent() throws SchemaException {
    if (!hasApplicablePolicy()) {
        return SchemaConstants.INTENT_UNKNOWN;
    }
    if (intent == null) {
        ResourceSchema schema = ResourceSchemaFactory.getCompleteSchema(resource);
        ResourceObjectDefinition def = schema.findObjectDefinition(getKind(), null);
        if (def instanceof ResourceObjectTypeDefinition) {
            // TODO ???
            intent = ((ResourceObjectTypeDefinition) def).getIntent();
        }
    }
    return intent;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceObjectTypeDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition)

Example 37 with ResourceObjectDefinition

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

the class ShadowUpdater method fixShadow.

/**
 * Re-reads the shadow, re-evaluates the identifiers and stored values
 * (including their normalization under matching rules), updates them if necessary.
 *
 * Returns fixed shadow.
 */
@NotNull
PrismObject<ShadowType> fixShadow(@NotNull ProvisioningContext ctx, @NotNull PrismObject<ShadowType> origRepoShadow, @NotNull OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException {
    PrismObject<ShadowType> currentRepoShadow = repositoryService.getObject(ShadowType.class, origRepoShadow.getOid(), null, result);
    ProvisioningContext shadowCtx = ctx.spawnForShadow(currentRepoShadow);
    ResourceObjectDefinition oDef = shadowCtx.getObjectDefinitionRequired();
    PrismContainer<Containerable> attributesContainer = currentRepoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer != null) {
        ObjectDelta<ShadowType> shadowDelta = currentRepoShadow.createModifyDelta();
        for (Item<?, ?> item : attributesContainer.getValue().getItems()) {
            fixAttribute(oDef, item, shadowDelta);
        }
        if (!shadowDelta.isEmpty()) {
            LOGGER.trace("Fixing shadow {} with delta:\n{}", origRepoShadow, shadowDelta.debugDumpLazily());
            executeShadowModification(ctx, origRepoShadow, shadowDelta.getModifications(), result);
            shadowDelta.applyTo(currentRepoShadow);
        } else {
            LOGGER.trace("No need to fixing shadow {} (empty delta)", origRepoShadow);
        }
    } else {
        LOGGER.trace("No need to fixing shadow {} (no attributes)", origRepoShadow);
    }
    return currentRepoShadow;
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 38 with ResourceObjectDefinition

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

the class ShadowUpdater method computeUpdateShadowAttributeChanges.

private void computeUpdateShadowAttributeChanges(ProvisioningContext ctx, Collection<ItemDelta<?, ?>> repoShadowChanges, PrismObject<ShadowType> resourceShadow, PrismObject<ShadowType> repoShadow) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    for (ResourceAttributeDefinition<?> attrDef : objectDefinition.getAttributeDefinitions()) {
        if (ProvisioningUtil.shouldStoreAttributeInShadow(objectDefinition, attrDef.getItemName(), cachingStrategy)) {
            ResourceAttribute<Object> resourceAttr = ShadowUtil.getAttribute(resourceShadow, attrDef.getItemName());
            PrismProperty<Object> repoAttr = repoShadow.findProperty(ItemPath.create(ShadowType.F_ATTRIBUTES, attrDef.getItemName()));
            PropertyDelta attrDelta;
            if (resourceAttr == null && repoAttr == null) {
                continue;
            }
            ResourceAttribute<Object> normalizedResourceAttribute = resourceAttr.clone();
            helper.normalizeAttribute(normalizedResourceAttribute, attrDef);
            if (repoAttr == null) {
                attrDelta = attrDef.createEmptyDelta(ItemPath.create(ShadowType.F_ATTRIBUTES, attrDef.getItemName()));
                attrDelta.setValuesToReplace(PrismValueCollectionsUtil.cloneCollection(normalizedResourceAttribute.getValues()));
            } else {
                attrDelta = repoAttr.diff(normalizedResourceAttribute);
            // LOGGER.trace("DIFF:\n{}\n-\n{}\n=:\n{}", repoAttr==null?null:repoAttr.debugDump(1), normalizedResourceAttribute==null?null:normalizedResourceAttribute.debugDump(1), attrDelta==null?null:attrDelta.debugDump(1));
            }
            if (attrDelta != null && !attrDelta.isEmpty()) {
                helper.normalizeDelta(attrDelta, attrDef);
                repoShadowChanges.add(attrDelta);
            }
        }
    }
    String newPrimaryIdentifierValue = helper.determinePrimaryIdentifierValue(ctx, resourceShadow);
    String existingPrimaryIdentifierValue = repoShadow.asObjectable().getPrimaryIdentifierValue();
    if (!Objects.equals(existingPrimaryIdentifierValue, newPrimaryIdentifierValue)) {
        repoShadowChanges.add(prismContext.deltaFor(ShadowType.class).item(ShadowType.F_PRIMARY_IDENTIFIER_VALUE).replace(newPrimaryIdentifierValue).asItemDelta());
    }
// TODO: reflect activation updates on cached shadow
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) PropertyDeltaCollectionsUtil.findPropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDeltaCollectionsUtil.findPropertyDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 39 with ResourceObjectDefinition

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

the class ShadowUpdater method extractRepoShadowChanges.

@SuppressWarnings("rawtypes")
@NotNull
private Collection<? extends ItemDelta<?, ?>> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    // If type is not present, OC def is fine
    ResourceObjectDefinition objectDefinition = ctx.getObjectDefinitionRequired();
    CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
    Collection<ItemDelta<?, ?>> repoChanges = new ArrayList<>();
    for (ItemDelta itemDelta : objectChange) {
        if (ShadowType.F_ATTRIBUTES.equivalent(itemDelta.getParentPath())) {
            QName attrName = itemDelta.getElementName();
            if (objectDefinition.isSecondaryIdentifier(attrName) || (objectDefinition.getAllIdentifiers().size() == 1 && objectDefinition.isPrimaryIdentifier(attrName))) {
                // Change of secondary identifier, or primary identifier when it is only one, 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 = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
                repoChanges.add(nameDelta);
            }
            if (objectDefinition.isPrimaryIdentifier(attrName)) {
                // Change of primary identifier $shadow/primaryIdentifier.
                String newPrimaryIdentifier = null;
                if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
                    newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
                } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
                    newPrimaryIdentifier = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
                }
                ResourceAttribute<String> primaryIdentifier = helper.getPrimaryIdentifier(shadow);
                // noinspection unchecked
                ResourceAttributeDefinition<String> rDef = (ResourceAttributeDefinition<String>) objectDefinition.findAttributeDefinitionRequired(primaryIdentifier.getElementName());
                String normalizedNewPrimaryIdentifier = helper.getNormalizedAttributeValue(rDef, newPrimaryIdentifier);
                PropertyDelta<String> primaryIdentifierDelta = prismContext.deltaFactory().property().createReplaceDelta(shadow.getDefinition(), ShadowType.F_PRIMARY_IDENTIFIER_VALUE, normalizedNewPrimaryIdentifier);
                repoChanges.add(primaryIdentifierDelta);
            }
            if (!ProvisioningUtil.shouldStoreAttributeInShadow(objectDefinition, attrName, cachingStrategy)) {
                continue;
            }
        } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getParentPath())) {
            if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
                continue;
            }
        } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getPath())) {
            // should not occur, but for completeness...
            if (((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd() != null) {
                for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
                    ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
                }
            }
            if (((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace() != null) {
                for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
                    ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
                }
            }
        } else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            addPasswordDelta(repoChanges, itemDelta, objectDefinition);
            continue;
        }
        helper.normalizeDelta(itemDelta, objectDefinition);
        repoChanges.add(itemDelta);
    }
    return repoChanges;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with ResourceObjectDefinition

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

the class ShadowUpdater method retrieveIndexOnlyAttributesIfNeeded.

private PrismObject<ShadowType> retrieveIndexOnlyAttributesIfNeeded(ProvisioningContext shadowCtx, PrismObject<ShadowType> repoShadow, OperationResult result) throws SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, ObjectNotFoundException {
    @Nullable ResourceObjectDefinition objectDefinition = shadowCtx.getObjectDefinition();
    if (objectDefinition == null) {
        // TODO consider throwing an exception
        LOGGER.warn("No object class definition for {}", shadowCtx);
        return repoShadow;
    }
    if (!objectDefinition.hasIndexOnlyAttributes()) {
        LOGGER.trace("No index only attributes -> nothing to retrieve");
        return repoShadow;
    }
    if (ShadowUtil.getAttributes(repoShadow).stream().noneMatch(Item::isIncomplete)) {
        LOGGER.trace("All repo attributes are complete -> nothing to retrieve");
        return repoShadow;
    }
    LOGGER.debug("Re-reading the shadow, retrieving all attributes (including index-only ones): {}", repoShadow);
    Collection<SelectorOptions<GetOperationOptions>> options = SchemaService.get().getOperationOptionsBuilder().item(ShadowType.F_ATTRIBUTES).retrieve(RetrieveOption.INCLUDE).build();
    PrismObject<ShadowType> retrievedRepoShadow = repositoryService.getObject(ShadowType.class, repoShadow.getOid(), options, result);
    shadowCaretaker.applyAttributesDefinition(shadowCtx, retrievedRepoShadow);
    shadowCaretaker.updateShadowState(shadowCtx, retrievedRepoShadow);
    LOGGER.trace("Full repo shadow:\n{}", retrievedRepoShadow.debugDumpLazily(1));
    return retrievedRepoShadow;
}
Also used : ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) Nullable(org.jetbrains.annotations.Nullable)

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