Search in sources :

Example 1 with ProcessFunctionParameterValue

use of com.sldeditor.rendertransformation.ProcessFunctionParameterValue in project sldeditor by robward-scisys.

the class BuiltInProcessFunctionTest method testExtractParametersFunctionName.

/**
 * Test method for
 * {@link com.sldeditor.rendertransformation.BuiltInProcessFunction#extractParameters(org.opengis.filter.capability.FunctionName, org.geotools.process.function.ProcessFunction)}.
 */
@Test
public void testExtractParametersFunctionName() {
    BuiltInProcessFunction obj = new BuiltInProcessFunction();
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(null, null);
    assertTrue(valueList.isEmpty());
    ProcessFunctionFactory processFunctionFactory = new ProcessFunctionFactory();
    List<FunctionName> functionNameList = processFunctionFactory.getFunctionNames();
    for (FunctionName functionName : functionNameList) {
        valueList = obj.extractParameters(functionName, null);
        assertEquals(functionName.getArguments().size(), valueList.size());
        for (int index = 0; index < functionName.getArguments().size(); index++) {
            Parameter<?> expectedParameter = functionName.getArguments().get(index);
            ProcessFunctionParameterValue actualParameter = valueList.get(index);
            assertTrue(functionName.getName(), expectedParameter.getName().compareTo(actualParameter.name) == 0);
            assertEquals(functionName.getName(), expectedParameter.getType(), actualParameter.type);
            assertTrue(functionName.getName(), expectedParameter.getType().getSimpleName().compareTo(actualParameter.dataType) == 0);
            assertEquals(functionName.getName(), !expectedParameter.isRequired(), actualParameter.optional);
            assertEquals(functionName.getName(), expectedParameter.getMinOccurs(), actualParameter.minOccurences);
            assertEquals(functionName.getName(), expectedParameter.getMaxOccurs(), actualParameter.maxOccurences);
        }
    }
    System.out.println(String.format("Tested %d functions", functionNameList.size()));
}
Also used : BuiltInProcessFunction(com.sldeditor.rendertransformation.BuiltInProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) Test(org.junit.Test)

Example 2 with ProcessFunctionParameterValue

use of com.sldeditor.rendertransformation.ProcessFunctionParameterValue 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 3 with ProcessFunctionParameterValue

use of com.sldeditor.rendertransformation.ProcessFunctionParameterValue in project sldeditor by robward-scisys.

the class CustomProcessFunctionTest method createProcessDescriptionEnum.

