Search in sources :

Example 6 with ReferenceDelta

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

the class TestDeltaConverter method testRefWithObject.

@Test
public void testRefWithObject() throws SchemaException, IOException, JAXBException {
    System.out.println("===[ testRefWithObject ]====");
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-add-account.xml"), ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext());
    System.out.println("delta: " + objectDelta.debugDump());
    assertNotNull("No object delta", objectDelta);
    objectDelta.checkConsistence();
    assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid());
    ReferenceDelta accoutRefDelta = objectDelta.findReferenceModification(UserType.F_LINK_REF);
    assertNotNull("No accountRef delta", accoutRefDelta);
    Collection<PrismReferenceValue> valuesToAdd = accoutRefDelta.getValuesToAdd();
    assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
    PrismReferenceValue accountRefVal = valuesToAdd.iterator().next();
    assertNotNull("No object in accountRef value", accountRefVal.getObject());
    objectDelta.assertDefinitions();
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) File(java.io.File) Test(org.testng.annotations.Test)

Example 7 with ReferenceDelta

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

the class TestDeltaConverter method testModifyInducement.

@Test
public void testModifyInducement() throws Exception {
    System.out.println("===[ testModifyInducement ]====");
    ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "role-modify-inducement.xml"), ObjectModificationType.COMPLEX_TYPE);
    // WHEN
    ObjectDelta<RoleType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, RoleType.class, getPrismContext());
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    // THEN
    assertNotNull("No object delta", objectDelta);
    objectDelta.checkConsistence();
    assertEquals("Wrong OID", "00000000-8888-6666-0000-100000000005", objectDelta.getOid());
    ReferenceDelta targetRefDelta = objectDelta.findReferenceModification(new ItemPath(new NameItemPathSegment(RoleType.F_INDUCEMENT), new IdItemPathSegment(5L), new NameItemPathSegment(AssignmentType.F_TARGET_REF)));
    assertNotNull("No targetRef delta", targetRefDelta);
    Collection<PrismReferenceValue> valuesToAdd = targetRefDelta.getValuesToAdd();
    assertEquals("Wrong number of values to add", 1, valuesToAdd.size());
    PrismReferenceValue targetRefVal = valuesToAdd.iterator().next();
    assertNotNull("Null value in targetRef delta", targetRefVal);
    assertEquals("wrong OID in targetRef", "12345678-d34d-b33f-f00d-987987987987", targetRefVal.getOid());
    assertEquals("wrong target type in targetRef", RoleType.COMPLEX_TYPE, targetRefVal.getTargetType());
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) File(java.io.File) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 8 with ReferenceDelta

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

the class ResourceContentPanel method changeOwner.

