Search in sources :

Example 6 with FeatureAttributeDescriptor

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor in project ddf by codice.

the class TestWfsFilterDelegate method intersectsMultiple.

private void intersectsMultiple(boolean indexed) {
    List<String> gmlProps = new ArrayList<>();
    gmlProps.add(MOCK_GEOM);
    gmlProps.add(MOCK_GEOM2);
    when(mockFeatureMetacardType.getGmlProperties()).thenReturn(gmlProps);
    for (String gmlProp : gmlProps) {
        when(mockFeatureMetacardType.getAttributeDescriptor(gmlProp)).thenReturn(new FeatureAttributeDescriptor(gmlProp, gmlProp, indexed, false, false, false, BasicTypes.STRING_TYPE));
    }
    SpatialOperatorType operator = new SpatialOperatorType();
    operator.setName(SPATIAL_OPERATORS.Intersects.toString());
    FilterCapabilities capabilities = MockWfsServer.getFilterCapabilities();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().clear();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().add(operator);
    WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, capabilities, GeospatialUtil.EPSG_4326_URN, null, GeospatialUtil.LAT_LON_ORDER);
    FilterType filter = delegate.intersects(Metacard.ANY_GEO, POLYGON);
    if (indexed) {
        assertNotNull(filter);
        assertTrue(filter.isSetLogicOps());
        assertNotNull(filter.getLogicOps());
    } else {
        assertNull(filter);
    }
}
Also used : FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) FilterType(net.opengis.filter.v_2_0_0.FilterType) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) SpatialOperatorType(net.opengis.filter.v_2_0_0.SpatialOperatorType) ArrayList(java.util.ArrayList)

Example 7 with FeatureAttributeDescriptor

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor in project ddf by codice.

the class TestWfsFilterDelegate method setupFilterDelegate.

private WfsFilterDelegate setupFilterDelegate(String spatialOpType) {
    List<String> gmlProps = new ArrayList<>();
    gmlProps.add(MOCK_GEOM);
    when(mockFeatureMetacardType.getGmlProperties()).thenReturn(gmlProps);
    when(mockFeatureMetacardType.getAttributeDescriptor(MOCK_GEOM)).thenReturn(new FeatureAttributeDescriptor(MOCK_GEOM, MOCK_GEOM, true, false, false, false, BasicTypes.STRING_TYPE));
    SpatialOperatorType operator = new SpatialOperatorType();
    operator.setName(spatialOpType);
    FilterCapabilities capabilities = MockWfsServer.getFilterCapabilities();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().clear();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().add(operator);
    return new WfsFilterDelegate(mockFeatureMetacardType, capabilities, GeospatialUtil.EPSG_4326_URN, null, GeospatialUtil.LAT_LON_ORDER);
}
Also used : FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) SpatialOperatorType(net.opengis.filter.v_2_0_0.SpatialOperatorType) ArrayList(java.util.ArrayList)

Example 8 with FeatureAttributeDescriptor

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor in project ddf by codice.

the class TestWfsFilterDelegate method makeDelegateForLogicalSupportTests.

private WfsFilterDelegate makeDelegateForLogicalSupportTests() {
    String mockProperty = "myPropertyName";
    String mockType = "myType";
    List<String> mockProperties = new ArrayList<>(1);
    mockProperties.add(mockProperty);
    when(mockFeatureMetacardType.getProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getGmlProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getTextualProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getTemporalProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getName()).thenReturn(mockType);
    FeatureAttributeDescriptor mockFeatureAttributeDescriptor = mock(FeatureAttributeDescriptor.class);
    when(mockFeatureAttributeDescriptor.isIndexed()).thenReturn(true);
    when(mockFeatureAttributeDescriptor.getPropertyName()).thenReturn(mockProperty);
    when(mockFeatureMetacardType.getAttributeDescriptor(mockProperty)).thenReturn(mockFeatureAttributeDescriptor);
    FilterCapabilities filterCap = MockWfsServer.getFilterCapabilities();
    //Create new ScalarCapabiltiesType without Logical Operator support
    ScalarCapabilitiesType scalar = new ScalarCapabilitiesType();
    scalar.setComparisonOperators(new ComparisonOperatorsType());
    for (COMPARISON_OPERATORS compOp : COMPARISON_OPERATORS.values()) {
        ComparisonOperatorType operator = new ComparisonOperatorType();
        operator.setName(compOp.toString());
        scalar.getComparisonOperators().getComparisonOperator().add(operator);
    }
    filterCap.setScalarCapabilities(scalar);
    return new WfsFilterDelegate(mockFeatureMetacardType, filterCap, GeospatialUtil.EPSG_4326_URN, null, GeospatialUtil.LAT_LON_ORDER);
}
Also used : FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) ComparisonOperatorsType(net.opengis.filter.v_2_0_0.ComparisonOperatorsType) ScalarCapabilitiesType(net.opengis.filter.v_2_0_0.ScalarCapabilitiesType) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) ArrayList(java.util.ArrayList) ComparisonOperatorType(net.opengis.filter.v_2_0_0.ComparisonOperatorType) COMPARISON_OPERATORS(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20Constants.COMPARISON_OPERATORS)

Example 9 with FeatureAttributeDescriptor

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor in project ddf by codice.

the class TestWfsFilterDelegate method setupMockMetacardType.

