Search in sources :

Example 1 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSearchByMultipleTypes.

@Test
public void testSearchByMultipleTypes() throws Exception {
    //Setup
    int pageSize = 10;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
    Filter filter0 = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "8");
    Filter filter1 = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "9");
    Filter filter2 = builder.attribute(Metacard.ANY_TEXT).is().like().text("*");
    Filter typeSearchFilters = builder.anyOf(filter0, filter1);
    QueryImpl query = new QueryImpl(builder.allOf(filter2, typeSearchFilters));
    query.setPageSize(pageSize);
    //Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    int numTypes = featureType.getAbstractQueryExpression().size();
    //Validate
    assertEquals(2, numTypes);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 2 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSortingAscendingNoFeaturePropertyMappingSortingSupported.

/**
     * Verify that the SortBy is NOT set.  In this case, there is no mapping for the incoming sort property of TEMPORAL so no SortBy should be set.
     * <p/>
     * <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
     * <ns5:GetFeature startIndex="1" count="1" service="WFS" version="2.0.0" xmlns:ns2="http://www.opengis.net/ows/1.1" xmlns="http://www.opengis.net/fes/2.0" xmlns:ns4="http://www.opengis.net/gml" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.opengis.net/wfs/2.0">
     * <ns5:Query typeNames="SampleFeature0" handle="SampleFeature0">
     * <Filter>
     * <PropertyIsLike wildCard="*" singleChar="?" escapeChar="!">
     * <Literal>*</Literal>
     * <ValueReference>title</ValueReference>
     * </PropertyIsLike>
     * </Filter>
     * </ns5:Query>
     * </ns5:GetFeature>
     */
@Test
public void testSortingAscendingNoFeaturePropertyMappingSortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 3 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testSortingAscendingSortingNotSupported.

/**
     * Verify that the SortBy is NOT set.  In this case, sorting is not supported in the capabilities.
     */
