Search in sources :

Example 6 with TimeValuePair

use of org.n52.shetland.ogc.om.TimeValuePair in project arctic-sea by 52North.

the class OmObservation method convertSingleValueToMultiValue.

/**
 * Convert {@link SingleObservationValue} to {@link TVPValue}.
 *
 * @param singleValue
 *            Single observation value
 *
 * @return Converted TVPValue value
 */
public TVPValue convertSingleValueToMultiValue(final SingleObservationValue<?> singleValue) {
    MultiObservationValues<List<TimeValuePair>> multiValue = new MultiObservationValues<>();
    TVPValue tvpValue = new TVPValue();
    if (singleValue.isSetUnit()) {
        tvpValue.setUnit(singleValue.getUnit());
    } else if (singleValue.getValue().isSetUnit()) {
        tvpValue.setUnit(singleValue.getValue().getUnit());
    }
    if (singleValue.isSetMetadata()) {
        multiValue.setMetadata(singleValue.getMetadata());
    }
    if (singleValue.isSetDefaultPointMetadata()) {
        multiValue.setDefaultPointMetadata(singleValue.getDefaultPointMetadata());
    }
    TimeValuePair timeValuePair = new TimeValuePair(singleValue.getPhenomenonTime(), singleValue.getValue());
    tvpValue.addValue(timeValuePair);
    multiValue.setValue(tvpValue);
    value = multiValue;
    return tvpValue;
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) List(java.util.List)

Example 7 with TimeValuePair

use of org.n52.shetland.ogc.om.TimeValuePair in project arctic-sea by 52North.

the class ObservationEncoder method encodeTVPValue.

private JsonNode encodeTVPValue(TVPValue value) throws EncodingException {
    ArrayNode arrayNode = nodeFactory().arrayNode();
    for (TimeValuePair tvp : value.getValue()) {
        ObjectNode node = nodeFactory().objectNode();
        node.set(JSONConstants.TIME, encodeObjectToJson(tvp.getTime()));
        node.set(JSONConstants.VALUE, encodeValue(value));
        arrayNode.add(node);
    }
    return arrayNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 8 with TimeValuePair

use of org.n52.shetland.ogc.om.TimeValuePair in project arctic-sea by 52North.

the class ObservationEncoder method encodeTVPValue.

private JsonNode encodeTVPValue(OmObservation o) throws EncodingException {
    TVPValue tvpValue = (TVPValue) o.getValue().getValue();
    ObjectNode result = nodeFactory().objectNode();
    List<TimeValuePair> values = tvpValue.getValue();
    if (values != null && !values.isEmpty()) {
        String obsProp = o.getObservationConstellation().getObservableProperty().getIdentifier();
        SweTime timeDef = new SweTime();
        timeDef.setDefinition(OmConstants.PHENOMENON_TIME);
        timeDef.setUom(OmConstants.PHEN_UOM_ISO8601);
        SweField timeField = new SweField(OmConstants.PHENOMENON_TIME_NAME, timeDef);
        SweField valueField = getFieldForValue(obsProp, values.get(0).getValue());
        result.putArray(JSONConstants.FIELDS).add(encodeObjectToJson(timeField)).add(encodeObjectToJson(valueField));
        ArrayNode jvalues = result.putArray(JSONConstants.VALUES);
        for (TimeValuePair tvp : values) {
            if (tvp != null && tvp.getValue() != null && tvp.getValue().isSetValue()) {
                jvalues.addArray().add(encodeObjectToJson(tvp.getTime())).add(getTokenForValue(tvp.getValue()));
            }
        }
    }
    return result;
}
Also used : SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) TVPValue(org.n52.shetland.ogc.om.values.TVPValue) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SweField(org.n52.shetland.ogc.swe.SweField) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 9 with TimeValuePair

use of org.n52.shetland.ogc.om.TimeValuePair in project arctic-sea by 52North.

the class WmlTVPEncoderv20XmlStreamWriter method writeResult.

@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) {
        // XML streaming to client
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) observation.getValue();
        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) {
        // Database streaming + XML streaming to client
        StreamingValue<?> observationValue = (StreamingValue<?>) observation.getValue();
        if (observationValue.isSetUnit()) {
            writeDefaultPointMetadata(observationValue, observationValue.getUnit());
        } else if (observation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty && ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).isSetUnit()) {
            writeDefaultPointMetadata(observationValue, ((OmObservableProperty) observation.getObservationConstellation().getObservableProperty()).getUnit());
        } else {
            writeDefaultPointMetadata(observationValue, null);
        }
        try {
            while (observationValue.hasNext()) {
                TimeValuePair timeValuePair = observationValue.nextValue();
                if (timeValuePair != null) {
                    writePoint(getTimeString(timeValuePair.getTime()), getValue(timeValuePair.getValue()));
                }
            }
        } catch (DateTimeFormatException | OwsExceptionReport e) {
            throw new EncodingException(e);
        }
        close();
    } else {
        super.writeResult();
    }
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) EncodingException(org.n52.svalbard.encode.exception.EncodingException) OmObservation(org.n52.shetland.ogc.om.OmObservation) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) List(java.util.List) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Example 10 with TimeValuePair

