Search in sources :

Example 21 with Filter

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

the class GetObservationRequest method setResultFilter.

public GetObservationRequest setResultFilter(ComparisonFilter filter) {
    this.resultFilter = filter;
    addExtension(new ResultFilter(filter));
    return this;
}
Also used : ResultFilter(org.n52.shetland.ogc.sos.ResultFilter)

Example 22 with Filter

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

the class ODataFesParser method decode.

@Override
public Filter<?> decode(String objectToDecode) throws DecodingException {
    LOG.debug("Parsing filter: {}", objectToDecode);
    if (objectToDecode == null || objectToDecode.isEmpty()) {
        return null;
    }
    try {
        String encode = urlEscaper.escape(objectToDecode);
        // >=4.4.0
        // UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT, BASE_URI);
        // >=4.2.0 <4.4.0
        // UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT);
        // >=4.0.0 <4.2.0
        UriInfo parseUri = parser.parseUri(PATH, "$filter=" + encode, FRAGMENT, this.edm);
        return parseUri.getFilterOption().getExpression().accept(new ExpressionGenerator()).accept(new RenamingVisitor(csdlProvider::mapProperty)).accept(new FilterGenerator());
    } catch (ODataException ex) {
        throw new DecodingException(ex);
    }
}
Also used : ODataException(org.apache.olingo.commons.api.ex.ODataException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) UriInfo(org.apache.olingo.server.api.uri.UriInfo)

Example 23 with Filter

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

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

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

the class FesEncoderv20 method setSpatialFilterCapabilities.

/**
 * Sets the SpatialFilterCapabilities.
 *
 * @param spatialCapabilitiesType FES SpatialCapabilities.
 * @param sosFilterCaps SOS spatial filter information
 *
 * @throws EncodingException if the spatial operator is not supported
 */
private void setSpatialFilterCapabilities(final SpatialCapabilitiesType spatialCapabilitiesType, org.n52.shetland.ogc.filter.FilterCapabilities sosFilterCaps) throws EncodingException {
    // set GeometryOperands
    if (sosFilterCaps.getSpatialOperands() != null && !sosFilterCaps.getSpatialOperands().isEmpty()) {
        GeometryOperandsType spatialOperands = spatialCapabilitiesType.addNewGeometryOperands();
        sosFilterCaps.getSpatialOperands().forEach(operand -> spatialOperands.addNewGeometryOperand().setName(operand));
    }
    // set SpatialOperators
    if (sosFilterCaps.getSpatialOperators() != null && !sosFilterCaps.getSpatialOperators().isEmpty()) {
        SpatialOperatorsType spatialOps = spatialCapabilitiesType.addNewSpatialOperators();
        Set<SpatialOperator> keys = sosFilterCaps.getSpatialOperators().keySet();
        for (SpatialOperator spatialOperator : keys) {
            SpatialOperatorType operator = spatialOps.addNewSpatialOperator();
            operator.setName(getEnum4SpatialOperator(spatialOperator));
            GeometryOperandsType geomOps = operator.addNewGeometryOperands();
            sosFilterCaps.getSpatialOperators().get(spatialOperator).forEach(operand -> geomOps.addNewGeometryOperand().setName(operand));
        }
    }
}
Also used : SpatialOperatorsType(net.opengis.fes.x20.SpatialOperatorsType) SpatialOperatorType(net.opengis.fes.x20.SpatialOperatorType) GeometryOperandsType(net.opengis.fes.x20.GeometryOperandsType) SpatialOperator(org.n52.shetland.ogc.filter.FilterConstants.SpatialOperator)

Aggregations

Test (org.junit.Test)10 SpatialFilter (org.n52.shetland.ogc.filter.SpatialFilter)10 XmlObject (org.apache.xmlbeans.XmlObject)9 ComparisonFilter (org.n52.shetland.ogc.filter.ComparisonFilter)9 XmlException (org.apache.xmlbeans.XmlException)6 DecodingException (org.n52.svalbard.decode.exception.DecodingException)6 URI (java.net.URI)3 Objects (java.util.Objects)3 Set (java.util.Set)3 BinaryTemporalOpType (net.opengis.fes.x20.BinaryTemporalOpType)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 LocalizedString (org.n52.janmayen.i18n.LocalizedString)3 MultilingualString (org.n52.janmayen.i18n.MultilingualString)3 TimeOperator (org.n52.shetland.ogc.filter.FilterConstants.TimeOperator)3 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)3 OwsDomain (org.n52.shetland.ogc.ows.OwsDomain)3 OwsLanguageString (org.n52.shetland.ogc.ows.OwsLanguageString)3 OwsMetadata (org.n52.shetland.ogc.ows.OwsMetadata)3 Strings (com.google.common.base.Strings)2 Arrays (java.util.Arrays)2