Search in sources :

Example 1 with Validation

use of org.n52.faroe.Validation in project arctic-sea by 52North.

the class XmlHelper method validateDocument.

/**
 * checks whether the XMLDocument is valid
 *
 * @param doc
 *            the document which should be checked
 *
 * @throws T
 *             * if the Document is not valid
 */
/*
     * TODO Replace this version with a method that uses LaxValidationCases and
     * provides means to access the errors after validating the document
     */
public static <X extends XmlObject, T extends Throwable> X validateDocument(X doc, Function<Throwable, T> supplier) throws T {
    // Create an XmlOptions instance and set the error listener.
    LinkedList<XmlError> validationErrors = new LinkedList<>();
    XmlOptions validationOptions = new XmlOptions().setErrorListener(validationErrors).setLoadLineNumbers(XmlOptions.LOAD_LINE_NUMBERS_END_ELEMENT);
    // Create Exception with error message if the xml document is invalid
    if (!doc.validate(validationOptions)) {
        String message;
        // getValidation error and throw service exception for the first
        // error
        Iterator<XmlError> iter = validationErrors.iterator();
        List<XmlError> errors = new LinkedList<>();
        while (iter.hasNext()) {
            XmlError error = iter.next();
            boolean shouldPass = false;
            if (error instanceof XmlValidationError) {
                for (LaxValidationCase lvc : LaxValidationCase.values()) {
                    if (lvc.shouldPass((XmlValidationError) error)) {
                        shouldPass = true;
                        LOGGER.debug("Lax validation case found for XML validation error: {}", error);
                        break;
                    }
                }
            }
            if (!shouldPass) {
                errors.add(error);
            }
        }
        CompositeException exceptions = new CompositeException();
        for (XmlError error : errors) {
            // get name of the missing or invalid parameter
            message = error.getMessage();
            if (message != null) {
                exceptions.add(new DecodingException(message, "[XmlBeans validation error:] %s", message));
            }
        }
        if (!errors.isEmpty()) {
            throw supplier.apply(exceptions);
        }
    }
    return doc;
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions) CompositeException(org.n52.janmayen.exception.CompositeException) XmlError(org.apache.xmlbeans.XmlError) DecodingException(org.n52.svalbard.decode.exception.DecodingException) LinkedList(java.util.LinkedList) XmlValidationError(org.apache.xmlbeans.XmlValidationError)

Example 2 with Validation

use of org.n52.faroe.Validation in project arctic-sea by 52North.

the class SosDecoderv20 method parseGetFeatureOfInterest.

// private SwesExtensions parseSwesExtensions(final XmlObject[]
// extensionArray) throws OwsExceptionReport
// {
// final SwesExtensions extensions = new SwesExtensions();
// for (final XmlObject xbSwesExtension : extensionArray) {
// 
// final Object obj = CodingHelper.decodeXmlElement(xbSwesExtension);
// if (obj instanceof SwesExtension<?>) {
// extensions.addSwesExtension((SwesExtension<?>) obj);
// }
// }
// return extensions;
// }
/**
 * parses the passes XmlBeans document and creates a SOS
 * getFeatureOfInterest request
 *
 * @param getFoiDoc
 *            XmlBeans document representing the getFeatureOfInterest
 *            request
 * @return Returns SOS getFeatureOfInterest request
 *
 * @throws DecodingException
 *             * if validation of the request failed
 */
private OwsServiceRequest parseGetFeatureOfInterest(final GetFeatureOfInterestDocument getFoiDoc) throws DecodingException {
    final GetFeatureOfInterestRequest getFoiRequest = new GetFeatureOfInterestRequest();
    final GetFeatureOfInterestType getFoiType = getFoiDoc.getGetFeatureOfInterest();
    getFoiRequest.setService(getFoiType.getService());
    getFoiRequest.setVersion(getFoiType.getVersion());
    getFoiRequest.setFeatureIdentifiers(Arrays.asList(getFoiType.getFeatureOfInterestArray()));
    getFoiRequest.setObservedProperties(Arrays.asList(getFoiType.getObservedPropertyArray()));
    getFoiRequest.setProcedures(Arrays.asList(getFoiType.getProcedureArray()));
    getFoiRequest.setSpatialFilters(parseSpatialFilters4GetFeatureOfInterest(getFoiType.getSpatialFilterArray()));
    getFoiRequest.setExtensions(parseExtensibleRequest(getFoiType));
    return getFoiRequest;
}
Also used : GetFeatureOfInterestRequest(org.n52.shetland.ogc.sos.request.GetFeatureOfInterestRequest) GetFeatureOfInterestType(net.opengis.sos.x20.GetFeatureOfInterestType)

