Search in sources :

Example 1 with PrismParserNoIO

use of com.evolveum.midpoint.prism.PrismParserNoIO in project midpoint by Evolveum.

the class LegacyValidator method validateObjectInternal.

private EventResult validateObjectInternal(Element objectElement, OperationResult objectResult, OperationResult validatorResult) {
    try {
        Node postValidationTree = null;
        if (validateSchemas) {
            postValidationTree = validateSchema(objectElement, objectResult);
            if (postValidationTree == null) {
                // There was an error
                return EventResult.skipObject(objectResult.getMessage());
            }
        }
        if (handler != null) {
            EventResult cont;
            try {
                cont = handler.preMarshall(objectElement, postValidationTree, objectResult);
            } catch (RuntimeException e) {
                objectResult.recordFatalError("Internal error: preMarshall call failed: " + e.getMessage(), e);
                throw e;
            }
            if (!cont.isCont()) {
                if (objectResult.isUnknown()) {
                    objectResult.recordFatalError("Stopped after preMarshall, no reason given");
                }
                return cont;
            }
        }
        if (!objectResult.isAcceptable()) {
            // continue with this object.
            if (objectResult.isUnknown()) {
                objectResult.recordFatalError("Result not acceptable after preMarshall, no reason given");
            }
            return EventResult.skipObject();
        }
        PrismParserNoIO parser = prismContext.parserFor(objectElement);
        if (compatMode) {
            parser = parser.compat();
        }
        T containerable = parser.parseRealValue();
        objectResult.addContext(OperationResult.CONTEXT_OBJECT, containerable.toString());
        if (containerable instanceof Objectable) {
            Objectable objectable = (Objectable) containerable;
            try {
                objectable.asPrismObject().checkConsistence();
            } catch (RuntimeException e) {
                objectResult.recordFatalError("Internal object inconsistence, probably a parser bug: " + e.getMessage(), e);
                return EventResult.skipObject(e.getMessage());
            }
            if (verbose) {
                LOGGER.trace("Processing OID {}", objectable.getOid());
            }
            validateObject(objectable, objectResult);
        }
        if (handler != null) {
            EventResult cont;
            try {
                cont = handler.postMarshall(containerable, objectElement, objectResult);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: postMarshall call failed: " + e.getMessage(), e);
                throw e;
            }
            if (!cont.isCont()) {
                if (objectResult.isUnknown()) {
                    objectResult.recordFatalError("Stopped after postMarshall, no reason given");
                }
                return cont;
            }
        }
        objectResult.recomputeStatus();
        return EventResult.cont();
    } catch (SchemaException ex) {
        if (verbose) {
            LOGGER.trace("Schema exception", ex);
        }
        if (handler != null) {
            try {
                handler.handleGlobalError(validatorResult, ex);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: handleGlobalError call failed: " + e.getMessage(), e);
                throw e;
            }
        }
        objectResult.recordFatalError(ex);
        return EventResult.skipObject(ex.getMessage());
    } catch (RuntimeException ex) {
        validatorResult.recordFatalError("Couldn't parse object: " + ex.getMessage(), ex);
        if (verbose) {
            LOGGER.trace("Couldn't parse object", ex);
        }
        if (handler != null) {
            try {
                handler.handleGlobalError(validatorResult);
            } catch (RuntimeException e) {
                // Make sure that unhandled exceptions are recorded in object result before they are rethrown
                objectResult.recordFatalError("Internal error: handleGlobalError call failed: " + e.getMessage(), e);
                throw e;
            }
        }
        objectResult.recordFatalError(ex);
        return EventResult.skipObject(ex.getMessage());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Node(org.w3c.dom.Node) Objectable(com.evolveum.midpoint.prism.Objectable) PrismParserNoIO(com.evolveum.midpoint.prism.PrismParserNoIO)

Example 2 with PrismParserNoIO

use of com.evolveum.midpoint.prism.PrismParserNoIO in project midpoint by Evolveum.

the class PerfTestPrismObjectSize method fromFileToXNode.

@Test(dataProvider = "combinations")
public void fromFileToXNode(ContainerTestParams config) throws Exception {
    for (String format : FILE_FORMATS) {
        String input = getPrismContext().serializerFor(format).serialize(config.testObject());
        PrismParserNoIO parser = getPrismContext().parserFor(input);
        String monitorId = monitorName("parse.xnode", config.monitorId(), format);
        String note = "Measures parsing of JSON/XML/YAML to XNodes. Test parameters: " + config;
        measure(monitorId, note, parser::parseToXNode);
    }
}
Also used : PrismParserNoIO(com.evolveum.midpoint.prism.PrismParserNoIO) Test(org.testng.annotations.Test)

Example 3 with PrismParserNoIO

use of com.evolveum.midpoint.prism.PrismParserNoIO in project midpoint by Evolveum.

the class PerfTestPrismObjectSize method fromXnodeToPrism.

@Test(dataProvider = "combinationsConflicts")
public void fromXnodeToPrism(ContainerTestParams config) throws Exception {
    RootXNode input = config.testObject();
    PrismParserNoIO parser = getPrismContext().parserFor(input);
    String monitorId = monitorName("parse.prism", config.monitorId());
    String note = "Measures unmarshalling of Prism Objects from XNodes. Test parameters: " + config;
    measure(monitorId, note, parser::parse);
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismParserNoIO(com.evolveum.midpoint.prism.PrismParserNoIO) Test(org.testng.annotations.Test)

Aggregations

PrismParserNoIO (com.evolveum.midpoint.prism.PrismParserNoIO)3 Test (org.testng.annotations.Test)2 Objectable (com.evolveum.midpoint.prism.Objectable)1 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 Node (org.w3c.dom.Node)1