Search in sources :

Example 1 with FunctionImpl

use of org.geotools.filter.FunctionImpl in project ddf by codice.

the class FilterAdapterTest method testProximityFilterNoParameters.

@Test(expected = IllegalArgumentException.class)
public void testProximityFilterNoParameters() {
    FunctionImpl function = new FunctionImpl();
    function.setName("proximity");
    assertFilterEquals("proximity(Test,1,property)=true", FF.equals(function, FF.literal(true)));
}
Also used : FunctionImpl(org.geotools.filter.FunctionImpl) Test(org.junit.Test)

Example 2 with FunctionImpl

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

Example 3 with FunctionImpl

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

the class FunctionField method getExpression.

/**
 * Gets the expression.
 *
 * @return the expression
 */
public Expression getExpression() {
    String functionNameString = (String) functionComboBox.getSelectedItem();
    FunctionName functionName = functionNameMap.get(functionNameString);
    Expression newExpression = functionNameMgr.createExpression(functionName);
    if (newExpression instanceof FunctionExpression) {
        FunctionExpression expression = (FunctionExpression) newExpression;
        if (expression != null) {
            List<Expression> params = new ArrayList<Expression>();
            boolean validSymbolFlag = (params.size() == functionName.getArgumentCount());
            if (validSymbolFlag) {
                expression.setParameters(params);
            }
        }
    } else if (newExpression instanceof FunctionImpl) {
        FunctionImpl expression = (FunctionImpl) newExpression;
        if (expression != null) {
        // List<Expression> params = new ArrayList<Expression>();
        // List<FieldConfigBase> functionFields = field.getFunctionFields();
        // if(functionFields != null)
        // {
        // for(FieldConfigBase functionField : functionFields)
        // {
        // Expression functionFieldExpression = functionField.getExpression();
        // 
        // if(functionFieldExpression != null)
        // {
        // params.add(functionFieldExpression);
        // }
        // }
        // }
        // 
        // boolean validSymbolFlag = (params.size() == functionName.getArgumentCount());
        // if(validSymbolFlag)
        // {
        // expression.setParameters(params);
        // }
        // 
        // String key = String.format("%s@%s", field.getClass().getName(),
        // Integer.toHexString(field.hashCode()));
        // SelectedSymbol.getInstance().setValidSymbol(key, validSymbolFlag);
        }
    }
    return newExpression;
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) FunctionExpression(org.geotools.filter.FunctionExpression) Expression(org.opengis.filter.expression.Expression) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList)

Example 4 with FunctionImpl

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

the class ExpressionNodeTest method testSetExpression.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.expression.ExpressionNode#setExpression(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testSetExpression() {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    ExpressionNode node = new ExpressionNode();
    // Test literal expression
    String expressionString = "Literalexpression";
    Expression literal = ff.literal(expressionString);
    node.setExpression(literal);
    String expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.literal") + " " + expressionString;
    String actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    String propertyName = "testproperty";
    Expression attribute = ff.property(propertyName);
    node.setExpression(attribute);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test attribute expression
    literal = ff.literal(ff.property(propertyName));
    node.setExpression(literal);
    expected = Localisation.getField(ExpressionPanelv2.class, "ExpressionPanelv2.attribute") + " [" + attribute + "]";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test math expression
    Expression maths = ff.multiply(ff.literal(6), ff.literal(7));
    node.setExpression(maths);
    expected = "*";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function
    FunctionImpl function = new ConcatenateFunction();
    List<Expression> params = new ArrayList<Expression>();
    params.add(ff.literal("world"));
    params.add(ff.literal("dog"));
    function.setParameters(params);
    node.setExpression(function);
    expected = "Concatenate([world], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test function expression
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    String name = "strConcat";
    List<Expression> parameters = new ArrayList<Expression>();
    parameters.add(ff.literal("cat"));
    parameters.add(ff.literal("dog"));
    Function functionExpression = functionFactory.function(name, parameters, null);
    node.setExpression(functionExpression);
    expected = "strConcat([cat], [dog])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
    // Test environment function
    EnvFunction envExpression = (EnvFunction) ff.function("env", ff.literal("foo"), ff.literal(0));
    node.setExpression(envExpression);
    expected = "env([foo], [0])";
    actual = node.toString();
    assertTrue(actual.compareTo(expected) == 0);
}
Also used : EnvFunction(org.geotools.filter.function.EnvFunction) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) Function(org.opengis.filter.expression.Function) EnvFunction(org.geotools.filter.function.EnvFunction) Expression(org.opengis.filter.expression.Expression) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) ExpressionNode(com.sldeditor.filter.v2.expression.ExpressionNode) FunctionImpl(org.geotools.filter.FunctionImpl) ArrayList(java.util.ArrayList) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 5 with FunctionImpl

use of org.geotools.filter.FunctionImpl in project ddf by codice.

the class FilterAdapterTest method testProximityFilter.

@Test
public void testProximityFilter() {
    FunctionImpl function = new FunctionImpl();
    function.setName("proximity");
    function.setParameters(Arrays.asList(TEST_PROPERTY, FF.literal(1), FF.literal("property")));
    assertFilterEquals("proximity(Test,1,property)=true", FF.equals(function, FF.literal(true)));
}
Also used : FunctionImpl(org.geotools.filter.FunctionImpl) Test(org.junit.Test)

Aggregations

FunctionImpl (org.geotools.filter.FunctionImpl)8 Expression (org.opengis.filter.expression.Expression)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 FunctionExpression (org.geotools.filter.FunctionExpression)2 EnvFunction (org.geotools.filter.function.EnvFunction)2 FunctionName (org.opengis.filter.capability.FunctionName)2 ExpressionNode (com.sldeditor.filter.v2.expression.ExpressionNode)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)1 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)1 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)1 ConcatenateFunction (org.geotools.filter.function.string.ConcatenateFunction)1 FilterFactory (org.opengis.filter.FilterFactory)1 Function (org.opengis.filter.expression.Function)1 Parameter (org.opengis.parameter.Parameter)1