Search in sources :

Example 6 with CQLException

use of org.geotools.filter.text.cql2.CQLException in project hale by halestudio.

the class FilterGeoECqlImpl method createFilter.

@Override
protected Filter createFilter(String filterTerm) throws CQLException {
    CQLException filterException = null;
    try {
        return ECQL.toFilter(filterTerm);
    } catch (CQLException e) {
        filterException = e;
    }
    // Try if filterTerm can be evaluated as an Expression and if so,
    // use it in a EqualsTrue filter. This is the same as if
    // "= true" were added to the filter term.
    Expression expr;
    try {
        expr = ECQL.toExpression(filterTerm);
        return new EqualsTrue(expr);
    } catch (CQLException e) {
        throw filterException;
    }
}
Also used : Expression(org.opengis.filter.expression.Expression) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 7 with CQLException

use of org.geotools.filter.text.cql2.CQLException in project ddf by codice.

the class CqlRequest method createFilter.

private Filter createFilter(FilterBuilder filterBuilder) {
    Filter filter = null;
    try {
        filter = ECQL.toFilter(cql);
    } catch (CQLException e) {
        halt(400, "Unable to parse CQL filter");
    }
    if (filter == null) {
        LOGGER.debug("Received an empty filter. Using a wildcard contextual filter instead.");
        filter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text(FilterDelegate.WILDCARD_CHAR);
    }
    return filter;
}
Also used : Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 8 with CQLException

use of org.geotools.filter.text.cql2.CQLException in project ddf by codice.

the class CswQueryFactory method buildFilter.

private CswRecordMapperFilterVisitor buildFilter(QueryConstraintType constraint) throws CswException {
    CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, metacardTypes);
    Filter filter = null;
    if (constraint != null) {
        if (constraint.isSetCqlText()) {
            try {
                filter = CQL.toFilter(constraint.getCqlText());
            } catch (CQLException e) {
                throw new CswException("Unable to parse CQL Constraint: " + e.getMessage(), e);
            }
        } else if (constraint.isSetFilter()) {
            FilterType constraintFilter = constraint.getFilter();
            filter = parseFilter(constraintFilter);
        }
    } else {
        // not supported by catalog:
        //filter = Filter.INCLUDE;
        filter = builder.attribute(Core.ID).is().like().text(FilterDelegate.WILDCARD_CHAR);
    }
    if (filter == null) {
        throw new CswException("Invalid Filter Expression", CswConstants.NO_APPLICABLE_CODE, null);
    }
    filter = transformCustomFunctionToFilter(filter);
    try {
        visitor.setVisitedFilter((Filter) filter.accept(visitor, new FilterFactoryImpl()));
    } catch (UnsupportedOperationException ose) {
        throw new CswException(ose.getMessage(), CswConstants.INVALID_PARAMETER_VALUE, null);
    }
    return visitor;
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) Filter(org.opengis.filter.Filter) CswRecordMapperFilterVisitor(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 9 with CQLException

use of org.geotools.filter.text.cql2.CQLException in project GeoGig by boundlessgeo.

the class RepositoryFilter method addFilter.

/**
     * Adds a new filter to the repository.
     * 
     * @param featurePath the path of the features to filter, "default" for a fall back filter
     * @param filterType the format of the filter text, for example "CQL"
     * @param filterText the filter text
     */
public void addFilter(String featurePath, String filterType, String filterText) {
    Preconditions.checkState(featurePath != null && filterType != null && filterText != null, "Missing filter parameter.");
    if (filterType.equals("CQL")) {
        try {
            Filter newFilter = CQL.toFilter(filterText);
            repositoryFilters.put(featurePath, newFilter);
            filterDescriptions.add(new FilterDescription(featurePath, filterType, filterText));
        } catch (CQLException e) {
            Throwables.propagate(e);
        }
    }
}
Also used : Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException)

Example 10 with CQLException

use of org.geotools.filter.text.cql2.CQLException in project incubator-rya by apache.

the class GeoMesaGeoIndexer method getIteratorWrapper.

private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final String filterString) {
    return new CloseableIteration<Statement, QueryEvaluationException>() {

        private FeatureIterator<SimpleFeature> featureIterator = null;

        FeatureIterator<SimpleFeature> getIterator() throws QueryEvaluationException {
            if (featureIterator == null) {
                Filter cqlFilter;
                try {
                    cqlFilter = ECQL.toFilter(filterString);
                } catch (final CQLException e) {
                    logger.error("Error parsing query: " + LogUtils.clean(filterString), e);
                    throw new QueryEvaluationException(e);
                }
                final Query query = new Query(featureType.getTypeName(), cqlFilter);
                try {
                    featureIterator = featureSource.getFeatures(query).features();
                } catch (final IOException e) {
                    logger.error("Error performing query: " + LogUtils.clean(filterString), e);
                    throw new QueryEvaluationException(e);
                }
            }
            return featureIterator;
        }

        @Override
        public boolean hasNext() throws QueryEvaluationException {
            return getIterator().hasNext();
        }

        @Override
        public Statement next() throws QueryEvaluationException {
            final SimpleFeature feature = getIterator().next();
            final String subjectString = feature.getAttribute(SUBJECT_ATTRIBUTE).toString();
            final String predicateString = feature.getAttribute(PREDICATE_ATTRIBUTE).toString();
            final String objectString = feature.getAttribute(OBJECT_ATTRIBUTE).toString();
            final String contextString = feature.getAttribute(CONTEXT_ATTRIBUTE).toString();
            final Statement statement = StatementSerializer.readStatement(subjectString, predicateString, objectString, contextString);
            return statement;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Remove not implemented");
        }

        @Override
        public void close() throws QueryEvaluationException {
            getIterator().close();
        }
    };
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) FeatureIterator(org.geotools.feature.FeatureIterator) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Query(org.geotools.data.Query) NearQuery(org.apache.rya.indexing.accumulo.geo.GeoTupleSet.GeoSearchFunctionFactory.NearQuery) Filter(org.opengis.filter.Filter) RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) CQLException(org.geotools.filter.text.cql2.CQLException) IOException(java.io.IOException) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

CQLException (org.geotools.filter.text.cql2.CQLException)19 Filter (org.opengis.filter.Filter)12 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)3 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 Statement (org.openrdf.model.Statement)3 ParseException (com.vividsolutions.jts.io.ParseException)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 Filter (eu.esdihumboldt.hale.common.instance.model.Filter)2 CloseableIteration (info.aduna.iteration.CloseableIteration)2 ParseException (java.text.ParseException)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 Expression (org.opengis.filter.expression.Expression)2 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2