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;
}
}
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;
}
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;
}
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);
}
}
}
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();
}
};
}
Aggregations