Search in sources :

Example 41 with SchemaException

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

the class QueryConvertor method parseRefFilter.

private static <C extends Containerable> RefFilter parseRefFilter(MapXNode clauseXMap, PrismContainerDefinition<C> pcd, boolean preliminaryParsingOnly, PrismContext prismContext) throws SchemaException {
    ItemPath itemPath = getPath(clauseXMap);
    if (itemPath == null || itemPath.isEmpty()) {
        throw new SchemaException("Cannot convert query, because query does not contain property path.");
    }
    QName itemName = ItemPath.getName(itemPath.last());
    ItemDefinition itemDefinition = null;
    if (pcd != null) {
        itemDefinition = pcd.findItemDefinition(itemPath);
        if (itemDefinition == null && !preliminaryParsingOnly) {
            throw new SchemaException("No definition for item " + itemPath + " in " + pcd);
        }
    }
    XNode valueXnode = clauseXMap.get(ELEMENT_VALUE);
    if (valueXnode != null) {
        if (preliminaryParsingOnly) {
            return null;
        }
        RootXNode valueRoot = new RootXNode(ELEMENT_VALUE, valueXnode);
        Item<?, ?> item = prismContext.parserFor(valueRoot).name(itemName).definition(itemDefinition).context(ParsingContext.allowMissingRefTypes()).parseItem();
        if (!(item instanceof PrismReference)) {
            throw new IllegalStateException("Expected PrismReference, got " + item);
        }
        PrismReference ref = (PrismReference) item;
        if (item.getValues().size() < 1) {
            throw new IllegalStateException("No values to search specified for item " + itemName);
        }
        return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, PrismValue.cloneCollection(ref.getValues()));
    } else {
        ExpressionWrapper expressionWrapper = parseExpression(clauseXMap, prismContext);
        if (expressionWrapper != null) {
            if (preliminaryParsingOnly) {
                return null;
            } else {
                return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, expressionWrapper);
            }
        } else {
            if (preliminaryParsingOnly) {
                return null;
            } else {
                return RefFilter.createReferenceEqual(itemPath, (PrismReferenceDefinition) itemDefinition, (ExpressionWrapper) null);
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 42 with SchemaException

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

the class QueryConvertor method serializeFullTextFilter.

private static MapXNode serializeFullTextFilter(FullTextFilter filter, PrismSerializer<RootXNode> xnodeSerializer) throws SchemaException {
    MapXNode clauseMap = new MapXNode();
    if (filter.getValues() != null && !filter.getValues().isEmpty()) {
        ListXNode valuesNode = new ListXNode();
        for (String value : filter.getValues()) {
            XNode val = createPrimitiveXNode(value, DOMUtil.XSD_STRING);
            valuesNode.add(val);
        }
        clauseMap.put(ELEMENT_VALUE, valuesNode);
    } else if (filter.getExpression() != null) {
    // TODO serialize expression
    } else {
        throw new SchemaException("FullText filter with no values nor expression");
    }
    return createFilter(CLAUSE_FULL_TEXT, clauseMap);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 43 with SchemaException

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

the class AssignmentEvaluator method resolveTargetsFromFilter.

@NotNull
private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> targetClass, SearchFilterType filter, AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(lensContext, null, ctx.task, ctx.result));
    try {
        PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(ctx.result);
        ExpressionVariables variables = Utils.getDefaultExpressionVariables(segment.source, null, null, systemConfiguration.asObjectable());
        variables.addVariableDefinition(ExpressionConstants.VAR_SOURCE, segment.getOrderOneObject());
        AssignmentPathVariables assignmentPathVariables = LensUtil.computeAssignmentPathVariables(ctx.assignmentPath);
        if (assignmentPathVariables != null) {
            Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
        }
        ObjectFilter origFilter = QueryConvertor.parseFilter(filter, targetClass, prismContext);
        ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), prismContext, " evaluating resource filter expression ", ctx.task, ctx.result);
        if (evaluatedFilter == null) {
            throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + segment.source);
        }
        return repository.searchObjects(targetClass, ObjectQuery.createObjectQuery(evaluatedFilter), null, ctx.result);
    // we don't check for no targets here; as we don't care for referential integrity
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) NotNull(org.jetbrains.annotations.NotNull)

Example 44 with SchemaException

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

the class PersonaProcessor method readExistingPersonas.

public <F extends FocusType> List<FocusType> readExistingPersonas(LensContext<F> context, Task task, OperationResult result) {
    LensFocusContext<F> focusContext = context.getFocusContext();
    PrismObject<F> focus = focusContext.getObjectNew();
    List<FocusType> personas = new ArrayList<>();
    String desc = "personaRef in " + focus;
    for (ObjectReferenceType personaRef : focus.asObjectable().getPersonaRef()) {
        try {
            FocusType persona = objectResolver.resolve(personaRef, FocusType.class, null, desc, task, result);
            personas.add(persona);
        } catch (ObjectNotFoundException | SchemaException e) {
            LOGGER.warn("Cannot find persona {} referenced from {}", personaRef.getOid(), focus);
        // But go on...
        }
    }
    return personas;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ArrayList(java.util.ArrayList)

Example 45 with SchemaException

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

the class AssignmentProcessor method evaluateConstructions.

private <F extends FocusType> void evaluateConstructions(LensContext<F> context, Collection<EvaluatedAssignmentImpl<F>> evaluatedAssignments, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (evaluatedAssignments == null) {
        return;
    }
    ObjectDeltaObject<F> focusOdo = null;
    LensFocusContext<F> focusContext = context.getFocusContext();
    if (focusContext != null) {
        focusOdo = focusContext.getObjectDeltaObject();
    }
    Iterator<EvaluatedAssignmentImpl<F>> iterator = evaluatedAssignments.iterator();
    while (iterator.hasNext()) {
        EvaluatedAssignmentImpl<F> evaluatedAssignment = iterator.next();
        try {
            evaluatedAssignment.evaluateConstructions(focusOdo, context.getSystemConfiguration(), task, result);
        } catch (ObjectNotFoundException ex) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
            }
            iterator.remove();
            if (!ModelExecuteOptions.isForce(context.getOptions())) {
                ModelUtils.recordFatalError(result, ex);
            }
        } catch (SchemaException ex) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
            }
            ModelUtils.recordFatalError(result, ex);
            String resourceOid = FocusTypeUtil.determineConstructionResource(evaluatedAssignment.getAssignmentType());
            if (resourceOid == null) {
                // This is a role assignment or something like that. Just throw the original exception for now.
                throw ex;
            }
            ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid, FocusTypeUtil.determineConstructionKind(evaluatedAssignment.getAssignmentType()), FocusTypeUtil.determineConstructionIntent(evaluatedAssignment.getAssignmentType()));
            LensProjectionContext accCtx = context.findProjectionContext(rad);
            if (accCtx != null) {
                accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
            }
            iterator.remove();
        }
    }
}
Also used : EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)235 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)214 QName (javax.xml.namespace.QName)132 SystemException (com.evolveum.midpoint.util.exception.SystemException)113 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)100 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)92 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)89 Task (com.evolveum.midpoint.task.api.Task)87 PrismObject (com.evolveum.midpoint.prism.PrismObject)86 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)69 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)68 ArrayList (java.util.ArrayList)67 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)59 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)49 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)46 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)34 Test (org.testng.annotations.Test)34