Search in sources :

Example 51 with PrismObject

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

the class PageAccounts method loadShadowOwner.

private <F extends FocusType> F loadShadowOwner(IModel<SelectableBean> model) {
    F owner = null;
    ShadowType shadow = getShadow(model);
    String shadowOid;
    if (shadow != null) {
        shadowOid = shadow.getOid();
    } else {
        return null;
    }
    Task task = createSimpleTask(OPERATION_LOAD_ACCOUNT_OWNER);
    OperationResult result = new OperationResult(OPERATION_LOAD_ACCOUNT_OWNER);
    try {
        PrismObject prismOwner = getModelService().searchShadowOwner(shadowOid, null, task, result);
        if (prismOwner != null) {
            owner = (F) prismOwner.asObjectable();
        }
    } catch (ObjectNotFoundException exception) {
    //owner was not found, it's possible and it's ok on unlinked accounts
    } catch (Exception ex) {
        result.recordFatalError(getString("PageAccounts.message.ownerNotFound", shadowOid), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Could not load owner of account with oid: " + shadowOid, ex);
    } finally {
        result.computeStatusIfUnknown();
    }
    if (WebComponentUtil.showResultInPage(result)) {
        showResult(result, false);
    }
    return owner;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 52 with PrismObject

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

the class PageSelfDashboard method getAssignmentDescription.

private String getAssignmentDescription(PrismObject value) {
    Object orgIdentifier = null;
    if (OrgType.class.isAssignableFrom(value.getCompileTimeClass())) {
        orgIdentifier = value.getPropertyRealValue(OrgType.F_IDENTIFIER, String.class);
    }
    String description = (orgIdentifier != null ? orgIdentifier + " " : "") + (value.asObjectable() instanceof ObjectType && value.asObjectable().getDescription() != null ? value.asObjectable().getDescription() : "");
    return description;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 53 with PrismObject

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

the class TestParseMetarole method assertPrismContainerValueLocal.

@Override
protected void assertPrismContainerValueLocal(PrismContainerValue<RoleType> value) throws SchemaException {
    PrismObject user = value.asContainerable().asPrismObject();
    user.checkConsistence();
    assertMetarolePrism(user, false);
    assertMetaroleJaxb(value.asContainerable(), false);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 54 with PrismObject

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

the class ShadowIntegrityCheckResultHandler method checkShadow.

private void checkShadow(ShadowCheckResult checkResult, PrismObject<ShadowType> shadow, Task workerTask, OperationResult result) throws SchemaException {
    ShadowType shadowType = shadow.asObjectable();
    ObjectReferenceType resourceRef = shadowType.getResourceRef();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Checking shadow {} (resource {})", ObjectTypeUtil.toShortString(shadowType), resourceRef != null ? resourceRef.getOid() : "(null)");
    }
    statistics.incrementShadows();
    if (resourceRef == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("No resourceRef"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    String resourceOid = resourceRef.getOid();
    if (resourceOid == null) {
        checkResult.recordError(Statistics.NO_RESOURCE_OID, new SchemaException("Null resource OID"));
        fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE_OID);
        applyFixes(checkResult, shadow, workerTask, result);
        return;
    }
    PrismObject<ResourceType> resource = resources.get(resourceOid);
    if (resource == null) {
        statistics.incrementResources();
        try {
            resource = provisioningService.getObject(ResourceType.class, resourceOid, null, workerTask, result);
        } catch (ObjectNotFoundException e) {
            checkResult.recordError(Statistics.NO_RESOURCE, new ObjectNotFoundException("Resource object does not exist: " + e.getMessage(), e));
            fixNoResourceIfRequested(checkResult, Statistics.NO_RESOURCE);
            applyFixes(checkResult, shadow, workerTask, result);
            return;
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SchemaException("Resource object has schema problems: " + e.getMessage(), e));
            return;
        } catch (CommonException | RuntimeException e) {
            checkResult.recordError(Statistics.CANNOT_GET_RESOURCE, new SystemException("Resource object cannot be fetched for some reason: " + e.getMessage(), e));
            return;
        }
        resources.put(resourceOid, resource);
    }
    checkResult.setResource(resource);
    ShadowKindType kind = shadowType.getKind();
    if (kind == null) {
        // TODO or simply assume account?
        checkResult.recordError(Statistics.NO_KIND_SPECIFIED, new SchemaException("No kind specified"));
        return;
    }
    if (checkExtraData) {
        checkOrFixShadowActivationConsistency(checkResult, shadow, fixExtraData);
    }
    PrismObject<ShadowType> fetchedShadow = null;
    if (checkFetch) {
        fetchedShadow = fetchShadow(checkResult, shadow, resource, workerTask, result);
        if (fetchedShadow != null) {
            shadow.setUserData(KEY_EXISTS_ON_RESOURCE, "true");
        }
    }
    if (checkOwners) {
        List<PrismObject<FocusType>> owners = searchOwners(shadow, result);
        if (owners != null) {
            shadow.setUserData(KEY_OWNERS, owners);
            if (owners.size() > 1) {
                checkResult.recordError(Statistics.MULTIPLE_OWNERS, new SchemaException("Multiple owners: " + owners));
            }
        }
        if (shadowType.getSynchronizationSituation() == SynchronizationSituationType.LINKED && (owners == null || owners.isEmpty())) {
            checkResult.recordError(Statistics.LINKED_WITH_NO_OWNER, new SchemaException("Linked shadow with no owner"));
        }
        if (shadowType.getSynchronizationSituation() != SynchronizationSituationType.LINKED && owners != null && !owners.isEmpty()) {
            checkResult.recordError(Statistics.NOT_LINKED_WITH_OWNER, new SchemaException("Shadow with an owner but not marked as linked (marked as " + shadowType.getSynchronizationSituation() + ")"));
        }
    }
    String intent = shadowType.getIntent();
    if (checkIntents && (intent == null || intent.isEmpty())) {
        checkResult.recordWarning(Statistics.NO_INTENT_SPECIFIED, "None or empty intent");
    }
    if (fixIntents && (intent == null || intent.isEmpty())) {
        doFixIntent(checkResult, fetchedShadow, shadow, resource, workerTask, result);
    }
    Pair<String, ShadowKindType> key = new ImmutablePair<>(resourceOid, kind);
    ObjectTypeContext context = contextMap.get(key);
    if (context == null) {
        context = new ObjectTypeContext();
        context.setResource(resource);
        RefinedResourceSchema resourceSchema;
        try {
            resourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(context.getResource(), LayerType.MODEL, prismContext);
        } catch (SchemaException e) {
            checkResult.recordError(Statistics.CANNOT_GET_REFINED_SCHEMA, new SchemaException("Couldn't derive resource schema: " + e.getMessage(), e));
            return;
        }
        if (resourceSchema == null) {
            checkResult.recordError(Statistics.NO_RESOURCE_REFINED_SCHEMA, new SchemaException("No resource schema"));
            return;
        }
        context.setObjectClassDefinition(resourceSchema.getRefinedDefinition(kind, shadowType));
        if (context.getObjectClassDefinition() == null) {
            // TODO or warning only?
            checkResult.recordError(Statistics.NO_OBJECT_CLASS_REFINED_SCHEMA, new SchemaException("No refined object class definition for kind=" + kind + ", intent=" + intent));
            return;
        }
        contextMap.put(key, context);
    }
    try {
        provisioningService.applyDefinition(shadow, workerTask, result);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        checkResult.recordError(Statistics.OTHER_FAILURE, new SystemException("Couldn't apply definition to shadow from repo", e));
        return;
    }
    Set<RefinedAttributeDefinition<?>> identifiers = new HashSet<>();
    Collection<? extends RefinedAttributeDefinition<?>> primaryIdentifiers = context.getObjectClassDefinition().getPrimaryIdentifiers();
    identifiers.addAll(primaryIdentifiers);
    identifiers.addAll(context.getObjectClassDefinition().getSecondaryIdentifiers());
    PrismContainer<ShadowAttributesType> attributesContainer = shadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // might happen on unfinished shadows?
        checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("No attributes container"));
        return;
    }
    for (RefinedAttributeDefinition<?> identifier : identifiers) {
        PrismProperty property = attributesContainer.getValue().findProperty(identifier.getName());
        if (property == null || property.size() == 0) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "No value for identifier " + identifier.getName());
            continue;
        }
        if (property.size() > 1) {
            // we don't expect multi-valued identifiers
            checkResult.recordError(Statistics.OTHER_FAILURE, new SchemaException("Multi-valued identifier " + identifier.getName() + " with values " + property.getValues()));
            continue;
        }
        // size == 1
        String value = (String) property.getValue().getValue();
        if (value == null) {
            checkResult.recordWarning(Statistics.OTHER_FAILURE, "Null value for identifier " + identifier.getName());
            continue;
        }
        if (checkUniqueness) {
            if (!checkDuplicatesOnPrimaryIdentifiersOnly || primaryIdentifiers.contains(identifier)) {
                addIdentifierValue(checkResult, context, identifier.getName(), value, shadow);
            }
        }
        if (checkNormalization) {
            doCheckNormalization(checkResult, identifier, value, context);
        }
    }
    applyFixes(checkResult, shadow, workerTask, result);
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) HashSet(java.util.HashSet) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)

Example 55 with PrismObject

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

PrismObject (com.evolveum.midpoint.prism.PrismObject)488 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)358 Test (org.testng.annotations.Test)227 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)219 Task (com.evolveum.midpoint.task.api.Task)205 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)97 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)95 ArrayList (java.util.ArrayList)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)79 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)64 QName (javax.xml.namespace.QName)59 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)50 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)40 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)37 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)37 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)37 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)37 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)37 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)34