use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class OmEncoderv100 method addSingleObservationToResult.
// FIXME String.equals(QName) !?
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
String observationType = sosObservation.getObservationConstellation().getObservationType();
SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
if (observationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
} else if (observationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) observationValue.getValue();
XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
} else {
xbInteger.setNil();
}
xbResult.set(xbInteger);
} else if (observationValue.getValue() instanceof TextValue) {
TextValue textValue = (TextValue) observationValue.getValue();
XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
xbString.setStringValue(textValue.getValue());
} else {
xbString.setNil();
}
xbResult.set(xbString);
} else if (observationValue.getValue() instanceof BooleanValue) {
BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
if (booleanValue.getValue() != null) {
xbBoolean.setBooleanValue(booleanValue.getValue());
} else {
xbBoolean.setNil();
}
xbResult.set(xbBoolean);
} else if (observationValue.getValue() instanceof CategoryValue) {
CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (observationValue.getValue() instanceof GeometryValue) {
GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
if (geometryValue.getValue() != null) {
xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
} else {
xbResult.setNil();
}
} else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType) || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
}
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class WmlTVPEncoderv20 method addValues.
private String addValues(MeasurementTimeseriesType measurementTimeseries, ObservationValue<?> observationValue) throws CodedException {
String unit = null;
if (observationValue instanceof SingleObservationValue) {
SingleObservationValue<?> singleObservationValue = (SingleObservationValue<?>) observationValue;
String time = getTimeString(singleObservationValue.getPhenomenonTime());
unit = singleObservationValue.getValue().getUnit();
String value = null;
if (singleObservationValue.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) singleObservationValue.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (singleObservationValue.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) singleObservationValue.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue());
}
} else if (singleObservationValue.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) singleObservationValue.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
} else if (observationValue instanceof MultiObservationValues) {
MultiObservationValues<?> mov = (MultiObservationValues<?>) observationValue;
TVPValue tvpValue = (TVPValue) mov.getValue();
List<TimeValuePair> timeValuePairs = tvpValue.getValue();
unit = tvpValue.getUnit();
for (TimeValuePair timeValuePair : timeValuePairs) {
String time = getTimeString(timeValuePair.getTime());
String value = null;
if (timeValuePair.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeValuePair.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeValuePair.getValue() instanceof ProfileValue) {
ProfileValue profileValue = (ProfileValue) timeValuePair.getValue();
if (profileValue.isSetValue()) {
if (profileValue.getValue().iterator().next().getSimpleValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) profileValue.getValue().iterator().next().getSimpleValue();
if (quantityValue.isSetValue()) {
value = Double.toString(quantityValue.getValue().doubleValue());
}
}
}
} else if (timeValuePair.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeValuePair.getValue();
if (countValue.isSetValue()) {
value = Integer.toString(countValue.getValue());
}
} else {
throw new NoApplicableCodeException().withMessage("The types of values '%s' is not yet supported", mov.getValue().getClass().getSimpleName());
}
addValuesToMeasurementTVP(measurementTimeseries.addNewPoint().addNewMeasurementTVP(), time, value);
}
}
return unit;
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class TrajectoryObservationTypeEncoderTest method getCountObservation.
private OmObservation getCountObservation() throws EncodingException, ParseException, DecodingException, XmlException, IOException {
MultiObservationValues<List<TimeLocationValueTriple>> multiObservationValues = new MultiObservationValues<List<TimeLocationValueTriple>>();
TLVTValue tlvtValue = new TLVTValue();
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(15)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(16)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(17)));
tlvtValue.addValue(getTimeLocationValueTriple(new CountValue(18)));
multiObservationValues.setValue(tlvtValue);
OmObservation observation = createObservation();
observation.setValue(multiObservationValues);
return observation;
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class ObservationDecoder method parseNamedValueValue.
private NamedValue<?> parseNamedValueValue(JsonNode value) throws DecodingException {
if (value.isTextual()) {
NamedValue<W3CHrefAttribute> nv = new NamedValue<>();
nv.setValue(new HrefAttributeValue(new W3CHrefAttribute(value.asText())));
return nv;
} else if (value.isBoolean()) {
NamedValue<Boolean> nv = new NamedValue<>();
nv.setValue(new BooleanValue(value.asBoolean()));
return nv;
} else if (value.isInt()) {
NamedValue<Integer> nv = new NamedValue<>();
nv.setValue(new CountValue(value.asInt()));
return nv;
} else if (value.isObject()) {
if (value.has(JSONConstants.CODESPACE)) {
NamedValue<String> nv = new NamedValue<>();
nv.setValue(parseCategroyValue(value));
return nv;
} else if (value.has(JSONConstants.UOM)) {
NamedValue<BigDecimal> nv = new NamedValue<>();
nv.setValue(parseQuantityValue(value));
return nv;
} else if (value.has(JSONConstants.COORDINATES)) {
NamedValue<Geometry> nv = new NamedValue<>();
nv.setValue(new GeometryValue(geometryDecoder.decodeJSON(value, false)));
return nv;
}
}
throw new DecodingException("%s is not yet supported", value.toString());
}
use of org.n52.shetland.ogc.om.values.CountValue in project arctic-sea by 52North.
the class AbstractTimeLocationValueTripleTypeEncoder method createMeasurementTimeLocationValueTripleType.
/**
* Create a {@link MeasurementTimeLocationValueTripleType} from
* {@link TimeLocationValueTriple}
*
* @param timeLocationValueTriple
* The {@link TimeLocationValueTriple} to encode
* @return The encoded {@link TimeLocationValueTriple}
* @throws EncodingException
* If an error occurs
*/
private TimeValuePairType createMeasurementTimeLocationValueTripleType(TimeLocationValueTriple timeLocationValueTriple) throws EncodingException {
MeasurementTimeLocationValueTripleType mtlvtt = MeasurementTimeLocationValueTripleType.Factory.newInstance();
mtlvtt.addNewTime().setStringValue(getTimeString(timeLocationValueTriple.getTime()));
mtlvtt.addNewLocation().addNewPoint().set(encodeGML(timeLocationValueTriple.getLocation()));
String value = null;
if (timeLocationValueTriple.getValue() instanceof QuantityValue) {
QuantityValue quantityValue = (QuantityValue) timeLocationValueTriple.getValue();
if (quantityValue.isSetValue()) {
value = quantityValue.getValue().toPlainString();
}
} else if (timeLocationValueTriple.getValue() instanceof CountValue) {
CountValue countValue = (CountValue) timeLocationValueTriple.getValue();
if (countValue.getValue() != null) {
value = Integer.toString(countValue.getValue().intValue());
}
}
if (value != null && !value.isEmpty()) {
mtlvtt.addNewValue().setStringValue(value);
} else {
mtlvtt.addNewValue().setNil();
mtlvtt.addNewMetadata().addNewTVPMeasurementMetadata().addNewNilReason().setNilReason(MISSING);
}
return mtlvtt;
}
Aggregations