Search in sources :

Example 16 with Time

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

the class AbstractOmEncoderv20 method setValidTime.

private void setValidTime(OmObservation observation, OMObservationType xb) throws EncodingException {
    Time validTime = observation.getValidTime();
    if (validTime == null) {
        return;
    }
    if (validTime.getGmlId() == null) {
        validTime.setGmlId(OmConstants.VALID_TIME_NAME + "_" + observation.getObservationID());
    }
    xb.addNewValidTime().addNewTimePeriod().set(encodeGML(validTime));
}
Also used : Time(org.n52.shetland.ogc.gml.time.Time)

Example 17 with Time

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

the class OgcDecoderv100 method parseTemporalOperatorType.

/**
 * parses a single temporal filter of the requests and returns SOS temporal filter
 *
 * @param xbBinaryTemporalOp XmlObject representing the temporal filter
 *
 * @return Returns SOS representation of temporal filter
 *
 * @throws DecodingException if parsing of the element failed
 */
private Object parseTemporalOperatorType(BinaryTemporalOpType xbBinaryTemporalOp) throws DecodingException {
    TemporalFilter temporalFilter = new TemporalFilter();
    // FIXME local workaround against SOSHelper check value reference
    String valueRef = "phenomenonTime";
    try {
        NodeList nodes = xbBinaryTemporalOp.getDomNode().getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
                // GML decoder will return TimeInstant or TimePriod
                Object timeObject = decodeXmlElement(XmlObject.Factory.parse(nodes.item(i)));
                if (timeObject instanceof PropertyNameType) {
                    PropertyNameType propType = (PropertyNameType) timeObject;
                // TODO here apply logic for ogc property
                // om:samplingTime etc
                // valueRef = propType.getDomNode().getNodeValue();
                }
                if (timeObject instanceof Time) {
                    TimeOperator operator;
                    Time time = (Time) timeObject;
                    String localName = XmlHelper.getLocalName(xbBinaryTemporalOp);
                    // change to SOS 1.0. TMDuring kind of
                    if (localName.equals(TimeOperator.TM_During.name()) && time instanceof TimePeriod) {
                        operator = TimeOperator.TM_During;
                    } else if (localName.equals(TimeOperator.TM_Equals.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_Equals;
                    } else if (localName.equals(TimeOperator.TM_After.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_After;
                    } else if (localName.equals(TimeOperator.TM_Before.name()) && time instanceof TimeInstant) {
                        operator = TimeOperator.TM_Before;
                    } else {
                        throw unsupportedTemporalFilterOperand();
                    }
                    temporalFilter.setOperator(operator);
                    temporalFilter.setTime(time);
                    // actually it should be eg om:samplingTime
                    temporalFilter.setValueReference(valueRef);
                    break;
                }
            }
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing temporal filter!", xmle);
    }
    return temporalFilter;
}
Also used : TimeOperator(org.n52.shetland.ogc.filter.FilterConstants.TimeOperator) TemporalFilter(org.n52.shetland.ogc.filter.TemporalFilter) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlException(org.apache.xmlbeans.XmlException) NodeList(org.w3c.dom.NodeList) XmlObject(org.apache.xmlbeans.XmlObject) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) PropertyNameType(net.opengis.ogc.PropertyNameType)

Example 18 with Time

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

the class OmEncoderv100 method addResultTime.

