Search in sources :

Example 36 with Time

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

the class OmDecoderv20 method getObservationValue.

private ObservationValue<?> getObservationValue(OMObservationType omObservation) throws DecodingException {
    Time phenomenonTime = getPhenomenonTime(omObservation);
    ObservationValue<?> observationValue;
    if (!omObservation.getResult().getDomNode().hasChildNodes() && phenomenonTime.isSetNilReason() && phenomenonTime.getNilReason().equals(NilReason.template)) {
        observationValue = new SingleObservationValue<>(new NilTemplateValue());
    } else {
        observationValue = getResult(omObservation);
    }
    observationValue.setPhenomenonTime(phenomenonTime);
    return observationValue;
}
Also used : Time(org.n52.shetland.ogc.gml.time.Time) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue)

Example 37 with Time

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

the class FesDecoderv20 method parseTemporalFilterType.

/**
 * parses a single temporal filter of the requests and returns SOS temporal
 * filter
 *
 * @param xbTemporalOpsType
 *            XmlObject representing the temporal filter
 * @return Returns SOS representation of temporal filter
 *
 * @throws DecodingException
 *             * if parsing of the element failed
 */
private TemporalFilter parseTemporalFilterType(TemporalOpsType xbTemporalOpsType) throws DecodingException {
    TemporalFilter temporalFilter = new TemporalFilter();
    try {
        if (xbTemporalOpsType instanceof BinaryTemporalOpType) {
            BinaryTemporalOpType btot = (BinaryTemporalOpType) xbTemporalOpsType;
            if (btot.getValueReference() != null && !btot.getValueReference().isEmpty()) {
                temporalFilter.setValueReference(btot.getValueReference().trim());
            }
            NodeList nodes = btot.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)) {
                    Object timeObject = decodeXmlObject(Factory.parse(nodes.item(i)));
                    if (timeObject instanceof Time) {
                        TimeOperator operator;
                        Time time = (Time) timeObject;
                        String localName = XmlHelper.getLocalName(xbTemporalOpsType);
                        if (localName.equals(TimeOperator2.After.name())) {
                            operator = TimeOperator.TM_After;
                        } else if (localName.equals(TimeOperator2.Before.name())) {
                            operator = TimeOperator.TM_Before;
                        } else if (localName.equals(TimeOperator2.Begins.name())) {
                            operator = TimeOperator.TM_Begins;
                        } else if (localName.equals(TimeOperator2.BegunBy.name())) {
                            operator = TimeOperator.TM_BegunBy;
                        } else if (localName.equals(TimeOperator2.TContains.name())) {
                            operator = TimeOperator.TM_Contains;
                        } else if (localName.equals(TimeOperator2.During.name())) {
                            operator = TimeOperator.TM_During;
                        } else if (localName.equals(TimeOperator2.EndedBy.name())) {
                            operator = TimeOperator.TM_EndedBy;
                        } else if (localName.equals(TimeOperator2.Ends.name())) {
                            operator = TimeOperator.TM_Ends;
                        } else if (localName.equals(TimeOperator2.TEquals.name())) {
                            operator = TimeOperator.TM_Equals;
                        } else if (localName.equals(TimeOperator2.Meets.name())) {
                            operator = TimeOperator.TM_Meets;
                        } else if (localName.equals(TimeOperator2.MetBy.name())) {
                            operator = TimeOperator.TM_MetBy;
                        } else if (localName.equals(TimeOperator2.TOverlaps.name())) {
                            operator = TimeOperator.TM_Overlaps;
                        } else if (localName.equals(TimeOperator2.OverlappedBy.name())) {
                            operator = TimeOperator.TM_OverlappedBy;
                        } else {
                            throw unsupportedTemporalOperator();
                        }
                        temporalFilter.setOperator(operator);
                        temporalFilter.setTime(time);
                        break;
                    } else {
                        throw new DecodingException(Sos2Constants.GetObservationParams.temporalFilter, "The requested temporal filter value is not supported by this SOS!");
                    }
                }
            }
        } else {
            throw unsupportedTemporalOperator();
        }
    } 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) 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) BinaryTemporalOpType(net.opengis.fes.x20.BinaryTemporalOpType)

Example 38 with Time

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

the class GetCapabilitiesResponseEncoder method encodePhenomenonTime.

private void encodePhenomenonTime(SosObservationOffering offering, int offeringCounter, ObservationOfferingType xbObsOff) throws EncodingException {
    // set up phenomenon time [0..1]
    if (offering.getPhenomenonTime() instanceof TimePeriod) {
        TimePeriod tp = (TimePeriod) offering.getPhenomenonTime();
        if (!tp.isEmpty()) {
            tp.setGmlId(String.format(ID_FORMAT_STRING, Sos2Constants.EN_PHENOMENON_TIME, offeringCounter));
            XmlObject xmlObject = encodeGml(tp);
            xbObsOff.addNewPhenomenonTime().addNewTimePeriod().set(xmlObject);
            xbObsOff.getPhenomenonTime().substitute(Sos2Constants.QN_SOS_PHENOMENON_TIME, xbObsOff.getPhenomenonTime().schemaType());
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) XmlObject(org.apache.xmlbeans.XmlObject)

Example 39 with Time

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

the class AbstractOmEncoderv20 method setPhenomenonTime.

private void setPhenomenonTime(OmObservation observation, OMObservationType xb) throws EncodingException {
    // set validTime
    Time phenomenonTime = observation.getPhenomenonTime();
    if (phenomenonTime.getGmlId() == null) {
        phenomenonTime.setGmlId(OmConstants.PHENOMENON_TIME_NAME + "_" + observation.getObservationID());
    }
    addPhenomenonTime(xb.addNewPhenomenonTime(), phenomenonTime);
}
Also used : Time(org.n52.shetland.ogc.gml.time.Time)

Example 40 with Time

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

the class AbstractOmEncoderv20 method addResultTime.

/**
 * Method to add the result time to the XML observation object
 *
 * @param xbObs
 *            XML observation object
 * @param sosObservation
 *            SOS observation object
 * @throws EncodingException
 *             If an error occurs.
 */
private void addResultTime(OMObservationType xbObs, OmObservation sosObservation) throws EncodingException {
    TimeInstant resultTime = sosObservation.getResultTime();
    Time phenomenonTime = sosObservation.getPhenomenonTime();
    // get result time from SOS result time representation
    if (sosObservation.getResultTime() != null) {
        if (resultTime.equals(phenomenonTime)) {
            xbObs.addNewResultTime().setHref("#" + phenomenonTime.getGmlId());
        } else {
            addResultTime(xbObs, resultTime);
        }
    } else {
        // representation
        if (phenomenonTime instanceof TimeInstant) {
            xbObs.addNewResultTime().setHref("#" + phenomenonTime.getGmlId());
        } else if (phenomenonTime instanceof TimePeriod) {
            TimeInstant rsTime = new TimeInstant(((TimePeriod) sosObservation.getPhenomenonTime()).getEnd());
            addResultTime(xbObs, rsTime);
        }
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) Time(org.n52.shetland.ogc.gml.time.Time) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

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