Search in sources :

Example 1 with DefaultFunctionFactory

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

the class FieldConfigBaseTest method testFunctionUpdated.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#functionUpdated(org.opengis.filter.expression.Expression)}.
 */
@Test
public void testFunctionUpdated() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);
    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    FunctionName functionName = null;
    for (FunctionName func : functionFactory.getFunctionNames()) {
        if (func.getName() == "greaterThan") {
            functionName = func;
            break;
        }
    }
    assertNotNull(functionName);
    Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
    field.functionUpdated(testExpression);
    assertTrue(listener.hasBeenCalled());
    assertEquals(ExpressionTypeEnum.E_FUNCTION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression.toString().startsWith(functionName.getName()));
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) Expression(org.opengis.filter.expression.Expression) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 2 with DefaultFunctionFactory

use of org.geotools.filter.function.DefaultFunctionFactory 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 3 with DefaultFunctionFactory

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

the class FieldConfigBaseTest method testPopulateExpressionExpression.

/**
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression)}.
 * Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigBase#populate(org.opengis.filter.expression.Expression, org.opengis.filter.expression.Expression)}.
 */
@Test
public void testPopulateExpressionExpression() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false));
    AttributeSelection attributeSelectionPanel = AttributeSelection.createAttributes(String.class, field, false);
    field.testAttributeSelectionPanel(attributeSelectionPanel);
    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);
    assertFalse(listener.hasBeenCalled());
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    // Test function
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    FunctionName functionName = null;
    for (FunctionName func : functionFactory.getFunctionNames()) {
        if (func.getName() == "greaterThan") {
            functionName = func;
            break;
        }
    }
    assertNotNull(functionName);
    Expression testExpression = ff.function(functionName.getFunctionName(), ff.literal(1), ff.literal(2));
    field.populate(testExpression);
    // Updated because the attribute pulldown changed
    assertTrue(listener.hasBeenCalled());
    assertEquals(ExpressionTypeEnum.E_EXPRESSION, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression.toString().startsWith(functionName.getName()));
    // Attribute expression wrapped in a literal expression
    String testAttributeName = "test attribute";
    NameImpl name = new NameImpl(testAttributeName);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl(name);
    Expression literalExpression = ff.literal(attributeExpression);
    field.populate(literalExpression);
    assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
// Process Function
// ProcessFunctionFactory factory = new ProcessFunctionFactory();
// FunctionTableModel functionParameterTableModel = new FunctionTableModel();
// ProcessFunction processFunction = functionParameterTableModel.getExpression(factory);
// field.populate(processFunction);
// assertEquals(ExpressionTypeEnum.E_VALUE, field.getExpressionType());
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) NameImpl(org.geotools.feature.NameImpl) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) AttributeSelection(com.sldeditor.ui.attribute.AttributeSelection) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.Test)

Example 4 with DefaultFunctionFactory

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

the class FilterManagerTest method testConvertParameters.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FilterManager#convertParameters(java.lang.Class, com.sldeditor.ui.detail.config.FieldId, org.opengis.filter.capability.FunctionName)}.
 */
@Test
public void testConvertParameters() {
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    List<FunctionName> functionNameList = functionFactory.getFunctionNames();
    // Try with empty parameters
    Class<?> panelId = null;
    List<GroupConfigInterface> list = FilterManager.getInstance().convertParameters(panelId, null);
    assertTrue(list.isEmpty());
    // Find a known function
    for (FunctionName functionName : functionNameList) {
        list = FilterManager.getInstance().convertParameters(panelId, functionName);
        System.out.println(functionName.getName());
        assertEquals(1, list.size());
        GroupConfig groupConfig = (GroupConfig) list.get(0);
        List<FieldConfigBase> fieldList = groupConfig.getFieldConfigList();
        assertEquals(functionName.getName(), fieldList.size(), Math.abs(functionName.getArgumentCount()));
        List<String> argList = new ArrayList<String>();
        for (int fieldIndex = 0; fieldIndex < fieldList.size(); fieldIndex++) {
            checkFieldType(fieldIndex, fieldList, functionName, argList);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(functionName.getName());
        sb.append("(");
        for (int index = 0; index < argList.size(); index++) {
            if (index > 0) {
                sb.append(", ");
            }
            sb.append(argList.get(index));
        }
        sb.append(")");
        String prototype = groupConfig.getLabel();
        assertNotNull(functionName.getName(), prototype);
        assertNotNull(functionName.getName(), sb.toString());
        assertTrue(prototype.compareTo(sb.toString()) == 0);
    }
}
Also used : FieldConfigBase(com.sldeditor.ui.detail.config.FieldConfigBase) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FunctionName(org.opengis.filter.capability.FunctionName) GroupConfig(com.sldeditor.ui.detail.config.base.GroupConfig) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) Test(org.junit.Test)

Example 5 with DefaultFunctionFactory

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

the class FilterManagerTest method testCreateExpression.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FilterManager#createExpression(org.opengis.filter.capability.FunctionName)}.
 */
@Test
public void testCreateExpression() {
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    List<FunctionName> functionNameList = functionFactory.getFunctionNames();
    FunctionName functionName = null;
    Expression expression = FilterManager.getInstance().createExpression(functionName);
    assertNull(expression);
    functionName = functionNameList.get(0);
    expression = FilterManager.getInstance().createExpression(functionName);
    assertNotNull(expression);
    FunctionExpression funcExpression = (FunctionExpression) expression;
    assertTrue(functionName.getName().compareTo(funcExpression.getName()) == 0);
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionExpression(org.geotools.filter.FunctionExpression) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) FunctionExpression(org.geotools.filter.FunctionExpression) Expression(org.opengis.filter.expression.Expression) Test(org.junit.Test)

Aggregations

DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)7 Test (org.junit.Test)7 FunctionName (org.opengis.filter.capability.FunctionName)6 Expression (org.opengis.filter.expression.Expression)5 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)3 ArrayList (java.util.ArrayList)3 FilterFactory (org.opengis.filter.FilterFactory)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 FunctionExpression (org.geotools.filter.FunctionExpression)2 ExpressionNode (com.sldeditor.filter.v2.expression.ExpressionNode)1 FunctionNameFilterAll (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll)1 FunctionNameFilterInterface (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface)1 AttributeSelection (com.sldeditor.ui.attribute.AttributeSelection)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 GroupConfig (com.sldeditor.ui.detail.config.base.GroupConfig)1 GroupConfigInterface (com.sldeditor.ui.detail.config.base.GroupConfigInterface)1 LineString (com.vividsolutions.jts.geom.LineString)1 NameImpl (org.geotools.feature.NameImpl)1 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)1