Search in sources :

Example 16 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class BuiltInProcessFunctionTest method testExtractParametersProcessFunction.

/**
 * Test method for
 * {@link com.sldeditor.rendertransformation.BuiltInProcessFunction#extractParameters(org.opengis.filter.capability.FunctionName, org.geotools.process.function.ProcessFunction)}.
 */
@Test
public void testExtractParametersProcessFunction() {
    BuiltInProcessFunction obj = new BuiltInProcessFunction();
    String testData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + "<StyledLayerDescriptor version=\"1.0.0\" xsi:schemaLocation=\"http://www.opengis.net/sld StyledLayerDescriptor.xsd\" xmlns=\"http://www.opengis.net/sld\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<ogc:Function name=\"vec:PointStacker\">" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>data</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>cellSize</ogc:Literal>" + "  <ogc:Literal>30</ogc:Literal>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputBBOX</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_bbox</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + "  <ogc:Literal>outputWidth</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_width</ogc:Literal>" + "  </ogc:Function>" + "</ogc:Function>" + "<ogc:Function name=\"parameter\">" + " <ogc:Literal>outputHeight</ogc:Literal>" + "  <ogc:Function name=\"env\">" + "        <ogc:Literal>wms_height</ogc:Literal>" + "  </ogc:Function>" + " </ogc:Function>" + "</ogc:Function>" + "</StyledLayerDescriptor>";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    ProcessFunction tx = null;
    try {
        builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(testData));
        Document doc = builder.parse(is);
        ExpressionDOMParser parser = new ExpressionDOMParser(CommonFactoryFinder.getFilterFactory2(null));
        tx = (ProcessFunction) parser.expression(doc.getDocumentElement().getFirstChild());
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(null, tx);
    assertTrue(valueList.isEmpty());
    ProcessFunctionFactory processFunctionFactory = new ProcessFunctionFactory();
    for (FunctionName functionName : processFunctionFactory.getFunctionNames()) {
        if (functionName.getName().compareTo("PointStacker") == 0) {
            valueList = obj.extractParameters(functionName, tx);
            assertEquals(functionName.getArguments().size(), valueList.size());
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) IOException(java.io.IOException) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) BuiltInProcessFunction(com.sldeditor.rendertransformation.BuiltInProcessFunction) ProcessFunction(org.geotools.process.function.ProcessFunction) BuiltInProcessFunction(com.sldeditor.rendertransformation.BuiltInProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ExpressionDOMParser(org.geotools.filter.ExpressionDOMParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 17 with FunctionName

use of org.opengis.filter.capability.FunctionName 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 18 with FunctionName

use of org.opengis.filter.capability.FunctionName 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)

Example 19 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class FunctionManagerTest method testGetFunctionNameList2.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
 * Testing FunctionNameFilterRaster
 */
@Test
public void testGetFunctionNameList2() {
    Class<?> returnType = FunctionManager.getInstance().getFunctionType(null);
    assertNull(returnType);
    List<FunctionName> functionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, null);
    FunctionName propertyFunction = null;
    FunctionName idFunction = null;
    FunctionName areaFunction = null;
    FunctionName ceilFunction = null;
    for (FunctionName functionName : functionNameList) {
        if (functionName.getName().compareTo("property") == 0) {
            propertyFunction = functionName;
        } else if (functionName.getName().compareTo("id") == 0) {
            idFunction = functionName;
        } else if (functionName.getName().compareTo("Area") == 0) {
            areaFunction = functionName;
        } else if (functionName.getName().compareTo("ceil") == 0) {
            ceilFunction = functionName;
        }
    }
    assertNotNull(propertyFunction);
    assertNotNull(areaFunction);
    assertNotNull(ceilFunction);
    assertNotNull(idFunction);
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    FunctionNameFilterRaster rasterFilter = new FunctionNameFilterRaster();
    rasterFilter.accept(null);
    functionNameFilterList.add(rasterFilter);
    List<FunctionName> rasterFunctionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, functionNameFilterList);
    assertFalse(rasterFunctionNameList.contains(propertyFunction));
    assertFalse(rasterFunctionNameList.contains(areaFunction));
    assertFalse(rasterFunctionNameList.contains(idFunction));
    assertTrue(rasterFunctionNameList.contains(ceilFunction));
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) ArrayList(java.util.ArrayList) FunctionNameFilterRaster(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster) Test(org.junit.Test)

Example 20 with FunctionName

use of org.opengis.filter.capability.FunctionName in project sldeditor by robward-scisys.

the class FunctionManagerTest method testGetFunctionNameList.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
 */
@Test
public void testGetFunctionNameList() {
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    List<FunctionName> functionNameList = functionFactory.getFunctionNames();
    // CHECKSTYLE:OFF
    Class<?>[] allowedNumberTypes = { Number.class, Double.class, Float.class, Integer.class, Long.class, Object.class };
    // CHECKSTYLE:ON
    List<Class<?>> allowedNumberTypesList = Arrays.asList(allowedNumberTypes);
    int count = 0;
    for (FunctionName functionName : functionNameList) {
        Class<?> type = functionName.getReturn().getType();
        if (allowedNumberTypesList.contains(type)) {
            count++;
        }
    }
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    functionNameFilterList.add(new FunctionNameFilterAll());
    List<FunctionName> actualList = FunctionManager.getInstance().getFunctionNameList(Number.class, functionNameFilterList);
    assertEquals(count, actualList.size());
    // Try with null
    actualList = FunctionManager.getInstance().getFunctionNameList(null, null);
    assertEquals(functionNameList.size(), actualList.size());
    // Try with non-matching class
    actualList = FunctionManager.getInstance().getFunctionNameList(FunctionManagerTest.class, functionNameFilterList);
    assertTrue(actualList.isEmpty());
}
Also used : FunctionNameFilterAll(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll) ArrayList(java.util.ArrayList) FunctionName(org.opengis.filter.capability.FunctionName) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) Test(org.junit.Test)

Aggregations

FunctionName (org.opengis.filter.capability.FunctionName)21 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 Expression (org.opengis.filter.expression.Expression)7 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)6 FunctionNameFilterInterface (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface)5 FunctionExpression (org.geotools.filter.FunctionExpression)5 FunctionNameFilterAll (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll)4 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)4 FieldConfigString (com.sldeditor.ui.detail.config.FieldConfigString)3 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)3 FieldIdEnum (com.sldeditor.common.xml.ui.FieldIdEnum)2 FunctionNameFilterRaster (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster)2 BuiltInProcessFunction (com.sldeditor.rendertransformation.BuiltInProcessFunction)2 ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 LineString (com.vividsolutions.jts.geom.LineString)2 Point (com.vividsolutions.jts.geom.Point)2 FunctionImpl (org.geotools.filter.FunctionImpl)2 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)2