use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class GeotoolsFilterAdapterImpl method visit.
public Object visit(PropertyIsLike filter, Object delegate) {
String propertyName;
String wildcard = filter.getWildCard();
String singleChar = filter.getSingleChar();
String escapeChar = filter.getEscape();
if (filter.getExpression() == null || filter.getLiteral() == null) {
throw new UnsupportedOperationException("Expression and Literal must not be null for PropertyIsLike.");
}
if (wildcard.length() > 1 || singleChar.length() > 1 || escapeChar.length() > 1) {
throw new UnsupportedOperationException("Wildcard, single, and escape characters must be a single character for PropertyIsLike.");
}
if (wildcard.equals(singleChar) || wildcard.equals(escapeChar) || singleChar.equals(escapeChar)) {
throw new UnsupportedOperationException("Wildcard, single, and escape characters must be different for PropertyIsLike.");
}
String pattern = normalizePattern(filter.getLiteral(), wildcard, singleChar, escapeChar);
boolean matchCase = filter.isMatchingCase();
boolean isFuzzy = false;
if (filter.getExpression() instanceof FuzzyFunction) {
FuzzyFunction fuzzy = (FuzzyFunction) filter.getExpression();
propertyName = ((PropertyName) (fuzzy.getParameters().get(0))).getPropertyName();
isFuzzy = true;
} else if (filter.getExpression() instanceof PropertyName) {
PropertyName expression = (PropertyName) filter.getExpression();
propertyName = expression.getPropertyName();
} else {
throw new UnsupportedOperationException("Only support PropertyName expression for PropertyIsLike filter.");
}
boolean isXpathSearch = (propertyName.indexOf('/') != -1 || propertyName.indexOf('@') != -1);
if (!isFuzzy && !isXpathSearch) {
return ((FilterDelegate<?>) delegate).propertyIsLike(propertyName, pattern, matchCase);
} else if (isFuzzy && !isXpathSearch) {
// TODO check if wildcards are escaped
return ((FilterDelegate<?>) delegate).propertyIsFuzzy(propertyName, pattern);
} else if (!isFuzzy && isXpathSearch) {
if (pattern.trim().isEmpty() || pattern.trim().equals(FilterDelegate.WILDCARD_CHAR)) {
return ((FilterDelegate<?>) delegate).xpathExists(propertyName);
} else {
return ((FilterDelegate<?>) delegate).xpathIsLike(propertyName, pattern, matchCase);
}
} else if (isFuzzy && isXpathSearch) {
// TODO check if wildcards are escaped
return ((FilterDelegate<?>) delegate).xpathIsFuzzy(propertyName, pattern);
} else {
throw new UnsupportedOperationException("Unsupported operands for PropertyIsLike.");
}
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class FilterBuilderTest method andOrNull.
@Test
public void andOrNull() {
FilterVisitor visitor = spy(new DefaultFilterVisitor() {
});
// FilterBuilder builder = new GeotoolsFilterBuilder();
//
//
FilterBuilder builder = new GeotoolsFilterBuilder();
Filter filter = builder.allOf(builder.anyOf(builder.attribute(FOO_ATTRIBUTE).is().empty()));
filter.accept(visitor, null);
InOrder inOrder = inOrder(visitor);
inOrder.verify(visitor, times(1)).visit(isA(And.class), anyObject());
inOrder.verify(visitor).visit(isA(Or.class), anyObject());
ArgumentCaptor<PropertyIsNull> propertyIsNullArgument = ArgumentCaptor.forClass(PropertyIsNull.class);
verify(visitor).visit(propertyIsNullArgument.capture(), anyObject());
ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
});
propertyIsNullArgument.getValue().getExpression().accept(expVisitor, null);
ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
verify(expVisitor).visit(propertyNameArgument.capture(), anyObject());
assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class FilterBuilderTest method afterDate.
@Test
public void afterDate() {
final Date date = new Date();
FilterVisitor visitor = spy(new DefaultFilterVisitor() {
});
FilterBuilder builder = new GeotoolsFilterBuilder();
Filter filter = builder.attribute(FOO_ATTRIBUTE).is().after().date(date);
filter.accept(visitor, null);
ArgumentCaptor<After> expressionArgument = ArgumentCaptor.forClass(After.class);
verify(visitor).visit(expressionArgument.capture(), anyObject());
ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
});
expressionArgument.getValue().getExpression1().accept(expVisitor, null);
ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
verify(expVisitor).visit(propertyNameArgument.capture(), anyObject());
assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
expressionArgument.getValue().getExpression2().accept(expVisitor, null);
ArgumentCaptor<Literal> literalArgument = ArgumentCaptor.forClass(Literal.class);
verify(expVisitor).visit(literalArgument.capture(), anyObject());
assertEquals(date, ((Instant) literalArgument.getValue().getValue()).getPosition().getDate());
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class QueryRunnable method getResultComparator.
protected Comparator<Result> getResultComparator(Query query) {
Comparator<Result> sortComparator = new RelevanceResultComparator(SortOrder.DESCENDING);
SortBy sortBy = query.getSortBy();
if (sortBy != null && sortBy.getPropertyName() != null) {
PropertyName sortingProp = sortBy.getPropertyName();
String sortType = sortingProp.getPropertyName();
SortOrder sortOrder = (sortBy.getSortOrder() == null) ? SortOrder.DESCENDING : sortBy.getSortOrder();
// Temporal searches are currently sorted by the effective time
if (Metacard.EFFECTIVE.equals(sortType) || Result.TEMPORAL.equals(sortType)) {
sortComparator = new TemporalResultComparator(sortOrder);
} else if (Metacard.CREATED.equals(sortType) || Metacard.MODIFIED.equals(sortType)) {
sortComparator = new TemporalResultComparator(sortOrder, sortType);
} else if (Result.DISTANCE.equals(sortType)) {
sortComparator = new DistanceResultComparator(sortOrder);
} else if (Result.RELEVANCE.equals(sortType)) {
sortComparator = new RelevanceResultComparator(sortOrder);
}
}
return sortComparator;
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testVisitWithMappedName.
@Test
public void testVisitWithMappedName() {
AttributeExpressionImpl propName = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, CswConstants.CSW_ALTERNATIVE, CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
CswRecordMapperFilterVisitor visitor = new CswRecordMapperFilterVisitor(metacardType, mockMetacardTypeList);
PropertyName propertyName = (PropertyName) visitor.visit(propName, null);
assertThat(propertyName.getPropertyName(), is(Core.TITLE));
assertThat(propertyName.getPropertyName(), not(is(CswConstants.CSW_ALTERNATIVE)));
}
Aggregations