Search in sources :

Example 1 with WfsFeatureCollection

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

the class WfsSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    ExtendedWfs wfs = factory.getClient();
    Query query = request.getQuery();
    LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
    if (query.getStartIndex() < 1) {
        throw new UnsupportedQueryException("Start Index is one-based and must be an integer greater than 0; should not be [" + query.getStartIndex() + "]");
    }
    Query modifiedQuery;
    int origPageSize = query.getPageSize();
    if (origPageSize <= 0 || origPageSize > WFS_MAX_FEATURES_RETURNED) {
        origPageSize = WFS_MAX_FEATURES_RETURNED;
    }
    int pageNumber = query.getStartIndex() / origPageSize + 1;
    if (!supportsStartIndex) {
        modifiedQuery = new QueryImpl(query, 1, Constants.DEFAULT_PAGE_SIZE, query.getSortBy(), false, 300000L);
        int modifiedPageSize = Math.min(pageNumber * origPageSize, WFS_MAX_FEATURES_RETURNED);
        LOGGER.debug("WFS Source {}: modified page size = {}", getId(), modifiedPageSize);
        ((QueryImpl) modifiedQuery).setPageSize(modifiedPageSize);
    } else {
        modifiedQuery = query;
    }
    final ExtendedGetFeatureType getHits = buildGetFeatureRequestHits(modifiedQuery);
    final ExtendedGetFeatureType getResults = buildGetFeatureRequestResults(modifiedQuery);
    try {
        LOGGER.debug("WFS Source {}: Getting hits.", getId());
        final WfsFeatureCollection hitsResponse = wfs.getFeature(getHits);
        final long totalHits = hitsResponse.getNumberOfFeatures();
        LOGGER.debug("The query has {} hits.", totalHits);
        LOGGER.debug("WFS Source {}: Sending query ...", getId());
        final WfsFeatureCollection featureCollection = wfs.getFeature(getResults);
        if (featureCollection == null) {
            throw new UnsupportedQueryException("Invalid results returned from server");
        }
        availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
        LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), featureCollection.getFeatureMembers().size());
        LOGGER.debug("WFS Source {}: startIndex = {}, origPageSize = {}, pageNumber = {}", getId(), query.getStartIndex(), origPageSize, pageNumber);
        List<Result> results;
        if (supportsStartIndex) {
            results = new ArrayList<>(featureCollection.getFeatureMembers().size());
            for (Metacard mc : featureCollection.getFeatureMembers()) {
                addTransformedResult(mc, results);
            }
        } else {
            // Only return the number of results originally asked for in the
            // query, or the entire list of results if it is smaller than the
            // original page size.
            int numberOfResultsToReturn = Math.min(origPageSize, featureCollection.getFeatureMembers().size());
            results = new ArrayList<>(numberOfResultsToReturn);
            int stopIndex = Math.min(origPageSize + query.getStartIndex(), featureCollection.getFeatureMembers().size() + 1);
            LOGGER.debug("WFS Source {}: stopIndex = {}", getId(), stopIndex);
            for (int i = query.getStartIndex(); i < stopIndex; i++) {
                Metacard mc = featureCollection.getFeatureMembers().get(i - 1);
                addTransformedResult(mc, results);
            }
        }
        return new SourceResponseImpl(request, results, totalHits);
    } catch (WfsException wfse) {
        LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        throw new UnsupportedQueryException("Error received from WFS Server", wfse);
    } catch (Exception ce) {
        String msg = handleClientException(ce);
        throw new UnsupportedQueryException(msg, ce);
    }
}
Also used : Query(ddf.catalog.operation.Query) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) WebApplicationException(javax.ws.rs.WebApplicationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection)

Example 2 with WfsFeatureCollection

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

the class FeatureTransformationServiceTest method testApplyBadXML.

@Test
public void testApplyBadXML() {
    InputStream inputStream = new BufferedInputStream(FeatureTransformationServiceTest.class.getResourceAsStream("/Broken.xml"));
    WfsMetadata wfsMetadata = mock(WfsMetadata.class);
    when(wfsMetadata.getFeatureMemberNodeNames()).thenReturn(Collections.singletonList("featureMember"));
    WfsFeatureCollection wfsFeatureCollection = featureTransformationService.apply(inputStream, wfsMetadata);
    ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
    ArgumentCaptor<WfsMetadata> wfsMetadataArgumentCaptor = ArgumentCaptor.forClass(WfsMetadata.class);
    verify(transformerList.get(0), times(0)).apply(inputStreamArgumentCaptor.capture(), wfsMetadataArgumentCaptor.capture());
    assertThat(wfsFeatureCollection.getNumberOfFeatures(), is(10L));
    assertThat(wfsFeatureCollection.getFeatureMembers(), hasSize(0));
}
Also used : WfsMetadata(org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection) Test(org.junit.Test)

