Search in sources :

Example 36 with ObjectNotFoundException

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

the class ImportObjectsFromFileTaskHandler method launch.

/**
     * Launch an import. Calling this method will start import in a new
     * thread, possibly on a different node.
     *
     * @param input
     * @param task
     * @param parentResult
     */
public void launch(File input, Task task, OperationResult parentResult) {
    LOGGER.debug("Launching import accounts from file {}", input);
    OperationResult result = parentResult.createSubresult(ImportObjectsFromFileTaskHandler.class.getName() + ".launch");
    result.addParam("input", input);
    // TODO
    // Set handler URI so we will be called back
    task.setHandlerUri(HANDLER_URI);
    // Readable task name
    PolyStringType polyString = new PolyStringType("Import from file " + input);
    task.setName(polyString);
    //        ((Collection)modifications).add(objectClassDelta);        
    try {
        PrismProperty filenameProp = filenamePropertyDefinition.instantiate();
        filenameProp.setRealValue(input.getAbsolutePath());
        task.setExtensionProperty(filenameProp);
        task.savePendingModifications(result);
    //            task.modify(modifications, result);
    } catch (ObjectNotFoundException e) {
        LOGGER.error("Task object not found, expecting it to exist (task {})", task, e);
        result.recordFatalError("Task object not found", e);
        throw new IllegalStateException("Task object not found, expecting it to exist", e);
    } catch (ObjectAlreadyExistsException e) {
        LOGGER.error("Task object was not updated (task {})", task, e);
        result.recordFatalError("Task object was not updated", e);
        throw new IllegalStateException("Task object was not updated", e);
    } catch (SchemaException e) {
        LOGGER.error("Error dealing with schema (task {})", task, e);
        result.recordFatalError("Error dealing with schema", e);
        throw new IllegalStateException("Error dealing with schema", e);
    }
    // Switch task to background. This will start new thread and call
    // the run(task) method.
    // Note: the thread may be actually started on a different node
    taskManager.switchToBackground(task, result);
    result.setBackgroundTaskOid(task.getOid());
    LOGGER.trace("Import objects from file {} switched to background, control thread returning with task {}", input, task);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 37 with ObjectNotFoundException

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

the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
    for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
        ShadowType shadowType;
        try {
            shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
        } catch (ObjectNotFoundException e) {
            // Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
            // the chance to react yet. Just ignore such shadow.
            LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
            continue;
        }
        if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            ObjectReferenceType shadowRef = new ObjectReferenceType();
            shadowRef.setOid(linkRef.getOid());
            shadowAssociationType.setShadowRef(shadowRef);
        }
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Example 38 with ObjectNotFoundException

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

the class LazyXPathVariableResolver method resolveVariable.

