Search in sources :

Example 1 with FeatureAttributeDescriptor

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

the class WfsFilterDelegate method buildAfterFilterType.

private FilterType buildAfterFilterType(String propertyName, String date) {
    TemporalOperand timeInstantTemporalOperand = new TemporalOperand();
    timeInstantTemporalOperand.setName(new QName(Wfs20Constants.GML_3_2_NAMESPACE, Wfs20Constants.TIME_INSTANT));
    if (!isTemporalOperandSupported(timeInstantTemporalOperand)) {
        throw new UnsupportedOperationException("Temporal Operand [" + timeInstantTemporalOperand.getName() + "] is not supported.");
    }
    if (!isValidInputParameters(propertyName, date)) {
        throw new IllegalArgumentException(MISSING_PARAMETERS_MSG);
    }
    if (!isPropertyTemporalType(propertyName)) {
        throw new IllegalArgumentException("Property [" + propertyName + "] is not of type " + timeInstantTemporalOperand.getName() + ".");
    }
    FilterType filter = filterObjectFactory.createFilterType();
    if (featureMetacardType.getProperties().contains(propertyName)) {
        FeatureAttributeDescriptor featureAttributeDescriptor = (FeatureAttributeDescriptor) featureMetacardType.getAttributeDescriptor(propertyName);
        if (featureAttributeDescriptor.isIndexed()) {
            filter.setTemporalOps(createAfter(featureAttributeDescriptor.getPropertyName(), featureMetacardType.getName(), date));
        } else {
            throw new IllegalArgumentException(String.format(PROPERTY_NOT_QUERYABLE, propertyName));
        }
    } else {
        return null;
    }
    if (!isTemporalOpSupported(TEMPORAL_OPERATORS.After)) {
        if (isTemporalOpSupported(TEMPORAL_OPERATORS.During)) {
            return buildDuringFilterType(propertyName, date, convertDateToIso8601Format(new Date()));
        }
    }
    return filter;
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) QName(javax.xml.namespace.QName) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) TemporalOperand(net.opengis.filter.v_2_0_0.TemporalOperandsType.TemporalOperand) Date(java.util.Date)

Example 2 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(net.opengis.filter.v_2_0_0.FilterType) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString)

Example 3 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 (Metacard.CONTENT_TYPE.equals(propertyName)) {
        return returnFilter;
    }
    // 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.getId().add(createFeatureIdFilter(literal.toString()));
            } else {
                LOGGER.debug("feature type does not match metacard type; invalidating filter");
                return null;
            }
        } else {
            returnFilter.getId().add(createFeatureIdFilter(literal.toString()));
        }
    } else {
        return null;
    }
    return returnFilter;
}
Also used : FilterType(net.opengis.filter.v_2_0_0.FilterType) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) ArrayList(java.util.ArrayList) LineString(com.vividsolutions.jts.geom.LineString)

Example 4 with FeatureAttributeDescriptor

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

the class TestWfsFilterDelegate method testIntersectsLonLat.

@Test
public void testIntersectsLonLat() throws SAXException, IOException, JAXBException {
    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(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.LON_LAT_ORDER);
    FilterType filter = delegate.intersects(Metacard.ANY_GEO, POLYGON);
    assertTrue(filter.getSpatialOps().getValue() instanceof BinarySpatialOpType);
    assertFalse(filter.isSetLogicOps());
    assertXMLEqual(MockWfsServer.getIntersectsLonLatXmlFilter(), getXmlFromMarshaller(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) BinarySpatialOpType(net.opengis.filter.v_2_0_0.BinarySpatialOpType) Test(org.junit.Test)

Example 5 with FeatureAttributeDescriptor

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

the class TestWfsFilterDelegate method testIntersectsWithEnvelopeLonLat.

@Test
public void testIntersectsWithEnvelopeLonLat() throws SAXException, IOException, JAXBException {
    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(SPATIAL_OPERATORS.Intersects.toString());
    FilterCapabilities capabilities = MockWfsServer.getFilterCapabilities();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().clear();
    capabilities.getSpatialCapabilities().getSpatialOperators().getSpatialOperator().add(operator);
    capabilities.getSpatialCapabilities().getGeometryOperands().getGeometryOperand().clear();
    GeometryOperand geoOperand = new GeometryOperand();
    geoOperand.setName(Wfs20Constants.ENVELOPE);
    capabilities.getSpatialCapabilities().getGeometryOperands().getGeometryOperand().add(geoOperand);
    WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, capabilities, GeospatialUtil.EPSG_4326_URN, null, GeospatialUtil.LON_LAT_ORDER);
    FilterType filter = delegate.intersects(Metacard.ANY_GEO, POLYGON);
    assertTrue(filter.getSpatialOps().getValue() instanceof BinarySpatialOpType);
    assertFalse(filter.isSetLogicOps());
    assertXMLEqual(MockWfsServer.getIntersectsWithEnvelopeLonLatXmlFilter(), getXmlFromMarshaller(filter));
}
Also used : GeometryOperand(net.opengis.filter.v_2_0_0.GeometryOperandsType.GeometryOperand) 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) BinarySpatialOpType(net.opengis.filter.v_2_0_0.BinarySpatialOpType) Test(org.junit.Test)

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