Search in sources :

Example 6 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class ItemDeltaItem method findIdi.

public <IV extends PrismValue, ID extends ItemDefinition> ItemDeltaItem<IV, ID> findIdi(ItemPath path) {
    if (path.isEmpty()) {
        return (ItemDeltaItem<IV, ID>) this;
    }
    Item<IV, ID> subItemOld = null;
    ItemPath subResidualPath = null;
    ItemPath newResolvePath = resolvePath.subPath(path);
    if (itemOld != null) {
        PartiallyResolvedItem<IV, ID> partialItemOld = itemOld.findPartial(path);
        if (partialItemOld != null) {
            subItemOld = partialItemOld.getItem();
            subResidualPath = partialItemOld.getResidualPath();
        }
    }
    Item<IV, ID> subItemNew = null;
    if (itemNew != null) {
        PartiallyResolvedItem<IV, ID> partialItemNew = itemNew.findPartial(path);
        if (partialItemNew != null) {
            subItemNew = partialItemNew.getItem();
            if (subResidualPath == null) {
                subResidualPath = partialItemNew.getResidualPath();
            }
        }
    }
    ItemDelta<IV, ID> subDelta = null;
    if (delta != null) {
        if (delta instanceof ContainerDelta<?>) {
            subDelta = (ItemDelta<IV, ID>) ((ContainerDelta<?>) delta).getSubDelta(path);
        } else {
            CompareResult compareComplex = delta.getPath().compareComplex(newResolvePath);
            if (compareComplex == CompareResult.EQUIVALENT || compareComplex == CompareResult.SUBPATH) {
                subDelta = (ItemDelta<IV, ID>) delta;
            }
        }
    }
    ItemDeltaItem<IV, ID> subIdi = new ItemDeltaItem<IV, ID>(subItemOld, subDelta, subItemNew);
    subIdi.setResidualPath(subResidualPath);
    subIdi.resolvePath = newResolvePath;
    if (subItemDeltas != null) {
        Item<IV, ID> subAnyItem = subIdi.getAnyItem();
        Collection<ItemDelta<?, ?>> subSubItemDeltas = new ArrayList<>();
        for (ItemDelta<?, ?> subItemDelta : subItemDeltas) {
            CompareResult compareComplex = subItemDelta.getPath().compareComplex(subAnyItem.getPath());
            if (compareComplex == CompareResult.EQUIVALENT || compareComplex == CompareResult.SUBPATH) {
                subSubItemDeltas.add(subItemDelta);
            }
        }
        if (!subSubItemDeltas.isEmpty()) {
            // Niceness optimization
            if (subDelta == null && subSubItemDeltas.size() == 1) {
                ItemDelta<?, ?> subSubItemDelta = subSubItemDeltas.iterator().next();
                if (subSubItemDelta.isApplicableTo(subAnyItem)) {
                    subDelta = (ItemDelta<IV, ID>) subSubItemDelta;
                    subIdi.setDelta(subDelta);
                } else {
                    subIdi.setSubItemDeltas(subSubItemDeltas);
                }
            } else {
                subIdi.setSubItemDeltas(subSubItemDeltas);
            }
        }
    }
    return subIdi;
}
Also used : ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) CompareResult(com.evolveum.midpoint.prism.path.ItemPath.CompareResult) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class AddAssignmentAspect method assignmentToDelta.

// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) {
    PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew();
    PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT);
    ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> addRoleDelta = new ContainerDelta<>(new ItemPath(), FocusType.F_ASSIGNMENT, prismContainerDefinition, prismContext);
    PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone();
    addRoleDelta.addValueToAdd(assignmentValue);
    Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext);
    return ObjectDelta.createModifyDelta(objectOid, addRoleDelta, focusClass, modelContext.getPrismContext());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 8 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class ResourceObjectConverter method executeEntitlementChangesModify.

