Search in sources :

Example 6 with Extension

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

the class SwesExtensionDecoderv20 method decode.

@Override
public SwesExtension<?> decode(XmlObject xmlObject) throws DecodingException, UnsupportedDecoderInputException {
    if (isSwesExtension(xmlObject)) {
        XmlObject[] children = xmlObject.selectPath("./*");
        if (children.length == 1) {
            Object xmlObj = decodeXmlElement(children[0]);
            if (xmlObj instanceof SweAbstractDataComponent) {
                SwesExtension<SweAbstractDataComponent> extension = new SwesExtension<>();
                extension.setValue((SweAbstractDataComponent) xmlObj);
                return extension;
            }
        }
    }
    throw new UnsupportedDecoderXmlInputException(this, xmlObject);
}
Also used : SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) SwesExtension(org.n52.shetland.ogc.swes.SwesExtension)

Example 7 with Extension

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

the class SwesExtensionEncoderv20Test method shouldEncodeSweTypeBoolean.

@Test
public void shouldEncodeSweTypeBoolean() throws EncodingException {
    String identifier = "test-identifier";
    String definition = "test-definition";
    Boolean value = Boolean.TRUE;
    SweBoolean sweBoolean = new SweBoolean();
    sweBoolean.setDefinition(definition);
    sweBoolean.setIdentifier(identifier);
    sweBoolean.setValue(value);
    SwesExtension<SweBoolean> extension = new SwesExtension<>();
    extension.setValue(sweBoolean);
    XmlObject encodedObject = encoder.encode(extension);
    Assert.assertThat(encodedObject, Matchers.instanceOf(BooleanPropertyType.class));
    BooleanType xbBoolean = ((BooleanPropertyType) encodedObject).getBoolean();
    Assert.assertThat(xbBoolean.getDefinition(), Is.is(definition));
    Assert.assertThat(xbBoolean.getIdentifier(), Is.is(identifier));
    Assert.assertThat(xbBoolean.getValue(), Is.is(value));
}
Also used : BooleanType(net.opengis.swe.x20.BooleanType) XmlObject(org.apache.xmlbeans.XmlObject) SwesExtension(org.n52.shetland.ogc.swes.SwesExtension) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) Test(org.junit.Test)

Example 8 with Extension

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

the class SosDecoderv20Test method should_decode_text_swesExtensions.

@Test
public void should_decode_text_swesExtensions() throws XmlException, OwsExceptionReport, DecodingException {
    final GetObservationDocument doc = GetObservationDocument.Factory.parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<sos:GetObservation service=\"SOS\" version=\"2.0.0\"\n" + "    xmlns:sos=\"http://www.opengis.net/sos/2.0\"\n" + "    xmlns:swe=\"http://www.opengis.net/swe/2.0\"\n" + "    xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" + "    xmlns:swes=\"http://www.opengis.net/swes/2.0\"\n" + "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sos.xsd\">\n" + "    <swes:extension>\n" + "        <swe:Text definition=\"my-text-extension\">\n" + "            <swe:value>true</swe:value>\n" + "        </swe:Text>\n" + "    </swes:extension>\n" + "</sos:GetObservation>");
    final OwsServiceCommunicationObject decodedObject = decoder.decode(doc);
    assertThat(decodedObject, instanceOf(GetObservationRequest.class));
    final GetObservationRequest request = (GetObservationRequest) decodedObject;
    assertThat(request.getExtension("my-text-extension").map(e -> e.getValue()).map(v -> (SweText) v).map(v -> v.getValue()).orElse(null), is("true"));
}
Also used : OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) OwsServiceCommunicationObject(org.n52.shetland.ogc.ows.service.OwsServiceCommunicationObject) Arrays(java.util.Arrays) DecodingException(org.n52.svalbard.decode.exception.DecodingException) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) InsertResultTemplateDocument(net.opengis.sos.x20.InsertResultTemplateDocument) Test(org.junit.Test) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) GetObservationDocument(net.opengis.sos.x20.GetObservationDocument) Assert.assertThat(org.junit.Assert.assertThat) XmlException(org.apache.xmlbeans.XmlException) XmlOptions(org.apache.xmlbeans.XmlOptions) After(org.junit.After) Matchers.is(org.hamcrest.Matchers.is) TRUE(java.lang.Boolean.TRUE) Producer(org.n52.janmayen.Producer) Before(org.junit.Before) GetObservationRequest(org.n52.shetland.ogc.sos.request.GetObservationRequest) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) GetObservationDocument(net.opengis.sos.x20.GetObservationDocument) Test(org.junit.Test)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)4 Test (org.junit.Test)2 OwsDomain (org.n52.shetland.ogc.ows.OwsDomain)2 OwsOperation (org.n52.shetland.ogc.ows.OwsOperation)2 OwsOperationMetadataExtension (org.n52.shetland.ogc.ows.OwsOperationMetadataExtension)2 OwsOperationsMetadata (org.n52.shetland.ogc.ows.OwsOperationsMetadata)2 SwesExtension (org.n52.shetland.ogc.swes.SwesExtension)2 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 TRUE (java.lang.Boolean.TRUE)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 GetObservationDocument (net.opengis.sos.x20.GetObservationDocument)1 InsertResultTemplateDocument (net.opengis.sos.x20.InsertResultTemplateDocument)1 BooleanPropertyType (net.opengis.swe.x20.BooleanPropertyType)1 BooleanType (net.opengis.swe.x20.BooleanType)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 Matchers.is (org.hamcrest.Matchers.is)1 IsInstanceOf.instanceOf (org.hamcrest.core.IsInstanceOf.instanceOf)1