Search in sources :

Example 1 with AttributeType

use of ddf.catalog.data.AttributeType in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsGreaterThan filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since Solr Provider doesn't support greater on temporal  (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // also not supported by provider (DDF-311)
        //TODO: work around 1: return getFactory(extraData).after(expr1, expr2);
        Object val = null;
        Expression other = null;
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }
        if (val != null) {
            Date orig = (Date) val;
            orig.setTime(orig.getTime() + 1);
            Instant start = new DefaultInstant(new DefaultPosition(orig));
            Instant end = new DefaultInstant(new DefaultPosition(new Date()));
            DefaultPeriod period = new DefaultPeriod(start, end);
            Literal literal = getFactory(extraData).literal(period);
            return getFactory(extraData).during(other, literal);
        }
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).greater(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Date(java.util.Date)

Example 2 with AttributeType

use of ddf.catalog.data.AttributeType in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsBetween filter, Object extraData) {
    Expression expr = visit(filter.getExpression(), extraData);
    AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression()).getPropertyName());
    LiteralExpressionImpl typedLowerExpression = (LiteralExpressionImpl) filter.getLowerBoundary();
    setExpressionType(type, typedLowerExpression);
    LiteralExpressionImpl typedUpperExpression = (LiteralExpressionImpl) filter.getUpperBoundary();
    setExpressionType(type, typedUpperExpression);
    Expression lower = visit((Expression) typedLowerExpression, expr);
    Expression upper = visit((Expression) typedUpperExpression, expr);
    return getFactory(extraData).between(expr, lower, upper);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 3 with AttributeType

use of ddf.catalog.data.AttributeType in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since Solr Provider doesn't support greaterOrEqual on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // also not supported by provider (DDF-311)
        //TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
        //After after = getFactory(extraData).after(expr1, expr2);
        //return getFactory(extraData).or(tEquals, after);
        Object val = null;
        Expression other = null;
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }
        if (val != null) {
            Date orig = (Date) val;
            Instant start = new DefaultInstant(new DefaultPosition(orig));
            Instant end = new DefaultInstant(new DefaultPosition(new Date()));
            DefaultPeriod period = new DefaultPeriod(start, end);
            Literal literal = getFactory(extraData).literal(period);
            return getFactory(extraData).during(other, literal);
        }
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).greaterOrEqual(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Instant(org.opengis.temporal.Instant) DefaultPosition(org.geotools.temporal.object.DefaultPosition) DefaultInstant(org.geotools.temporal.object.DefaultInstant) Date(java.util.Date)

Example 4 with AttributeType

use of ddf.catalog.data.AttributeType in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsEqualTo filter, Object extraData) {
    if (StringUtils.equals(Core.SOURCE_ID, ((PropertyName) filter.getExpression1()).getPropertyName())) {
        sourceIds.add((String) ((Literal) filter.getExpression2()).getValue());
        return null;
    }
    AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
    LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
    setExpressionType(type, typedExpression);
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit((Expression) typedExpression, expr1);
    return getFactory(extraData).equal(expr1, expr2, filter.isMatchingCase());
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal)

Example 5 with AttributeType

use of ddf.catalog.data.AttributeType in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsLessThan filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since solr provider doesn't support lessthan on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        return getFactory(extraData).before(expr1, expr2);
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).less(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Aggregations

AttributeType (ddf.catalog.data.AttributeType)9 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)7 Expression (org.opengis.filter.expression.Expression)7 Literal (org.opengis.filter.expression.Literal)4 Date (java.util.Date)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)2 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)2 DefaultPosition (org.geotools.temporal.object.DefaultPosition)2 Instant (org.opengis.temporal.Instant)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Instant (java.time.Instant)1 Calendar (java.util.Calendar)1 Nullable (javax.annotation.Nullable)1