Example 3 with WfsFeatureCollection

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

the class FeatureTransformationServiceTest method testFeatureMembersWithNoNumberOfFeaturesAttribute.

@Test
public void testFeatureMembersWithNoNumberOfFeaturesAttribute() throws Exception {
    try (final InputStream inputStream = getClass().getResourceAsStream("/NeverlandNoNumberOfFeaturesAttribute.xml")) {
        final WfsMetadata wfsMetadata = mock(WfsMetadata.class);
        when(wfsMetadata.getFeatureMemberNodeNames()).thenReturn(Collections.singletonList("featureMember"));
        final WfsFeatureCollection wfsFeatureCollection = featureTransformationService.apply(inputStream, wfsMetadata);
        assertThat(wfsFeatureCollection.getNumberOfFeatures(), is(10L));
        assertThat(wfsFeatureCollection.getFeatureMembers(), hasSize(10));
    }
}
Also used : WfsMetadata(org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection) Test(org.junit.Test)

Example 4 with WfsFeatureCollection

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

the class FeatureTransformationServiceTest method testMultipleFeatureMemberNodeNames.

@Test
public void testMultipleFeatureMemberNodeNames() throws Exception {
    try (final InputStream inputStream = getClass().getResourceAsStream("/Tasmania.xml")) {
        final WfsMetadata wfsMetadata = mock(WfsMetadata.class);
        when(wfsMetadata.getFeatureMemberNodeNames()).thenReturn(Arrays.asList("tasmania_water_bodies", "streams", "roads", "poi", "giant_polygon", "archsites", "bugsites", "tasmania_state_boundaries", "tiger_roads", "states", "tasmania_cities", "restricted", "poly_landmarks", "tasmania_roads"));
        final WfsFeatureCollection wfsFeatureCollection = featureTransformationService.apply(inputStream, wfsMetadata);
        assertThat(wfsFeatureCollection.getNumberOfFeatures(), is(2L));
        assertThat(wfsFeatureCollection.getFeatureMembers(), hasSize(2));
    }
}
Also used : WfsMetadata(org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection) Test(org.junit.Test)

Example 5 with WfsFeatureCollection

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

the class FeatureTransformationServiceTest method validateTenMetacards.

private void validateTenMetacards(String inputFileName, String featureNodeName) {
    InputStream inputStream = new BufferedInputStream(FeatureTransformationServiceTest.class.getResourceAsStream(inputFileName));
    WfsMetadata wfsMetadata = mock(WfsMetadata.class);
    when(wfsMetadata.getFeatureMemberNodeNames()).thenReturn(Collections.singletonList(featureNodeName));
    WfsFeatureCollection wfsFeatureCollection = featureTransformationService.apply(inputStream, wfsMetadata);
    ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
    ArgumentCaptor<WfsMetadata> wfsMetadataArgumentCaptor = ArgumentCaptor.forClass(WfsMetadata.class);
    verify(transformerList.get(0), times(FEATURE_MEMBER_COUNT)).apply(inputStreamArgumentCaptor.capture(), wfsMetadataArgumentCaptor.capture());
    for (int i = 0; i < FEATURE_MEMBER_COUNT; i++) {
        assertThat(inputStreamArgumentCaptor.getAllValues().get(i), notNullValue());
        assertThat(wfsMetadataArgumentCaptor.getAllValues().get(i), notNullValue());
    }
    assertThat(wfsFeatureCollection.getNumberOfFeatures(), is(10L));
    assertThat(wfsFeatureCollection.getFeatureMembers(), hasSize(10));
}
Also used : WfsMetadata(org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) WfsFeatureCollection(org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection) Endpoint(org.apache.camel.Endpoint)

Aggregations

WfsFeatureCollection (org.codice.ddf.spatial.ogc.wfs.catalog.WfsFeatureCollection)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStream (java.io.InputStream)4 WfsMetadata (org.codice.ddf.spatial.ogc.wfs.featuretransformer.WfsMetadata)4 Test (org.junit.Test)3 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 Query (ddf.catalog.operation.Query)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JAXBException (javax.xml.bind.JAXBException)1 Endpoint (org.apache.camel.Endpoint)1 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1