private PrismObject<ShadowType> executeEntitlementChangesModify(ProvisioningContext ctx, PrismObject<ShadowType> subjectShadowBefore, PrismObject<ShadowType> subjectShadowAfter, OperationProvisioningScriptsType scripts, Collection<? extends ItemDelta> subjectDeltas, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectAlreadyExistsException, ExpressionEvaluationException {
    Map<ResourceObjectDiscriminator, ResourceObjectOperations> roMap = new HashMap<>();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("executeEntitlementChangesModify, old shadow:\n{}", subjectShadowBefore.debugDump(1));
    }
    for (ItemDelta subjectDelta : subjectDeltas) {
        ItemPath subjectItemPath = subjectDelta.getPath();
        if (new ItemPath(ShadowType.F_ASSOCIATION).equivalent(subjectItemPath)) {
            ContainerDelta<ShadowAssociationType> containerDelta = (ContainerDelta<ShadowAssociationType>) subjectDelta;
            subjectShadowAfter = entitlementConverter.collectEntitlementsAsObjectOperation(ctx, roMap, containerDelta, subjectShadowBefore, subjectShadowAfter, parentResult);
        } else {
            ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta(ShadowType.F_ASSOCIATION, subjectShadowBefore.getDefinition());
            PrismContainer<ShadowAssociationType> associationContainer = subjectShadowBefore.findContainer(ShadowType.F_ASSOCIATION);
            if (associationContainer == null || associationContainer.isEmpty()) {
                LOGGER.trace("No shadow association container in old shadow. Skipping processing entitlements change for {}.", subjectItemPath);
                continue;
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing association container in old shadow for {}:\n{}", subjectItemPath, associationContainer.debugDump(1));
            }
            // For these that do not, it is harmful, so it must be skipped.
            for (PrismContainerValue<ShadowAssociationType> associationValue : associationContainer.getValues()) {
                QName associationName = associationValue.asContainerable().getName();
                if (associationName == null) {
                    throw new IllegalStateException("No association name in " + associationValue);
                }
                RefinedAssociationDefinition associationDefinition = ctx.getObjectClassDefinition().findAssociationDefinition(associationName);
                if (associationDefinition == null) {
                    throw new IllegalStateException("No association definition for " + associationValue);
                }
                if (!associationDefinition.requiresExplicitReferentialIntegrity()) {
                    continue;
                }
                QName valueAttributeName = associationDefinition.getResourceObjectAssociationType().getValueAttribute();
                if (!ShadowUtil.matchesAttribute(subjectItemPath, valueAttributeName)) {
                    continue;
                }
                LOGGER.trace("Processing association {} on rename", associationName);
                associationDelta.addValuesToDelete(associationValue.clone());
                associationDelta.addValuesToAdd(associationValue.clone());
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Resulting association delta for {}:\n{}", subjectItemPath, associationDelta.debugDump(1));
            }
            if (!associationDelta.isEmpty()) {
                entitlementConverter.collectEntitlementsAsObjectOperation(ctx, roMap, associationDelta, subjectShadowBefore, subjectShadowAfter, parentResult);
            }
        //				shadowAfter.findOrCreateContainer(ShadowType.F_ASSOCIATION).addAll((Collection) association.getClonedValues());
        //				entitlementConverter.processEntitlementsAdd(resource, shadowAfter, objectClassDefinition);
        }
    }
    executeEntitlements(ctx, roMap, parentResult);
    return subjectShadowAfter;
}
Also used : QName(javax.xml.namespace.QName) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 9 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class ResourceObjectConverter method collectAttributeAndEntitlementChanges.

private void collectAttributeAndEntitlementChanges(ProvisioningContext ctx, Collection<? extends ItemDelta> objectChange, Collection<Operation> operations, PrismObject<ShadowType> shadow, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (operations == null) {
        operations = new ArrayList<Operation>();
    }
    RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
    for (ItemDelta itemDelta : objectChange) {
        if (isAttributeDelta(itemDelta) || SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
            if (itemDelta instanceof PropertyDelta) {
                PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
                RefinedAttributeDefinition<Object> attrDef = objectClassDefinition.findAttributeDefinition(itemDelta.getElementName());
                if (attrDef != null) {
                    attributeModification.setMatchingRuleQName(attrDef.getMatchingRuleQName());
                    if (itemDelta.getDefinition() == null) {
                        itemDelta.setDefinition(attrDef);
                    }
                }
                operations.add(attributeModification);
            } else if (itemDelta instanceof ContainerDelta) {
                // - it is processed earlier
                continue;
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else if (SchemaConstants.PATH_ACTIVATION.equivalent(itemDelta.getParentPath())) {
            Collection<Operation> activationOperations = determineActivationChange(ctx, shadow.asObjectable(), objectChange, result);
            if (activationOperations != null) {
                operations.addAll(activationOperations);
            }
        } else if (new ItemPath(ShadowType.F_ASSOCIATION).equivalent(itemDelta.getPath())) {
            if (itemDelta instanceof ContainerDelta) {
                entitlementConverter.collectEntitlementChange(ctx, (ContainerDelta<ShadowAssociationType>) itemDelta, operations);
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else if (new ItemPath(ShadowType.F_AUXILIARY_OBJECT_CLASS).equivalent(itemDelta.getPath())) {
            if (itemDelta instanceof PropertyDelta) {
                PropertyModificationOperation attributeModification = new PropertyModificationOperation((PropertyDelta) itemDelta);
                operations.add(attributeModification);
            } else {
                throw new UnsupportedOperationException("Not supported delta: " + itemDelta);
            }
        } else {
            LOGGER.trace("Skip converting item delta: {}. It's not resource object change, but it is shadow change.", itemDelta);
        }
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with ContainerDelta

use of com.evolveum.midpoint.prism.delta.ContainerDelta in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method createReplaceAccountConstructionUserDelta.

protected ObjectDelta<UserType> createReplaceAccountConstructionUserDelta(String userOid, Long id, ConstructionType newValue) throws SchemaException {
    PrismContainerDefinition pcd = getAssignmentDefinition().findContainerDefinition(AssignmentType.F_CONSTRUCTION);
    ContainerDelta<ConstructionType> acDelta = new ContainerDelta<ConstructionType>(new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)), pcd, prismContext);
    //                ContainerDelta.createDelta(prismContext, ConstructionType.class, AssignmentType.F_CONSTRUCTION);
    acDelta.setValueToReplace(newValue.asPrismContainerValue());
    //        PropertyDelta.createModificationReplaceProperty(
    //                        new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(id), new NameItemPathSegment(AssignmentType.F_CONSTRUCTION)),
    //                        ppd,
    //                        newValue);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    modifications.add(acDelta);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(userOid, modifications, UserType.class, prismContext);
    return userDelta;
}
Also used : ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ArrayList(java.util.ArrayList) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)19 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)5 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 Task (com.evolveum.midpoint.task.api.Task)3 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)3 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)3 Collection (java.util.Collection)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismReference (com.evolveum.midpoint.prism.PrismReference)2 Trace (com.evolveum.midpoint.util.logging.Trace)2 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)2 PolicyConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType)2 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)2