Example 3 with Validation

use of org.n52.faroe.Validation in project arctic-sea by 52North.

the class SwesDecoderv20 method parseDescribeSensor.

/**
 * parses the passes XmlBeans document and creates a SOS describeSensor
 * request
 *
 * @param xbDescSenDoc
 *            XmlBeans document representing the describeSensor request
 * @return Returns SOS describeSensor request
 *
 * @throws DecodingException
 *             * if validation of the request failed
 */
private OwsServiceRequest parseDescribeSensor(final DescribeSensorDocument xbDescSenDoc) throws DecodingException {
    final DescribeSensorRequest descSensorRequest = new DescribeSensorRequest();
    final DescribeSensorType xbDescSensor = xbDescSenDoc.getDescribeSensor();
    descSensorRequest.setService(xbDescSensor.getService());
    descSensorRequest.setVersion(xbDescSensor.getVersion());
    descSensorRequest.setProcedure(xbDescSensor.getProcedure());
    descSensorRequest.setProcedureDescriptionFormat(xbDescSensor.getProcedureDescriptionFormat());
    if (xbDescSensor.isSetValidTime()) {
        descSensorRequest.setValidTime(getValidTime(xbDescSensor.getValidTime()));
    }
    // extensions
    descSensorRequest.setExtensions(parseExtensibleRequest(xbDescSensor));
    return descSensorRequest;
}
Also used : DescribeSensorType(net.opengis.swes.x20.DescribeSensorType) DescribeSensorRequest(org.n52.shetland.ogc.sos.request.DescribeSensorRequest)

Example 4 with Validation

use of org.n52.faroe.Validation in project arctic-sea by 52North.

the class SosDecoderv100 method decode.

@Override
public OwsServiceCommunicationObject decode(XmlObject xmlObject) throws DecodingException {
    OwsServiceCommunicationObject request = null;
    LOGGER.debug("REQUESTTYPE:" + xmlObject.getClass());
    /*
         * Add O&M 1.0.0 namespace to GetObservation document. XmlBeans removes
         * the namespace from the document because there are no om:... elements
         * in the document. But the validation fails if the <resultModel>
         * element is set with e.g. om:Measurement.
         */
    if (xmlObject instanceof GetObservationDocument) {
        XmlCursor cursor = xmlObject.newCursor();
        cursor.toFirstChild();
        cursor.insertNamespace(OmConstants.NS_OM_PREFIX, OmConstants.NS_OM);
        cursor.dispose();
    }
    // validate document
    XmlHelper.validateDocument(xmlObject);
    if (xmlObject instanceof GetCapabilitiesDocument) {
        // getCapabilities request
        GetCapabilitiesDocument getCapsDoc = (GetCapabilitiesDocument) xmlObject;
        request = parseGetCapabilities(getCapsDoc);
    } else if (xmlObject instanceof DescribeSensorDocument) {
        // DescribeSensor request (still SOS 1.0 NS_URI
        DescribeSensorDocument descSensorDoc = (DescribeSensorDocument) xmlObject;
        request = parseDescribeSensor(descSensorDoc);
    } else if (xmlObject instanceof GetObservationDocument) {
        // getObservation request
        GetObservationDocument getObsDoc = (GetObservationDocument) xmlObject;
        request = parseGetObservation(getObsDoc);
    } else if (xmlObject instanceof GetFeatureOfInterestDocument) {
        // getFeatureOfInterest request
        GetFeatureOfInterestDocument getFoiDoc = (GetFeatureOfInterestDocument) xmlObject;
        request = parseGetFeatureOfInterest(getFoiDoc);
    } else if (xmlObject instanceof GetObservationByIdDocument) {
        // getObservationById request
        GetObservationByIdDocument getObsByIdDoc = (GetObservationByIdDocument) xmlObject;
        request = parseGetObservationById(getObsByIdDoc);
    } else {
        throw new UnsupportedDecoderXmlInputException(this, xmlObject);
    }
    return request;
}
Also used : OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) GetObservationDocument(net.opengis.sos.x10.GetObservationDocument) DescribeSensorDocument(net.opengis.sos.x10.DescribeSensorDocument) GetFeatureOfInterestDocument(net.opengis.sos.x10.GetFeatureOfInterestDocument) GetObservationByIdDocument(net.opengis.sos.x10.GetObservationByIdDocument) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) GetCapabilitiesDocument(net.opengis.sos.x10.GetCapabilitiesDocument) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 5 with Validation

