Search in sources :

Example 41 with SystemException

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

the class PrismObject method createNewValue.

public PrismObjectValue<O> createNewValue() {
    checkMutability();
    PrismObjectValue<O> newValue = new PrismObjectValue<>(prismContext);
    try {
        add(newValue, false);
        return newValue;
    } catch (SchemaException e) {
        // This should not happen
        throw new SystemException("Internal Error: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 42 with SystemException

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

the class AssociationTargetSearchExpressionEvaluator method createPrismValue.

protected PrismContainerValue<ShadowAssociationType> createPrismValue(String oid, QName targetTypeQName, List<ItemDelta<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> additionalAttributeDeltas, ExpressionEvaluationContext params) {
    ShadowAssociationType associationType = new ShadowAssociationType();
    PrismContainerValue<ShadowAssociationType> associationCVal = associationType.asPrismContainerValue();
    associationType.setName(params.getMappingQName());
    ObjectReferenceType targetRef = new ObjectReferenceType();
    targetRef.setOid(oid);
    targetRef.setType(targetTypeQName);
    associationType.setShadowRef(targetRef);
    try {
        if (additionalAttributeDeltas != null) {
            ItemDelta.applyTo(additionalAttributeDeltas, associationCVal);
        }
        getPrismContext().adopt(associationCVal, ShadowType.COMPLEX_TYPE, new ItemPath(ShadowType.F_ASSOCIATION));
        if (InternalsConfig.consistencyChecks) {
            associationCVal.assertDefinitions("associationCVal in assignment expression in " + params.getContextDescription());
        }
    } catch (SchemaException e) {
        // Should not happen
        throw new SystemException(e);
    }
    return associationCVal;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 43 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException 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 44 with SystemException

use of com.evolveum.midpoint.util.exception.SystemException 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)

Example 45 with SystemException

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

the class ShadowManager method lookupShadowInRepository.

/**
	 * Locates the appropriate Shadow in repository that corresponds to the
	 * provided resource object.
	 *
	 * DEAD flag is cleared - in memory as well as in repository.
	 * 
	 * @param parentResult
	 * 
	 * @return current shadow object that corresponds to provided
	 *         resource object or null if the object does not exist
	 */
public PrismObject<ShadowType> lookupShadowInRepository(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, OperationResult parentResult) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    ObjectQuery query = createSearchShadowQuery(ctx, resourceShadow, prismContext, parentResult);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Searching for shadow using filter:\n{}", query.debugDump());
    }
    //		PagingType paging = new PagingType();
    // TODO: check for errors
    List<PrismObject<ShadowType>> results = repositoryService.searchObjects(ShadowType.class, query, null, parentResult);
    MiscSchemaUtil.reduceSearchResult(results);
    LOGGER.trace("lookupShadow found {} objects", results.size());
    if (results.size() == 0) {
        return null;
    }
    if (results.size() > 1) {
        for (PrismObject<ShadowType> result : results) {
            LOGGER.trace("Search result:\n{}", result.debugDump());
        }
        LOGGER.error("More than one shadow found for " + resourceShadow);
        // TODO: Better error handling later
        throw new IllegalStateException("More than one shadow found for " + resourceShadow);
    }
    PrismObject<ShadowType> shadow = results.get(0);
    checkConsistency(shadow);
    if (Boolean.TRUE.equals(shadow.asObjectable().isDead())) {
        LOGGER.debug("Repository shadow {} is marked as dead - resetting the flag", ObjectTypeUtil.toShortString(shadow));
        shadow.asObjectable().setDead(false);
        List<ItemDelta<?, ?>> deltas = DeltaBuilder.deltaFor(ShadowType.class, prismContext).item(ShadowType.F_DEAD).replace().asItemDeltas();
        try {
            repositoryService.modifyObject(ShadowType.class, shadow.getOid(), deltas, parentResult);
        } catch (ObjectAlreadyExistsException e) {
            throw new SystemException("Unexpected exception when resetting 'dead' flag: " + e.getMessage(), e);
        }
    }
    return shadow;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12