Search in sources :

Example 1 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl 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 LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.

the class FieldConfigPopulationTest method testExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.ui.detail.config.FieldId, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#populateField(com.sldeditor.common.xml.ui.FieldIdEnum, org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigPopulation#getExpression(com.sldeditor.common.xml.ui.FieldIdEnum)}.
 */
@Test
public void testExpression() {
    FieldIdEnum fieldId = FieldIdEnum.DESCRIPTION;
    GraphicPanelFieldManager fieldConfigManager = new GraphicPanelFieldManager(String.class);
    FieldConfigInteger intField = new FieldConfigInteger(new FieldConfigCommonData(Geometry.class, fieldId, "label", true));
    intField.createUI();
    fieldConfigManager.add(fieldId, intField);
    FieldConfigPopulation obj = new FieldConfigPopulation(fieldConfigManager);
    int expectedValue = 1256;
    StyleBuilder styleBuilder = new StyleBuilder();
    Expression expression = styleBuilder.literalExpression(expectedValue);
    obj.populateField(fieldId, expression);
    LiteralExpressionImpl actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
    assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
    actualValue = (LiteralExpressionImpl) obj.getExpression(fieldId);
    assertEquals(expectedValue, ((Integer) actualValue.getValue()).intValue());
    // This shouldn't work as it does not know about the field
    FieldIdEnum wrongFieldEnum = FieldIdEnum.ELSE_FILTER;
    obj.populateField(wrongFieldEnum, expression);
    assertNull(obj.getExpression(wrongFieldEnum));
    // Try with null
    obj.populateField(fieldId, null);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FieldConfigPopulation(com.sldeditor.ui.detail.config.FieldConfigPopulation) FieldConfigInteger(com.sldeditor.ui.detail.config.FieldConfigInteger) Expression(org.opengis.filter.expression.Expression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) StyleBuilder(org.geotools.styling.StyleBuilder) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) Test(org.junit.Test)

Example 5 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project sldeditor by robward-scisys.

the class ExpressionNode method setExpression.

/**
 * Sets the expression.
 *
 * @param expression the expression to set
 */
public void setExpression(Expression expression) {
    this.expression = expression;
    if (expression instanceof LiteralExpressionImpl) {
        Object value = ((LiteralExpressionImpl) expression).getValue();
        if (value instanceof AttributeExpressionImpl) {
            this.expression = (AttributeExpressionImpl) value;
        }
    }
    setDisplayString();
    this.removeAllChildren();
    if (this.expression instanceof EnvFunction) {
        EnvFunction envVarExpression = (EnvFunction) this.expression;
        ExpressionNode childNode = new ExpressionNode();
        childNode.setExpressionType(ExpressionTypeEnum.ENVVAR);
        Expression envVarLiteral = envVarExpression.getParameters().get(0);
        Class<?> dataType = Object.class;
        if (envMgr != null) {
            dataType = envMgr.getDataType(envVarLiteral);
        }
        childNode.setType(dataType);
        childNode.setName(Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.envVar"));
        childNode.setExpression(envVarLiteral);
        this.insert(childNode, this.getChildCount());
    } else if (this.expression instanceof FunctionExpression) {
        FunctionExpression functionExpression = (FunctionExpression) this.expression;
        FunctionName functionName = functionExpression.getFunctionName();
        TypeManager.getInstance().setDataType(functionName.getReturn().getType());
        int argCount = functionName.getArgumentCount();
        if (functionName.getArgumentCount() < 0) {
            argCount *= -1;
        }
        for (int index = 0; index < argCount; index++) {
            ExpressionNode childNode = new ExpressionNode();
            Parameter<?> parameter = functionName.getArguments().get(index);
            childNode.setType(parameter.getType());
            childNode.setName(parameter.getName());
            if (index < functionExpression.getParameters().size()) {
                childNode.setExpression(functionExpression.getParameters().get(index));
            }
            this.insert(childNode, this.getChildCount());
        }
    } else if (this.expression instanceof FunctionImpl) {
        FunctionImpl functionExpression = (FunctionImpl) this.expression;
        FunctionName functionName = functionExpression.getFunctionName();
        TypeManager.getInstance().setDataType(functionName.getReturn().getType());
        int maxArgument = Math.abs(functionName.getArgumentCount());
        for (int index = 0; index < maxArgument; index++) {
            ExpressionNode childNode = new ExpressionNode();
            Parameter<?> parameter = functionName.getArguments().get(0);
            childNode.setType(parameter.getType());
            childNode.setName(parameter.getName());
            if (index < functionExpression.getParameters().size()) {
                childNode.setExpression(functionExpression.getParameters().get(index));
            }
            this.insert(childNode, this.getChildCount());
        }
    } else if (expression instanceof MathExpressionImpl) {
        MathExpressionImpl mathsExpression = (MathExpressionImpl) expression;
        String expressionText = Localisation.getString(ExpressionPanelv2.class, "ExpressionPanelv2.expression");
        ExpressionNode childNode1 = new ExpressionNode();
        childNode1.setType(Number.class);
        childNode1.setName(expressionText + " 1");
        childNode1.setExpression(mathsExpression.getExpression1());
        this.insert(childNode1, this.getChildCount());
        ExpressionNode childNode2 = new ExpressionNode();
        childNode2.setType(Number.class);
        childNode2.setName(expressionText + " 2");
        childNode2.setExpression(mathsExpression.getExpression2());
        this.insert(childNode2, this.getChildCount());
    } else if (expression instanceof AttributeExpressionImpl) {
        @SuppressWarnings("unused") AttributeExpressionImpl property = (AttributeExpressionImpl) expression;
    // TypeManager.getInstance().setLiteralType(literal.getValue().getClass());
    } else if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
        if (literal.getValue() != null) {
            TypeManager.getInstance().setDataType(literal.getValue().getClass());
        }
    }
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) MathExpressionImpl(org.geotools.filter.MathExpressionImpl) FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) Expression(org.opengis.filter.expression.Expression) FunctionExpression(org.geotools.filter.FunctionExpression) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FunctionImpl(org.geotools.filter.FunctionImpl) Parameter(org.opengis.parameter.Parameter)

Aggregations

LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)57 Expression (org.opengis.filter.expression.Expression)35 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)19 AttributeType (ddf.catalog.data.AttributeType)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)6 MarkImpl (org.geotools.styling.MarkImpl)6 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)5 ArrayList (java.util.ArrayList)5 Geometry (com.vividsolutions.jts.geom.Geometry)4 Date (java.util.Date)4 ConstantExpression (org.geotools.filter.ConstantExpression)4 IsEqualsToImpl (org.geotools.filter.IsEqualsToImpl)4 Test (org.junit.Test)4 Literal (org.opengis.filter.expression.Literal)4 XMLFieldLiteralString (com.sldeditor.common.xml.ui.XMLFieldLiteralString)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 FunctionExpression (org.geotools.filter.FunctionExpression)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 GraphicPanelFieldManager (com.sldeditor.ui.detail.GraphicPanelFieldManager)2