use of org.n52.faroe.Validation in project arctic-sea by 52North.

the class SosDecoderv100 method parseGetFeatureOfInterest.

/**
 * parses the passes XmlBeans document and creates a SOS
 * getFeatureOfInterest request
 *
 * @param getFoiDoc
 *            XmlBeans document representing the getFeatureOfInterest
 *            request
 * @return Returns SOS getFeatureOfInterest request
 *
 * @throws DecodingException
 *             * if validation of the request failed
 */
private OwsServiceRequest parseGetFeatureOfInterest(GetFeatureOfInterestDocument getFoiDoc) throws DecodingException {
    GetFeatureOfInterestRequest getFoiRequest = new GetFeatureOfInterestRequest();
    GetFeatureOfInterest getFoi = getFoiDoc.getGetFeatureOfInterest();
    getFoiRequest.setService(getFoi.getService());
    getFoiRequest.setVersion(getFoi.getVersion());
    getFoiRequest.setFeatureIdentifiers(Arrays.asList(getFoi.getFeatureOfInterestIdArray()));
    getFoiRequest.setSpatialFilters(parseSpatialFilters4GetFeatureOfInterest(getFoi.getLocation()));
    return getFoiRequest;
}
Also used : GetFeatureOfInterest(net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest) GetFeatureOfInterestRequest(org.n52.shetland.ogc.sos.request.GetFeatureOfInterestRequest)

Aggregations

GetFeatureOfInterestRequest (org.n52.shetland.ogc.sos.request.GetFeatureOfInterestRequest)2 LinkedList (java.util.LinkedList)1 DescribeSensorDocument (net.opengis.sos.x10.DescribeSensorDocument)1 GetCapabilitiesDocument (net.opengis.sos.x10.GetCapabilitiesDocument)1 GetFeatureOfInterestDocument (net.opengis.sos.x10.GetFeatureOfInterestDocument)1 GetFeatureOfInterest (net.opengis.sos.x10.GetFeatureOfInterestDocument.GetFeatureOfInterest)1 GetObservationByIdDocument (net.opengis.sos.x10.GetObservationByIdDocument)1 GetObservationDocument (net.opengis.sos.x10.GetObservationDocument)1 GetFeatureOfInterestType (net.opengis.sos.x20.GetFeatureOfInterestType)1 DescribeSensorType (net.opengis.swes.x20.DescribeSensorType)1 XmlCursor (org.apache.xmlbeans.XmlCursor)1 XmlError (org.apache.xmlbeans.XmlError)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 XmlValidationError (org.apache.xmlbeans.XmlValidationError)1 CompositeException (org.n52.janmayen.exception.CompositeException)1 OwsServiceCommunicationObject (org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject)1 DescribeSensorRequest (org.n52.shetland.ogc.sos.request.DescribeSensorRequest)1 DecodingException (org.n52.svalbard.decode.exception.DecodingException)1 UnsupportedDecoderXmlInputException (org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException)1