Search in sources :

Example 31 with NameImpl

use of org.geotools.feature.NameImpl in project sldeditor by robward-scisys.

the class FunctionTableModelTest method testProcessBriefType.

/**
 * Test all the methods using a ProcessBriefType.
 *
 * <p>Not tested because it needs to interact with GeoServer to create a receive a remote custom
 * WPS function.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Disabled
@Test
void testProcessBriefType() {
    FunctionTableModel model = new FunctionTableModel();
    assertEquals(0, model.getRowCount());
    model.addNewValue(0);
    ProcessBriefType customFunction = createCustomFunction();
    FunctionName name = new FunctionNameImpl(new NameImpl("vec", "PointStacker"), parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(customFunction);
    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());
    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));
    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));
    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));
    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());
    assertEquals(2, model.getNoOfOccurences(value));
    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());
    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);
    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());
    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);
    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}
Also used : FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) NameImpl(org.geotools.feature.NameImpl) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) ProcessBriefType(net.opengis.wps10.ProcessBriefType) FilterFactory(org.opengis.filter.FilterFactory) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) Expression(org.opengis.filter.expression.Expression) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 32 with NameImpl

use of org.geotools.feature.NameImpl in project sldeditor by robward-scisys.

the class FunctionTableModelTest method testProcessFunction.

/**
 * Test all the methods using a ProcessFunction
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
void testProcessFunction() {
    FunctionTableModel model = new FunctionTableModel();
    assertEquals(0, model.getRowCount());
    model.addNewValue(0);
    ProcessFunction processFunction = createProcessFunction();
    FunctionName name = new FunctionNameImpl(new NameImpl("vec", "PointStacker"), parameter("cellSize", Double.class), new Parameter("outputBBOX", Number.class, null, null, false, 0, 100, null, null), parameter("outputWidth", Number.class), parameter("outputHeight", Number.class));
    assertFalse(name.getArguments().get(0).isRequired());
    assertTrue(name.getArguments().get(1).isRequired());
    model.populate(name, processFunction);
    assertEquals(3, model.getRowCount());
    assertEquals(4, model.getColumnCount());
    // Get value
    assertEquals("outputBBOX", model.getValueAt(0, 0));
    assertEquals(Number.class.getSimpleName(), model.getValueAt(0, 1));
    assertEquals(true, model.getValueAt(0, 2));
    assertEquals("env([wms_bbox])", model.getValueAt(0, 3));
    assertNull(model.getValueAt(0, 4));
    // Is editable
    assertFalse(model.isCellEditable(0, 0));
    assertFalse(model.isCellEditable(0, 1));
    assertTrue(model.isCellEditable(0, FunctionTableModel.getOptionalColumn()));
    assertFalse(model.isCellEditable(0, 3));
    assertFalse(model.isCellEditable(0, 4));
    // Set value
    model.setValueAt(true, 0, 2);
    assertTrue((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    model.setValueAt(false, 0, 2);
    assertFalse((Boolean) model.getValueAt(0, FunctionTableModel.getOptionalColumn()));
    // Get row
    assertNull(model.getValue(-1));
    assertNull(model.getValue(10));
    // Add a new value
    assertEquals(0, model.getNoOfOccurences(null));
    ProcessFunctionParameterValue value = model.getValue(0);
    assertEquals(1, model.getNoOfOccurences(value));
    model.addNewValue(0);
    assertEquals(4, model.getRowCount());
    assertEquals(2, model.getNoOfOccurences(value));
    // Remove value
    model.removeValue(3);
    assertEquals(3, model.getRowCount());
    // Get expression
    ProcessFunction actualFunction = model.getExpression(null);
    assertNull(actualFunction);
    model.setValueAt(true, 0, FunctionTableModel.getOptionalColumn());
    ProcessFunctionFactory factory = new ProcessFunctionFactory();
    actualFunction = model.getExpression(factory);
    assertNotNull(actualFunction);
    // Update expression
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    Expression expression = ff.literal(4.2);
    model.update(expression, 0);
    model.update(null, 1);
}
Also used : ProcessFunction(org.geotools.process.function.ProcessFunction) FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) NameImpl(org.geotools.feature.NameImpl) Expression(org.opengis.filter.expression.Expression) ProcessFunctionParameterValue(com.sldeditor.rendertransformation.ProcessFunctionParameterValue) Parameter(org.geotools.data.Parameter) FunctionNameImpl(org.geotools.filter.capability.FunctionNameImpl) ProcessFunctionFactory(org.geotools.process.function.ProcessFunctionFactory) FilterFactory(org.opengis.filter.FilterFactory) FunctionTableModel(com.sldeditor.rendertransformation.FunctionTableModel) Test(org.junit.jupiter.api.Test)

Example 33 with NameImpl

use of org.geotools.feature.NameImpl in project sldeditor by robward-scisys.

the class DataSourceInfo method getPropertyDescriptorList.

/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();
                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type = featureTypeFactory.createGeometryType(new NameImpl(RASTER_GEOMETRY_FIELD), GridCoverage2D.class, crs, isIdentifiable, isAbstract, restrictions, superType, description);
                GeometryDescriptor descriptor = featureTypeFactory.createGeometryDescriptor(type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);
                rasterPropertyDescriptorList.add(descriptor);
            }
            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) NameImpl(org.geotools.feature.NameImpl) GeometryDescriptor(org.opengis.feature.type.GeometryDescriptor) Filter(org.opengis.filter.Filter) InternationalString(org.opengis.util.InternationalString) AttributeType(org.opengis.feature.type.AttributeType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 34 with NameImpl

use of org.geotools.feature.NameImpl 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)

Aggregations

NameImpl (org.geotools.feature.NameImpl)34 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)13 QName (javax.xml.namespace.QName)9 Test (org.junit.Test)7 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)6 Expression (org.opengis.filter.expression.Expression)6 PropertyName (org.opengis.filter.expression.PropertyName)6 IOException (java.io.IOException)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 DataStore (org.geotools.data.DataStore)4 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)4 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)4 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 Name (org.opengis.feature.type.Name)4 Color (java.awt.Color)3 SimpleFeatureTypeImpl (org.geotools.feature.simple.SimpleFeatureTypeImpl)3 Test (org.junit.jupiter.api.Test)3 ObjectId (org.locationtech.geogig.api.ObjectId)3 TYPE (org.locationtech.geogig.api.RevObject.TYPE)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3