Search in sources :

Example 11 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ShadowCache method futurizeShadow.

private PrismObject<ShadowType> futurizeShadow(PrismObject<ShadowType> shadow, Collection<SelectorOptions<GetOperationOptions>> options, ResourceType resource) throws SchemaException {
    PointInTimeType pit = GetOperationOptions.getPointInTimeType(SelectorOptions.findRootOptions(options));
    if (pit != PointInTimeType.FUTURE) {
        return shadow;
    }
    PrismObject<ShadowType> resultShadow = shadow;
    ShadowType resultShadowType = resultShadow.asObjectable();
    List<PendingOperationType> sortedOperations = sortOperations(resultShadowType.getPendingOperation());
    boolean resourceReadIsCachingOnly = resourceReadIsCachingOnly(resource);
    for (PendingOperationType pendingOperation : sortedOperations) {
        OperationResultStatusType resultStatus = pendingOperation.getResultStatus();
        if (resultStatus == OperationResultStatusType.FATAL_ERROR || resultStatus == OperationResultStatusType.NOT_APPLICABLE) {
            continue;
        }
        if (resourceReadIsCachingOnly) {
            // Re-applying them will mean additional risk of corrupting the data.
            if (resultStatus != null && resultStatus != OperationResultStatusType.IN_PROGRESS && resultStatus != OperationResultStatusType.UNKNOWN) {
                continue;
            }
        } else {
        // We want to apply all the deltas, even those that are already completed. They might not be reflected on the resource yet.
        // E.g. they may be not be present in the CSV export until the next export cycle is scheduled
        }
        ObjectDeltaType pendingDeltaType = pendingOperation.getDelta();
        ObjectDelta<ShadowType> pendingDelta = DeltaConvertor.createObjectDelta(pendingDeltaType, prismContext);
        if (pendingDelta.isAdd()) {
            if (Boolean.FALSE.equals(resultShadowType.isExists())) {
                resultShadow = pendingDelta.getObjectToAdd().clone();
                resultShadow.setOid(shadow.getOid());
                resultShadowType = resultShadow.asObjectable();
                resultShadowType.setExists(true);
                resultShadowType.setName(shadow.asObjectable().getName());
            }
        }
        if (pendingDelta.isModify()) {
            pendingDelta.applyTo(resultShadow);
        }
        if (pendingDelta.isDelete()) {
            resultShadowType.setDead(true);
            resultShadowType.setExists(false);
        }
    }
    //		}
    return resultShadow;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)

Example 12 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ShadowCache method extendShadow.

private PrismObject<ShadowType> extendShadow(PrismObject<ShadowType> shadow, OperationResult shadowResult, ResourceType resource, Collection<? extends ItemDelta> modifications) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    shadowType.setResult(shadowResult.createOperationResultType());
    shadowType.setResource(resource);
    if (modifications != null) {
        ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, shadowType.getClass(), prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Storing delta to shadow:\n{}", objectDelta.debugDump());
        }
        ContainerDelta<ShadowAssociationType> associationDelta = objectDelta.findContainerDelta(ShadowType.F_ASSOCIATION);
        if (associationDelta != null) {
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToAdd());
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToReplace());
            normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToDelete());
        }
        ObjectDeltaType objectDeltaType = DeltaConvertor.toObjectDeltaType(objectDelta);
        shadowType.setObjectChange(objectDeltaType);
    }
    return shadow;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)

Example 13 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ShadowCacheProvisioner method mergeDeltas.

@SuppressWarnings({ "unchecked", "rawtypes" })
private ObjectDelta mergeDeltas(PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> modifications) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    if (shadowType.getObjectChange() != null) {
        ObjectDeltaType deltaType = shadowType.getObjectChange();
        Collection<? extends ItemDelta> pendingModifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), shadow.getDefinition());
        // See e.g. MID-1709.
        return ObjectDelta.summarize(ObjectDelta.createModifyDelta(shadow.getOid(), pendingModifications, ShadowType.class, getPrismContext()), ObjectDelta.createModifyDelta(shadow.getOid(), modifications, ShadowType.class, getPrismContext()));
    }
    return null;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 14 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ShadowCacheReconciler method beforeModifyOnResource.

@Override
public Collection<? extends ItemDelta> beforeModifyOnResource(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, Collection<? extends ItemDelta> modifications) throws SchemaException {
    ObjectDeltaType shadowDelta = shadow.asObjectable().getObjectChange();
    //TODO: error handling
    if (shadowDelta != null) {
        modifications = DeltaConvertor.toModifications(shadowDelta.getItemDelta(), shadow.getDefinition());
    }
    // for the older versions
    ObjectDelta<? extends ObjectType> objectDelta = ObjectDelta.createModifyDelta(shadow.getOid(), modifications, ShadowType.class, getPrismContext());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Storing delta to shadow:\n{}", objectDelta.debugDump());
    }
    ContainerDelta<ShadowAssociationType> associationDelta = objectDelta.findContainerDelta(ShadowType.F_ASSOCIATION);
    if (associationDelta != null) {
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToAdd());
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToReplace());
        normalizeAssociationDeltasBeforeSave(associationDelta.getValuesToDelete());
    }
    if (modifications == null) {
        modifications = new ArrayList<ItemDelta>();
    }
    return modifications;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 15 with ObjectDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType in project midpoint by Evolveum.

the class ShadowManager method addPendingOperationAdd.

private void addPendingOperationAdd(PrismObject<ShadowType> repoShadow, AsynchronousOperationReturnValue<PrismObject<ShadowType>> addResult) throws SchemaException {
    if (!addResult.isInProgress()) {
        return;
    }
    PrismObject<ShadowType> resourceShadow = addResult.getReturnValue();
    ShadowType repoShadowType = repoShadow.asObjectable();
    ObjectDelta<ShadowType> addDelta = resourceShadow.createAddDelta();
    ObjectDeltaType addDeltaType = DeltaConvertor.toObjectDeltaType(addDelta);
    PendingOperationType pendingOperation = new PendingOperationType();
    pendingOperation.setDelta(addDeltaType);
    pendingOperation.setRequestTimestamp(clock.currentTimeXMLGregorianCalendar());
    pendingOperation.setResultStatus(OperationResultStatusType.IN_PROGRESS);
    pendingOperation.setAsynchronousOperationReference(addResult.getOperationResult().getAsynchronousOperationReference());
    repoShadowType.getPendingOperation().add(pendingOperation);
    repoShadowType.setExists(false);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)

Aggregations

ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)165 Test (org.testng.annotations.Test)54 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)53 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)50 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)47 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)44 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)41 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)37 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)33 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)30 ChangeRecordEntry (org.opends.server.util.ChangeRecordEntry)30 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)23 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)21 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 QName (javax.xml.namespace.QName)16 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)15 SystemException (com.evolveum.midpoint.util.exception.SystemException)13