Search in sources :

Example 16 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue 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)

Example 17 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class OrgStructFunctionsImpl method getManagersOfOrg.

@Override
public Collection<UserType> getManagersOfOrg(String orgOid, boolean preAuthorized) throws SchemaException, SecurityViolationException {
    Set<UserType> retval = new HashSet<UserType>();
    OperationResult result = new OperationResult("getManagerOfOrg");
    PrismReferenceValue parentOrgRefVal = new PrismReferenceValue(orgOid, OrgType.COMPLEX_TYPE);
    parentOrgRefVal.setRelation(SchemaConstants.ORG_MANAGER);
    ObjectQuery objectQuery = QueryBuilder.queryFor(ObjectType.class, prismContext).item(ObjectType.F_PARENT_ORG_REF).ref(parentOrgRefVal).build();
    List<PrismObject<ObjectType>> members = searchObjects(ObjectType.class, objectQuery, result, preAuthorized);
    for (PrismObject<ObjectType> member : members) {
        if (member.asObjectable() instanceof UserType) {
            UserType user = (UserType) member.asObjectable();
            retval.add(user);
        }
    }
    return retval;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 18 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class ObjectMerger method computeProjectionDeltas.

private <O extends ObjectType> void computeProjectionDeltas(final ObjectDelta<O> leftLinkDelta, ObjectDelta<O> rightLinkDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, SecurityViolationException {
    List<ShadowType> projectionsLeft = getProjections(objectLeft, task, result);
    List<ShadowType> projectionsRight = getProjections(objectRight, task, result);
    List<ShadowType> mergedProjections = new ArrayList<>();
    List<ShadowType> matchedProjections = new ArrayList<>();
    ProjectionMergeConfigurationType defaultProjectionMergeConfig = null;
    for (ProjectionMergeConfigurationType projectionMergeConfig : mergeConfiguration.getProjection()) {
        if (projectionMergeConfig.getProjectionDiscriminator() == null && projectionMergeConfig.getSituation() == null) {
            defaultProjectionMergeConfig = projectionMergeConfig;
        } else {
            takeProjections(projectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft, projectionsLeft, projectionsRight, projectionMergeConfig);
            takeProjections(projectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight, projectionsLeft, projectionsRight, projectionMergeConfig);
        }
    }
    LOGGER.trace("Merged projections (before default): {}", mergedProjections);
    LOGGER.trace("Matched projections (before default): {}", matchedProjections);
    if (defaultProjectionMergeConfig != null) {
        takeUnmatchedProjections(defaultProjectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft);
        takeUnmatchedProjections(defaultProjectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight);
    }
    LOGGER.trace("Merged projections: {}", mergedProjections);
    checkConflict(mergedProjections);
    for (ShadowType mergedProjection : mergedProjections) {
        PrismReferenceValue leftLinkRef = findLinkRef(objectLeft, mergedProjection);
        if (leftLinkRef == null) {
            PrismReferenceValue linkRefRight = findLinkRef(objectRight, mergedProjection);
            LOGGER.trace("Moving projection right->left: {}", mergedProjection);
            addUnlinkDelta(rightLinkDelta, linkRefRight);
            addLinkDelta(leftLinkDelta, linkRefRight);
        } else {
            LOGGER.trace("Projection already at the left: {}", mergedProjection);
        }
    }
    for (PrismReferenceValue leftLinkRef : getLinkRefs(objectLeft)) {
        if (!hasProjection(mergedProjections, leftLinkRef)) {
            LOGGER.trace("Removing left projection: {}", leftLinkRef);
            addUnlinkDelta(leftLinkDelta, leftLinkRef);
        } else {
            LOGGER.trace("Left projection stays: {}", leftLinkRef);
        }
    }
}
Also used : ProjectionMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeConfigurationType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList)

Example 19 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class TestModelCrudService method test119ModifyUserDeleteAccount.

@Test
public void test119ModifyUserDeleteAccount() throws Exception {
    TestUtil.displayTestTile(this, "test119ModifyUserDeleteAccount");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestModelCrudService.class.getName() + ".test119ModifyUserDeleteAccount");
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    account.setOid(accountOid);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
    modifications.add(accountDelta);
    // WHEN
    modelCrudService.modifyObject(UserType.class, USER_JACK_OID, modifications, null, task, result);
    // THEN
    // Check accountRef
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    assertUserJack(userJack);
    UserType userJackType = userJack.asObjectable();
    assertEquals("Unexpected number of accountRefs", 0, userJackType.getLinkRef().size());
    // Check is shadow is gone
    try {
        PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
        AssertJUnit.fail("Shadow " + accountOid + " still exists");
    } catch (ObjectNotFoundException e) {
    // This is OK
    }
    // Check if dummy resource account is gone
    assertNoDummyAccount("jack");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) Test(org.testng.annotations.Test)

Example 20 with PrismReferenceValue

use of com.evolveum.midpoint.prism.PrismReferenceValue in project midpoint by Evolveum.

the class OrgClosureManager method getParentOidsToAdd.

// filters out those OIDs that are already present in originalObject (beware, it may be null)
private Set<String> getParentOidsToAdd(Collection<? extends ItemDelta> modifications, PrismObject<? extends ObjectType> originalObject) {
    Set<String> oids = new HashSet<>();
    Set<String> existingOids = getParentOidsFromObject(originalObject);
    for (ItemDelta delta : modifications) {
        if (delta.getValuesToAdd() != null) {
            for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToAdd()) {
                String oid = val.getOid();
                if (!existingOids.contains(oid)) {
                    // if it's already there, we don't want to add it
                    oids.add(oid);
                }
            }
        }
        if (delta.getValuesToReplace() != null) {
            // at this point we can assume this is not mixed with DELETE or ADD deltas
            // we mark all 'new' values in REPLACE delta not present in existing object as being added
            // and we do this for the latest REPLACE ItemDelta
            oids = new HashSet<>();
            for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToReplace()) {
                String oid = val.getOid();
                if (!existingOids.contains(oid)) {
                    // if it's already there, we don't want to add it
                    oids.add(oid);
                }
            }
        }
    }
    return oids;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)126 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)64 Test (org.testng.annotations.Test)47 Task (com.evolveum.midpoint.task.api.Task)45 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)32 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)27 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)25 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)24 ArrayList (java.util.ArrayList)22 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)20 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)16 PrismReference (com.evolveum.midpoint.prism.PrismReference)15 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)15 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)15 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)12 Collection (java.util.Collection)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)11