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());
}
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;
}
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()));
}
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));
}
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;
}
Aggregations