Search in sources :

Example 51 with ReferenceDelta

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

the class ContainerWrapper method computeReferenceDeltas.

private ReferenceDelta computeReferenceDeltas(ReferenceWrapper referenceWrapper, ItemPath containerPath) {
    PrismReferenceDefinition propertyDef = referenceWrapper.getItemDefinition();
    ReferenceDelta pDelta = new ReferenceDelta(containerPath, propertyDef.getName(), propertyDef, propertyDef.getPrismContext());
    addItemDelta(referenceWrapper, pDelta, propertyDef, containerPath.subPath(propertyDef.getName()));
    return pDelta;
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta)

Example 52 with ReferenceDelta

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

the class ContainerWrapper method collectModifications.

public <O extends ObjectType> void collectModifications(ObjectDelta<O> delta) throws SchemaException {
    if (getItemDefinition().getName().equals(ShadowType.F_ASSOCIATION)) {
        //create ContainerDelta for association container
        //HACK HACK HACK create correct procession for association container data
        //according to its structure
        ContainerDelta<ShadowAssociationType> associationDelta = ContainerDelta.createDelta(ShadowType.F_ASSOCIATION, (PrismContainerDefinition<ShadowAssociationType>) getItemDefinition());
        for (ItemWrapper itemWrapper : getItems()) {
            AssociationWrapper associationItemWrapper = (AssociationWrapper) itemWrapper;
            List<ValueWrapper> assocValueWrappers = associationItemWrapper.getValues();
            for (ValueWrapper assocValueWrapper : assocValueWrappers) {
                PrismContainerValue<ShadowAssociationType> assocValue = (PrismContainerValue<ShadowAssociationType>) assocValueWrapper.getValue();
                if (!assocValue.isEmpty()) {
                    if (assocValueWrapper.getStatus() == ValueStatus.DELETED) {
                        associationDelta.addValueToDelete(assocValue.clone());
                    } else if (assocValueWrapper.getStatus().equals(ValueStatus.ADDED)) {
                        associationDelta.addValueToAdd(assocValue.clone());
                    }
                }
            }
        }
        if (!associationDelta.isEmpty()) {
            delta.addModification(associationDelta);
        }
    } else {
        if (!hasChanged()) {
            return;
        }
        for (ItemWrapper itemWrapper : getItems()) {
            if (!itemWrapper.hasChanged()) {
                continue;
            }
            ItemPath containerPath = getPath() != null ? getPath() : new ItemPath();
            if (itemWrapper instanceof PropertyWrapper) {
                ItemDelta pDelta = computePropertyDeltas((PropertyWrapper) itemWrapper, containerPath);
                if (!pDelta.isEmpty()) {
                    //HACK to remove a password replace delta is to be created
                    if (getName().equals(CredentialsType.F_PASSWORD)) {
                        if (pDelta.getValuesToDelete() != null) {
                            pDelta.resetValuesToDelete();
                            pDelta.setValuesToReplace(new ArrayList());
                        }
                    }
                    delta.addModification(pDelta);
                }
            } else if (itemWrapper instanceof ReferenceWrapper) {
                ReferenceDelta pDelta = computeReferenceDeltas((ReferenceWrapper) itemWrapper, containerPath);
                if (!pDelta.isEmpty()) {
                    delta.addModification(pDelta);
                }
            } else {
                LOGGER.trace("Delta from wrapper: ignoring {}", itemWrapper);
            }
        }
    }
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 53 with ReferenceDelta

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

the class PrismAsserts method assertReferenceReplace.

public static void assertReferenceReplace(ObjectDelta<?> objectDelta, QName refName, String... expectedOids) {
    ReferenceDelta refDelta = objectDelta.findReferenceModification(refName);
    assertNotNull("Reference delta for " + refName + " not found", refDelta);
    assertOidSet("delta " + refDelta + " for " + refName, "replace", refDelta.getValuesToReplace(), expectedOids);
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta)

Example 54 with ReferenceDelta

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

the class OperationalDataManager method createModifyMetadataDeltas.

public <F extends ObjectType, T extends ObjectType> Collection<? extends ItemDelta<?, ?>> createModifyMetadataDeltas(LensContext<F> context, ItemPath metadataPath, PrismObjectDefinition<T> def, XMLGregorianCalendar now, Task task) {
    Collection<? extends ItemDelta<?, ?>> deltas = new ArrayList<>();
    String channel = LensUtil.getChannel(context, task);
    if (channel != null) {
        PropertyDelta<String> delta = PropertyDelta.createModificationReplaceProperty(metadataPath.subPath(MetadataType.F_MODIFY_CHANNEL), def, channel);
        ((Collection) deltas).add(delta);
    }
    PropertyDelta<XMLGregorianCalendar> delta = PropertyDelta.createModificationReplaceProperty(metadataPath.subPath(MetadataType.F_MODIFY_TIMESTAMP), def, now);
    ((Collection) deltas).add(delta);
    if (task.getOwner() != null) {
        ReferenceDelta refDelta = ReferenceDelta.createModificationReplace(metadataPath.subPath(MetadataType.F_MODIFIER_REF), def, task.getOwner().getOid());
        ((Collection) deltas).add(refDelta);
    }
    return deltas;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList) Collection(java.util.Collection) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta)

Example 55 with ReferenceDelta

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

the class TestModelServiceContract method test128ModifyUserDeleteAccountRef.

@Test
public void test128ModifyUserDeleteAccountRef() throws Exception {
    TestUtil.displayTestTile(this, "test128ModifyUserDeleteAccountRef");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test128ModifyUserDeleteAccountRef");
    OperationResult result = task.getResult();
    preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), accountJackOid);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    assertShadowFetchOperationCountIncrement(0);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    assertUserJack(userJack);
    // Check accountRef
    assertUserNoAccountRefs(userJack);
    // Check shadow (if it is unchanged)
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
    assertDummyAccountShadowRepo(accountShadow, accountJackOid, "jack");
    // Check account (if it is unchanged)
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
    assertDummyAccountShadowModel(accountModel, accountJackOid, "jack", "Jack Sparrow");
    // Check account in dummy resource (if it is unchanged)
    assertDefaultDummyAccount("jack", "Jack Sparrow", true);
    // Check audit
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(1);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    // Check notifications
    notificationManager.setDisabled(true);
    checkDummyTransportMessages("accountPasswordNotifier", 0);
    checkDummyTransportMessages("userPasswordNotifier", 0);
    checkDummyTransportMessages("simpleAccountNotifier-SUCCESS", 0);
    checkDummyTransportMessages("simpleAccountNotifier-FAILURE", 0);
    checkDummyTransportMessages("simpleAccountNotifier-ADD-SUCCESS", 0);
    checkDummyTransportMessages("simpleAccountNotifier-DELETE-SUCCESS", 0);
    checkDummyTransportMessages("simpleUserNotifier", 0);
    checkDummyTransportMessages("simpleUserNotifier-ADD", 0);
    assertSteadyResources();
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowDiscriminatorObjectDelta(com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Aggregations

ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)49 Task (com.evolveum.midpoint.task.api.Task)44 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)42 Test (org.testng.annotations.Test)41 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)27 Collection (java.util.Collection)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 ArrayList (java.util.ArrayList)12 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)11 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6