Search in sources :

Example 11 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class FieldDecoder method decodeTime.

protected SweAbstractDataComponent decodeTime(JsonNode node) throws DecodingException {
    SweTime swe = new SweTime();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        String value = node.path(JSONConstants.VALUE).textValue();
        swe.setValue(parseDateTime(value));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime)

Example 12 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class ObservationEncoder method encodeTVPValue.

private JsonNode encodeTVPValue(OmObservation o) throws EncodingException {
    TVPValue tvpValue = (TVPValue) o.getValue().getValue();
    ObjectNode result = nodeFactory().objectNode();
    List<TimeValuePair> values = tvpValue.getValue();
    if (values != null && !values.isEmpty()) {
        String obsProp = o.getObservationConstellation().getObservableProperty().getIdentifier();
        SweTime timeDef = new SweTime();
        timeDef.setDefinition(OmConstants.PHENOMENON_TIME);
        timeDef.setUom(OmConstants.PHEN_UOM_ISO8601);
        SweField timeField = new SweField(OmConstants.PHENOMENON_TIME_NAME, timeDef);
        SweField valueField = getFieldForValue(obsProp, values.get(0).getValue());
        result.putArray(JSONConstants.FIELDS).add(encodeObjectToJson(timeField)).add(encodeObjectToJson(valueField));
        ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
        for (TimeValuePair tvp : values) {
            if (tvp != null && tvp.getValue() != null && tvp.getValue().isSetValue()) {
                jvalues.addArray().add(encodeObjectToJson(tvp.getTime())).add(getTokenForValue(tvp.getValue()));
            }
        }
    }
    return result;
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 13 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime 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 14 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTime.

@Test
public void should_encode_Datarecord_with_fieldTime() throws EncodingException {
    final String field1Name = "test-name";
    final DateTime field1Value = new DateTime(System.currentTimeMillis());
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTime().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    assertThat(field1.isSetTime(), is(TRUE));
    assertThat(field1.getName(), is(field1Name));
    final DateTime xbTime = new DateTime(((XmlCalendar) field1.getTime().getValue()).getTimeInMillis(), DateTimeZone.UTC);
    assertThat(xbTime.toDateTime(field1Value.getZone()), is(field1Value));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with SweTime

use of org.n52.shetland.ogc.swe.simpleType.SweTime in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createTime.

private Time createTime(SweTime component) throws EncodingException {
    Time xml = Time.Factory.newInstance(getXmlOptions());
    if (component.isSetValue()) {
        XmlDateTime xbDateTime = createDateTime(component.getValue());
        xml.setValue(xbDateTime);
    }
    if (component.isSetUom()) {
        if (component.getUom().startsWith(URN) || component.getUom().startsWith(HTTP)) {
            xml.addNewUom().setHref(component.getUom());
        } else {
            xml.addNewUom().setCode(component.getUom());
        }
    }
    if (component.isSetQuality()) {
        xml.setQuality(createQuality(component.getQuality())[0]);
    }
    if (component.isSetContstraint()) {
        createConstraint(xml.getConstraint(), component.getConstraint());
    }
    return xml;
}
Also used : XmlDateTime(org.apache.xmlbeans.XmlDateTime) Time(net.opengis.swe.x101.TimeDocument.Time) XmlDateTime(org.apache.xmlbeans.XmlDateTime) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) DateTime(org.joda.time.DateTime)

Aggregations

SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)17 SweField (org.n52.shetland.ogc.swe.SweField)9 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)8 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)7 XmlObject (org.apache.xmlbeans.XmlObject)6 Test (org.junit.Test)5 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)5 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)4 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)4 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)4 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)4 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 DateTime (org.joda.time.DateTime)3 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)3 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)3