Search in sources :

Example 46 with AttributeExpressionImpl

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

the class FieldConfigBaseTest method testAttributeUpdated.

/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigBase#attributeUpdated(java.lang.String)}.
 */
@Test
public void testAttributeUpdated() {
    FieldIdEnum expectedFieldId = FieldIdEnum.NAME;
    String expectedLabel = "test label";
    TestFieldConfigBase field = new TestFieldConfigBase(new FieldConfigCommonData(String.class, expectedFieldId, expectedLabel, false, false));
    TestUpdateSymbolInterface listener = new TestUpdateSymbolInterface();
    field.addDataChangedListener(listener);
    String attributeName = "test attribute";
    assertFalse(listener.hasBeenCalled());
    field.attributeUpdated(attributeName);
    assertTrue(listener.hasBeenCalled());
    assertEquals(ExpressionTypeEnum.E_ATTRIBUTE, field.getExpressionType());
    Expression expression = field.getExpression();
    assertTrue(expression instanceof AttributeExpressionImpl);
    assertTrue(attributeName.compareTo(expression.toString()) == 0);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) FieldIdEnum(com.sldeditor.common.xml.ui.FieldIdEnum) Test(org.junit.jupiter.api.Test)

Example 47 with AttributeExpressionImpl

use of org.geotools.filter.AttributeExpressionImpl 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, 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.jupiter.api.Test)

Example 48 with AttributeExpressionImpl

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

the class ExpressionPanelv2 method addExpression.

/**
 * Adds the expression.
 *
 * @param node the node
 * @return the expression
 */
private Expression addExpression(ExpressionNode node) {
    Expression localExpression = node.getExpression();
    if (localExpression instanceof LiteralExpressionImpl) {
        return localExpression;
    } else if (localExpression instanceof AttributeExpressionImpl) {
        return localExpression;
    } else if (localExpression instanceof FunctionExpressionImpl) {
        FunctionExpressionImpl functionExpression = (FunctionExpressionImpl) localExpression;
        List<Expression> parameterlist = new ArrayList<>();
        for (int childIndex = 0; childIndex < node.getChildCount(); childIndex++) {
            ExpressionNode childNode = (ExpressionNode) node.getChildAt(childIndex);
            parameterlist.add(addExpression(childNode));
        }
        functionExpression.setParameters(parameterlist);
        return functionExpression;
    } else if (localExpression instanceof MathExpressionImpl) {
        MathExpressionImpl mathExpression = (MathExpressionImpl) localExpression;
        ExpressionNode leftChildNode = (ExpressionNode) node.getChildAt(0);
        mathExpression.setExpression1(addExpression(leftChildNode));
        ExpressionNode rightChildNode = (ExpressionNode) node.getChildAt(1);
        mathExpression.setExpression2(addExpression(rightChildNode));
        return mathExpression;
    } else if (localExpression instanceof ConcatenateFunction) {
        ConcatenateFunction concatenateExpression = (ConcatenateFunction) localExpression;
        List<Expression> parameters = new ArrayList<>();
        for (int index = 0; index < node.getChildCount(); index++) {
            ExpressionNode expressionNode = (ExpressionNode) node.getChildAt(0);
            parameters.add(addExpression(expressionNode));
        }
        concatenateExpression.setParameters(parameters);
        return concatenateExpression;
    }
    return null;
}
Also used : MathExpressionImpl(org.geotools.filter.MathExpressionImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) ArrayList(java.util.ArrayList) ConcatenateFunction(org.geotools.filter.function.string.ConcatenateFunction) FunctionExpressionImpl(org.geotools.filter.FunctionExpressionImpl)

Example 49 with AttributeExpressionImpl

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

the class DataSourceAttributePanel method setAttribute.

/**
 * Sets the attribute.
 *
 * @param expression the new attribute
 */
public void setAttribute(Expression expression) {
    String propertyName = null;
    if (expression instanceof PropertyExistsFunction) {
        Expression e = ((PropertyExistsFunction) expression).getParameters().get(0);
        Object value = ((LiteralExpressionImpl) e).getValue();
        propertyName = ((AttributeExpressionImpl) value).getPropertyName();
    } else if (expression instanceof AttributeExpressionImpl) {
        propertyName = ((AttributeExpressionImpl) expression).getPropertyName();
    } else if (expression instanceof LiteralExpressionImpl) {
        propertyName = AttributeUtils.extract((String) ((LiteralExpressionImpl) expression).getValue());
    }
    if (propertyName != null) {
        oldValueObj = propertyName;
        attributeComboBox.setSelectedItem(propertyName);
    } else {
        oldValueObj = propertyName;
        attributeComboBox.setSelectedIndex(-1);
    }
}
Also used : PropertyExistsFunction(org.geotools.filter.function.PropertyExistsFunction) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 50 with AttributeExpressionImpl

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

