Search in sources :

Example 1 with SweQuantityRange

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

the class FieldDecoder method decodeQuantityRange.

protected SweAbstractDataComponent decodeQuantityRange(JsonNode node) {
    SweQuantityRange swe = new SweQuantityRange();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        BigDecimal start = BigDecimal.valueOf(node.path(JSONConstants.VALUE).path(0).doubleValue());
        BigDecimal end = BigDecimal.valueOf(node.path(JSONConstants.VALUE).path(1).doubleValue());
        swe.setValue(new RangeValue<BigDecimal>(start, end));
    }
    return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) BigDecimal(java.math.BigDecimal)

Example 2 with SweQuantityRange

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

the class FieldDecoderTest method testQuantityRangeWithValue.

@Test
public void testQuantityRangeWithValue() throws DecodingException {
    ObjectNode json = createField().put(JSONConstants.TYPE, JSONConstants.QUANTITY_RANGE_TYPE).put(JSONConstants.UOM, UOM);
    json.putArray(JSONConstants.VALUE).add(QUANTITY_VALUE_START).add(QUANTITY_VALUE_END);
    SweField field = checkCommon(json, true);
    assertThat(field.getElement(), is(instanceOf(SweQuantityRange.class)));
    SweQuantityRange swe = (SweQuantityRange) field.getElement();
    errors.checkThat(swe.getUom(), is(UOM));
    errors.checkThat(swe.getValue(), is(notNullValue()));
    errors.checkThat(swe.getValue().getRangeStart().doubleValue(), is(QUANTITY_VALUE_START));
    errors.checkThat(swe.getValue().getRangeEnd().doubleValue(), is(QUANTITY_VALUE_END));
}
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 3 with SweQuantityRange

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

the class SweCommonDecoderV101 method parseQuantityRange.

private SweQuantityRange parseQuantityRange(QuantityRange xbQuantityRange) throws DecodingException {
    SweQuantityRange sosQuantityRange = new SweQuantityRange();
    if (xbQuantityRange.isSetAxisID()) {
        sosQuantityRange.setAxisID(xbQuantityRange.getAxisID());
    }
    if (xbQuantityRange.isSetDefinition()) {
        sosQuantityRange.setDefinition(xbQuantityRange.getDefinition());
    }
    if (xbQuantityRange.isSetDescription()) {
        sosQuantityRange.setDescription(xbQuantityRange.getDescription().getStringValue());
    }
    if (xbQuantityRange.isSetUom() && xbQuantityRange.getUom().isSetCode()) {
        sosQuantityRange.setUom(xbQuantityRange.getUom().getCode());
    }
    if (xbQuantityRange.isSetValue()) {
        try {
            List<?> value = xbQuantityRange.getValue();
            BigDecimal rangeStart = new BigDecimal(value.get(0).toString());
            BigDecimal rangeEnd = new BigDecimal(value.get(1).toString());
            sosQuantityRange.setValue(new RangeValue<>(rangeStart, rangeEnd));
        } catch (final NumberFormatException | NullPointerException | IndexOutOfBoundsException nfe) {
            throw createParsingException(nfe);
        }
    }
    if (xbQuantityRange.isSetConstraint()) {
        LOGGER.error("Decoding of swe:QuantityRange/swe:constraint is not implemented");
    }
    if (xbQuantityRange.getQualityArray() != null && xbQuantityRange.getQualityArray().length > 0) {
        LOGGER.error("Decoding of swe:QuantityRange/swe:quality is not implemented");
    }
    return sosQuantityRange;
}
Also used : SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) BigDecimal(java.math.BigDecimal)

Example 4 with SweQuantityRange

use of org.n52.shetland.ogc.swe.simpleType.SweQuantityRange 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)

Example 5 with SweQuantityRange

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

the class SweCommonEncoderv101 method encode.

@Override
public XmlObject encode(Object element, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof SweAbstractSimpleType) {
        encodedObject = createSimpleType((SweAbstractSimpleType<?>) element, context);
    // }
    // if (element instanceof SweBoolean) {
    // encodedObject = createBoolean((SweBoolean) element);
    // } else if (element instanceof SweCategory) {
    // encodedObject = createCategory((SweCategory) element);
    // } else if (element instanceof SweCount) {
    // encodedObject = createCount((SweCount) element);
    // } else if (element instanceof SweObservableProperty) {
    // encodedObject = createObservableProperty((SweObservableProperty)
    // element);
    // } else if (element instanceof SweQuantity) {
    // encodedObject = createQuantity((SweQuantity) element);
    // } else if (element instanceof SweQuantityRange) {
    // encodedObject = createQuantityRange((SweQuantityRange) element);
    // } else if (element instanceof SweText) {
    // encodedObject = createText((SweText) element);
    // } else if (element instanceof SweTime) {
    // encodedObject = createTime((SweTime) element);
    // } else if (element instanceof SweTimeRange) {
    // encodedObject = createTimeRange((SweTimeRange) element);
    } else if (element instanceof SweCoordinate) {
        encodedObject = createCoordinate((SweCoordinate<?>) element);
    } else if (element instanceof SweDataArray) {
        encodedObject = createDataArray((SweDataArray) element);
    } else if (element instanceof SweDataRecord) {
        DataRecordType drt = createDataRecord((SweDataRecord) element);
        if (context.has(XmlBeansEncodingFlags.DOCUMENT)) {
            DataRecordDocument drd = DataRecordDocument.Factory.newInstance(getXmlOptions());
            drd.setDataRecord(drt);
            encodedObject = drd;
        } else {
            encodedObject = drt;
        }
    } else if (element instanceof SweEnvelope) {
        encodedObject = createEnvelope((SweEnvelope) element);
    } else if (element instanceof SweSimpleDataRecord) {
        encodedObject = createSimpleDataRecord((SweSimpleDataRecord) element);
    } else if (element instanceof TimePeriod) {
        encodedObject = createTimeGeometricPrimitivePropertyType((TimePeriod) element);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : DataRecordType(net.opengis.swe.x101.DataRecordType) SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) SweAbstractSimpleType(org.n52.shetland.ogc.swe.simpleType.SweAbstractSimpleType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) EncodingException(org.n52.svalbard.encode.exception.EncodingException) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) DataRecordDocument(net.opengis.swe.x101.DataRecordDocument) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

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