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());
}
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));
}
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;
}
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() };
}
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;
}
Aggregations