private void addResultTime(ObservationType xbObs, OmObservation sosObservation) throws EncodingException {
    Time phenomenonTime = sosObservation.getPhenomenonTime();
    if (sosObservation.isSetResultTime()) {
        if (sosObservation.getResultTime().equals(phenomenonTime)) {
            xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
        } else {
            TimeInstant resultTime = sosObservation.getResultTime();
            if (!resultTime.isSetGmlId()) {
                resultTime.setGmlId(RESULT_TIME_ID_PREFIX.concat(sosObservation.getObservationID()));
            }
            addResultTime(xbObs, resultTime);
        }
    } else {
        if (phenomenonTime instanceof TimeInstant) {
            xbObs.addNewResultTime().setHref("#".concat(phenomenonTime.getGmlId()));
        } else if (phenomenonTime instanceof TimePeriod) {
            TimeInstant resultTime = new TimeInstant(((TimePeriod) sosObservation.getPhenomenonTime()).getEnd());
            resultTime.setGmlId(RESULT_TIME_ID_PREFIX + sosObservation.getObservationID());
            addResultTime(xbObs, resultTime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 19 with Time

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

the class OmEncoderv100 method addValuesToObservation.

private List<OmObservableProperty> addValuesToObservation(ObservationType xbObs, OmObservation sosObservation, EncodingContext additionalValues) throws EncodingException {
    xbObs.setId(OBSERVATION_ID_PREFIX + Long.toString(System.currentTimeMillis()));
    if (!sosObservation.isSetObservationID()) {
        sosObservation.setObservationID(xbObs.getId().replace(OBSERVATION_ID_PREFIX, ""));
    }
    String observationID = sosObservation.getObservationID();
    // set samplingTime
    Time samplingTime = sosObservation.getPhenomenonTime();
    if (samplingTime.getGmlId() == null) {
        samplingTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observationID);
    }
    addSamplingTime(xbObs, samplingTime);
    // set resultTime
    addResultTime(xbObs, sosObservation);
    // set procedure
    xbObs.addNewProcedure().setHref(sosObservation.getObservationConstellation().getProcedure().getIdentifier());
    // set observedProperty (phenomenon)
    List<OmObservableProperty> phenComponents = null;
    if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmObservableProperty) {
        xbObs.addNewObservedProperty().setHref(sosObservation.getObservationConstellation().getObservableProperty().getIdentifier());
        phenComponents = new ArrayList<>(1);
        phenComponents.add((OmObservableProperty) sosObservation.getObservationConstellation().getObservableProperty());
    } else if (sosObservation.getObservationConstellation().getObservableProperty() instanceof OmCompositePhenomenon) {
        OmCompositePhenomenon compPhen = (OmCompositePhenomenon) sosObservation.getObservationConstellation().getObservableProperty();
        xbObs.addNewObservedProperty().setHref(compPhen.getIdentifier());
        phenComponents = compPhen.getPhenomenonComponents();
    }
    // set feature
    addFeatureOfInterest(xbObs, sosObservation.getObservationConstellation().getFeatureOfInterest());
    return phenComponents;
}
Also used : OmCompositePhenomenon(org.n52.shetland.ogc.om.OmCompositePhenomenon) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) XmlString(org.apache.xmlbeans.XmlString) OmObservableProperty(org.n52.shetland.ogc.om.OmObservableProperty)

Example 20 with Time

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

the class GmlEncoderv311 method createTimePeriodType.

/**
 * Creates a XML TimePeriod from the SOS time object.
 *
 * @param timePeriod
 *            SOS time object
 * @param timePeriodType
 *            the xml time period (may be {@code null})
 * @return XML TimePeriod
 *
 * @throws EncodingException
 *             if an error occurs.
 */
private TimePeriodType createTimePeriodType(TimePeriod timePeriod, TimePeriodType timePeriodType) throws EncodingException {
    try {
        TimePeriodType tpt;
        if (timePeriodType == null) {
            tpt = TimePeriodType.Factory.newInstance(getXmlOptions());
        } else {
            tpt = timePeriodType;
        }
        if (timePeriod.getGmlId() != null && !timePeriod.getGmlId().isEmpty()) {
            tpt.setId(timePeriod.getGmlId());
        }
        tpt.setBeginPosition(createTimePositionType(timePeriod.getStartTimePosition()));
        tpt.setEndPosition(createTimePositionType(timePeriod.getEndTimePosition()));
        return tpt;
    } catch (XmlRuntimeException | XmlValueDisconnectedException x) {
        throw new EncodingException("Error while creating TimePeriod!", x);
    }
}
Also used : XmlRuntimeException(org.apache.xmlbeans.XmlRuntimeException) XmlValueDisconnectedException(org.apache.xmlbeans.impl.values.XmlValueDisconnectedException) TimePeriodType(net.opengis.gml.TimePeriodType) EncodingException(org.n52.svalbard.encode.exception.EncodingException)

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