Search in sources :

Example 31 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType 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 32 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ShadowIntegrityCheckResultHandler method searchOwners.

private List<PrismObject<FocusType>> searchOwners(PrismObject<ShadowType> shadow, OperationResult result) {
    try {
        ObjectQuery ownerQuery = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_LINK_REF).ref(shadow.getOid()).build();
        List<PrismObject<FocusType>> owners = repositoryService.searchObjects(FocusType.class, ownerQuery, null, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Owners for {}: {}", ObjectTypeUtil.toShortString(shadow), owners);
        }
        return owners;
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't create/execute owners query for shadow {}", e, ObjectTypeUtil.toShortString(shadow));
        return null;
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 33 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class MidpointFunctionsImpl method computeProjectionLifecycle.

@Override
public <F extends FocusType> String computeProjectionLifecycle(F focus, ShadowType shadow, ResourceType resource) {
    if (focus == null || shadow == null) {
        return null;
    }
    if (!(focus instanceof UserType)) {
        return null;
    }
    if (shadow.getKind() != null && shadow.getKind() != ShadowKindType.ACCOUNT) {
        return null;
    }
    ProtectedStringType passwordPs = FocusTypeUtil.getPasswordValue((UserType) focus);
    if (passwordPs != null && passwordPs.canGetCleartext()) {
        return null;
    }
    CredentialsCapabilityType credentialsCapabilityType = ResourceTypeUtil.getEffectiveCapability(resource, CredentialsCapabilityType.class);
    if (credentialsCapabilityType == null) {
        return null;
    }
    PasswordCapabilityType passwordCapabilityType = credentialsCapabilityType.getPassword();
    if (passwordCapabilityType == null) {
        return null;
    }
    if (passwordCapabilityType.isEnabled() == Boolean.FALSE) {
        return null;
    }
    return SchemaConstants.LIFECYCLE_PROPOSED;
}
Also used : PasswordCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.PasswordCapabilityType) CredentialsCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CredentialsCapabilityType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 34 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ObjectMerger method getProjections.

private <O extends ObjectType> List<ShadowType> getProjections(PrismObject<O> objectRight, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (!objectRight.canRepresent(FocusType.class)) {
        return new ArrayList<>(0);
    }
    List<ObjectReferenceType> linkRefs = ((FocusType) objectRight.asObjectable()).getLinkRef();
    List<ShadowType> projections = new ArrayList<>(linkRefs.size());
    for (ObjectReferenceType linkRef : linkRefs) {
        projections.add(getProjection(linkRef, task, result));
    }
    return projections;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) 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)

Example 35 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ObjectTemplateProcessor method getUpdatedFocusOdo.

private <F extends FocusType> ObjectDeltaObject<F> getUpdatedFocusOdo(LensContext<F> context, ObjectDeltaObject<F> focusOdo, Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, ObjectTemplateMappingType mappingType, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
    ObjectDeltaObject<F> focusOdoCloned = null;
    for (VariableBindingDefinitionType source : mappingType.getSource()) {
        if (source.getPath() == null) {
            continue;
        }
        ItemPath path = stripFocusVariableSegment(source.getPath().getItemPath());
        if (path.startsWithVariable()) {
            continue;
        }
        DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>> triple = DeltaSetTriple.find(outputTripleMap, path);
        if (triple == null) {
            continue;
        }
        if (focusOdoCloned == null) {
            LOGGER.trace("Cloning and updating focusOdo because of chained mappings; chained source path: {}", path);
            focusOdoCloned = focusOdo.clone();
        } else {
            LOGGER.trace("Updating focusOdo because of chained mappings; chained source path: {}", path);
        }
        Class<F> focusClass = context.getFocusContext().getObjectTypeClass();
        ItemDefinition<?> itemDefinition = getObjectDefinition(focusClass).findItemDefinition(path);
        // TODO not much sure about the parameters
        ItemDelta itemDelta = LensUtil.consolidateTripleToDelta(path, (DeltaSetTriple) triple, itemDefinition, getAprioriItemDelta(focusOdo.getObjectDelta(), path), focusOdo.getNewObject(), null, null, true, true, false, " updating chained source (" + path + ") in " + contextDesc, true);
        LOGGER.trace("Updating focus ODO with delta:\n{}", itemDelta.debugDumpLazily());
        focusOdoCloned.update(itemDelta);
    }
    return focusOdoCloned != null ? focusOdoCloned : focusOdo;
}
Also used : VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7