use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class ObservationEncoder method encodeSweDataArrayValue.
private JsonNode encodeSweDataArrayValue(Value<?> value) throws EncodingException {
SweDataArrayValue sweDataArrayValue = (SweDataArrayValue) value;
ObjectNode result = nodeFactory().objectNode();
ArrayNode jfields = result.putArray(JSONConstants.FIELDS);
ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
List<SweField> fields = ((SweDataRecord) sweDataArrayValue.getValue().getElementType()).getFields();
List<List<String>> values = sweDataArrayValue.getValue().getValues();
TokenConverter[] conv = new TokenConverter[fields.size()];
int i = 0;
for (SweField field : fields) {
try {
conv[i++] = TokenConverter.forField(field);
} catch (IllegalArgumentException e) {
throw new UnsupportedEncoderInputException(this, field);
}
jfields.add(encodeObjectToJson(field));
}
for (List<String> block : values) {
ArrayNode jblock = jvalues.addArray();
i = 0;
for (String token : block) {
jblock.add(conv[i++].convert(token));
}
}
return result;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class ObservationEncoder method encodeReferenceValue.
private JsonNode encodeReferenceValue(ReferenceValue value) {
ReferenceType ref = value.getValue();
ObjectNode node = nodeFactory().objectNode();
node.put(JSONConstants.HREF, ref.getHref());
if (ref.isSetRole()) {
node.put(JSONConstants.ROLE, ref.getRole());
}
if (ref.isSetTitle()) {
node.put(JSONConstants.TITLE, ref.getTitle());
}
return node;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class ObservationEncoder method encodeQualityValue.
private JsonNode encodeQualityValue(Value<?> value) {
QuantityValue quantityValue = (QuantityValue) value;
ObjectNode node = nodeFactory().objectNode();
node.put(JSONConstants.UOM, quantityValue.getUnit());
node.put(JSONConstants.VALUE, quantityValue.getValue());
return node;
}
use of org.n52.shetland.ogc.om.values.Value in project arctic-sea by 52North.
the class ObservationEncoder method encodeComplexValue.
private JsonNode encodeComplexValue(Value<?> value) throws EncodingException {
ArrayNode result = nodeFactory().arrayNode();
ComplexValue complexValue = (ComplexValue) value;
SweAbstractDataRecord sweDataRecord = complexValue.getValue();
for (SweField field : sweDataRecord.getFields()) {
result.add(encodeObjectToJson(field));
}
return result;
}
use of org.n52.shetland.ogc.om.values.Value 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);
}
Aggregations