Search in sources :

Example 6 with DateTimeHelper.parseIsoString2DateTime

use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseTimeRange.

private SweTimeRange parseTimeRange(TimeRangeType xbTime) throws DecodingException {
    SweTimeRange sosTimeRange = new SweTimeRange();
    if (xbTime.isSetValue()) {
        List<?> value = xbTime.getValue();
        if (value != null && !value.isEmpty()) {
            RangeValue<DateTime> range = new RangeValue<>();
            Iterator<?> iter = value.iterator();
            if (iter.hasNext()) {
                range.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
            }
            if (iter.hasNext()) {
                range.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iter.next().toString()));
            }
            sosTimeRange.setValue(range);
        }
    }
    if (xbTime.getUom() != null) {
        sosTimeRange.setUom(xbTime.getUom().getHref());
    }
    if (xbTime.isSetConstraint()) {
        sosTimeRange.setConstraint(parseConstraint(xbTime.getConstraint()));
    }
    if (xbTime.getQualityArray() != null) {
        sosTimeRange.setQuality(parseQuality(xbTime.getQualityArray()));
    }
    return sosTimeRange;
}
Also used : SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue)

Example 7 with DateTimeHelper.parseIsoString2DateTime

use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_fieldTime.

@Test
public void should_encode_simpleDatarecord_with_fieldTime() throws EncodingException {
    final String name = "field-1";
    final DateTime value = new DateTime(DateTimeZone.UTC);
    final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweTime().setValue(value))));
    assertThat(encode, instanceOf(SimpleDataRecordType.class));
    final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
    final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
    assertThat(xbSimpleDataRecord.getFieldArray().length, is(1));
    assertThat(field1.getName(), is(name));
    assertThat(field1.isSetTime(), is(TRUE));
    assertThat(DateTimeHelper.parseIsoString2DateTime(field1.getTime().getValue().toString()).toString(), is(value.toString()));
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) AnyScalarPropertyType(net.opengis.swe.x101.AnyScalarPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) DateTime(org.joda.time.DateTime) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.Test)

Example 8 with DateTimeHelper.parseIsoString2DateTime

use of org.n52.shetland.util.DateTimeHelper.parseIsoString2DateTime in project arctic-sea by 52North.

the class GmlDecoderv321 method parseTimePosition.

private TimeInstant parseTimePosition(TimePositionType xbTimePosition) throws DecodingException {
    TimeInstant ti = new TimeInstant();
    String timeString = xbTimePosition.getStringValue();
    if (timeString != null && !timeString.isEmpty()) {
        try {
            // TODO better differentiate between ISO8601 and indeterminate
            // value
            ti.setValue(DateTimeHelper.parseIsoString2DateTime(timeString));
            ti.setRequestedTimeLength(DateTimeHelper.getTimeLengthBeforeTimeZone(timeString));
        } catch (DateTimeParseException ex) {
            ti.setIndeterminateValue(new IndeterminateValue(timeString));
        }
    }
    if (xbTimePosition.isSetIndeterminatePosition()) {
        ti.setIndeterminateValue(new IndeterminateValue(xbTimePosition.getIndeterminatePosition().toString()));
    }
    return ti;
}
Also used : DateTimeParseException(org.n52.shetland.util.DateTimeParseException) IndeterminateValue(org.n52.shetland.ogc.gml.time.IndeterminateValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Aggregations

DateTime (org.joda.time.DateTime)6 RangeValue (org.n52.shetland.ogc.swe.RangeValue)4 XmlObject (org.apache.xmlbeans.XmlObject)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IndeterminateValue (org.n52.shetland.ogc.gml.time.IndeterminateValue)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 SweAllowedTimes (org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes)2 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)2 DateTimeParseException (org.n52.shetland.util.DateTimeParseException)2 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)1 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)1 Before (org.junit.Before)1 Test (org.junit.Test)1 SweField (org.n52.shetland.ogc.swe.SweField)1 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)1 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)1 FieldDecoder (org.n52.svalbard.decode.json.FieldDecoder)1