Search in sources :

Example 1 with FilterDelegate

use of ddf.catalog.filter.FilterDelegate in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object delegate) {
    ExpressionValues filterValues = getExpressions(filter, delegate);
    String propertyName = filterValues.propertyName;
    Object literal = filterValues.literal;
    // Are property name and literal reversed?
    if (filter.getExpression1() instanceof Literal) {
        // convert literal >= property to property <= literal
        Filter lessThanOrEqual = FF.lessOrEqual(FF.property(propertyName), FF.literal(literal));
        return lessThanOrEqual.accept(this, delegate);
    }
    if (literal instanceof String) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (String) literal);
    } else if (literal instanceof Date) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (Date) literal);
    } else if (literal instanceof Integer) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Integer) literal).intValue());
    } else if (literal instanceof Short) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Short) literal).shortValue());
    } else if (literal instanceof Long) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Long) literal).longValue());
    } else if (literal instanceof Float) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Float) literal).floatValue());
    } else if (literal instanceof Double) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Double) literal).doubleValue());
    } else if (literal instanceof Boolean) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    } else if (literal instanceof byte[]) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    } else {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Date(java.util.Date) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal)

Example 2 with FilterDelegate

use of ddf.catalog.filter.FilterDelegate 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.");
    }
}
Also used : FuzzyFunction(ddf.catalog.impl.filter.FuzzyFunction) PropertyName(org.opengis.filter.expression.PropertyName) FilterDelegate(ddf.catalog.filter.FilterDelegate)

Example 3 with FilterDelegate

use of ddf.catalog.filter.FilterDelegate in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(During during, Object delegate) {
    ExpressionValues filterValues = getExpressions(during, delegate);
    // Absolute
    if (filterValues.literal instanceof Period) {
        Period period = (Period) filterValues.literal;
        Date start = period.getBeginning().getPosition().getDate();
        Date end = period.getEnding().getPosition().getDate();
        return ((FilterDelegate<?>) delegate).during(filterValues.propertyName, start, end);
    // Relative
    } else if (filterValues.literal instanceof DefaultPeriodDuration) {
        // TODO should support PeriodDuration and reconstruct the duration
        // instead of using an implementation to get the milliseconds
        DefaultPeriodDuration duration = (DefaultPeriodDuration) filterValues.literal;
        return ((FilterDelegate<?>) delegate).relative(filterValues.propertyName, duration.getTimeInMillis());
    } else {
        throw new UnsupportedOperationException("Unsupported implementation of Period or PeriodDuration for During filter.");
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Period(org.opengis.temporal.Period) Date(java.util.Date) DefaultPeriodDuration(org.geotools.temporal.object.DefaultPeriodDuration)

Example 4 with FilterDelegate

use of ddf.catalog.filter.FilterDelegate in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

@SuppressWarnings("unchecked")
public Object visit(Or filter, Object delegate) {
    List<Object> results = new ArrayList<>();
    List<Filter> childList = filter.getChildren();
    if (childList != null) {
        for (Filter child : childList) {
            results.add(child.accept(this, delegate));
        }
        if (results.size() > 0) {
            return ((FilterDelegate<Object>) delegate).or(results);
        }
    }
    // No children or the children returned 0 results
    throw new UnsupportedOperationException("No valid operands for And filter.");
}
Also used : IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) FilterDelegate(ddf.catalog.filter.FilterDelegate) ArrayList(java.util.ArrayList)

Example 5 with FilterDelegate

use of ddf.catalog.filter.FilterDelegate in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(PropertyIsGreaterThan filter, Object delegate) {
    ExpressionValues filterValues = getExpressions(filter, delegate);
    String propertyName = filterValues.propertyName;
    Object literal = filterValues.literal;
    // Are property name and literal reversed?
    if (filter.getExpression1() instanceof Literal) {
        // convert literal > property to property < literal
        Filter lessThan = FF.less(FF.property(propertyName), FF.literal(literal));
        return lessThan.accept(this, delegate);
    }
    if (literal instanceof String) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (String) literal);
    } else if (literal instanceof Date) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (Date) literal);
    } else if (literal instanceof Integer) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Integer) literal).intValue());
    } else if (literal instanceof Short) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Short) literal).shortValue());
    } else if (literal instanceof Long) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Long) literal).longValue());
    } else if (literal instanceof Float) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Float) literal).floatValue());
    } else if (literal instanceof Double) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Double) literal).doubleValue());
    } else if (literal instanceof Boolean) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    } else if (literal instanceof byte[]) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    } else {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Date(java.util.Date) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal)

Aggregations

FilterDelegate (ddf.catalog.filter.FilterDelegate)8 Date (java.util.Date)6 ExcludeFilter (org.opengis.filter.ExcludeFilter)5 Filter (org.opengis.filter.Filter)5 IncludeFilter (org.opengis.filter.IncludeFilter)5 Literal (org.opengis.filter.expression.Literal)4 Period (org.opengis.temporal.Period)2 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)1 ArrayList (java.util.ArrayList)1 DefaultPeriodDuration (org.geotools.temporal.object.DefaultPeriodDuration)1 PropertyName (org.opengis.filter.expression.PropertyName)1