Search in sources :

Example 46 with Time

use of org.n52.shetland.ogc.gml.time.Time 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 47 with Time

use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.

the class SosDecoderv20 method checkReferencedElements.

private void checkReferencedElements(final List<OmObservation> observations, final Map<String, Time> phenomenonTimes, final Map<String, TimeInstant> resultTimes, final Map<String, AbstractFeature> features) throws DecodingException {
    for (final OmObservation observation : observations) {
        // phenomenonTime
        final Time phenomenonTime = observation.getPhenomenonTime();
        if (phenomenonTime.isReferenced()) {
            observation.getValue().setPhenomenonTime(phenomenonTimes.get(phenomenonTime.getGmlId()));
        }
        // resultTime
        final TimeInstant resultTime = observation.getResultTime();
        if (resultTime.isReferenced()) {
            if (resultTimes.containsKey(resultTime.getGmlId())) {
                observation.setResultTime(resultTimes.get(resultTime.getGmlId()));
            } else if (phenomenonTimes.containsKey(resultTime.getGmlId())) {
                final Time iTime = phenomenonTimes.get(resultTime.getGmlId());
                if (iTime instanceof TimeInstant) {
                    observation.setResultTime((TimeInstant) iTime);
                } else if (iTime instanceof TimePeriod) {
                    final TimePeriod timePeriod = (TimePeriod) iTime;
                    observation.setResultTime(new TimeInstant(timePeriod.getEnd()));
                } else {
                    throw new DecodingException("observation.resultTime", "The time value type is not supported");
                }
            }
        }
        // featureOfInterest
        final AbstractFeature featureOfInterest = observation.getObservationConstellation().getFeatureOfInterest();
        if (featureOfInterest.isReferenced()) {
            observation.getObservationConstellation().setFeatureOfInterest(features.get(featureOfInterest.getGmlId()));
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 48 with Time

use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.

the class GmlDecoderv321 method parseTimeInstant.

/**
 * parses TimeInstant
 *
 * @param xbTimeIntant XmlBean representation of TimeInstant
 *
 * @return Returns a TimeInstant created from the TimeInstantType
 *
 * @throws DecodingException if the time string is invalid
 */
private Object parseTimeInstant(TimeInstantType xbTimeIntant) throws DecodingException {
    TimeInstant ti = parseTimePosition(xbTimeIntant.getTimePosition());
    ti.setGmlId(xbTimeIntant.getId());
    return ti;
}
Also used : TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 49 with Time

use of org.n52.shetland.ogc.gml.time.Time in project arctic-sea by 52North.

the class SweCommonEncoderv101 method createTime.

private Time createTime(SweTime component) throws EncodingException {
    Time xml = Time.Factory.newInstance(getXmlOptions());
    if (component.isSetValue()) {
        XmlDateTime xbDateTime = createDateTime(component.getValue());
        xml.setValue(xbDateTime);
    }
    if (component.isSetUom()) {
        if (component.getUom().startsWith(URN) || component.getUom().startsWith(HTTP)) {
            xml.addNewUom().setHref(component.getUom());
        } else {
            xml.addNewUom().setCode(component.getUom());
        }
    }
    if (component.isSetQuality()) {
        xml.setQuality(createQuality(component.getQuality())[0]);
    }
    if (component.isSetContstraint()) {
        createConstraint(xml.getConstraint(), component.getConstraint());
    }
    return xml;
}
Also used : XmlDateTime(org.apache.xmlbeans.XmlDateTime) Time(net.opengis.swe.x101.TimeDocument.Time) XmlDateTime(org.apache.xmlbeans.XmlDateTime) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) DateTime(org.joda.time.DateTime)

Example 50 with Time

use of org.n52.shetland.ogc.gml.time.Time 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

Time (org.n52.shetland.ogc.gml.time.Time)24 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)18 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)17 DateTime (org.joda.time.DateTime)12 Test (org.junit.Test)11 XmlObject (org.apache.xmlbeans.XmlObject)9 OmObservation (org.n52.shetland.ogc.om.OmObservation)8 DecodingException (org.n52.svalbard.decode.exception.DecodingException)7 EncodingException (org.n52.svalbard.encode.exception.EncodingException)7 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)6 TimePosition (org.n52.shetland.ogc.gml.time.TimePosition)5 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)4 XmlException (org.apache.xmlbeans.XmlException)3 XmlString (org.apache.xmlbeans.XmlString)3 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 MultiObservationValues (org.n52.shetland.ogc.om.MultiObservationValues)3 OmObservableProperty (org.n52.shetland.ogc.om.OmObservableProperty)3 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)3 TimeValuePair (org.n52.shetland.ogc.om.TimeValuePair)3