the class FieldConfigColourTest method testGenerateExpression.

/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#generateExpression()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#populateExpression(java.lang.Object,
 * org.opengis.filter.expression.Expression)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#setTestValue(com.sldeditor.ui.detail.config.FieldId,
 * java.lang.String)}. Test method for {@link
 * com.sldeditor.ui.detail.config.FieldConfigColour#getColourExpression()}. Test method for
 * {@link com.sldeditor.ui.detail.config.FieldConfigColour#getColourOpacityExpression()}. Test
 * method for {@link com.sldeditor.ui.detail.config.FieldConfigColour#getStringValue()}.
 */
@Test
public void testGenerateExpression() {
    boolean valueOnly = true;
    class TestFieldConfigColour extends FieldConfigColour {

        public TestFieldConfigColour(FieldConfigCommonData commonData) {
            super(commonData);
        }

        public Expression callGenerateExpression() {
            return generateExpression();
        }
    }
    TestFieldConfigColour field = new TestFieldConfigColour(new FieldConfigCommonData(Geometry.class, FieldIdEnum.NAME, "label", valueOnly, false));
    Expression actualExpression = field.callGenerateExpression();
    assertNull(actualExpression);
    field.setTestValue(FieldIdEnum.UNKNOWN, (String) null);
    field.populateExpression(null);
    assertNull(field.getColourExpression());
    assertNull(field.getColourOpacityExpression());
    // Try string values - erroneous
    field.createUI();
    field.populateExpression("");
    String actualValue = field.getStringValue();
    assertTrue(actualValue.compareTo("#000000") == 0);
    String colour1 = "#123456";
    field.populateExpression(colour1);
    actualValue = field.getStringValue();
    assertTrue(colour1.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour1) == 0);
    String colour2 = "#AABBCC";
    field.setTestValue(FieldIdEnum.UNKNOWN, colour2);
    actualValue = field.getStringValue();
    assertTrue(colour2.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour2) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    LiteralExpressionImpl literal = (LiteralExpressionImpl) actualExpression;
    double opacity = (Double) literal.getValue();
    double expectedOpacity = 1.0;
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.0001);
    // Try using FieldConfigBase.populate(colour expression, opacity)
    String colour3 = "#001122";
    expectedOpacity = DefaultSymbols.defaultColourOpacity();
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    field.populate(ff.literal(colour3));
    actualValue = field.getStringValue();
    assertTrue(colour3.compareTo(actualValue) == 0);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(colour3) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression instanceof LiteralExpressionImpl);
    literal = (LiteralExpressionImpl) actualExpression;
    opacity = (Double) literal.getValue();
    assertTrue(Math.abs(opacity - expectedOpacity) < 0.1);
    AttributeExpressionImpl attributeExpression = new AttributeExpressionImpl("colour");
    field.populate(attributeExpression);
    actualExpression = field.getColourExpression();
    assertTrue(actualExpression instanceof AttributeExpressionImpl);
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
    actualExpression = field.getColourOpacityExpression();
    assertTrue(actualExpression.toString().compareTo(attributeExpression.toString()) == 0);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) FieldConfigCommonData(com.sldeditor.ui.detail.config.FieldConfigCommonData) FieldConfigColour(com.sldeditor.ui.detail.config.FieldConfigColour) FilterFactory(org.opengis.filter.FilterFactory) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)50 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)20 Expression (org.opengis.filter.expression.Expression)19 NameImpl (org.geotools.feature.NameImpl)13 Test (org.junit.Test)10 PropertyName (org.opengis.filter.expression.PropertyName)10 LikeFilterImpl (org.geotools.filter.LikeFilterImpl)9 ArrayList (java.util.ArrayList)8 QName (javax.xml.namespace.QName)8 FunctionExpressionImpl (org.geotools.filter.FunctionExpressionImpl)7 MathExpressionImpl (org.geotools.filter.MathExpressionImpl)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)5 HashMap (java.util.HashMap)4 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)3 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)3 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 Date (java.util.Date)3 FunctionExpression (org.geotools.filter.FunctionExpression)3