Search in sources :

Example 31 with SchemaException

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

the class PrismUnmarshaller method parseReferenceValueAsCompositeObject.

private PrismReferenceValue parseReferenceValueAsCompositeObject(XNode node, PrismReferenceDefinition definition, ParsingContext pc) throws SchemaException {
    if (!(node instanceof MapXNode)) {
        throw new IllegalArgumentException("Cannot parse reference composite object from " + node);
    }
    MapXNode map = (MapXNode) node;
    QName targetTypeName = definition.getTargetTypeName();
    PrismObjectDefinition<Objectable> objectDefinition = null;
    if (map.getTypeQName() != null) {
        objectDefinition = getSchemaRegistry().findObjectDefinitionByType(map.getTypeQName());
    }
    if (objectDefinition == null && targetTypeName != null) {
        objectDefinition = getSchemaRegistry().findObjectDefinitionByType(targetTypeName);
    }
    if (objectDefinition == null) {
        throw new SchemaException("No object definition for composite object in reference element " + definition.getCompositeObjectElementName());
    }
    PrismObject<Objectable> compositeObject;
    try {
        compositeObject = parseObject(map, objectDefinition, pc);
    } catch (SchemaException e) {
        throw new SchemaException(e.getMessage() + " while parsing composite object in reference element " + definition.getCompositeObjectElementName(), e);
    }
    PrismReferenceValue refVal = new PrismReferenceValue();
    setReferenceObject(refVal, compositeObject);
    ((PrismReferenceDefinitionImpl) definition).setComposite(true);
    return refVal;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName)

Example 32 with SchemaException

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

the class AbstractJsonLexicalProcessor method parseFromStart.

@NotNull
private RootXNode parseFromStart(JsonParser unconfiguredParser, ParsingContext parsingContext) throws SchemaException {
    JsonParsingContext ctx = null;
    try {
        JsonParser parser = configureParser(unconfiguredParser);
        parser.nextToken();
        if (parser.currentToken() == null) {
            throw new SchemaException("Nothing to parse: the input is empty.");
        }
        ctx = new JsonParsingContext(parser, parsingContext);
        XNode xnode = parseValue(ctx);
        if (!(xnode instanceof MapXNode) || ((MapXNode) xnode).size() != 1) {
            throw new SchemaException("Expected MapXNode with a single key; got " + xnode + " instead. At " + getPositionSuffix(ctx));
        }
        processDefaultNamespaces(xnode, null, ctx);
        processSchemaNodes(xnode);
        Entry<QName, XNode> entry = ((MapXNode) xnode).entrySet().iterator().next();
        RootXNode root = new RootXNode(entry.getKey(), entry.getValue());
        if (entry.getValue() != null) {
            // TODO - ok ????
            root.setTypeQName(entry.getValue().getTypeQName());
        }
        return root;
    } catch (IOException e) {
        throw new SchemaException("Cannot parse JSON/YAML object: " + e.getMessage() + (ctx != null ? " At: " + getPositionSuffix(ctx) : ""), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) JsonParser(com.fasterxml.jackson.core.JsonParser) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with SchemaException

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

the class AbstractJsonLexicalProcessor method write.

@NotNull
@Override
public String write(@NotNull RootXNode root, SerializationContext prismSerializationContext) throws SchemaException {
    StringWriter out = new StringWriter();
    try (JsonGenerator generator = createJacksonGenerator(out)) {
        JsonSerializationContext ctx = new JsonSerializationContext(generator, prismSerializationContext);
        // TODO default namespace
        serialize(root.toMapXNode(), ctx, false);
    } catch (IOException ex) {
        throw new SchemaException("Error during serializing to JSON/YAML: " + ex.getMessage(), ex);
    }
    return out.toString();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with SchemaException

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

the class DomLexicalWriter method serializeInternal.

@NotNull
private Element serializeInternal(@NotNull RootXNode rootxnode, Element parentElement) throws SchemaException {
    QName rootElementName = rootxnode.getRootElementName();
    Element topElement = createElement(rootElementName, parentElement);
    if (parentElement != null) {
        parentElement.appendChild(topElement);
    }
    QName typeQName = rootxnode.getTypeQName();
    if (typeQName != null && rootxnode.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(topElement, setQNamePrefixExplicitIfNeeded(typeQName));
    }
    XNode subnode = rootxnode.getSubnode();
    if (subnode instanceof PrimitiveXNode) {
        serializePrimitiveElementOrAttribute((PrimitiveXNode) subnode, topElement, rootElementName, false);
        return DOMUtil.getFirstChildElement(topElement);
    }
    if (subnode instanceof MapXNode) {
        // at this point we can put frequently used namespaces (e.g. c, t, q, ri) into the document to eliminate their use
        // on many places inside the doc (MID-2198)
        DOMUtil.setNamespaceDeclarations(topElement, getNamespacePrefixMapper().getNamespacesDeclaredByDefault());
        serializeMap((MapXNode) subnode, topElement);
    } else if (subnode.isHeterogeneousList()) {
        DOMUtil.setNamespaceDeclarations(topElement, getNamespacePrefixMapper().getNamespacesDeclaredByDefault());
        serializeExplicitList((ListXNode) subnode, topElement);
    } else {
        throw new SchemaException("Sub-root xnode is not a map nor an explicit list, cannot serialize to XML (it is " + subnode + ")");
    }
    addDefaultNamespaceDeclaration(topElement);
    return topElement;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with SchemaException

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

the class AbstractJsonLexicalProcessor method processSchemaNodes.

// Schema nodes can be detected only after namespaces are resolved.
// We simply convert primitive nodes to schema ones.
private void processSchemaNodes(XNode xnode) throws SchemaException, IOException {
    if (xnode instanceof MapXNode) {
        MapXNode map = (MapXNode) xnode;
        XNode schemaNode = null;
        for (Entry<QName, XNode> entry : map.entrySet()) {
            QName fieldName = entry.getKey();
            XNode subnode = entry.getValue();
            if (DOMUtil.XSD_SCHEMA_ELEMENT.equals(fieldName)) {
                schemaNode = subnode;
            } else {
                processSchemaNodes(subnode);
            }
        }
        if (schemaNode != null) {
            if (schemaNode instanceof PrimitiveXNode) {
                PrimitiveXNode<?> primitiveXNode = (PrimitiveXNode<?>) schemaNode;
                if (primitiveXNode.isParsed()) {
                    throw new SchemaException("Cannot convert from PrimitiveXNode to SchemaXNode: node is already parsed: " + primitiveXNode);
                }
                SchemaXNode schemaXNode = new SchemaXNode();
                map.replace(DOMUtil.XSD_SCHEMA_ELEMENT, schemaXNode);
                schemaXNode.setSchemaElement(((JsonValueParser) primitiveXNode.getValueParser()).asDomElement());
            } else {
                throw new SchemaException("Cannot convert 'schema' field to SchemaXNode: not a PrimitiveNode but " + schemaNode);
            }
        }
    } else if (xnode instanceof ListXNode) {
        for (XNode item : (ListXNode) xnode) {
            processSchemaNodes(item);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

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