Search in sources :

Example 6 with TimeInstant

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

the class GmlDecoderv311 method parseTimePosition.

private TimeInstant parseTimePosition(TimePositionType xbTimePosition) throws DecodingException {
    TimeInstant ti = new TimeInstant();
    String timeString = xbTimePosition.getStringValue();
    if (timeString != null && !timeString.isEmpty()) {
        try {
            // TODO better differnetiate between ISO8601 and an
            // indeterminate value
            DateTime dateTime = DateTimeHelper.parseIsoString2DateTime(timeString);
            ti.setValue(dateTime);
            ti.setRequestedTimeLength(DateTimeHelper.getTimeLengthBeforeTimeZone(timeString));
        } catch (DateTimeParseException ex) {
            ti.setIndeterminateValue(new IndeterminateValue(timeString));
        }
    }
    if (xbTimePosition.getIndeterminatePosition() != null) {
        ti.setIndeterminateValue(new IndeterminateValue(xbTimePosition.getIndeterminatePosition().toString()));
    }
    return ti;
}
Also used : DateTimeParseException(org.n52.shetland.util.DateTimeParseException) IndeterminateValue(org.n52.shetland.ogc.gml.time.IndeterminateValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) DateTime(org.joda.time.DateTime)

Example 7 with TimeInstant

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

the class GmlDecoderv311 method parseTimePeriod.

private Object parseTimePeriod(TimePeriodType xbTimePeriod) throws DecodingException {
    // begin position
    TimePositionType xbBeginTPT = xbTimePeriod.getBeginPosition();
    TimeInstant begin = null;
    if (xbBeginTPT != null) {
        begin = parseTimePosition(xbBeginTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:beginPosition Element with valid ISO:8601 String!");
    }
    // end position
    TimePositionType xbEndTPT = xbTimePeriod.getEndPosition();
    TimeInstant end = null;
    if (xbEndTPT != null) {
        end = parseTimePosition(xbEndTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:endPosition Element with valid ISO:8601 String!");
    }
    TimePeriod timePeriod = new TimePeriod(begin, end);
    timePeriod.setGmlId(xbTimePeriod.getId());
    return timePeriod;
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimePositionType(net.opengis.gml.TimePositionType) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 8 with TimeInstant

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

the class GmlDecoderv321 method parseTimePeriod.

/**
 * creates SOS representation of time period from XMLBeans representation of time period
 *
 * @param xbTimePeriod XMLBeans representation of time period
 *
 * @return Returns SOS representation of time period
 *
 * @throws DecodingException if the time string is invalid
 */
private Object parseTimePeriod(TimePeriodType xbTimePeriod) throws DecodingException {
    // begin position
    TimePositionType xbBeginTPT = xbTimePeriod.getBeginPosition();
    TimeInstant begin = null;
    if (xbBeginTPT != null) {
        begin = parseTimePosition(xbBeginTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:beginPosition Element with valid ISO:8601 String!");
    }
    // end position
    TimePositionType xbEndTPT = xbTimePeriod.getEndPosition();
    TimeInstant end = null;
    if (xbEndTPT != null) {
        end = parseTimePosition(xbEndTPT);
    } else {
        throw new DecodingException("gml:TimePeriod must contain gml:endPosition Element with valid ISO:8601 String!");
    }
    TimePeriod timePeriod = new TimePeriod(begin, end);
    timePeriod.setGmlId(xbTimePeriod.getId());
    return timePeriod;
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DecodingException(org.n52.svalbard.decode.exception.DecodingException) TimePositionType(net.opengis.gml.x32.TimePositionType) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 9 with TimeInstant

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

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

Aggregations

TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)38 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)16 Time (org.n52.shetland.ogc.gml.time.Time)13 DateTime (org.joda.time.DateTime)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)12 Test (org.junit.Test)9 XmlObject (org.apache.xmlbeans.XmlObject)7 DecodingException (org.n52.svalbard.decode.exception.DecodingException)5 EncodingException (org.n52.svalbard.encode.exception.EncodingException)5 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)4 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)4 XmlString (org.apache.xmlbeans.XmlString)3 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 URI (java.net.URI)2 Date (java.util.Date)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 EReportingChange (org.n52.shetland.aqd.EReportingChange)2 GeographicalName (org.n52.shetland.inspire.GeographicalName)2