Search in sources :

Example 66 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class WfsSourceTest method testSortingNoSortBySortingSupported.

@Test
public void testSortingNoSortBySortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 0);
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    // 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) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 67 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class WfsSourceTest method testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties.

@Test
public void testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties() throws Exception {
    final MetacardMapperImpl metacardMapper = new MetacardMapperImpl();
    metacardMapper.setFeatureType("{http://example.com}SampleFeature0");
    metacardMapper.setResourceUriMapping("title");
    metacardMappers.add(metacardMapper);
    final WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 1);
    final Filter filter = builder.attribute(Core.RESOURCE_URI).is().equalTo().text("anything");
    final Query query = new QueryImpl(filter);
    final QueryRequest queryRequest = new QueryRequestImpl(query);
    source.query(queryRequest);
    final ArgumentCaptor<GetFeatureType> getFeatureCaptor = ArgumentCaptor.forClass(GetFeatureType.class);
    verify(mockWfs).getFeature(getFeatureCaptor.capture());
    final GetFeatureType getFeatureType = getFeatureCaptor.getValue();
    final String getFeatureXml = marshal(getFeatureType);
    assertThat(getFeatureXml, hasXPath("/wfs:GetFeature/wfs:Query/ogc:Filter/ogc:PropertyIsEqualTo[ogc:ValueReference='title' and ogc:Literal='anything']").withNamespaceContext(NAMESPACE_CONTEXT));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) MetacardMapperImpl(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.impl.MetacardMapperImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 68 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class WfsSourceTest method testSrsNameProvided.

@Test
public void testSrsNameProvided() throws Exception {
    int pageSize = 10;
    WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 10, false);
    source.setSrsName(GeospatialUtil.EPSG_4326);
    Filter filter = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "0");
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(pageSize);
    // Execute
    GetFeatureType featureType = source.buildGetFeatureRequest(query);
    QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
    assertThat(queryType.getSrsName(), is(GeospatialUtil.EPSG_4326));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryType(net.opengis.wfs.v_2_0_0.QueryType) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 69 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class WfsSource method buildGetFeatureRequest.

private ExtendedGetFeatureType buildGetFeatureRequest(Query query, ResultTypeType resultType, BigInteger maxFeatures) throws UnsupportedQueryException {
    List<ContentType> contentTypes = getContentTypesFromQuery(query);
    List<QueryType> queries = new ArrayList<>();
    for (Entry<QName, WfsFilterDelegate> filterDelegateEntry : featureTypeFilters.entrySet()) {
        if (contentTypes.isEmpty() || isFeatureTypeInQuery(contentTypes, filterDelegateEntry.getKey().getLocalPart())) {
            QueryType wfsQuery = new QueryType();
            wfsQuery.setTypeName(Collections.singletonList(filterDelegateEntry.getKey()));
            if (StringUtils.isNotBlank(srsName)) {
                wfsQuery.setSrsName(srsName);
            }
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setFilter(filter);
                }
                if (!this.disableSorting && query.getSortBy() != null && query.getSortBy().getPropertyName() != null && query.getSortBy().getPropertyName().getPropertyName() != null) {
                    SortByType sortByType = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
                    if (sortByType != null && sortByType.getSortProperty() != null && sortByType.getSortProperty().size() > 0) {
                        LOGGER.debug("Sorting using sort property [{}] and sort order [{}].", sortByType.getSortProperty().get(0).getPropertyName(), sortByType.getSortProperty().get(0).getSortOrder());
                        wfsQuery.setSortBy(sortByType);
                    } else {
                        throw new UnsupportedQueryException("Source " + this.getId() + " does not support specified sort property " + query.getSortBy().getPropertyName().getPropertyName());
                    }
                } else {
                    LOGGER.debug("Sorting is disabled or sort not specified.");
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (!queries.isEmpty()) {
        ExtendedGetFeatureType getFeatureType = new ExtendedGetFeatureType();
        getFeatureType.setMaxFeatures(maxFeatures);
        getFeatureType.getQuery().addAll(queries);
        getFeatureType.setService(Wfs11Constants.WFS);
        getFeatureType.setVersion(Wfs11Constants.VERSION_1_1_0);
        getFeatureType.setResultType(resultType);
        if (supportsStartIndex && resultType.equals(ResultTypeType.RESULTS)) {
            // Convert DDF index of 1 back to index of 0 for WFS
            getFeatureType.setStartIndex(BigInteger.valueOf(query.getStartIndex() - 1));
        }
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.wfs.v_1_1_0.QueryType)

Example 70 with GetFeatureType

use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.

the class WfsSource method logMessage.

private void logMessage(GetFeatureType getFeature) {
    if (LOGGER.isDebugEnabled()) {
        try {
            StringWriter writer = new StringWriter();
            JAXBContext contextObj = JAXBContext.newInstance(GetFeatureType.class);
            Marshaller marshallerObj = contextObj.createMarshaller();
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshallerObj.marshal(new ObjectFactory().createGetFeature(getFeature), writer);
            LOGGER.debug("WfsSource {}: {}", getId(), writer);
        } catch (JAXBException e) {
            LOGGER.debug("An error occurred debugging the GetFeature request", e);
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ObjectFactory(net.opengis.wfs.v_1_1_0.ObjectFactory) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)58 Test (org.junit.Test)57 Filter (org.opengis.filter.Filter)34 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)32 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)31 QueryType (net.opengis.wfs.v_2_0_0.QueryType)21 ArrayList (java.util.ArrayList)19 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)19 QueryType (net.opengis.wfs.v_1_1_0.QueryType)17 Matchers.containsString (org.hamcrest.Matchers.containsString)15 SortByImpl (ddf.catalog.filter.impl.SortByImpl)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12 SortBy (org.opengis.filter.sort.SortBy)12 Query (ddf.catalog.operation.Query)9 QName (javax.xml.namespace.QName)9 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)8 Metacard (ddf.catalog.data.Metacard)5 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)5 JAXBElement (javax.xml.bind.JAXBElement)5 SortByType (net.opengis.filter.v_2_0_0.SortByType)5