Search in sources :

Example 1 with SweQuantity

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

the class FieldDecoderTest method testQuantity.

@Test
public void testQuantity() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.QUANTITY_TYPE).put(JSONConstants.UOM, UOM);
    SweField field = checkCommon(json, false);
    assertThat(field.getElement(), is(instanceOf(SweQuantity.class)));
    SweQuantity swe = (SweQuantity) field.getElement();
    errors.checkThat(swe.getUom(), is(UOM));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) Test(org.junit.Test)

Example 2 with SweQuantity

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

the class InsertResultTemplateRequestDecoderTest method resultStructure.

@Test
public void resultStructure() throws IOException, DecodingException {
    InsertResultTemplateRequest req = load();
    assertThat(req.getResultStructure(), is(notNullValue()));
    assertThat(req.getResultStructure().isDecoded(), is(true));
    assertThat(req.getResultStructure().isEncoded(), is(false));
    assertThat(req.getResultStructure().get().get(), is(instanceOf(SweDataRecord.class)));
    SweDataRecord structure = (SweDataRecord) req.getResultStructure().get().get();
    assertThat(structure.getFields(), is(notNullValue()));
    assertThat(structure.getFields(), hasSize(3));
    SweField field1 = structure.getFields().get(0);
    assertThat(field1, is(notNullValue()));
    errors.checkThat(field1.getName().getValue(), is("phenomenonTime"));
    assertThat(field1.getElement(), is(instanceOf(SweTimeRange.class)));
    SweTimeRange phenomenonTime = (SweTimeRange) field1.getElement();
    errors.checkThat(phenomenonTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/PhenomenonTime"));
    errors.checkThat(phenomenonTime.getUom(), is("http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"));
    SweField field2 = structure.getFields().get(1);
    assertThat(field2, is(notNullValue()));
    errors.checkThat(field2.getName().getValue(), is("resultTime"));
    assertThat(field2.getElement(), is(instanceOf(SweTime.class)));
    SweTime resultTime = (SweTime) field2.getElement();
    errors.checkThat(resultTime.getDefinition(), is("http://www.opengis.net/def/property/OGC/0/ResultTime"));
    errors.checkThat(resultTime.getUom(), is("testunit1"));
    SweField field3 = structure.getFields().get(2);
    assertThat(field3, is(notNullValue()));
    errors.checkThat(field3.getName().getValue(), is("observable_property_6"));
    assertThat(field3.getElement(), is(instanceOf(SweQuantity.class)));
    SweQuantity quantity = (SweQuantity) field3.getElement();
    errors.checkThat(quantity.getDefinition(), is("http://www.52north.org/test/observableProperty/6"));
    errors.checkThat(quantity.getUom(), is("test_unit_6"));
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) InsertResultTemplateRequest(org.n52.shetland.ogc.sos.request.InsertResultTemplateRequest) Test(org.junit.Test)

Example 3 with SweQuantity

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

the class FieldEncoder method encodeSweQuantityField.

private ObjectNode encodeSweQuantityField(SweField field) {
    ObjectNode jfield = createField(field);
    jfield.put(JSONConstants.TYPE, JSONConstants.QUANTITY_TYPE);
    SweQuantity sweQuantity = (SweQuantity) field.getElement();
    if (sweQuantity.isSetValue()) {
        jfield.put(JSONConstants.VALUE, sweQuantity.getValue());
    }
    jfield.put(JSONConstants.UOM, sweQuantity.getUom());
    return jfield;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 4 with SweQuantity

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

the class ObservationEncoder method getFieldForValue.

private SweField getFieldForValue(String phenomenon, Value<?> value) throws EncodingException {
    final SweAbstractDataComponent def;
    if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof CategoryValue) {
        SweCategory sweCategory = new SweCategory();
        CategoryValue categoryValue = (CategoryValue) value;
        sweCategory.setCodeSpace(categoryValue.getUnit());
        def = sweCategory;
    } else if (value instanceof CountValue) {
        def = new SweCount();
    } else if (value instanceof QuantityValue) {
        SweQuantity sweQuantity = new SweQuantity();
        QuantityValue quantityValue = (QuantityValue) value;
        sweQuantity.setUom(quantityValue.getUnit());
        def = sweQuantity;
    } else if (value instanceof TextValue) {
        def = new SweText();
    } else if (value instanceof NilTemplateValue) {
        def = new SweText();
    } else if (value instanceof BooleanValue) {
        def = new SweBoolean();
    } else if (value instanceof GeometryValue) {
        def = new SweText();
    } else {
        throw new UnsupportedEncoderInputException(this, value);
    }
    def.setDefinition(phenomenon);
    return new SweField(phenomenon, def);
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) SweField(org.n52.shetland.ogc.swe.SweField) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue)

Example 5 with SweQuantity

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

the class SweCommonEncoderv101 method createQuality.

private QualityPropertyType[] createQuality(Collection<SweQuality> quality) {
    if (!quality.isEmpty()) {
        ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
        for (SweQuality sweQuality : quality) {
            QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
            if (sweQuality instanceof SweText) {
                xbQuality.addNewText().set(createText((SweText) sweQuality));
            } else if (sweQuality instanceof SweCategory) {
                xbQuality.addNewCategory().set(createCategory((SweCategory) sweQuality));
            } else if (sweQuality instanceof SweQuantity) {
                xbQuality.addNewQuantity().set(createQuantity((SweQuantity) sweQuality));
            } else if (sweQuality instanceof SweQuantityRange) {
                xbQuality.addNewQuantityRange().set(createQuantityRange((SweQuantityRange) sweQuality));
            }
            xbQualities.add(xbQuality);
        }
        return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
    }
    return new QualityPropertyType[] { QualityPropertyType.Factory.newInstance() };
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) QualityPropertyType(net.opengis.swe.x101.QualityPropertyType) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory)

Aggregations

SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)22 Test (org.junit.Test)11 XmlObject (org.apache.xmlbeans.XmlObject)9 SweField (org.n52.shetland.ogc.swe.SweField)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)9 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)8 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)8 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)7 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)5 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)5 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)5 SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 BigDecimal (java.math.BigDecimal)3 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)3 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)3 DataRecordType (net.opengis.swe.x101.DataRecordType)3 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)3