Search in sources :

Example 6 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class SensorMLEncoderv20 method createComponents.

/**
 * Creates the components section of the SensorML description.
 *
 * @param sosComponents
 *            SOS SWE representation.
 *
 * @return encoded sml:components
 *
 * @throws EncodingException
 *             if the process encoding fails
 */
private ComponentListPropertyType createComponents(final List<SmlComponent> sosComponents) throws EncodingException {
    ComponentListPropertyType clpt = ComponentListPropertyType.Factory.newInstance(getXmlOptions());
    final ComponentListType clt = clpt.addNewComponentList();
    for (final SmlComponent sosSMLComponent : sosComponents) {
        final Component component = clt.addNewComponent();
        if (sosSMLComponent.isSetName()) {
            component.setName(sosSMLComponent.getName());
        }
        if (sosSMLComponent.isSetHref()) {
            component.setHref(sosSMLComponent.getHref());
            if (sosSMLComponent.isSetTitle()) {
                component.setTitle(sosSMLComponent.getTitle());
            }
        } else if (sosSMLComponent.isSetProcess()) {
            XmlObject xmlObject = encode(sosSMLComponent.getProcess(), EncodingContext.of(XmlBeansEncodingFlags.TYPE));
            // }
            if (xmlObject != null) {
                // AbstractProcessType xbProcess = null;
                // if (xmlObject instanceof AbstractProcessType) {
                // xbProcess = (AbstractProcessType) xmlObject;
                // } else {
                // throw new NoApplicableCodeException()
                // .withMessage("The sensor type is not supported by this
                // SOS");
                // }
                // TODO add feature/parentProcs/childProcs to component - is
                // this already done?
                // XmlObject substituteElement =
                // XmlHelper.substituteElement(component.addNewAbstractProcess(),
                // xmlObject);
                // substituteElement.set(xmlObject);
                substitute(component.addNewAbstractProcess(), xmlObject);
            }
        }
    }
    return clpt;
}
Also used : ComponentListPropertyType(net.opengis.sensorml.x20.ComponentListPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) PhysicalComponent(org.n52.shetland.ogc.sensorML.v20.PhysicalComponent) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent) Component(net.opengis.sensorml.x20.ComponentListType.Component) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) ComponentListType(net.opengis.sensorml.x20.ComponentListType) SmlComponent(org.n52.shetland.ogc.sensorML.elements.SmlComponent)

Example 7 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class WmlTVPEncoderv20 method addValues.

private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
    String unit = null;
    if (observationValue instanceof SingleObservationValue) {
        SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
        String time = getTimeString(singleObservationValue.getPhenomenonTime());
        unit = singleObservationValue.getValue().getUnit();
        String value = null;
        if (singleObservationValue.getValue() instanceof QuantityValue) {
            QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
            if (quantityValue.isSetValue()) {
                value = quantityValue.getValue().toPlainString();
            }
        } else if (singleObservationValue.getValue() instanceof CountValue) {
            CountValue countValue = (CountValue) singleObservationValue.getValue();
            if (countValue.getValue() != null) {
                value = Integer.toString(countValue.getValue());
            }
        } else if (singleObservationValue.getValue() instanceof ProfileValue) {
            ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
            if (profileValue.isSetValue()) {
                if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                    QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                    if (quantityValue.isSetValue()) {
                        value = Double.toString(quantityValue.getValue().doubleValue());
                    }
                }
            }
        }
        addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
    } else if (observationValue instanceof MultiObservationValues) {
        MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
        TVPValue tvpValue = (TVPValue) mov.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        unit = tvpValue.getUnit();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            String time = getTimeString(timeValuePair.getTime());
            String value = null;
            if (timeValuePair.getValue() instanceof QuantityValue) {
                QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
                if (quantityValue.isSetValue()) {
                    value = quantityValue.getValue().toPlainString();
                }
            } else if (timeValuePair.getValue() instanceof ProfileValue) {
                ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
                if (profileValue.isSetValue()) {
                    if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
                        QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
                        if (quantityValue.isSetValue()) {
                            value = Double.toString(quantityValue.getValue().doubleValue());
                        }
                    }
                }
            } else if (timeValuePair.getValue() instanceof CountValue) {
                CountValue countValue = (CountValue) timeValuePair.getValue();
                if (countValue.isSetValue()) {
                    value = Integer.toString(countValue.getValue());
                }
            } else {
                throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
            }
            addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
        }
    }
    return unit;
}
Also used : SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) List(java.util.List) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 8 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class OwsEncoderv110Test method generateException.