use of org.n52.shetland.ogc.om.TimeValuePair in project arctic-sea by 52North.

the class WmlTDREncoderv20 method createMeasurementDomainRange.

/**
 * Create a XML MeasurementTimeseriesDomainRange object from SOS observation
 * for om:result
 *
 * @param sosObservation
 *            SOS observation
 * @return XML MeasurementTimeseriesDomainRange object for om:result
 * @throws EncodingException
 *             If an error occurs
 */
private XmlObject createMeasurementDomainRange(OmObservation sosObservation) throws EncodingException {
    if (!sosObservation.getObservationConstellation().isSetObservationType() || (sosObservation.getObservationConstellation().isSetObservationType() && isInvalidObservationType(sosObservation.getObservationConstellation().getObservationType()))) {
        throw new UnsupportedEncoderInputException(this, sosObservation.getObservationConstellation().isSetObservationType());
    }
    MeasurementTimeseriesDomainRangeDocument xbMearuementTimeseriesDomainRangeDoc = MeasurementTimeseriesDomainRangeDocument.Factory.newInstance();
    MeasurementTimeseriesCoverageType xbMeasurementTimeseriesDomainRange = xbMearuementTimeseriesDomainRangeDoc.addNewMeasurementTimeseriesDomainRange();
    xbMeasurementTimeseriesDomainRange.setId(TIMESERIES_ID_PREFIX + sosObservation.getObservationID());
    // set time position list
    xbMeasurementTimeseriesDomainRange.addNewDomainSet().set(getTimePositionList(sosObservation));
    // initialize unit
    AbstractPhenomenon observableProperty = sosObservation.getObservationConstellation().getObservableProperty();
    String unit = null;
    // create quantity list from values
    QuantityListDocument quantityListDoc = QuantityListDocument.Factory.newInstance();
    MeasureOrNilReasonListType quantityList = quantityListDoc.addNewQuantityList();
    if (sosObservation.getValue() instanceof MultiObservationValues) {
        MultiObservationValues<?> observationValue = (MultiObservationValues<?>) sosObservation.getValue();
        TVPValue tvpValue = (TVPValue) observationValue.getValue();
        List<TimeValuePair> timeValuePairs = tvpValue.getValue();
        if (Strings.isNullOrEmpty(unit) && CollectionHelper.isNotEmpty(timeValuePairs) && timeValuePairs.get(0).getValue().isSetUnit()) {
            unit = timeValuePairs.get(0).getValue().getUnit();
        }
        quantityList.setListValue(getValueList(timeValuePairs));
    }
    if (Strings.isNullOrEmpty(unit)) {
        unit = OGCConstants.UNKNOWN;
    }
    quantityList.setUom(unit);
    // set unit to SosObservableProperty if not set.
    if (observableProperty instanceof OmObservableProperty && !((OmObservableProperty) observableProperty).isSetUnit()) {
        ((OmObservableProperty) observableProperty).setUnit(unit);
    }
    // set up range set
    xbMeasurementTimeseriesDomainRange.addNewRangeSet().set(quantityListDoc);
    // set up rangeType
    xbMeasurementTimeseriesDomainRange.addNewRangeType().set(createDataRecord(sosObservation));
    // set om:Result
    return xbMearuementTimeseriesDomainRangeDoc;
}
Also used : TVPValue(org.n52.shetland.ogc.om.values.TVPValue) MeasureOrNilReasonListType(net.opengis.gml.x32.MeasureOrNilReasonListType) MultiObservationValues(org.n52.shetland.ogc.om.MultiObservationValues) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) MeasurementTimeseriesDomainRangeDocument(net.opengis.watermlDr.x20.MeasurementTimeseriesDomainRangeDocument) AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon) QuantityListDocument(net.opengis.gml.x32.QuantityListDocument) MeasurementTimeseriesCoverageType(net.opengis.watermlDr.x20.MeasurementTimeseriesCoverageType) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty) TimeValuePair(org.n52.shetland.ogc.om.TimeValuePair)

Aggregations

TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)9 TVPValue (org.n52.shetland.ogc.om.values.TVPValue)9 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)6 List (java.util.List)4 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 MeasureOrNilReasonListType (net.opengis.gml.x32.MeasureOrNilReasonListType)2 QuantityListDocument (net.opengis.gml.x32.QuantityListDocument)2 MeasurementTimeseriesCoverageType (net.opengis.watermlDr.x20.MeasurementTimeseriesCoverageType)2 MeasurementTimeseriesDomainRangeDocument (net.opengis.watermlDr.x20.MeasurementTimeseriesDomainRangeDocument)2 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)2 QuantityValue (org.n52.shetland.ogc.om.values.QuantityValue)2 SweDataArrayValue (org.n52.shetland.ogc.om.values.SweDataArrayValue)2 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)2 Date (java.util.Date)1 Before (org.junit.Before)1 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)1 AbstractPhenomenon (org.n52.shetland.ogc.om.AbstractPhenomenon)1 OmObservation (org.n52.shetland.ogc.om.OmObservation)1