Search in sources :

Example 1 with GetDataAvailabilityResponse

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

the class GetDataAvailabilityXmlEncoder method create.

@Override
protected XmlObject create(GetDataAvailabilityResponse response) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext ctx = EncodingContext.empty().with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        if (GetDataAvailabilityConstants.NS_GDA.equals(response.getResponseFormat())) {
            new GetDataAvailabilityStreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        } else if (GetDataAvailabilityConstants.NS_GDA_20.equals(response.getResponseFormat())) {
            new GetDataAvailabilityV20StreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        }
        XmlObject encodedObject = XmlObject.Factory.parse(baos.toString("UTF8"));
        XmlHelper.validateDocument(encodedObject, EncodingException::new);
        return encodedObject;
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding response", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) GetDataAvailabilityV20StreamWriter(org.n52.svalbard.write.GetDataAvailabilityV20StreamWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) XmlObject(org.apache.xmlbeans.XmlObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GetDataAvailabilityStreamWriter(org.n52.svalbard.write.GetDataAvailabilityStreamWriter)

Example 2 with GetDataAvailabilityResponse

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

the class GetDataAvailabilityJsonEncoder method encodeResponse.

@Override
protected void encodeResponse(ObjectNode json, GetDataAvailabilityResponse t) throws EncodingException {
    ArrayNode a = json.putArray(GetDataAvailabilityConstants.DATA_AVAILABILITY);
    for (DataAvailability da : t.getDataAvailabilities()) {
        ObjectNode objectNode = a.addObject();
        objectNode.put(JSONConstants.FEATURE_OF_INTEREST, da.getFeatureOfInterest().getHref()).put(JSONConstants.PROCEDURE, da.getProcedure().getHref()).put(JSONConstants.OBSERVED_PROPERTY, da.getObservedProperty().getHref()).set(JSONConstants.PHENOMENON_TIME, encodeObjectToJson(da.getPhenomenonTime()));
        if (t.isSetResponseFormat() && GetDataAvailabilityConstants.NS_GDA_20.equals(t.getResponseFormat())) {
            if (da.isSetOffering()) {
                objectNode.put(JSONConstants.OFFERING, da.getOffering().getHref());
            }
            if (da.isSetFormatDescriptors()) {
                ObjectNode fdNode = objectNode.putObject(GetDataAvailabilityConstants.FORMAT_DESCRIPTOR);
                encodeProcedureFormatDescriptor(da.getFormatDescriptor().getProcedureDescriptionFormatDescriptor(), fdNode);
                encodeObservationFormatDescriptor(da.getFormatDescriptor().getObservationFormatDescriptors(), fdNode);
            }
        }
        if (da.isSetCount()) {
            objectNode.put(JSONConstants.COUNT, da.getCount());
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DataAvailability(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with GetDataAvailabilityResponse

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

the class GetDataAvailabilityResponseDecoder method decodeV20.

private GetDataAvailabilityResponse decodeV20(net.opengis.sosgda.x20.GetDataAvailabilityResponseDocument document) throws DecodingException {
    GetDataAvailabilityResponse response = new GetDataAvailabilityResponse();
    setService(response);
    setVersions(response);
    response.setNamespace(GetDataAvailabilityConstants.NS_GDA_20);
    response.setDataAvailabilities(parseDataAvalabilities(document.getGetDataAvailabilityResponse()));
    return response;
}
Also used : GetDataAvailabilityResponse(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse)

Example 4 with GetDataAvailabilityResponse

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

the class GetDataAvailabilityResponseDecoder method decodeV10.

private GetDataAvailabilityResponse decodeV10(GetDataAvailabilityResponseDocument document) throws DecodingException {
    GetDataAvailabilityResponse response = new GetDataAvailabilityResponse();
    setService(response);
    setVersions(response);
    response.setNamespace(GetDataAvailabilityConstants.NS_GDA);
    response.setDataAvailabilities(parseDataAvalabilities(document.getGetDataAvailabilityResponse()));
    return response;
}
Also used : GetDataAvailabilityResponse(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse)

Example 5 with GetDataAvailabilityResponse

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

the class GetDataAvailabilityXmlEncoderTest method test.

@Test
public void test() throws EncodingException {
    GetDataAvailabilityResponse response = new GetDataAvailabilityResponse("SOS", "2.0.0");
    response.setNamespace(GetDataAvailabilityConstants.NS_GDA);
    DateTime begin = DateTime.now().withZone(DateTimeZone.UTC);
    DateTime end = begin.plusHours(1).withZone(DateTimeZone.UTC);
    TimePeriod timePeriod = new TimePeriod(begin, end);
    ReferenceType procedure = new ReferenceType("procedure");
    ReferenceType observedProperty = new ReferenceType("observedProperty");
    ReferenceType featureOfInterest = new ReferenceType("featureOfInterest");
    ReferenceType offering = new ReferenceType("offering");
    int count = 100;
    response.addDataAvailability(new DataAvailability(procedure, observedProperty, featureOfInterest, offering, timePeriod, count));
    XmlObject encoded = encoder.encode(response);
    System.out.println(encoded.xmlText());
    errors.checkThat(encoded.xmlText(), is(String.format("<gda:GetDataAvailabilityResponse xsi:schemaLocation=\"http://www.opengis.net/sosgda/1.0 http://waterml2.org/schemas/gda/1.0/gda.xsd\" " + "xmlns:gda=\"http://www.opengis.net/sosgda/1.0\" " + "xmlns:gml=\"http://www.opengis.net/gml/3.2\" " + "xmlns:swe=\"http://www.opengis.net/swe/2.0\" " + "xmlns:xlink=\"http://www.w3.org/1999/xlink\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "  <gda:dataAvailabilityMember gml:id=\"dam_1\">\n" + "    <gda:procedure xlink:href=\"procedure\" xlink:title=\"procedure\"/>\n" + "    <gda:observedProperty xlink:href=\"observedProperty\" xlink:title=\"observedProperty\"/>\n" + "    <gda:featureOfInterest xlink:href=\"featureOfInterest\" xlink:title=\"featureOfInterest\"/>\n" + "    <gda:phenomenonTime>\n" + "      <gml:TimePeriod gml:id=\"tp_1\">\n" + "        <gml:beginPosition>%s</gml:beginPosition>\n" + "        <gml:endPosition>%s</gml:endPosition>\n" + "      </gml:TimePeriod>\n" + "    </gda:phenomenonTime>\n" + "    <gda:count>100</gda:count>\n" + "    <gda:extension>\n" + "      <swe:Text definition=\"offering\">\n" + "        <swe:value>offering</swe:value>\n" + "      </swe:Text>\n" + "    </gda:extension>\n" + "  </gda:dataAvailabilityMember>\n" + "</gda:GetDataAvailabilityResponse>", begin.toString(ISODateTimeFormat.dateTime()), end.toString(ISODateTimeFormat.dateTime()))));
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DataAvailability(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability) GetDataAvailabilityResponse(org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse) XmlObject(org.apache.xmlbeans.XmlObject) DateTime(org.joda.time.DateTime) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) Test(org.junit.Test)

Aggregations

GetDataAvailabilityResponse (org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse)3 XmlObject (org.apache.xmlbeans.XmlObject)2 DataAvailability (org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Supplier (java.util.function.Supplier)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlException (org.apache.xmlbeans.XmlException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)1 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 GetDataAvailabilityStreamWriter (org.n52.svalbard.write.GetDataAvailabilityStreamWriter)1 GetDataAvailabilityV20StreamWriter (org.n52.svalbard.write.GetDataAvailabilityV20StreamWriter)1