Search in sources :

Example 41 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.

the class Mapping method parseSource.

private <IV extends PrismValue, ID extends ItemDefinition> Source<IV, ID> parseSource(VariableBindingDefinitionType sourceType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ItemPathType itemPathType = sourceType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in source definition in " + getMappingContextDescription());
    }
    ItemPath path = itemPathType.getItemPath();
    if (path.isEmpty()) {
        throw new SchemaException("Empty source path in " + getMappingContextDescription());
    }
    QName name = sourceType.getName();
    if (name == null) {
        name = ItemPath.getName(path.last());
    }
    ItemPath resolvePath = path;
    Object sourceObject = ExpressionUtil.resolvePath(path, variables, sourceContext, objectResolver, "source definition in " + getMappingContextDescription(), task, result);
    Item<IV, ID> itemOld = null;
    ItemDelta<IV, ID> delta = null;
    Item<IV, ID> itemNew = null;
    ItemPath residualPath = null;
    Collection<? extends ItemDelta<?, ?>> subItemDeltas = null;
    if (sourceObject != null) {
        if (sourceObject instanceof ItemDeltaItem<?, ?>) {
            itemOld = ((ItemDeltaItem<IV, ID>) sourceObject).getItemOld();
            delta = ((ItemDeltaItem<IV, ID>) sourceObject).getDelta();
            itemNew = ((ItemDeltaItem<IV, ID>) sourceObject).getItemNew();
            residualPath = ((ItemDeltaItem<IV, ID>) sourceObject).getResidualPath();
            resolvePath = ((ItemDeltaItem<IV, ID>) sourceObject).getResolvePath();
            subItemDeltas = ((ItemDeltaItem<IV, ID>) sourceObject).getSubItemDeltas();
        } else if (sourceObject instanceof Item<?, ?>) {
            itemOld = (Item<IV, ID>) sourceObject;
            itemNew = (Item<IV, ID>) sourceObject;
        } else {
            throw new IllegalStateException("Unknown resolve result " + sourceObject);
        }
    }
    // apply domain
    ValueSetDefinitionType domainSetType = sourceType.getSet();
    if (domainSetType != null) {
        ValueSetDefinition setDef = new ValueSetDefinition(domainSetType, name, "domain of " + name.getLocalPart() + " in " + getMappingContextDescription(), task, result);
        setDef.init(expressionFactory);
        try {
            if (itemOld != null) {
                itemOld = itemOld.clone();
                itemOld.filterValues(val -> setDef.containsTunnel(val));
            }
            if (itemNew != null) {
                itemNew = itemNew.clone();
                itemNew.filterValues(val -> setDef.containsTunnel(val));
            }
            if (delta != null) {
                delta = delta.clone();
                delta.filterValues(val -> setDef.containsTunnel(val));
            }
        } catch (TunnelException te) {
            Throwable cause = te.getCause();
            if (cause instanceof SchemaException) {
                throw (SchemaException) cause;
            } else if (cause instanceof ExpressionEvaluationException) {
                throw (ExpressionEvaluationException) cause;
            } else if (cause instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) cause;
            }
        }
    }
    Source<IV, ID> source = new Source<>(itemOld, delta, itemNew, name);
    source.setResidualPath(residualPath);
    source.setResolvePath(resolvePath);
    source.setSubItemDeltas(subItemDeltas);
    return source;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) Source(com.evolveum.midpoint.repo.common.expression.Source) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ValueSetDefinition(com.evolveum.midpoint.repo.common.expression.ValueSetDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 42 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.

the class Mapping method evaluateBody.

// TODO: rename to evaluate
public void evaluateBody(Task task, OperationResult parentResult) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    assertState(MappingEvaluationState.PREPARED);
    OperationResult result = parentResult.createMinorSubresult(Mapping.class.getName() + ".evaluate");
    traceEvaluationStart();
    try {
        // We may need to re-parse the sources here
        evaluateTimeConstraintValid(task, result);
        if (!timeConstraintValid) {
            outputTriple = null;
            result.recordNotApplicableIfUnknown();
            traceDeferred();
            return;
        }
        evaluateCondition(task, result);
        boolean conditionOutputOld = computeConditionResult(conditionOutputTriple.getNonPositiveValues());
        boolean conditionResultOld = conditionOutputOld && conditionMaskOld;
        boolean conditionOutputNew = computeConditionResult(conditionOutputTriple.getNonNegativeValues());
        boolean conditionResultNew = conditionOutputNew && conditionMaskNew;
        if (!conditionResultOld && !conditionResultNew) {
            outputTriple = null;
            transitionState(MappingEvaluationState.EVALUATED);
            result.recordNotApplicableIfUnknown();
            traceNotApplicable("condition is false");
            return;
        }
        // TODO: input filter
        evaluateExpression(task, result, conditionResultOld, conditionResultNew);
        fixDefinition();
        recomputeValues();
        setOrigin();
        // TODO: output filter
        checkRange(task, result);
        transitionState(MappingEvaluationState.EVALUATED);
        result.recordSuccess();
        traceSuccess(conditionResultOld, conditionResultNew);
    } catch (ExpressionEvaluationException | ObjectNotFoundException | RuntimeException | SchemaException | Error e) {
        result.recordFatalError(e);
        traceFailure(e);
        throw e;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 43 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.

the class ObjectWrapperFactory method createObjectWrapper.

public <O extends ObjectType> ObjectWrapper<O> createObjectWrapper(String displayName, String description, PrismObject<O> object, ContainerStatus status, boolean delayContainerCreation, AuthorizationPhaseType authorizationPhase, Task task) {
    if (authorizationPhase == null) {
        authorizationPhase = AuthorizationPhaseType.REQUEST;
    }
    try {
        //        	Task task = modelServiceLocator.createSimpleTask(CREATE_OBJECT_WRAPPER);
        OperationResult result = task.getResult();
        PrismObjectDefinition<O> objectDefinitionForEditing = modelServiceLocator.getModelInteractionService().getEditObjectDefinition(object, authorizationPhase, task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Edit definition for {}:\n{}", object, objectDefinitionForEditing.debugDump(1));
        }
        RefinedObjectClassDefinition objectClassDefinitionForEditing = null;
        if (isShadow(object)) {
            PrismReference resourceRef = object.findReference(ShadowType.F_RESOURCE_REF);
            PrismObject<ResourceType> resource = resourceRef.getValue().getObject();
            Validate.notNull(resource, "No resource object in the resourceRef");
            objectClassDefinitionForEditing = modelServiceLocator.getModelInteractionService().getEditObjectClassDefinition((PrismObject<ShadowType>) object, resource, authorizationPhase);
        }
        return createObjectWrapper(displayName, description, object, objectDefinitionForEditing, objectClassDefinitionForEditing, status, delayContainerCreation, result);
    } catch (SchemaException | ConfigurationException | ObjectNotFoundException ex) {
        throw new SystemException(ex);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 44 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.

the class SampleFormFocusTabPanel method initLayout.

private void initLayout(final LoadableModel<ObjectWrapper<F>> focusModel, LoadableModel<List<AssignmentEditorDto>> assignmentsModel, PageBase pageBase) {
    add(new Label(ID_HEADER, "Object details"));
    WebMarkupContainer body = new WebMarkupContainer("body");
    add(body);
    addPrismPropertyPanel(body, ID_PROP_NAME, FocusType.F_NAME);
    addPrismPropertyPanel(body, ID_PROP_FULL_NAME, UserType.F_FULL_NAME);
    // TODO: create proxy for these operations
    Task task = pageBase.createSimpleTask(OPERATION_SEARCH_ROLES);
    List<PrismObject<RoleType>> availableRoles;
    try {
        availableRoles = pageBase.getModelService().searchObjects(RoleType.class, null, null, task, task.getResult());
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        task.getResult().recordFatalError(e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load roles", e);
        availableRoles = new ArrayList<>();
    // TODO: better errror reporting
    }
    add(new SimpleRoleSelector<F, RoleType>(ID_ROLES, assignmentsModel, availableRoles));
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 45 with ObjectNotFoundException

use of com.evolveum.midpoint.util.exception.ObjectNotFoundException in project midpoint by Evolveum.

the class DefaultGuiProgressListener method getResourceName.

private String getResourceName(@NotNull String oid) {
    String name = nameCache.get(oid);
    if (name != null) {
        return name;
    }
    Task task = parentPage.createSimpleTask("getResourceName");
    OperationResult result = new OperationResult("getResourceName");
    // todo what about security?
    Collection<SelectorOptions<GetOperationOptions>> raw = SelectorOptions.createCollection(GetOperationOptions.createRaw());
    try {
        PrismObject<ResourceType> object = parentPage.getModelService().getObject(ResourceType.class, oid, raw, task, result);
        name = PolyString.getOrig(object.asObjectable().getName());
    } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't determine the name of resource {}", e, oid);
        name = "(" + oid + ")";
    }
    nameCache.put(oid, name);
    return name;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceOperationResult(com.evolveum.midpoint.web.component.progress.ProgressReportActivityDto.ResourceOperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)291 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)214 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)200 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)93 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)90 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)88 Task (com.evolveum.midpoint.task.api.Task)75 SystemException (com.evolveum.midpoint.util.exception.SystemException)71 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)64 PrismObject (com.evolveum.midpoint.prism.PrismObject)52 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)42 Test (org.testng.annotations.Test)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 ArrayList (java.util.ArrayList)35 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)33 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)30 QName (javax.xml.namespace.QName)29 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)28