Search in sources :

Example 6 with SweQuantityRange

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

the class SweCommonEncoderv20 method createQuality.

private QualityPropertyType[] createQuality(final Collection<SweQuality> quality) throws EncodingException {
    if (!quality.isEmpty()) {
        final ArrayList<QualityPropertyType> xbQualities = Lists.newArrayListWithCapacity(quality.size());
        for (final SweQuality sweQuality : quality) {
            final QualityPropertyType xbQuality = QualityPropertyType.Factory.newInstance();
            if (sweQuality instanceof SweText) {
                xbQuality.addNewText().set(((SweText) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweCategory) {
                xbQuality.addNewCategory().set(((SweCategory) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweQuantity) {
                xbQuality.addNewQuantity().set(((SweQuantity) sweQuality).accept(new SweDataComponentVisitorImpl()));
            } else if (sweQuality instanceof SweQuantityRange) {
                xbQuality.addNewQuantityRange().set(((SweQuantityRange) sweQuality).accept(new SweDataComponentVisitorImpl()));
            }
            xbQualities.add(xbQuality);
        }
        return xbQualities.toArray(new QualityPropertyType[xbQualities.size()]);
    }
    final QualityPropertyType[] result = { QualityPropertyType.Factory.newInstance() };
    return result;
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) QualityPropertyType(net.opengis.swe.x20.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)

Example 7 with SweQuantityRange

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

the class SweCommonDecoderV101Test method should_decode_Category_with_Quality_QuantityRange.

@Test
public void should_decode_Category_with_Quality_QuantityRange() throws DecodingException {
    final CategoryDocument xbQuantity = CategoryDocument.Factory.newInstance();
    final BigDecimal rangeStart = BigDecimal.valueOf(1.0);
    final BigDecimal rangeEnd = BigDecimal.valueOf(2.0);
    final ArrayList<BigDecimal> categoryValue = Lists.newArrayList(rangeStart, rangeEnd);
    xbQuantity.addNewCategory().addNewQuality().addNewQuantityRange().setValue(categoryValue);
    final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
    assertThat(decodedObject, is(instanceOf(SweCategory.class)));
    final SweCategory sweCategory = (SweCategory) decodedObject;
    assertThat(sweCategory.isSetQuality(), is(true));
    assertThat(sweCategory.getQuality().size(), is(1));
    assertThat(sweCategory.getQuality().iterator().next(), is(instanceOf(SweQuantityRange.class)));
    assertThat(((SweQuantityRange) sweCategory.getQuality().iterator().next()).getValue(), is(new RangeValue<BigDecimal>(rangeStart, rangeEnd)));
}
Also used : CategoryDocument(net.opengis.swe.x101.CategoryDocument) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) BigDecimal(java.math.BigDecimal) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Example 8 with SweQuantityRange

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

the class FieldDecoderTest method testQuantityRange.

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

Example 9 with SweQuantityRange

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

the class FieldEncoder method encodeSweQuantityRangeField.

private ObjectNode encodeSweQuantityRangeField(SweField field) {
    ObjectNode jfield = createField(field);
    jfield.put(JSONConstants.TYPE, JSONConstants.QUANTITY_RANGE_TYPE);
    SweQuantityRange sweQuantityRange = (SweQuantityRange) field.getElement();
    jfield.put(JSONConstants.UOM, sweQuantityRange.getUom());
    if (sweQuantityRange.isSetValue()) {
        ArrayNode av = jfield.putArray(JSONConstants.VALUE);
        av.add(sweQuantityRange.getValue().getRangeStart());
        av.add(sweQuantityRange.getValue().getRangeEnd());
    }
    return jfield;
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 10 with SweQuantityRange

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

the class SweCommonEncoderv101Test method should_encode_count_with_quality_QuantityRange.

@Test
public void should_encode_count_with_quality_QuantityRange() throws EncodingException {
    final RangeValue<BigDecimal> qualityQuantityRangeValue = new RangeValue<>(BigDecimal.valueOf(1.0), BigDecimal.valueOf(2.0));
    final SweCount sosCount = (SweCount) new SweCount().setQuality(Lists.newArrayList((SweQuality) new SweQuantityRange().setValue(qualityQuantityRangeValue)));
    final XmlObject encode = sweCommonEncoderv101.encode(sosCount);
    assertThat(encode, instanceOf(Count.class));
    final Count xbCount = (Count) encode;
    assertThat(xbCount.getQualityArray(), is(not(nullValue())));
    assertThat(xbCount.getQualityArray().length, is(1));
    assertThat(xbCount.getQualityArray(0).isSetQuantityRange(), is(true));
    assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(0)), is(qualityQuantityRangeValue.getRangeStart()));
    assertThat(BigDecimal.valueOf((Double) xbCount.getQualityArray(0).getQuantityRange().getValue().get(1)), is(qualityQuantityRangeValue.getRangeEnd()));
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) Count(net.opengis.swe.x101.CountDocument.Count) BigDecimal(java.math.BigDecimal) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Aggregations

SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)11 BigDecimal (java.math.BigDecimal)5 Test (org.junit.Test)5 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)5 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)4 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 XmlObject (org.apache.xmlbeans.XmlObject)3 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)3 NotYetSupportedEncodingException (org.n52.svalbard.encode.exception.NotYetSupportedEncodingException)3 DataRecordType (net.opengis.swe.x101.DataRecordType)2 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)2 RangeValue (org.n52.shetland.ogc.swe.RangeValue)2 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)2 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)2 SweEnvelope (org.n52.shetland.ogc.swe.SweEnvelope)2 SweField (org.n52.shetland.ogc.swe.SweField)2 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)2 SweCountRange (org.n52.shetland.ogc.swe.simpleType.SweCountRange)2 SweQuality (org.n52.shetland.ogc.swe.simpleType.SweQuality)2