Search in sources :

Example 1 with TemporalFilter

use of org.n52.shetland.ogc.filter.TemporalFilter 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 2 with TemporalFilter

use of org.n52.shetland.ogc.filter.TemporalFilter in project arctic-sea by 52North.

the class SosRequestEncoderv20 method createTemporalFilter.

private void createTemporalFilter(final net.opengis.sos.x20.GetResultType.TemporalFilter temporalFilter, final TemporalFilter sosTemporalFilter) throws EncodingException {
    final Encoder<XmlObject, TemporalFilter> encoder = getEncoder(FilterConstants.NS_FES_2, sosTemporalFilter);
    final XmlObject encodedObject = encoder.encode(sosTemporalFilter);
    temporalFilter.set(encodedObject);
}
Also used : TemporalFilter(org.n52.shetland.ogc.filter.TemporalFilter) XmlObject(org.apache.xmlbeans.XmlObject)

Example 3 with TemporalFilter

use of org.n52.shetland.ogc.filter.TemporalFilter 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 4 with TemporalFilter

use of org.n52.shetland.ogc.filter.TemporalFilter in project arctic-sea by 52North.

the class FesEncoderv20 method encodeTemporalFilterEquals.

private XmlObject encodeTemporalFilterEquals(TemporalFilter temporalFilter) throws EncodingException {
    final TEqualsDocument equalsDoc = TEqualsDocument.Factory.newInstance(getXmlOptions());
    final BinaryTemporalOpType equals = equalsDoc.addNewTEquals();
    if (temporalFilter.getTime() instanceof TimeInstant) {
        equals.set(encodeObjectToXml(GmlConstants.NS_GML_32, temporalFilter.getTime(), EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT)));
    } else {
        throw new EncodingException("The temporal filter value is not a TimeInstant!");
    }
    checkAndAddValueReference(equals, temporalFilter);
    return equalsDoc;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TEqualsDocument(net.opengis.fes.x20.TEqualsDocument) BinaryTemporalOpType(net.opengis.fes.x20.BinaryTemporalOpType) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 5 with TemporalFilter

use of org.n52.shetland.ogc.filter.TemporalFilter in project arctic-sea by 52North.

the class FesEncoderv20 method encodeTemporalFilterDuring.

private XmlObject encodeTemporalFilterDuring(TemporalFilter temporalFilter) throws EncodingException {
    final DuringDocument duringDoc = DuringDocument.Factory.newInstance(getXmlOptions());
    final BinaryTemporalOpType during = duringDoc.addNewDuring();
    if (temporalFilter.getTime() instanceof TimePeriod) {
        during.set(encodeObjectToXml(GmlConstants.NS_GML_32, temporalFilter.getTime(), EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT)));
    } else {
        throw new EncodingException("The temporal filter value is not a TimePeriod!");
    }
    checkAndAddValueReference(during, temporalFilter);
    return duringDoc;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) DuringDocument(net.opengis.fes.x20.DuringDocument) BinaryTemporalOpType(net.opengis.fes.x20.BinaryTemporalOpType)

Aggregations

TemporalFilter (org.n52.shetland.ogc.filter.TemporalFilter)4 BinaryTemporalOpType (net.opengis.fes.x20.BinaryTemporalOpType)3 XmlObject (org.apache.xmlbeans.XmlObject)3 XmlException (org.apache.xmlbeans.XmlException)2 TimeOperator (org.n52.shetland.ogc.filter.FilterConstants.TimeOperator)2 Time (org.n52.shetland.ogc.gml.time.Time)2 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)2 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)2 DecodingException (org.n52.svalbard.decode.exception.DecodingException)2 EncodingException (org.n52.svalbard.encode.exception.EncodingException)2 NodeList (org.w3c.dom.NodeList)2 DuringDocument (net.opengis.fes.x20.DuringDocument)1 TEqualsDocument (net.opengis.fes.x20.TEqualsDocument)1 PropertyNameType (net.opengis.ogc.PropertyNameType)1 GetResultDocument (net.opengis.sos.x20.GetResultDocument)1 GetResultType (net.opengis.sos.x20.GetResultType)1