/** * Write missing value metadata to stream * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeValueMetadata() throws XMLStreamException { start(WaterMLConstants.QN_METADATA); start(WaterMLConstants.QN_TVP_MEASUREMENT_METADATA); empty(WaterMLConstants.QN_NIL_REASON); addXlinkHrefAttr("missing"); endInline(WaterMLConstants.QN_TVP_MEASUREMENT_METADATA); endInline(WaterMLConstants.QN_METADATA); }
/** * Write wml:value to stream * * @param value value to write * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeValue(String value) throws XMLStreamException { if (!Strings.isNullOrEmpty(value)) { start(WaterMLConstants.QN_VALUE); chars(value); endInline(WaterMLConstants.QN_VALUE); } else { empty(WaterMLConstants.QN_VALUE); attr(W3CConstants.QN_XSI_NIL, "true"); writeValueMetadata(); } }
/** * Write wml:MeasurementTVP to stream * * @param time time as {@link String} * @param value value as {@link String} * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeMeasurementTVP(String time, String value) throws XMLStreamException { start(WaterMLConstants.QN_MEASUREMENT_TVP); writeTime(time); writeValue(value); end(WaterMLConstants.QN_MEASUREMENT_TVP); }
@Override protected void writeResult() throws XMLStreamException, EncodingException { start(OmConstants.QN_OM_20_RESULT); namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20); start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES); OmObservation observation = getElement(); attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID()); writeMeasurementTimeseriesMetadata(observation); if (observation.getValue() instanceof SingleObservationValue) { SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue(); writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit()); String time = getTimeString(observationValue.getPhenomenonTime()); writePoint(time, getValue(observation.getValue().getValue())); close(); } else if (observation.getValue() instanceof MultiObservationValues) { writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit()); TVPValue tvpValue = (TVPValue) observationValue.getValue(); List<TimeValuePair> timeValuePairs = tvpValue.getValue(); for (TimeValuePair timeValuePair : timeValuePairs) { if (timeValuePair != null) { writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue())); close(); } else if (observation.getValue() instanceof StreamingValue) { writeDefaultPointMetadata(observationValue, observationValue.getUnit()); } else if (observation.getObservationConstellation() .getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty())
/** * Write timeseries metadata to stream * * @param id * Observation id * * @throws XMLStreamException * If an error occurs when writing to stream */ private void writeMeasurementTimeseriesMetadata(OmObservation o) throws XMLStreamException { start(WaterMLConstants.QN_METADATA); start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES_METADATA); empty(WaterMLConstants.QN_TEMPORAL_EXTENT); addXlinkHrefAttr("#" + o.getPhenomenonTime().getGmlId()); if (o.isSetValue() && o.getValue().isSetMetadata() && o.getValue().getMetadata().isSetTimeseriesMetadata() && o.getValue().getMetadata().getTimeseriesmetadata() instanceof MeasurementTimeseriesMetadata) { start(WaterMLConstants.QN_CUMULATIVE); chars(Boolean.toString(((MeasurementTimeseriesMetadata) o.getValue().getMetadata().getTimeseriesmetadata()) .isCumulative())); endInline(WaterMLConstants.QN_CUMULATIVE); } end(WaterMLConstants.QN_MEASUREMENT_TIMESERIES_METADATA); end(WaterMLConstants.QN_METADATA); }
/** * Write wml:defaultPointMetadata to stream * * @param unit * the unit * * @throws XMLStreamException * If an error occurs when writing to stream */ private void writeDefaultPointMetadata(ObservationValue<?> value, String unit) throws XMLStreamException { start(WaterMLConstants.QN_DEFAULT_POINT_METADATA); start(WaterMLConstants.QN_DEFAULT_TVP_MEASUREMENT_METADATA); writeUOM(unit); writeInterpolationType(value); end(WaterMLConstants.QN_DEFAULT_TVP_MEASUREMENT_METADATA); end(WaterMLConstants.QN_DEFAULT_POINT_METADATA); }
/** * Write wml:point to stream * * @param time time as {@link String} * @param value value as {@link String} * * @throws XMLStreamException If an error occurs when writing to stream */ private void writePoint(String time, String value) throws XMLStreamException { if (!Strings.isNullOrEmpty(time)) { start(WaterMLConstants.QN_POINT); writeMeasurementTVP(time, value); end(WaterMLConstants.QN_POINT); } }
/** * Write wml:interpolationType to stream * * @throws XMLStreamException * If an error occurs when writing to stream */ private void writeInterpolationType(ObservationValue<?> value) throws XMLStreamException { empty(WaterMLConstants.QN_INTERPOLATION_TYPE); if (value != null && value.isSetMetadata() && value.getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) { InterpolationType interpolationtype = value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().getInterpolationtype(); addXlinkHrefAttr(interpolationtype.getIdentifier()); addXlinkTitleAttr(interpolationtype.getTitle()); } else { addXlinkHrefAttr("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous"); addXlinkTitleAttr("Instantaneous"); } }
@Override protected void checkAndWriteName() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetName()) { for (CodeType name : getElement().getObservationConstellation().getName()) { writeName(name); } } else { super.checkAndWriteName(); } }
@Override protected void checkAndWriteDescription() throws XMLStreamException { if (getElement().getObservationConstellation().isSetDescription()) { writeDescription(getElement().getObservationConstellation().getDescription()); } else { super.checkAndWriteDescription(); } }
@Override protected void checkAndWriteIdentifier() throws EncodingException, XMLStreamException { if (getElement().getObservationConstellation().isSetIdentifier()) { writeIdentifier(getElement().getObservationConstellation().getIdentifierCodeWithAuthority()); } else { super.checkAndWriteIdentifier(); } }
@Override protected void writeResult() throws XMLStreamException, EncodingException { start(OmConstants.QN_OM_20_RESULT); namespace(WaterMLConstants.NS_WML_20_PREFIX, WaterMLConstants.NS_WML_20); start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES); OmObservation observation = getElement(); attr(GmlConstants.QN_ID_32, "timeseries." + observation.getObservationID()); writeMeasurementTimeseriesMetadata(observation); if (observation.getValue() instanceof SingleObservationValue) { SingleObservationValue<?> observationValue = (SingleObservationValue<?>) observation.getValue(); writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit()); String time = getTimeString(observationValue.getPhenomenonTime()); writePoint(time, getValue(observation.getValue().getValue())); close(); } else if (observation.getValue() instanceof MultiObservationValues) { writeDefaultPointMetadata(observationValue, observationValue.getValue().getUnit()); TVPValue tvpValue = (TVPValue) observationValue.getValue(); List<TimeValuePair> timeValuePairs = tvpValue.getValue(); for (TimeValuePair timeValuePair : timeValuePairs) { if (timeValuePair != null) { writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue())); close(); } else if (observation.getValue() instanceof StreamingValue) { writeDefaultPointMetadata(observationValue, observationValue.getUnit()); } else if (observation.getObservationConstellation() .getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty())
/** * Write timeseries metadata to stream * * @param o {@link OmObservation} * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeMeasurementTimeseriesMetadata(OmObservation o) throws XMLStreamException { start(WaterMLConstants.QN_METADATA); start(WaterMLConstants.QN_MEASUREMENT_TIMESERIES_METADATA); empty(WaterMLConstants.QN_TEMPORAL_EXTENT); addXlinkHrefAttr("#" + o.getPhenomenonTime().getGmlId()); if (o.isSetValue() && o.getValue().isSetMetadata() && o.getValue().getMetadata().isSetTimeseriesMetadata() && o.getValue().getMetadata().getTimeseriesmetadata() instanceof MeasurementTimeseriesMetadata) { start(WaterMLConstants.QN_CUMULATIVE); chars(Boolean.toString(((MeasurementTimeseriesMetadata) o.getValue().getMetadata().getTimeseriesmetadata()) .isCumulative())); endInline(WaterMLConstants.QN_CUMULATIVE); } end(WaterMLConstants.QN_MEASUREMENT_TIMESERIES_METADATA); end(WaterMLConstants.QN_METADATA); }
/** * Write wml:defaultPointMetadata to stream * * @param value the observation value * @param unit the unit * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeDefaultPointMetadata(@Nullable ObservationValue<?> value, @Nullable String unit) throws XMLStreamException { start(WaterMLConstants.QN_DEFAULT_POINT_METADATA); start(WaterMLConstants.QN_DEFAULT_TVP_MEASUREMENT_METADATA); writeUOM(unit); writeInterpolationType(value); end(WaterMLConstants.QN_DEFAULT_TVP_MEASUREMENT_METADATA); end(WaterMLConstants.QN_DEFAULT_POINT_METADATA); }
/** * Write wml:point to stream * * @param time * time as {@link String} * @param value * value as {@link String} * * @throws XMLStreamException * If an error occurs when writing to stream */ private void writePoint(String time, String value) throws XMLStreamException { if (!Strings.isNullOrEmpty(time)) { start(WaterMLConstants.QN_POINT); writeMeasurementTVP(time, value); end(WaterMLConstants.QN_POINT); } }
/** * Write wml:interpolationType to stream * * @param value the observation value * * @throws XMLStreamException If an error occurs when writing to stream */ private void writeInterpolationType(@Nullable ObservationValue<?> value) throws XMLStreamException { empty(WaterMLConstants.QN_INTERPOLATION_TYPE); if (value != null && value.isSetMetadata() && value.getDefaultPointMetadata().isSetDefaultTVPMeasurementMetadata() && value.getDefaultPointMetadata().getDefaultTVPMeasurementMetadata().isSetInterpolationType()) { InterpolationType interpolationtype = (InterpolationType) value .getDefaultPointMetadata() .getDefaultTVPMeasurementMetadata() .getInterpolationtype(); addXlinkHrefAttr(interpolationtype.getIdentifier()); addXlinkTitleAttr(interpolationtype.getTitle()); } else { addXlinkHrefAttr("http://www.opengis.net/def/timeseriesType/WaterML/2.0/continuous"); addXlinkTitleAttr("Instantaneous"); } }