use of org.n52.shetland.ogc.swe.SweAbstractDataComponent 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.SweAbstractDataComponent in project arctic-sea by 52North.
the class FieldDecoder method decodeTimeRange.
protected SweAbstractDataComponent decodeTimeRange(JsonNode node) throws DecodingException {
SweTimeRange swe = new SweTimeRange();
if (node.hasNonNull(JSONConstants.VALUE)) {
String start = node.path(JSONConstants.VALUE).path(0).textValue();
String end = node.path(JSONConstants.VALUE).path(1).textValue();
swe.setValue(new RangeValue<DateTime>(parseDateTime(start), parseDateTime(end)));
}
return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method encodeResultStructure.
private void encodeResultStructure(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
ObjectNode jrs = json.putObject(JSONConstants.RESULT_STRUCTURE);
SweAbstractDataComponent structure;
SosResultStructure rs = t.getResultStructure();
if (rs.isDecoded()) {
structure = t.getResultStructure().get().get();
} else {
try {
XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractDataComponent.class);
Decoder<SweAbstractDataComponent, XmlObject> decoder = this.decoderRepository.getDecoder(key);
if (decoder == null) {
throw new NoDecoderForKeyException(key);
}
structure = decoder.decode(XmlObject.Factory.parse(rs.getXml().get()));
} catch (XmlException | DecodingException ex) {
throw new EncodingException(ex);
}
}
if (structure instanceof SweDataRecord) {
encodeSweDataRecord(structure, jrs);
} else {
LOG.warn("Unsupported structure: {}", structure == null ? null : structure.getClass());
}
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent 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);
}
use of org.n52.shetland.ogc.swe.SweAbstractDataComponent in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseAbstractDataComponent.
private SweAbstractDataComponent parseAbstractDataComponent(AbstractDataComponentType abstractDataComponent) throws DecodingException {
SweAbstractDataComponent sosAbstractDataComponent = null;
if (abstractDataComponent instanceof BooleanType) {
sosAbstractDataComponent = parseBoolean((BooleanType) abstractDataComponent);
} else if (abstractDataComponent instanceof CategoryType) {
sosAbstractDataComponent = parseCategory((CategoryType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountRangeType) {
sosAbstractDataComponent = parseCountRange((CountRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof CountType) {
sosAbstractDataComponent = parseCount((CountType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityType) {
sosAbstractDataComponent = parseQuantity((QuantityType) abstractDataComponent);
} else if (abstractDataComponent instanceof QuantityRangeType) {
sosAbstractDataComponent = parseQuantityRange((QuantityRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TextType) {
sosAbstractDataComponent = parseText((TextType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeType) {
sosAbstractDataComponent = parseTime((TimeType) abstractDataComponent);
} else if (abstractDataComponent instanceof TimeRangeType) {
sosAbstractDataComponent = parseTimeRange((TimeRangeType) abstractDataComponent);
} else if (abstractDataComponent instanceof VectorType) {
sosAbstractDataComponent = parseVector((VectorType) abstractDataComponent);
} else if (abstractDataComponent instanceof DataRecordType) {
SweDataRecord sosDataRecord = parseDataRecord((DataRecordType) abstractDataComponent);
DataRecordDocument dataRecordDoc = DataRecordDocument.Factory.newInstance(getXmlOptions());
dataRecordDoc.setDataRecord((DataRecordType) abstractDataComponent);
sosDataRecord.setXml(dataRecordDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataRecord;
} else if (abstractDataComponent instanceof DataArrayType) {
SweDataArray sosDataArray = parseDataArray((DataArrayType) abstractDataComponent);
DataArrayDocument dataArrayDoc = DataArrayDocument.Factory.newInstance(getXmlOptions());
dataArrayDoc.setDataArray1((DataArrayType) abstractDataComponent);
sosDataArray.setXml(dataArrayDoc.xmlText(getXmlOptions()));
sosAbstractDataComponent = sosDataArray;
} else {
throw new UnsupportedDecoderXmlInputException(this, abstractDataComponent);
}
if (sosAbstractDataComponent != null) {
if (abstractDataComponent.isSetDefinition()) {
sosAbstractDataComponent.setDefinition(abstractDataComponent.getDefinition());
}
if (abstractDataComponent.isSetDescription()) {
sosAbstractDataComponent.setDescription(abstractDataComponent.getDescription());
}
if (abstractDataComponent.isSetIdentifier()) {
sosAbstractDataComponent.setIdentifier(abstractDataComponent.getIdentifier());
}
if (abstractDataComponent.isSetLabel()) {
sosAbstractDataComponent.setLabel(abstractDataComponent.getLabel());
}
}
return sosAbstractDataComponent;
}
Aggregations