Search in sources :

Example 1 with SosResultEncoding

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

the class InsertResultTemplateRequestDecoder method parseResultEncoding.

private SosResultEncoding parseResultEncoding(JsonNode node) {
    SweTextEncoding textEncoding = new SweTextEncoding();
    textEncoding.setTokenSeparator(node.path(JSONConstants.TOKEN_SEPARATOR).textValue());
    textEncoding.setBlockSeparator(node.path(JSONConstants.BLOCK_SEPARATOR).textValue());
    if (!node.path(JSONConstants.DECIMAL_SEPARATOR).isMissingNode()) {
        textEncoding.setDecimalSeparator(node.path(JSONConstants.DECIMAL_SEPARATOR).textValue());
    }
    return new SosResultEncoding(textEncoding);
}
Also used : SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding)

Example 2 with SosResultEncoding

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

the class SosDecoderv20 method parseGetResultTemplateResponse.

private OwsServiceResponse parseGetResultTemplateResponse(final GetResultTemplateResponseDocument getResultTemplateResponseDoc) throws DecodingException {
    final GetResultTemplateResponse sosGetResultTemplateResponse = new GetResultTemplateResponse();
    final GetResultTemplateResponseType getResultTemplateResponse = getResultTemplateResponseDoc.getGetResultTemplateResponse();
    final SosResultEncoding resultEncoding = parseResultEncoding(getResultTemplateResponse.getResultEncoding().getAbstractEncoding());
    final SosResultStructure resultStructure = parseResultStructure(getResultTemplateResponse.getResultStructure().getAbstractDataComponent());
    sosGetResultTemplateResponse.setResultEncoding(resultEncoding);
    sosGetResultTemplateResponse.setResultStructure(resultStructure);
    return sosGetResultTemplateResponse;
}
Also used : GetResultTemplateResponseType(net.opengis.sos.x20.GetResultTemplateResponseType) GetResultTemplateResponse(org.n52.shetland.ogc.sos.response.GetResultTemplateResponse) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 3 with SosResultEncoding

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

the class InsertResultTemplateRequestEncoderTest method setup.

@Before
public void setup() throws InvalidSridException, ParseException {
    SensorML procedure = new SensorML();
    procedure.setIdentifier(procedureIdentifier);
    SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
    featureOfInterest.setIdentifier(featureIdentifier);
    featureOfInterest.setName(new CodeType(featureName));
    featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
    featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT(30 10)", 4326));
    observationTemplate = new OmObservationConstellation();
    observationTemplate.addOffering(offering);
    observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
    observationTemplate.setProcedure(procedure);
    observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
    observationTemplate.setFeatureOfInterest(featureOfInterest);
    SweTextEncoding textEncoding = new SweTextEncoding();
    textEncoding.setBlockSeparator(blockSeparator);
    textEncoding.setTokenSeparator(tokenSeparator);
    SweDataRecord resultStructure = new SweDataRecord();
    SweTime sweTime = new SweTime();
    sweTime.setDefinition(field1Definition);
    sweTime.setUom(field1Uom);
    resultStructure.addField(new SweField(field1Name, sweTime));
    request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
    request.setResultEncoding(new SosResultEncoding(textEncoding));
    request.setResultStructure(new SosResultStructure(resultStructure));
    request.setIdentifier(templateIdentifier);
    request.setObservationTemplate(observationTemplate);
    Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
    encoder = new InsertResultTemplateRequestEncoder();
    encoder.setXmlOptions(xmlOptions);
    OmEncoderv20 omEncoder = new OmEncoderv20();
    omEncoder.setXmlOptions(xmlOptions);
    SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
    samsEncoder.setXmlOptions(xmlOptions);
    GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
    gml32Encoder.setXmlOptions(xmlOptions);
    SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
    sweEncoderv20.setXmlOptions(xmlOptions);
    EncoderRepository encoderRepository = new EncoderRepository();
    encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
    encoderRepository.init();
    encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) XmlOptions(org.apache.xmlbeans.XmlOptions) SamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SensorML(org.n52.shetland.ogc.sensorML.SensorML) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) CodeType(org.n52.shetland.ogc.gml.CodeType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Before(org.junit.Before)

Example 4 with SosResultEncoding

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

the class GetResultTemplateResponseEncoder method encodeResultEncoding.

private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
    SweAbstractEncoding encoding = null;
    SosResultEncoding re = t.getResultEncoding();
    if (re.isDecoded()) {
        encoding = t.getResultEncoding().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
            Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (encoding instanceof SweTextEncoding) {
        encodeSweTextEncoding(encoding, jre);
    } else {
        LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweAbstractEncoding(org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding)

Example 5 with SosResultEncoding

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

the class GetResultTemplateResponseEncoder method createResultEncoding.

private ResultEncoding createResultEncoding(SosResultEncoding resultEncoding) throws EncodingException {
    // TODO move encoding to SWECommonEncoder
    final TextEncodingDocument xbEncoding;
    if (resultEncoding.isEncoded()) {
        try {
            xbEncoding = TextEncodingDocument.Factory.parse(resultEncoding.getXml().get());
        } catch (XmlException ex) {
            throw unsupportedResultEncoding(ex);
        }
    } else {
        XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultEncoding.get().get());
        if (xml instanceof TextEncodingDocument) {
            xbEncoding = (TextEncodingDocument) xml;
        } else {
            throw unsupportedResultEncoding();
        }
    }
    ResultEncoding xbResultEncoding = ResultEncoding.Factory.newInstance(getXmlOptions());
    xbResultEncoding.addNewAbstractEncoding().set(xbEncoding.getTextEncoding());
    XmlHelper.substituteElement(xbResultEncoding.getAbstractEncoding(), xbEncoding.getTextEncoding());
    return xbResultEncoding;
}
Also used : TextEncodingDocument(net.opengis.swe.x20.TextEncodingDocument) XmlException(org.apache.xmlbeans.XmlException) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding) ResultEncoding(net.opengis.sos.x20.GetResultTemplateResponseType.ResultEncoding) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

SosResultEncoding (org.n52.shetland.ogc.sos.SosResultEncoding)5 SweTextEncoding (org.n52.shetland.ogc.swe.encoding.SweTextEncoding)3 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 SosResultStructure (org.n52.shetland.ogc.sos.SosResultStructure)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GetResultTemplateResponseType (net.opengis.sos.x20.GetResultTemplateResponseType)1 ResultEncoding (net.opengis.sos.x20.GetResultTemplateResponseType.ResultEncoding)1 TextEncodingDocument (net.opengis.swe.x20.TextEncodingDocument)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 Before (org.junit.Before)1 CodeType (org.n52.shetland.ogc.gml.CodeType)1 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)1 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)1 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)1 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)1 SensorML (org.n52.shetland.ogc.sensorML.SensorML)1 InsertResultTemplateRequest (org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest)1 GetResultTemplateResponse (org.n52.shetland.ogc.sos.response.GetResultTemplateResponse)1 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)1