Search in sources :

Example 61 with SweField

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Example 62 with SweField

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));
    }
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 63 with SweField

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;
}
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 64 with SweField

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));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) 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) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) Test(org.junit.Test)

Example 65 with SweField

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));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) 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) Test(org.junit.Test)

Aggregations

SweField (org.n52.shetland.ogc.swe.SweField)59 Test (org.junit.Test)42 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 XmlObject (org.apache.xmlbeans.XmlObject)20 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)19 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)19 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)12 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)12 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)11 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)11 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)11 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)10 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)9 DataRecordType (net.opengis.swe.x101.DataRecordType)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)9 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 DateTime (org.joda.time.DateTime)4