private void setupMockMetacardType() {
    mockMetacardAttribute = "modified";
    mockFeatureType = "myFeatureType";
    mockFeatureProperty = "localpart.EXACT_COLLECT_DATE";
    List<String> mockProperties = new ArrayList<>(1);
    mockProperties.add(mockFeatureProperty);
    QName localName = new QName("EXACT_COLLECT_DATE", "localpart");
    when(mockFeatureMetacardType.getFeatureType()).thenReturn(localName);
    when(mockFeatureMetacardType.getProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getName()).thenReturn(mockFeatureType);
    when(mockFeatureMetacardType.getTemporalProperties()).thenReturn(mockProperties);
    FeatureAttributeDescriptor mockFeatureAttributeDescriptor = mock(FeatureAttributeDescriptor.class);
    when(mockFeatureAttributeDescriptor.isIndexed()).thenReturn(true);
    when(mockFeatureAttributeDescriptor.getPropertyName()).thenReturn("EXACT_COLLECT_DATE");
    when(mockFeatureMetacardType.getAttributeDescriptor(mockFeatureProperty)).thenReturn(mockFeatureAttributeDescriptor);
    mockMapper = mock(MetacardMapper.class);
    when(mockMapper.getFeatureProperty(mockMetacardAttribute)).thenReturn(mockFeatureProperty);
}
Also used : QName(javax.xml.namespace.QName) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) ArrayList(java.util.ArrayList) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 10 with FeatureAttributeDescriptor

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor in project ddf by codice.

the class WfsFilterDelegate method buildPropertyIsFilterType.

private FilterType buildPropertyIsFilterType(String propertyName, Object literal, PROPERTY_IS_OPS propertyIsType) {
    if (!isValidInputParameters(propertyName, literal)) {
        throw new IllegalArgumentException(MISSING_PARAMETERS_MSG);
    }
    FilterType returnFilter = new FilterType();
    // If this is a Content Type filter verify its for this Filter delegate.
    if (Metacard.CONTENT_TYPE.equals(propertyName)) {
        if (featureMetacardType.getName().equals(literal)) {
            return returnFilter;
        }
        return null;
    }
    // series of OR's
    if ((Metacard.ANY_TEXT.equalsIgnoreCase(propertyName))) {
        if (CollectionUtils.isEmpty(featureMetacardType.getTextualProperties())) {
            LOGGER.debug("Feature Type does not have Textual Properties to query.");
            return null;
        }
        if (featureMetacardType.getTextualProperties().size() == 1) {
            FeatureAttributeDescriptor attrDescriptor = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(featureMetacardType.getTextualProperties().get(0));
            if (attrDescriptor.isIndexed()) {
                returnFilter.setComparisonOps(createPropertyIsFilter(attrDescriptor.getPropertyName(), literal, propertyIsType));
            } else {
                LOGGER.debug("All textual properties have been blacklisted.  Removing from query.");
                return null;
            }
        } else {
            List<FilterType> binaryCompOpsToBeOred = new ArrayList<FilterType>();
            for (String property : featureMetacardType.getTextualProperties()) {
                // only build filters for queryable properties
                FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(property);
                if (attrDesc.isIndexed()) {
                    FilterType filter = new FilterType();
                    filter.setComparisonOps(createPropertyIsFilter(attrDesc.getPropertyName(), literal, propertyIsType));
                    binaryCompOpsToBeOred.add(filter);
                } else {
                    LOGGER.debug(String.format(PROPERTY_NOT_QUERYABLE, property));
                }
            }
            if (!binaryCompOpsToBeOred.isEmpty()) {
                returnFilter = or(binaryCompOpsToBeOred);
            } else {
                LOGGER.debug("All textual properties have been blacklisted.  Removing from query.");
                return null;
            }
        }
    // filter is for a specific property; check to see if it is valid
    } else if (featureMetacardType.getProperties().contains(propertyName)) {
        FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
        if (attrDesc.isIndexed()) {
            returnFilter.setComparisonOps(createPropertyIsFilter(attrDesc.getPropertyName(), literal, propertyIsType));
        } else {
            // blacklisted property encountered
            throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
        }
    } else if (Metacard.ID.equals(propertyName)) {
        LOGGER.debug("feature id query for : {}", literal);
        String[] idTokens = literal.toString().split("\\.");
        if (idTokens.length > 1) {
            if (idTokens[0].equals(featureMetacardType.getName())) {
                LOGGER.debug("feature type matches metacard type; creating featureID filter");
                returnFilter.getFeatureId().add(createFeatureIdFilter(literal.toString()));
            } else {
                LOGGER.debug("feature type does not match metacard type; invalidating filter");
                return null;
            }
        } else {
            returnFilter.getFeatureId().add(createFeatureIdFilter(literal.toString()));
        }
    } else {
        return null;
    }
    return returnFilter;
}
Also used : FilterType(ogc.schema.opengis.filter.v_1_0_0.FilterType) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString)

Aggregations

FeatureAttributeDescriptor (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor)17 ArrayList (java.util.ArrayList)13 FilterType (net.opengis.filter.v_2_0_0.FilterType)9 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)6 SpatialOperatorType (net.opengis.filter.v_2_0_0.SpatialOperatorType)5 LineString (com.vividsolutions.jts.geom.LineString)4 QName (javax.xml.namespace.QName)4 Test (org.junit.Test)4 BinarySpatialOpType (net.opengis.filter.v_2_0_0.BinarySpatialOpType)3 TemporalOperand (net.opengis.filter.v_2_0_0.TemporalOperandsType.TemporalOperand)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 GeometryOperand (net.opengis.filter.v_2_0_0.GeometryOperandsType.GeometryOperand)2 FilterType (ogc.schema.opengis.filter.v_1_0_0.FilterType)2 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)2 Function (com.google.common.base.Function)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 ComparisonOperatorType (net.opengis.filter.v_2_0_0.ComparisonOperatorType)1 ComparisonOperatorsType (net.opengis.filter.v_2_0_0.ComparisonOperatorsType)1