use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.
the class MockQuery method addContextualFilter.
public void addContextualFilter(String searchTerm, String selector) {
Filter filter = null;
if (selector != null) {
List<Filter> xpathFilters = new ArrayList<Filter>();
String[] selectors = selector.split(",");
for (int i = 0; i < selectors.length; i++) {
Expression xpathRef = new AttributeExpressionImpl(selectors[i]);
filter = FILTER_FACTORY.like(xpathRef, searchTerm);
xpathFilters.add(filter);
}
filter = FILTER_FACTORY.or(xpathFilters);
} else {
filter = FILTER_FACTORY.like(FILTER_FACTORY.property(Metacard.ANY_TEXT), searchTerm);
}
if (filter != null) {
filters.add(filter);
this.filter = getFilter();
}
}
use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.
the class OpenSearchQueryTest method verifyContextualFilter.
// private Document getDocument( String xml ) throws Exception
// {
// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setNamespaceAware( true );
// DocumentBuilder builder = factory.newDocumentBuilder();
// StringReader reader = new StringReader( xml );
// InputSource inputSource = new InputSource( reader );
// Document doc = builder.parse( inputSource );
// reader.close();
//
// return doc;
// }
// private String getFilterAsXml( Filter filter ) throws Exception
// {
// FilterTransformer transform = new FilterTransformer();
// transform.setIndentation( 2 );
// String filterXml = transform.transform( filter );
// LOGGER.debug( filterXml );
//
// return filterXml;
// }
private void verifyContextualFilter(Filter filter, String expectedPropertyName, String expectedSearchTerm) throws Exception {
LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
LOGGER.debug("propertyName = {}", expression.getPropertyName());
assertEquals(expectedPropertyName, expression.getPropertyName());
String extractedSearchTerm = likeFilter.getLiteral();
LOGGER.debug("extractedSearchTerm = [{}]", extractedSearchTerm);
assertEquals(expectedSearchTerm, extractedSearchTerm);
}
use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.
the class OpenSearchQueryTest method verifyLikeFilter.
private void verifyLikeFilter(Filter filter, String expectedPropertyName, String expectedValue) {
assertTrue(filter instanceof LikeFilterImpl);
LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
LOGGER.debug("propertyName = {}", expression.getPropertyName());
assertEquals(expectedPropertyName, expression.getPropertyName());
String pattern = likeFilter.getLiteral();
LOGGER.debug("value to search for = {}", pattern);
assertEquals(expectedValue, pattern);
}
use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.
the class OpenSearchQueryTest method verifyEqualsFilter.
private void verifyEqualsFilter(Filter filter, String expectedPropertyName, String expectedValue) {
assertTrue(filter instanceof IsEqualsToImpl);
IsEqualsToImpl equalsFilter = (IsEqualsToImpl) filter;
AttributeExpressionImpl expression1 = (AttributeExpressionImpl) equalsFilter.getExpression1();
LOGGER.debug("propertyName = {}", expression1.getPropertyName());
assertEquals(expectedPropertyName, expression1.getPropertyName());
LiteralExpressionImpl expression2 = (LiteralExpressionImpl) equalsFilter.getExpression2();
LOGGER.debug("version to search for = {}", expression2.getValue());
assertEquals(expectedValue, expression2.getValue());
}
use of org.geotools.filter.AttributeExpressionImpl in project ddf by codice.
the class OpenSearchFilterVisitor method visit.
/**
* PropertyIsLike filter maps to a Contextual search criteria.
*/
@Override
public Object visit(PropertyIsLike filter, Object data) {
LOGGER.trace("ENTERING: PropertyIsLike filter");
if (currentNest != NestedTypes.NOT) {
LikeFilterImpl likeFilter = (LikeFilterImpl) filter;
AttributeExpressionImpl expression = (AttributeExpressionImpl) likeFilter.getExpression();
String selectors = expression.getPropertyName();
LOGGER.debug("selectors = {}", selectors);
String searchPhrase = likeFilter.getLiteral();
LOGGER.debug("searchPhrase = [{}]", searchPhrase);
if (contextualSearch != null) {
contextualSearch.setSearchPhrase(contextualSearch.getSearchPhrase() + " " + currentNest.toString() + " " + searchPhrase);
} else {
contextualSearch = new ContextualSearch(selectors, searchPhrase, likeFilter.isMatchingCase());
}
}
LOGGER.trace("EXITING: PropertyIsLike filter");
return super.visit(filter, data);
}
Aggregations