private NoApplicableCodeException generateException() {
    final NoApplicableCodeException nace = new NoApplicableCodeException();
    nace.setVersion(Sos2Constants.SERVICEVERSION);
    return nace;
}
Also used : NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)

Example 9 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class SimpleBinding method encodeResponse.

protected Object encodeResponse(OwsServiceResponse response, MediaType contentType) throws OwsExceptionReport {
    try {
        OperationResponseEncoderKey key = new OperationResponseEncoderKey(new OwsOperationKey(response), contentType);
        Encoder<Object, OwsServiceResponse> encoder = getEncoder(key);
        if (encoder == null) {
            throw new NoEncoderForKeyException(key);
        }
        return encoder.encode(response);
    } catch (EncodingException ex) {
        throw new NoApplicableCodeException().withMessage(ex.getMessage()).causedBy(ex);
    }
}
Also used : NoEncoderForKeyException(org.n52.svalbard.encode.exception.NoEncoderForKeyException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OwsEncodingException(org.n52.iceland.coding.encode.OwsEncodingException) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) OperationResponseEncoderKey(org.n52.svalbard.encode.OperationResponseEncoderKey) OwsOperationKey(org.n52.shetland.ogc.ows.service.OwsOperationKey) OwsServiceResponse(org.n52.shetland.ogc.ows.service.OwsServiceResponse)

Example 10 with NoApplicableCodeException

use of org.n52.shetland.ogc.ows.exception.NoApplicableCodeException in project arctic-sea by 52North.

the class EXIBinding method decode.

/**
 * Parse the incoming EXI encoded {@link InputStream} transform to
 * {@link XmlObject}
 *
 * @param request
 *            {@link HttpServletRequest} with EXI encoded
 *            {@link InputStream}
 * @return {@link XmlObject} created from the EXI encoded
 *         {@link InputStream}
 * @throws OwsExceptionReport
 *             If an error occurs during parsing
 */
protected XmlObject decode(HttpServletRequest request) throws OwsExceptionReport {
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        EXIFactory ef = this.exiUtils.newEXIFactory();
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        if (ef.isFragment()) {
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        }
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
        // decode EXI encoded InputStream
        EXISource exiSource = new EXISource(ef);
        XMLReader exiReader = exiSource.getXMLReader();
        InputSource inputSource = new InputSource(request.getInputStream());
        inputSource.setEncoding(request.getCharacterEncoding());
        SAXSource saxSource = new SAXSource(inputSource);
        saxSource.setXMLReader(exiReader);
        transformer.transform(saxSource, new StreamResult(os));
        // create XmlObject from OutputStream
        return XmlHelper.parseXmlString(os.toString(StandardCharsets.UTF_8.name()));
    } catch (IOException | EXIException ex) {
        throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while reading request! Message: %s", ex.getMessage());
    } catch (TransformerException ex) {
        throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while transforming request! Message: %s", ex.getMessage());
    } catch (DecodingException ex) {
        throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while parsing request! Message: %s", ex.getMessage());
    }
}
Also used : InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) EXISource(com.siemens.ct.exi.api.sax.EXISource) StreamResult(javax.xml.transform.stream.StreamResult) NoApplicableCodeException(org.n52.shetland.ogc.ows.exception.NoApplicableCodeException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) OwsDecodingException(org.n52.iceland.coding.decode.OwsDecodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EXIException(com.siemens.ct.exi.exceptions.EXIException) SAXSource(javax.xml.transform.sax.SAXSource) XMLReader(org.xml.sax.XMLReader) TransformerException(javax.xml.transform.TransformerException) EXIFactory(com.siemens.ct.exi.EXIFactory)

Aggregations

NoApplicableCodeException (org.n52.shetland.ogc.ows.exception.NoApplicableCodeException)11 IOException (java.io.IOException)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 OwsDecodingException (org.n52.iceland.coding.decode.OwsDecodingException)3 OwsEncodingException (org.n52.iceland.coding.encode.OwsEncodingException)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 SOAPException (javax.xml.soap.SOAPException)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)2 SoapRequest (org.n52.shetland.w3c.soap.SoapRequest)2 SoapResponse (org.n52.shetland.w3c.soap.SoapResponse)2 XmlStringOperationDecoderKey (org.n52.svalbard.decode.XmlStringOperationDecoderKey)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 EXIFactory (com.siemens.ct.exi.EXIFactory)1 EXISource (com.siemens.ct.exi.api.sax.EXISource)1 EXIException (com.siemens.ct.exi.exceptions.EXIException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 List (java.util.List)1