private void changeOwner(ShadowType selected, AjaxRequestTarget target, FocusType ownerToChange, Operation operation) {
    List<ShadowType> selectedShadow = getSelectedShadowsList(selected);
    Collection<? extends ItemDelta> modifications = new ArrayList<>();
    ReferenceDelta delta = null;
    switch(operation) {
        case REMOVE:
            for (ShadowType shadow : selectedShadow) {
                modifications = new ArrayList<>();
                FocusType owner = loadShadowOwner(shadow.getOid());
                if (owner != null) {
                    delta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
                    ((Collection) modifications).add(delta);
                    changeOwnerInternal(owner.getOid(), modifications, target);
                }
            }
            break;
        case MODIFY:
            if (!isSatisfyConstraints(selectedShadow)) {
                break;
            }
            ShadowType shadow = selectedShadow.iterator().next();
            FocusType owner = loadShadowOwner(shadow.getOid());
            if (owner != null) {
                delta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
                ((Collection) modifications).add(delta);
                changeOwnerInternal(owner.getOid(), modifications, target);
            }
            modifications = new ArrayList<>();
            delta = ReferenceDelta.createModificationAdd(FocusType.F_LINK_REF, getFocusDefinition(), ObjectTypeUtil.createObjectRef(shadow).asReferenceValue());
            ((Collection) modifications).add(delta);
            changeOwnerInternal(ownerToChange.getOid(), modifications, target);
            break;
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Collection(java.util.Collection)

Example 9 with ReferenceDelta

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

the class OperationalDataManager method applyMetadataModify.

public <T extends ObjectType, F extends ObjectType> void applyMetadataModify(ObjectDelta<T> objectDelta, LensElementContext<T> objectContext, Class objectTypeClass, XMLGregorianCalendar now, Task task, LensContext<F> context, OperationResult result) throws SchemaException {
    String channel = LensUtil.getChannel(context, task);
    PrismObjectDefinition<T> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(objectTypeClass);
    ItemDelta.mergeAll(objectDelta.getModifications(), createModifyMetadataDeltas(context, new ItemPath(ObjectType.F_METADATA), def, now, task));
    List<PrismReferenceValue> approverReferenceValues = new ArrayList<PrismReferenceValue>();
    if (workflowManager != null) {
        for (ObjectReferenceType approverRef : workflowManager.getApprovedBy(task, result)) {
            approverReferenceValues.add(new PrismReferenceValue(approverRef.getOid()));
        }
    }
    if (!approverReferenceValues.isEmpty()) {
        ReferenceDelta refDelta = ReferenceDelta.createModificationReplace((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, approverReferenceValues);
        ((Collection) objectDelta.getModifications()).add(refDelta);
    } else {
        if (objectContext != null && objectContext.getObjectOld() != null) {
            if (objectContext.getObjectOld().asObjectable().getMetadata() != null) {
                List<ObjectReferenceType> existingModifyApproverRefs = objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef();
                LOGGER.trace("Original values of MODIFY_APPROVER_REF: {}", existingModifyApproverRefs);
                if (!existingModifyApproverRefs.isEmpty()) {
                    List<PrismReferenceValue> valuesToDelete = new ArrayList<PrismReferenceValue>();
                    for (ObjectReferenceType approverRef : objectContext.getObjectOld().asObjectable().getMetadata().getModifyApproverRef()) {
                        valuesToDelete.add(approverRef.asReferenceValue().clone());
                    }
                    ReferenceDelta refDelta = ReferenceDelta.createModificationDelete((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF)), def, valuesToDelete);
                    ((Collection) objectDelta.getModifications()).add(refDelta);
                }
            }
        }
    }
    if (FocusType.class.isAssignableFrom(objectTypeClass)) {
        applyAssignmentMetadataDelta((LensContext) context, (ObjectDelta) objectDelta, now, task, result);
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) Collection(java.util.Collection) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with ReferenceDelta

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

the class ShadowIntegrityCheckResultHandler method deleteShadows.

// shadowsToDelete do not contain 'already deleted shadows'
private void deleteShadows(DuplicateShadowsTreatmentInstruction instruction, StringBuilder sb, Task task, OperationResult result) {
    LOGGER.trace("Going to delete shadows:\n{}", instruction);
    if (instruction == null || instruction.getShadowsToDelete() == null) {
        return;
    }
    Collection<PrismObject<ShadowType>> shadowsToDelete = instruction.getShadowsToDelete();
    String shadowOidToReplaceDeleted = instruction.getShadowOidToReplaceDeletedOnes();
    for (PrismObject<ShadowType> shadowToDelete : shadowsToDelete) {
        LOGGER.info("Deleting redundant shadow{} {}", skippedForDryRun(), ObjectTypeUtil.toShortString(shadowToDelete));
        sb.append("   --> deleted redundant shadow").append(skippedForDryRun()).append(" ").append(ObjectTypeUtil.toShortString(shadowToDelete)).append("\n");
        String oid = shadowToDelete.getOid();
        List<PrismObject<FocusType>> owners;
        if (checkOwners) {
            owners = (List) shadowToDelete.getUserData(KEY_OWNERS);
        } else {
            owners = searchOwners(shadowToDelete, result);
        }
        if (!dryRun) {
            try {
                repositoryService.deleteObject(ShadowType.class, oid, result);
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, null);
                duplicateShadowsDeleted.add(oid);
            } catch (ObjectNotFoundException e) {
                // suspicious, but not a big deal
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logExceptionAsWarning(LOGGER, "Shadow {} couldn't be deleted, because it does not exist anymore", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            } catch (RuntimeException e) {
                task.recordObjectActionExecuted(shadowToDelete, ChangeType.DELETE, e);
                LoggingUtils.logUnexpectedException(LOGGER, "Shadow {} couldn't be deleted because of an unexpected exception", e, ObjectTypeUtil.toShortString(shadowToDelete));
                continue;
            }
        }
        if (owners == null || owners.isEmpty()) {
            continue;
        }
        for (PrismObject owner : owners) {
            List<ItemDelta> modifications = new ArrayList<>(2);
            ReferenceDelta deleteDelta = ReferenceDelta.createModificationDelete(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(oid, ShadowType.COMPLEX_TYPE));
            modifications.add(deleteDelta);
            if (shadowOidToReplaceDeleted != null) {
                ReferenceDelta addDelta = ReferenceDelta.createModificationAdd(FocusType.F_LINK_REF, owner.getDefinition(), new PrismReferenceValue(shadowOidToReplaceDeleted, ShadowType.COMPLEX_TYPE));
                modifications.add(addDelta);
            }
            LOGGER.info("Executing modify delta{} for owner {}:\n{}", skippedForDryRun(), ObjectTypeUtil.toShortString(owner), DebugUtil.debugDump(modifications));
            if (!dryRun) {
                try {
                    repositoryService.modifyObject((Class) owner.getClass(), owner.getOid(), modifications, result);
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, null);
                } catch (ObjectNotFoundException | SchemaException | ObjectAlreadyExistsException | RuntimeException e) {
                    task.recordObjectActionExecuted(owner, ChangeType.MODIFY, e);
                    LoggingUtils.logUnexpectedException(LOGGER, "Focal object {} (owner of {}) couldn't be updated", e, ObjectTypeUtil.toShortString(owner), ObjectTypeUtil.toShortString(shadowToDelete));
                }
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

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