use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class FieldEncoder method createField.
private ObjectNode createField(SweField field) {
ObjectNode jfield = nodeFactory().objectNode();
jfield.put(JSONConstants.NAME, field.getName().getValue());
SweAbstractDataComponent element = field.getElement();
if (element.isSetDefinition()) {
jfield.put(JSONConstants.DEFINITION, element.getDefinition());
}
if (element.isSetDescription()) {
jfield.put(JSONConstants.DESCRIPTION, element.getDescription());
}
if (element.isSetIdentifier()) {
jfield.put(JSONConstants.IDENTIFIER, element.getIdentifier());
}
if (element.isSetLabel()) {
jfield.put(JSONConstants.LABEL, element.getLabel());
}
return jfield;
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeSweDataRecord.
private void encodeSweDataRecord(SweAbstractDataComponent structure, ObjectNode node) throws EncodingException {
SweDataRecord sweDataRecord = (SweDataRecord) structure;
ArrayNode fields = node.putArray(JSONConstants.FIELDS);
for (SweField field : sweDataRecord.getFields()) {
fields.add(encodeObjectToJson(field));
}
}
use of org.n52.shetland.ogc.swe.SweField 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.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_simpleDatarecord_with_quantities.
@Test
public void should_encode_simpleDatarecord_with_quantities() throws EncodingException {
final String name = "field-1";
final String unit = "m";
final Double value = 1.1;
final String name2 = "field-2";
final String unit2 = "urn:ogc:def:uom:UCUM::m";
final Double value2 = 1.2;
final XmlObject encode = sweCommonEncoderv101.encode(new SweSimpleDataRecord().addField(new SweField(name, new SweQuantity().setUom(unit).setValue(value))).addField(new SweField(name2, new SweQuantity().setUom(unit2).setValue(value2))));
assertThat(encode, instanceOf(SimpleDataRecordType.class));
final SimpleDataRecordType xbSimpleDataRecord = (SimpleDataRecordType) encode;
assertThat(xbSimpleDataRecord.getFieldArray().length, is(2));
final AnyScalarPropertyType field1 = xbSimpleDataRecord.getFieldArray(0);
final AnyScalarPropertyType field2 = xbSimpleDataRecord.getFieldArray(1);
// unit in code
assertThat(field1.getName(), is(name));
assertThat(field1.isSetQuantity(), is(TRUE));
assertThat(field1.getQuantity().getValue(), is(value));
assertThat(field1.getQuantity().getUom().getCode(), is(unit));
// unit in href
assertThat(field2.getName(), is(name2));
assertThat(field2.isSetQuantity(), is(TRUE));
assertThat(field2.getQuantity().getValue(), is(value2));
assertThat(field2.getQuantity().getUom().getHref(), is(unit2));
}
use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldText.
@Test
public void should_encode_Datarecord_with_fieldText() throws EncodingException {
final String field1Name = "test-name";
final String field1Value = "test-value";
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweText().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.isSetText(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getText().getValue(), is(field1Value));
}
Aggregations