@Override
public Object resolveVariable(QName name) {
    if (variables == null) {
        return null;
    }
    if (name != null && (name.getNamespaceURI() == null || name.getNamespaceURI().isEmpty())) {
        LOGGER.warn("Using variable without a namespace (" + name + "), possible namespace problem (e.g. missing namespace prefix declaration) in " + contextDescription);
    }
    // Note: null is a legal variable name here. It corresponds to the root node
    Object variableValue = variables.get(name);
    if (variableValue == null) {
        // TODO: warning ???
        return null;
    }
    QName type = null;
    // Attempt to resolve object reference
    if (objectResolver != null && variableValue instanceof ObjectReferenceType) {
        ObjectReferenceType ref = (ObjectReferenceType) variableValue;
        if (ref.getOid() == null) {
            SchemaException newEx = new SchemaException("Null OID in reference in variable " + name + " in " + contextDescription, name);
            throw new TunnelException(newEx);
        } else {
            type = ref.getType();
            try {
                // TODO task
                variableValue = objectResolver.resolve(ref, ObjectType.class, null, contextDescription, null, result);
            } catch (ObjectNotFoundException e) {
                ObjectNotFoundException newEx = new ObjectNotFoundException("Object not found during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, ref.getOid());
                // We have no other practical way how to handle the error
                throw new TunnelException(newEx);
            } catch (SchemaException e) {
                ExpressionSyntaxException newEx = new ExpressionSyntaxException("Schema error during variable " + name + " resolution in " + contextDescription + ": " + e.getMessage(), e, name);
                throw new TunnelException(newEx);
            }
        }
    }
    try {
        return convertToXml(variableValue, name, prismContext, contextDescription);
    } catch (SchemaException e) {
        throw new TunnelException(e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException)

Example 39 with ObjectNotFoundException

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

the class XPathScriptEvaluator method evaluate.

private Object evaluate(QName returnType, String code, ExpressionVariables variables, ObjectResolver objectResolver, Collection<FunctionLibrary> functions, String contextDescription, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, ExpressionSyntaxException {
    XPathExpressionCodeHolder codeHolder = new XPathExpressionCodeHolder(code);
    //System.out.println("code " + code);
    XPath xpath = factory.newXPath();
    XPathVariableResolver variableResolver = new LazyXPathVariableResolver(variables, objectResolver, contextDescription, prismContext, result);
    xpath.setXPathVariableResolver(variableResolver);
    xpath.setNamespaceContext(new MidPointNamespaceContext(codeHolder.getNamespaceMap()));
    xpath.setXPathFunctionResolver(getFunctionResolver(functions));
    XPathExpression expr;
    try {
        expr = xpath.compile(codeHolder.getExpressionAsString());
    } catch (Exception e) {
        Throwable originalException = ExceptionUtil.lookForTunneledException(e);
        if (originalException != null && originalException instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) originalException;
        }
        if (originalException != null && originalException instanceof ExpressionSyntaxException) {
            throw (ExpressionSyntaxException) originalException;
        }
        if (e instanceof XPathExpressionException) {
            throw createExpressionEvaluationException(e, contextDescription);
        }
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new SystemException(e.getMessage(), e);
    }
    Object rootNode;
    try {
        rootNode = determineRootNode(variableResolver, contextDescription);
    } catch (SchemaException e) {
        throw new ExpressionSyntaxException(e.getMessage(), e);
    }
    Object evaluatedExpression;
    try {
        evaluatedExpression = expr.evaluate(rootNode, returnType);
    } catch (Exception e) {
        Throwable originalException = ExceptionUtil.lookForTunneledException(e);
        if (originalException != null && originalException instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) originalException;
        }
        if (originalException != null && originalException instanceof ExpressionSyntaxException) {
            throw (ExpressionSyntaxException) originalException;
        }
        if (e instanceof XPathExpressionException) {
            throw createExpressionEvaluationException(e, contextDescription);
        }
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new SystemException(e.getMessage(), e);
    }
    if (evaluatedExpression == null) {
        return null;
    }
    return evaluatedExpression;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 40 with ObjectNotFoundException

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

the class AbstractSearchExpressionEvaluator method executeSearchAttempt.

private <O extends ObjectType> List<V> executeSearchAttempt(final List<PrismObject> rawResult, Class<O> targetTypeClass, final QName targetTypeQName, ObjectQuery query, boolean searchOnResource, boolean tryAlsoRepository, final List<ItemDelta<V, D>> additionalAttributeDeltas, final ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    final List<V> list = new ArrayList<V>();
    Collection<SelectorOptions<GetOperationOptions>> options = new ArrayList<>();
    if (!searchOnResource) {
        options.add(SelectorOptions.create(GetOperationOptions.createNoFetch()));
    }
    extendOptions(options, searchOnResource);
    ResultHandler<O> handler = new ResultHandler<O>() {

        @Override
        public boolean handle(PrismObject<O> object, OperationResult parentResult) {
            if (rawResult != null) {
                rawResult.add(object);
            }
            list.add(createPrismValue(object.getOid(), targetTypeQName, additionalAttributeDeltas, params));
            return true;
        }
    };
    try {
        objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
    } catch (IllegalStateException e) {
        // this comes from checkConsistence methods
        throw new IllegalStateException(e.getMessage() + " in " + contextDescription, e);
    } catch (SchemaException e) {
        throw new SchemaException(e.getMessage() + " in " + contextDescription, e);
    } catch (SystemException e) {
        throw new SystemException(e.getMessage() + " in " + contextDescription, e);
    } catch (CommunicationException | ConfigurationException | SecurityViolationException e) {
        if (searchOnResource && tryAlsoRepository) {
            options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
            try {
                objectResolver.searchIterative(targetTypeClass, query, options, handler, task, result);
            } catch (SchemaException e1) {
                throw new SchemaException(e1.getMessage() + " in " + contextDescription, e1);
            } catch (CommunicationException | ConfigurationException | SecurityViolationException e1) {
                // shadow for group doesn't exist? (MID-2107)
                throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
            }
        } else {
            throw new ExpressionEvaluationException("Unexpected expression exception " + e + ": " + e.getMessage(), e);
        }
    } catch (ObjectNotFoundException e) {
        throw e;
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Assignment expression resulted in {} objects, using query:\n{}", list.size(), query.debugDump());
    }
    return list;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) 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