Search in sources :

Example 1 with SosResultStructure

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

the class GetResultTemplateResponseEncoder method encodeResultStructure.

private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
    SweAbstractDataComponent structure;
    SosResultStructure rs = t.getResultStructure();
    if (rs.isDecoded()) {
        structure = t.getResultStructure().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
            Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (structure instanceof SweDataRecord) {
        encodeSweDataRecord(structure, jrs);
    } else {
        LOG.warn("Unsupported structure: {}", structure == null ? null : structure.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) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure)

Example 2 with SosResultStructure

use of org.n52.shetland.ogc.sos.SosResultStructure 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 SosResultStructure

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

the class GetResultTemplateResponseEncoder method createResultStructure.

private ResultStructure createResultStructure(SosResultStructure resultStructure) throws EncodingException {
    // TODO move encoding to SWECommonEncoder
    final DataRecordDocument dataRecordDoc;
    if (resultStructure.isEncoded()) {
        try {
            dataRecordDoc = DataRecordDocument.Factory.parse(resultStructure.getXml().get());
        } catch (XmlException ex) {
            throw unsupportedResultStructure(ex);
        }
    } else {
        XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultStructure.get().get());
        if (xml instanceof DataRecordDocument) {
            dataRecordDoc = (DataRecordDocument) xml;
        } else {
            throw unsupportedResultStructure();
        }
    }
    ResultStructure xbResultStructure = ResultStructure.Factory.newInstance(getXmlOptions());
    xbResultStructure.addNewAbstractDataComponent().set(dataRecordDoc.getDataRecord());
    XmlHelper.substituteElement(xbResultStructure.getAbstractDataComponent(), dataRecordDoc.getDataRecord());
    return xbResultStructure;
}
Also used : ResultStructure(net.opengis.sos.x20.GetResultTemplateResponseType.ResultStructure) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) DataRecordDocument(net.opengis.swe.x20.DataRecordDocument)

Example 4 with SosResultStructure

use of org.n52.shetland.ogc.sos.SosResultStructure 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 5 with SosResultStructure

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

the class InsertResultTemplateRequestEncoderTest method shouldThrowExceptionWhenResultEncodingIsMissing.

@Test
public void shouldThrowExceptionWhenResultEncodingIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + InsertResultTemplateRequestEncoder.class.getSimpleName() + " can not encode 'missing resultEncoding'"));
    request = new InsertResultTemplateRequest("service", "version");
    request.setObservationTemplate(new OmObservationConstellation());
    request.setResultStructure(new SosResultStructure(new SweDataRecord()));
    OmObservationConstellation observationTemplate = new OmObservationConstellation();
    observationTemplate.addOffering(offering);
    request.setObservationTemplate(observationTemplate);
    encoder.create(request);
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) OmObservationConstellation(org.n52.shetland.ogc.om.OmObservationConstellation) SosResultStructure(org.n52.shetland.ogc.sos.SosResultStructure) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Test(org.junit.Test)

Aggregations

SosResultStructure (org.n52.shetland.ogc.sos.SosResultStructure)5 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)3 XmlException (org.apache.xmlbeans.XmlException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)2 SosResultEncoding (org.n52.shetland.ogc.sos.SosResultEncoding)2 InsertResultTemplateRequest (org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GetResultTemplateResponseType (net.opengis.sos.x20.GetResultTemplateResponseType)1 ResultStructure (net.opengis.sos.x20.GetResultTemplateResponseType.ResultStructure)1 DataRecordDocument (net.opengis.swe.x20.DataRecordDocument)1 XmlOptions (org.apache.xmlbeans.XmlOptions)1 Before (org.junit.Before)1 Test (org.junit.Test)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 SamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.SamplingFeature)1 SensorML (org.n52.shetland.ogc.sensorML.SensorML)1 GetResultTemplateResponse (org.n52.shetland.ogc.sos.response.GetResultTemplateResponse)1