Search in sources :

Example 31 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class SosRequestEncoderv20 method createTemporalFilter.

private void createTemporalFilter(final net.opengis.sos.x20.GetResultType.TemporalFilter temporalFilter, final TemporalFilter sosTemporalFilter) throws EncodingException {
    final Encoder<XmlObject, TemporalFilter> encoder = getEncoder(FilterConstants.NS_FES_2, sosTemporalFilter);
    final XmlObject encodedObject = encoder.encode(sosTemporalFilter);
    temporalFilter.set(encodedObject);
}
Also used : TemporalFilter(org.n52.shetland.ogc.filter.TemporalFilter) XmlObject(org.apache.xmlbeans.XmlObject)

Example 32 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class DescribeSensorV2RequestEncoderTest method shouldThrowExceptionIfServiceIsMissing.

@Test
public void shouldThrowExceptionIfServiceIsMissing() throws EncodingException {
    thrown.expect(UnsupportedEncoderInputException.class);
    thrown.expectMessage(Is.is("Encoder " + DescribeSensorV2RequestEncoder.class.getSimpleName() + " can not encode 'missing service'"));
    new DescribeSensorV2RequestEncoder().create(new DescribeSensorRequest());
}
Also used : DescribeSensorRequest(org.n52.shetland.ogc.sos.request.DescribeSensorRequest) Test(org.junit.Test)

Example 33 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class AbstractOmV20XmlStreamWriter method writeParameter.

/**
 * Write om:parameter to stream
 *
 * @throws XMLStreamException
 *             If an error occurs when writing to stream
 * @throws EncodingException
 *             If an error occurs when creating elements to be written
 */
protected void writeParameter() throws XMLStreamException, EncodingException {
    XmlEncoderKey key = new XmlEncoderKey(OmConstants.NS_OM_2, NamedValue.class);
    Encoder<XmlObject, NamedValue<?>> encoder = getEncoder(key);
    if (encoder != null) {
        for (NamedValue<?> namedValue : getElement().getParameter()) {
            start(OmConstants.QN_OM_20_PARAMETER);
            writeXmlObject(encoder.encode(namedValue), OmConstants.QN_OM_20_NAMED_VALUE);
            end(OmConstants.QN_OM_20_PARAMETER);
        }
    }
}
Also used : XmlEncoderKey(org.n52.svalbard.encode.XmlEncoderKey) XmlObject(org.apache.xmlbeans.XmlObject) NamedValue(org.n52.shetland.ogc.om.NamedValue)

Example 34 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class AqdGetObservationResponseXmlStreamWriter method writeFeatureCollectionDoc.

private void writeFeatureCollectionDoc() throws XMLStreamException, EncodingException {
    start(GmlConstants.QN_FEATURE_COLLECTION_32);
    addNamespaces();
    addSchemaLocations();
    FeatureCollection featureCollection = getElement();
    addGmlId(featureCollection.getGmlId());
    TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
    for (AbstractFeature abstractFeature : featureCollection.getMembers().values()) {
        long start = System.currentTimeMillis();
        Encoder<XmlObject, AbstractFeature> encoder = getEncoder(abstractFeature);
        if (abstractFeature instanceof OmObservation) {
            OmObservation observation = (OmObservation) abstractFeature;
            if (observation.getValue() instanceof ObservationStream) {
                try {
                    // start the timer task to write blank strings to avoid
                    // connection closing
                    startTimer();
                    ObservationStream mergeObservation = ((ObservationStream) observation.getValue()).merge();
                    LOGGER.debug("Observation processing requires {} ms", System.currentTimeMillis() - start);
                    int count = 0;
                    while (mergeObservation.hasNext()) {
                        OmObservation omObservation = mergeObservation.next();
                        if (abstractFeature.isSetGmlID()) {
                            if (count == 0) {
                                omObservation.setGmlId(abstractFeature.getGmlId());
                            } else {
                                omObservation.setGmlId(abstractFeature.getGmlId() + "_" + count);
                            }
                            count++;
                        }
                        omObservation.setResultTime(resultTime);
                        String xmlTextObservation = prepareObservation(omObservation, encoder);
                        // stop the timer task
                        stopTimer();
                        writeMember(xmlTextObservation);
                    }
                } catch (OwsExceptionReport ex) {
                    throw new EncodingException(ex);
                }
            } else {
                if (encoder instanceof XmlStreamWriter) {
                    encoder.encode(abstractFeature, getContext());
                } else {
                    writeMember(abstractFeature, encoder);
                }
            }
        } else {
            writeMember(abstractFeature, encoder);
        }
        LOGGER.debug("Writing member requires {} ms", System.currentTimeMillis() - start);
    }
    end(GmlConstants.QN_FEATURE_COLLECTION_32);
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) DateTime(org.joda.time.DateTime) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) ObservationStream(org.n52.shetland.ogc.om.ObservationStream) XmlObject(org.apache.xmlbeans.XmlObject) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 35 with Encoder

use of org.n52.svalbard.encode.Encoder in project arctic-sea by 52North.

the class WmlTVPEncoderv20Test method initObjects.

@Before
public void initObjects() {
    encoder = new WmlTVPEncoderv20();
    MultiValue<List<TimeValuePair>> value = new TVPValue();
    String unit = "test-unit";
    value.setUnit(unit);
    TimeValuePair tvp1 = new TimeValuePair(new TimeInstant(new Date(UTC_TIMESTAMP)), new QuantityValue(52.1234567890));
    List<TimeValuePair> valueList = CollectionHelper.list(tvp1);
    value.setValue(valueList);
    mv = new MultiObservationValues<>();
    mv.setValue(value);
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) List(java.util.List) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Date(java.util.Date) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)28 XmlObject (org.apache.xmlbeans.XmlObject)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)7 InsertResultTemplateRequest (org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest)7 InsertSensorRequest (org.n52.shetland.ogc.sos.request.InsertSensorRequest)7 Before (org.junit.Before)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)5 OmObservationConstellation (org.n52.shetland.ogc.om.OmObservationConstellation)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 OwsOperationKey (org.n52.shetland.ogc.ows.service.OwsOperationKey)5 InsertObservationRequest (org.n52.shetland.ogc.sos.request.InsertObservationRequest)5 NoEncoderForKeyException (org.n52.svalbard.encode.exception.NoEncoderForKeyException)5 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 ObservationStream (org.n52.shetland.ogc.om.ObservationStream)4 OwsServiceResponse (org.n52.shetland.ogc.ows.service.OwsServiceResponse)4 InsertResultRequest (org.n52.shetland.ogc.sos.request.InsertResultRequest)4 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)4 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)4 CodeType (org.n52.shetland.ogc.gml.CodeType)3