Search in sources :

Example 16 with FeatureAttributeDescriptor

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

the class TestWfsFilterDelegate method testSequentialPropertyIsNotOfTemporalType.

private void testSequentialPropertyIsNotOfTemporalType(String methName, Object... inputParams) throws Throwable {
    String mockMetacardAttribute = "myMetacardAttribute";
    String mockFeatureType = "myFeatureType";
    String mockFeatureProperty = "myFeatureProperty";
    List<String> mockProperties = new ArrayList<>(1);
    mockProperties.add(mockFeatureProperty);
    when(mockFeatureMetacardType.getProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getName()).thenReturn(mockFeatureType);
    List<String> mockTemporalProperties = Collections.emptyList();
    when(mockFeatureMetacardType.getTemporalProperties()).thenReturn(mockTemporalProperties);
    FeatureAttributeDescriptor mockFeatureAttributeDescriptor = mock(FeatureAttributeDescriptor.class);
    when(mockFeatureAttributeDescriptor.isIndexed()).thenReturn(true);
    when(mockFeatureAttributeDescriptor.getPropertyName()).thenReturn(mockFeatureProperty);
    when(mockFeatureMetacardType.getAttributeDescriptor(mockFeatureProperty)).thenReturn(mockFeatureAttributeDescriptor);
    MetacardMapper mockMapper = mock(MetacardMapper.class);
    when(mockMapper.getFeatureProperty(mockMetacardAttribute)).thenReturn(mockFeatureProperty);
    WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
    try {
        // Inject the mockMetacardAttribute at the head of the array
        Object[] methParams = ObjectArrays.concat(mockMetacardAttribute, inputParams);
        // Generate the array of class types for the reflection call
        Class<?>[] classTypes = FluentIterable.from(Arrays.asList(methParams)).transform(new Function<Object, Class>() {

            @Override
            public Class<?> apply(Object o) {
                // Autoboxing is a small problem with reflection when trying to be too clever
                return (o instanceof Long) ? long.class : o.getClass();
            }
        }).toArray(Class.class);
        Method method = WfsFilterDelegate.class.getMethod(methName, classTypes);
        method.invoke(delegate, methParams);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Function(com.google.common.base.Function) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) BeforeClass(org.junit.BeforeClass) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 17 with FeatureAttributeDescriptor

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

the class WfsFilterDelegate method buildGeospatialFilterType.

private FilterType buildGeospatialFilterType(String spatialOpType, String propertyName, String wkt, Double distance) {
    FilterType returnFilter = new FilterType();
    if (Metacard.ANY_GEO.equals(propertyName)) {
        if (CollectionUtils.isEmpty(featureMetacardType.getGmlProperties())) {
            LOGGER.debug("Feature Type does not have GEO properties to query");
            return null;
        }
        if (featureMetacardType.getGmlProperties().size() == 1) {
            FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(featureMetacardType.getGmlProperties().get(0));
            if (attrDesc != null && attrDesc.isIndexed()) {
                returnFilter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
            } else {
                LOGGER.debug("All GEO properties have been blacklisted. Removing from query");
                return null;
            }
        } else {
            List<FilterType> filtersToBeOred = new ArrayList<FilterType>();
            for (String property : featureMetacardType.getGmlProperties()) {
                FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(property);
                if (attrDesc != null && attrDesc.isIndexed()) {
                    FilterType filter = new FilterType();
                    filter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
                    filtersToBeOred.add(filter);
                } else {
                    LOGGER.debug(String.format(PROPERTY_NOT_QUERYABLE, property));
                }
            }
            if (!filtersToBeOred.isEmpty()) {
                returnFilter = or(filtersToBeOred);
            } else {
                LOGGER.debug("All GEO properties have been blacklisted. Removing from query.");
                returnFilter = null;
            }
        }
    } else if (featureMetacardType.getGmlProperties().contains(propertyName)) {
        FeatureAttributeDescriptor attrDesc = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
        if (attrDesc != null && attrDesc.isIndexed()) {
            FilterType filter = new FilterType();
            filter.setSpatialOps(createSpatialOpType(spatialOpType, attrDesc.getPropertyName(), wkt, distance));
            return filter;
        } else {
            // blacklisted property encountered
            throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
        }
    } 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