/**
 * Test the process description enumeration values.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void createProcessDescriptionEnum() {
    ProcessDescriptionType process = Wps10FactoryImpl.init().createProcessDescriptionType();
    CodeType codeType = Ows11FactoryImpl.init().createCodeType();
    codeType.setValue("JTS:area");
    process.setIdentifier(codeType);
    InputDescriptionType inputDescription = Wps10FactoryImpl.init().createInputDescriptionType();
    CodeType codeType2 = Ows11FactoryImpl.init().createCodeType();
    codeType2.setValue("dummyParameter");
    inputDescription.setIdentifier(codeType2);
    inputDescription.setMinOccurs(BigInteger.valueOf(1));
    inputDescription.setMaxOccurs(BigInteger.valueOf(1));
    AllowedValuesType allowedValues = Ows11FactoryImpl.init().createAllowedValuesType();
    EList allowedValueList = allowedValues.getValue();
    ValueType item1 = Ows11FactoryImpl.init().createValueType();
    item1.setValue("item 1");
    allowedValueList.add(item1);
    ValueType item2 = Ows11FactoryImpl.init().createValueType();
    item2.setValue("item 2");
    allowedValueList.add(item2);
    ValueType item3 = Ows11FactoryImpl.init().createValueType();
    item1.setValue("item 3");
    allowedValueList.add(item3);
    LiteralInputType literal = Wps10FactoryImpl.init().createLiteralInputType();
    literal.setAllowedValues(allowedValues);
    inputDescription.setLiteralData(literal);
    DataInputsType dataInputs = Wps10FactoryImpl.init().createDataInputsType();
    EList dataInputList = dataInputs.getInput();
    dataInputList.add(inputDescription);
    process.setDataInputs(dataInputs);
    CustomProcessFunction obj = new CustomProcessFunction();
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(process);
    assertEquals(1, valueList.size());
    ProcessFunctionParameterValue value = valueList.get(0);
    assertEquals(1, value.minOccurences);
    assertEquals(1, value.maxOccurences);
}
Also used : InputDescriptionType(net.opengis.wps10.InputDescriptionType) EList(org.eclipse.emf.common.util.EList) ValueType(net.opengis.ows11.ValueType) AllowedValuesType(net.opengis.ows11.AllowedValuesType) ProcessDescriptionType(net.opengis.wps10.ProcessDescriptionType) DataInputsType(net.opengis.wps10.DataInputsType) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) CustomProcessFunction(com.sldeditor.rendertransformation.CustomProcessFunction) CodeType(net.opengis.ows11.CodeType) LiteralInputType(net.opengis.wps10.LiteralInputType) Test(org.junit.Test)

Example 4 with ProcessFunctionParameterValue

use of com.sldeditor.rendertransformation.ProcessFunctionParameterValue in project sldeditor by robward-scisys.

the class CustomProcessFunctionTest method createProcessDescriptionBBox.

/**
 * Test the process description boundaing box values.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void createProcessDescriptionBBox() {
    ProcessDescriptionType process = Wps10FactoryImpl.init().createProcessDescriptionType();
    CodeType codeType = Ows11FactoryImpl.init().createCodeType();
    codeType.setValue("JTS:area");
    process.setIdentifier(codeType);
    InputDescriptionType inputDescription = Wps10FactoryImpl.init().createInputDescriptionType();
    CodeType codeType2 = Ows11FactoryImpl.init().createCodeType();
    codeType2.setValue("dummyParameter");
    inputDescription.setIdentifier(codeType2);
    inputDescription.setMinOccurs(BigInteger.valueOf(1));
    inputDescription.setMaxOccurs(BigInteger.valueOf(1));
    DataInputsType dataInputs = Wps10FactoryImpl.init().createDataInputsType();
    EList dataInputList = dataInputs.getInput();
    dataInputList.add(inputDescription);
    process.setDataInputs(dataInputs);
    SupportedCRSsType crs = Wps10FactoryImpl.init().createSupportedCRSsType();
    inputDescription.setBoundingBoxData(crs);
    CustomProcessFunction obj = new CustomProcessFunction();
    List<ProcessFunctionParameterValue> valueList = obj.extractParameters(process);
    assertEquals(1, valueList.size());
    ProcessFunctionParameterValue value = valueList.get(0);
    assertEquals(1, value.minOccurences);
    assertEquals(1, value.maxOccurences);
    assertTrue(value.dataType.compareTo("BBOX") == 0);
    SupportedComplexDataInputType complex = Wps10FactoryImpl.init().createSupportedComplexDataInputType();
    inputDescription.setComplexData(complex);
    inputDescription.setBoundingBoxData(null);
    valueList = obj.extractParameters(process);
    assertEquals(1, valueList.size());
    value = valueList.get(0);
    assertEquals(1, value.minOccurences);
    assertEquals(1, value.maxOccurences);
    assertTrue(value.dataType.compareTo("Geometry") == 0);
}
Also used : InputDescriptionType(net.opengis.wps10.InputDescriptionType) EList(org.eclipse.emf.common.util.EList) SupportedCRSsType(net.opengis.wps10.SupportedCRSsType) ProcessDescriptionType(net.opengis.wps10.ProcessDescriptionType) DataInputsType(net.opengis.wps10.DataInputsType) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) CustomProcessFunction(com.sldeditor.rendertransformation.CustomProcessFunction) CodeType(net.opengis.ows11.CodeType) SupportedComplexDataInputType(net.opengis.wps10.SupportedComplexDataInputType) Test(org.junit.Test)

Example 5 with ProcessFunctionParameterValue

use of com.sldeditor.rendertransformation.ProcessFunctionParameterValue in project sldeditor by robward-scisys.

the class CustomProcessFunctionTest method testExtractParameters.

/**
 * Test method for
 * {@link com.sldeditor.rendertransformation.CustomProcessFunction#extractParameters(net.opengis.wps10.ProcessDescriptionType)}.
 */
@Test
public void testExtractParameters() {
    CustomProcessFunction obj = new CustomProcessFunction();
    obj.extractParameters(null);
    ProcessFunctionParameterValue value = createProcessDescription("xs:int", "1234", 0, 1);
    assertEquals("1234", value.objectValue.getExpression().toString());
    value = createProcessDescription("xs:boolean", "true", 1, 1);
    assertEquals("true", value.objectValue.getExpression().toString());
    value = createProcessDescription("xs:double", "3.141", 1, 2);
    assertTrue(Math.abs(Double.valueOf("3.141") - Double.valueOf(value.objectValue.getExpression().toString())) < 0.001);
    value = createProcessDescription("xs:float", "1.234", 0, 1);
    assertTrue(Math.abs(Float.valueOf("1.234") - Float.valueOf(value.objectValue.getExpression().toString())) < 0.001);
    value = createProcessDescription("xs:long", "9876", 1, 1);
    assertEquals("9876", value.objectValue.getExpression().toString());
    value = createProcessDescription("xs:xxx", "string", 1, 1);
    assertEquals("string", value.objectValue.getExpression().toString());
}
Also used : ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) CustomProcessFunction(com.sldeditor.rendertransformation.CustomProcessFunction) Test(org.junit.Test)

Aggregations

ProcessFunctionParameterValue (com.sldeditor.rendertransformation.ProcessFunctionParameterValue)7 Test (org.junit.Test)6 CustomProcessFunction (com.sldeditor.rendertransformation.CustomProcessFunction)4 CodeType (net.opengis.ows11.CodeType)3 DataInputsType (net.opengis.wps10.DataInputsType)3 InputDescriptionType (net.opengis.wps10.InputDescriptionType)3 ProcessDescriptionType (net.opengis.wps10.ProcessDescriptionType)3 EList (org.eclipse.emf.common.util.EList)3 BuiltInProcessFunction (com.sldeditor.rendertransformation.BuiltInProcessFunction)2 LiteralInputType (net.opengis.wps10.LiteralInputType)2 ProcessFunctionFactory (org.geotools.process.function.ProcessFunctionFactory)2 FunctionName (org.opengis.filter.capability.FunctionName)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 AllowedValuesType (net.opengis.ows11.AllowedValuesType)1 DomainMetadataType (net.opengis.ows11.DomainMetadataType)1 ValueType (net.opengis.ows11.ValueType)1