@Test
public void testSortingAscendingSortingNotSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
    final int pageSize = 1;
    // Set ImplementsSorting to FALSE (sorting not supported)
    FilterCapabilities mockCapabilitiesSortingNotSupported = MockWfsServer.getFilterCapabilities();
    ConformanceType conformance = mockCapabilitiesSortingNotSupported.getConformance();
    List<DomainType> domainTypes = conformance.getConstraint();
    for (DomainType domainType : domainTypes) {
        if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
            ValueType valueType = new ValueType();
            valueType.setValue("FALSE");
            domainType.setDefaultValue(valueType);
            break;
        }
    }
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, mockCapabilitiesSortingNotSupported, GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
    MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
    when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
    when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
    List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
    mappers.add(mockMetacardMapper);
    source.setMetacardToFeatureMapper(mappers);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    query.setSortBy(sortBy);
    // Perform Test
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    // Verify
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertFalse(queryType.isSetAbstractSortingClause());
}
Also used : ValueType(net.opengis.ows.v_1_1_0.ValueType) SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) FilterCapabilities(net.opengis.filter.v_2_0_0.FilterCapabilities) QueryImpl(ddf.catalog.operation.impl.QueryImpl) DomainType(net.opengis.ows.v_1_1_0.DomainType) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ConformanceType(net.opengis.filter.v_2_0_0.ConformanceType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 4 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class TestWfsSource method testPagingPageSizeNegative.

/**
     * Verify that, per DDF Query API Javadoc, if the startIndex is negative, the WfsSource throws
     * an UnsupportedQueryException.
     *
     * @throws WfsException,                     SecurityServiceException
     * @throws TransformerConfigurationException
     * @throws UnsupportedQueryException
     */
@Test(expected = UnsupportedQueryException.class)
public void testPagingPageSizeNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    //Setup
    int pageSize = -4;
    int startIndex = 0;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
    Filter filter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
    Query query = new QueryImpl(filter, startIndex, pageSize, null, false, 0);
    //Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 5 with GetFeatureType

use of ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType in project ddf by codice.

the class WfsSource method buildGetFeatureRequest.

protected GetFeatureType buildGetFeatureRequest(Query query) throws UnsupportedQueryException {
    List<ContentType> contentTypes = getContentTypesFromQuery(query);
    List<QueryType> queries = new ArrayList<QueryType>();
    for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
        if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
            QueryType wfsQuery = new QueryType();
            String typeName = null;
            if (StringUtils.isEmpty(filterDelegateEntry.getKey().getPrefix())) {
                typeName = filterDelegateEntry.getKey().getLocalPart();
            } else {
                typeName = filterDelegateEntry.getKey().getPrefix() + ":" + filterDelegateEntry.getKey().getLocalPart();
            }
            if (StringUtils.isNotBlank(srsName)) {
                wfsQuery.setSrsName(srsName);
            }
            wfsQuery.setTypeNames(Arrays.asList(typeName));
            wfsQuery.setHandle(filterDelegateEntry.getKey().getLocalPart());
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setAbstractSelectionClause(new net.opengis.filter.v_2_0_0.ObjectFactory().createFilter(filter));
                }
                if (!this.disableSorting) {
                    if (query.getSortBy() != null) {
                        SortOrder sortOrder = query.getSortBy().getSortOrder();
                        if (filterDelegateEntry.getValue().isSortingSupported() && filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
                            JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                            if (sortBy != null) {
                                LOGGER.debug("Sorting using sort order of [{}].", sortOrder.identifier());
                                wfsQuery.setAbstractSortingClause(sortBy);
                            }
                        } else if (filterDelegateEntry.getValue().isSortingSupported() && CollectionUtils.isEmpty(filterDelegateEntry.getValue().getAllowedSortOrders())) {
                            JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                            if (sortBy != null) {
                                LOGGER.debug("No sort orders defined in getCapabilities.  Attempting to sort using sort order of [{}].", sortOrder.identifier());
                                wfsQuery.setAbstractSortingClause(sortBy);
                            }
                        } else if (filterDelegateEntry.getValue().isSortingSupported() && !filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
                            LOGGER.debug("Unsupported sort order of [{}]. Supported sort orders are {}.", sortOrder, filterDelegateEntry.getValue().getAllowedSortOrders());
                        } else if (!filterDelegateEntry.getValue().isSortingSupported()) {
                            LOGGER.debug("Sorting is not supported.");
                        }
                    }
                } else {
                    LOGGER.debug("Sorting is disabled.");
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (queries != null && !queries.isEmpty()) {
        GetFeatureType getFeatureType = new GetFeatureType();
        int pageSize = query.getPageSize();
        if (pageSize < 0) {
            LOGGER.debug("Page size has a negative value");
            throw new UnsupportedQueryException("Unable to build query. Page size has a negative value.");
        }
        int startIndex = query.getStartIndex();
        if (startIndex < 0) {
            LOGGER.debug("Start index has a negative value");
            throw new UnsupportedQueryException("Unable to build query. Start index has a negative value.");
        } else if (startIndex != 0) {
            //Convert DDF index of 1 back to index of 0 for WFS 2.0
            startIndex = query.getStartIndex() - 1;
        } else {
            LOGGER.debug("Query already has a start index of 0");
        }
        getFeatureType.setCount(BigInteger.valueOf(query.getPageSize()));
        getFeatureType.setStartIndex(BigInteger.valueOf(startIndex));
        List<JAXBElement<?>> incomingQueries = getFeatureType.getAbstractQueryExpression();
        for (QueryType queryType : queries) {
            incomingQueries.add(new net.opengis.wfs.v_2_0_0.ObjectFactory().createQuery(queryType));
        }
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) SortOrder(org.opengis.filter.sort.SortOrder) SortByType(net.opengis.filter.v_2_0_0.SortByType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(net.opengis.filter.v_2_0_0.FilterType) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)30 Test (org.junit.Test)29 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)19 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)18 Filter (org.opengis.filter.Filter)18 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 ArrayList (java.util.ArrayList)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12 QueryType (net.opengis.wfs.v_2_0_0.QueryType)11 Matchers.containsString (org.hamcrest.Matchers.containsString)7 SortByImpl (ddf.catalog.filter.impl.SortByImpl)6 QName (javax.xml.namespace.QName)6 SortBy (org.opengis.filter.sort.SortBy)6 Query (ddf.catalog.operation.Query)5 PropertyIsLikeType (ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)5 Metacard (ddf.catalog.data.Metacard)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)4 JAXBElement (javax.xml.bind.JAXBElement)3 JAXBException (javax.xml.bind.JAXBException)3