Search in sources :

Example 1 with DateTimeFormatException

use of org.n52.shetland.util.DateTimeFormatException in project arctic-sea by 52North.

the class InspireXmlEncoder method encodeObject.

private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        checkIfSupported(objectToEncode);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new InspireXmlStreamWriter(context, out, objectToEncode).write();
        String s = out.toString("UTF8");
        return XmlObject.Factory.parse(s);
    } catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) InspireXmlStreamWriter(org.n52.svalbard.write.InspireXmlStreamWriter) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with DateTimeFormatException

use of org.n52.shetland.util.DateTimeFormatException in project arctic-sea by 52North.

the class WmlTVPEncoderv20XmlStreamWriter method writeResult.

@Override
protected void writeResult() throws XMLStreamException, EncodingException {
    start(OmConstants.QN_OM_20_RESULT);
    namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20);
    start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES);
    OmObservation observation = getElement();
    attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID());
    writeMeasurementTimeseriesMetadata(observation);
    if (observation.getValue() instanceof SingleObservationValue) {
        SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        String time = getTimeString(observationValue.getPhenomenonTime());
        writePoint(time, getValue(observation.getValue().getValue()));
        close();
    } else if (observation.getValue() instanceof MultiObservationValues) {
        // XML streaming to client
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) observation.getValue();
        writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit());
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        for (TimeValuePair timeValuePair : timeValuePairs) {
            if (timeValuePair != null) {
                writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
            }
        }
        close();
    } else if (observation.getValue() instanceof StreamingValue) {
        // Database streaming + XML streaming to client
        StreamingValue<?> observationValue = (StreamingValue<?>) observation.getValue();
        if (observationValue.isSetUnit()) {
            writeDefaultPointMetadata(observationValue, observationValue.getUnit());
        } else if (observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
            writeDefaultPointMetadata(observationValue, ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
        } else {
            writeDefaultPointMetadata(observationValue, null);
        }
        try {
            while (observationValue.hasNext()) {
                TimeValuePair timeValuePair = observationValue.nextValue();
                if (timeValuePair != null) {
                    writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
                }
            }
        } catch (DateTimeFormatException | OwsExceptionReport e) {
            throw new EncodingException(e);
        }
        close();
    } else {
        super.writeResult();
    }
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) List(java.util.List) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Aggregations

DateTimeFormatException (org.n52.shetland.util.DateTimeFormatException)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 Supplier (java.util.function.Supplier)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlException (org.apache.xmlbeans.XmlException)1 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)1 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)1 OmObservation (org.n52.shetland.ogc.om.OmObservation)1 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)1 StreamingValue (org.n52.shetland.ogc.om.StreamingValue)1 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)1 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)1 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)1 InspireXmlStreamWriter (org.n52.svalbard.write.InspireXmlStreamWriter)1