Search in sources :

Example 1 with GetObservationResponse

use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.

the class GetObservationResponseDocumentDecoder method decode.

@Override
@SuppressFBWarnings("NP_LOAD_OF_KNOWN_NULL_VALUE")
public GetObservationResponse decode(GetObservationResponseDocument gord) throws DecodingException {
    if (gord != null) {
        GetObservationResponse response = new GetObservationResponse();
        setService(response);
        setVersions(response);
        GetObservationResponseType gort = gord.getGetObservationResponse();
        response.setExtensions(parseExtensibleResponse(gort));
        response.setObservationCollection(ObservationStream.of(parseObservtions(gort)));
        return response;
    }
    throw new UnsupportedDecoderInputException(this, gord);
}
Also used : GetObservationResponseType(net.opengis.sos.x20.GetObservationResponseType) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with GetObservationResponse

use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.

the class OmEncoderv100 method encode.

@Override
public XmlObject encode(Object element, EncodingContext additionalValues) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof OmObservation) {
        encodedObject = createObservation((OmObservation) element, additionalValues);
    } else if (element instanceof GetObservationResponse) {
        GetObservationResponse response = (GetObservationResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else if (element instanceof GetObservationByIdResponse) {
        GetObservationByIdResponse response = (GetObservationByIdResponse) element;
        encodedObject = createObservationCollection(response.getObservationCollection(), response.getResultModel());
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) GetObservationResponse(org.n52.shetland.ogc.sos.response.GetObservationResponse) XmlObject(org.apache.xmlbeans.XmlObject) GetObservationByIdResponse(org.n52.shetland.ogc.sos.response.GetObservationByIdResponse) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 3 with GetObservationResponse

use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.

the class GetObservationResponseEncoder method createResponse.

@Override
protected void createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
    try {
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(StreamingEncoderFlags.ENCODER, this);
        new GetObservationResponseXmlStreamWriter(context, outputStream, response).write();
    } catch (XMLStreamException xmlse) {
        throw new EncodingException(xmlse);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlOptions(org.apache.xmlbeans.XmlOptions) GetObservationResponseXmlStreamWriter(org.n52.svalbard.write.GetObservationResponseXmlStreamWriter)

Example 4 with GetObservationResponse

use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.

the class GetObservationResponseEncoder method createResponse.

@Override
protected XmlObject createResponse(ObservationEncoder<XmlObject, OmObservation> encoder, GetObservationResponse response) throws EncodingException {
    try {
        GetObservationResponseDocument doc = GetObservationResponseDocument.Factory.newInstance(getXmlOptions());
        GetObservationResponseType xbResponse = doc.addNewGetObservationResponse();
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            xbResponse.addNewObservationData().addNewOMObservation().set(encoder.encode(observationCollection.next()));
        }
        // in a single observation the gml:ids must be unique
        XmlHelper.makeGmlIdsUnique(doc.getDomNode());
        return doc;
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : ObservationStream(org.n52.shetland.ogc.om.ObservationStream) EncodingException(org.n52.svalbard.encode.exception.EncodingException) GetObservationResponseType(net.opengis.sos.x20.GetObservationResponseType) GetObservationResponseDocument(net.opengis.sos.x20.GetObservationResponseDocument) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 5 with GetObservationResponse

use of org.n52.shetland.ogc.sos.response.GetObservationResponse in project arctic-sea by 52North.

the class AqdEncoder method encodeGetObservationResponse.

private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
    try {
        FeatureCollection featureCollection = getFeatureCollection(response);
        // TODO get FLOW from response
        EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
        featureCollection.addMember(eReportingHeader);
        TimePeriod timePeriod = new TimePeriod();
        TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
        int counter = 1;
        ObservationStream observationCollection = response.getObservationCollection();
        while (observationCollection.hasNext()) {
            OmObservation observation = observationCollection.next();
            if (observation.getValue() instanceof ObservationStream) {
                ObservationStream value = (ObservationStream) observation.getValue();
                if (value instanceof StreamingValue) {
                    value = value.merge();
                }
                while (value.hasNext()) {
                    processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
                }
            } else {
                processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
            }
        }
        if (!timePeriod.isEmpty()) {
            eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
        }
        return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
    } catch (OwsExceptionReport ex) {
        throw new EncodingException(ex);
    }
}
Also used : FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractEReportingHeader(org.n52.shetland.aqd.AbstractEReportingHeader) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Aggregations

EncodingException (org.n52.svalbard.encode.exception.EncodingException)8 DateTime (org.joda.time.DateTime)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)6 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)5 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)4 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 Time (org.n52.shetland.ogc.gml.time.Time)3 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)3 GetObservationResponse (org.n52.shetland.ogc.sos.response.GetObservationResponse)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 GetObservationResponseType (net.opengis.sos.x20.GetObservationResponseType)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchElementException (java.util.NoSuchElementException)1 Supplier (java.util.function.Supplier)1 OMObservationDocument (net.opengis.om.x20.OMObservationDocument)1 GetObservationResponseDocument (net.opengis.sos.x20.GetObservationResponseDocument)1