Search in sources :

Example 1 with TimeRange

use of net.opengis.swe.x101.TimeRangeDocument.TimeRange in project arctic-sea by 52North.

the class SweCommonDecoderV101Test method should_decode_TimeRange.

@Test
public void should_decode_TimeRange() throws DecodingException {
    final TimeRangeDocument xbTimeRangeDoc = TimeRangeDocument.Factory.newInstance();
    TimeRange xbTimeRange = xbTimeRangeDoc.addNewTimeRange();
    final DateTime startDate = new DateTime(1970, 1, 1, 0, 0, DateTimeZone.UTC);
    final DateTime endDate = new DateTime(2013, 12, 31, 23, 59, DateTimeZone.UTC);
    final List<String> values = Lists.newArrayList(startDate.toString(), endDate.toString());
    xbTimeRange.setValue(values);
    final String iso8601Uom = "urn:ogc:def:unit:ISO:8601";
    xbTimeRange.addNewUom().setHref(iso8601Uom);
    final Object decodedObject = new SweCommonDecoderV101().decode(xbTimeRange);
    assertThat(decodedObject, is(instanceOf(SweTimeRange.class)));
    final SweTimeRange sweTimeRange = (SweTimeRange) decodedObject;
    assertThat(sweTimeRange.isSetUom(), is(true));
    assertThat(sweTimeRange.getUom(), is(iso8601Uom));
    assertThat(sweTimeRange.isSetValue(), is(true));
    assertThat(sweTimeRange.getValue().getRangeStart(), is(startDate));
    assertThat(sweTimeRange.getValue().getRangeEnd(), is(endDate));
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) TimeRange(net.opengis.swe.x101.TimeRangeDocument.TimeRange) TimeRangeDocument(net.opengis.swe.x101.TimeRangeDocument) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with TimeRange

use of net.opengis.swe.x101.TimeRangeDocument.TimeRange in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createTimeRange.

private TimeRange createTimeRange(SweTimeRange timeRange) throws EncodingException {
    TimeRange xbTimeRange = TimeRange.Factory.newInstance(getXmlOptions());
    addAbstractDataComponentValues(xbTimeRange, timeRange);
    if (timeRange.isSetValue()) {
        xbTimeRange.setValue(timeRange.getValue().getRangeAsStringList());
    }
    if (timeRange.isSetUom()) {
        xbTimeRange.addNewUom().setCode(timeRange.getUom());
    }
    if (timeRange.isSetQuality()) {
        xbTimeRange.setQuality(createQuality(timeRange.getQuality())[0]);
    }
    return xbTimeRange;
}
Also used : TimeRange(net.opengis.swe.x101.TimeRangeDocument.TimeRange) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange)

Aggregations

TimeRange (net.opengis.swe.x101.TimeRangeDocument.TimeRange)2 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)2 TimeRangeDocument (net.opengis.swe.x101.TimeRangeDocument)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1