Search in sources :

Example 46 with GetFeatureType

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

the class TestWfsSource method testGmlImport.

@Test
public void testGmlImport() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    List<Object> bbox = new ArrayList<Object>();
    bbox.add(new BBOX());
    setUp(GML_IMPORT_SCHEMA, bbox, SRS_NAME, ONE_FEATURE, null);
    Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
    QueryImpl intersectQuery = new QueryImpl(intersectFilter);
    intersectQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(intersectQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, intersectQuery);
    assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    assertTrue(query.getFilter().isSetSpatialOps());
    assertTrue(query.getFilter().getSpatialOps().getValue() instanceof SpatialOpsType);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) BBOX(ogc.schema.opengis.filter_capabilities.v_1_0_0.BBOX) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SpatialOpsType(ogc.schema.opengis.filter.v_1_0_0.SpatialOpsType) ArrayList(java.util.ArrayList) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 47 with GetFeatureType

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

the class TestWfsSource method testTwoContentTypeAndNoPropertyQuery.

@Test
public void testTwoContentTypeAndNoPropertyQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(NO_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
    Filter contentTypeFilter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
    Filter contentTypeFilter2 = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
    QueryImpl twoContentTypeQuery = new QueryImpl(builder.anyOf(Arrays.asList(contentTypeFilter, contentTypeFilter2)));
    twoContentTypeQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(twoContentTypeQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, twoContentTypeQuery);
    Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
    assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().size());
    assertEquals(sampleFeatures.get(0), getFeatureType.getQuery().get(0).getTypeName());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 48 with GetFeatureType

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

the class TestWfsSource method testQueryTwoFeaturesWithMixedPropertyNames.

@Test
public void testQueryTwoFeaturesWithMixedPropertyNames() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(TWO_TEXT_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
    Filter orderPersonFilter = builder.attribute(EXT_PREFIX + sampleFeatures.get(0).getLocalPart() + "." + ORDER_PERSON).is().like().text(LITERAL);
    Filter mctFeature1Fitler = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
    Filter feature1Filter = builder.allOf(Arrays.asList(orderPersonFilter, mctFeature1Fitler));
    Filter orderDogFilter = builder.attribute(EXT_PREFIX + sampleFeatures.get(1).getLocalPart() + "." + ORDER_DOG).is().like().text(LITERAL);
    Filter mctFeature2Fitler = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
    Filter feature2Filter = builder.allOf(Arrays.asList(orderDogFilter, mctFeature2Fitler));
    Filter totalFilter = builder.anyOf(Arrays.asList(feature1Filter, feature2Filter));
    QueryImpl inQuery = new QueryImpl(totalFilter);
    inQuery.setPageSize(MAX_FEATURES);
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(inQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertMaxFeatures(getFeatureType, inQuery);
    Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
    assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().size());
    // Feature 1
    QueryType query = getFeatureType.getQuery().get(0);
    assertThat(query.getTypeName(), equalTo(sampleFeatures.get(0)));
    // this should only have 1 filter which is a comparison
    assertTrue(query.getFilter().isSetComparisonOps());
    assertTrue(query.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
    PropertyIsLikeType pilt = (PropertyIsLikeType) query.getFilter().getComparisonOps().getValue();
    assertNotNull(pilt);
    assertEquals(ORDER_PERSON, pilt.getPropertyName().getContent());
    // Feature 2
    QueryType query2 = getFeatureType.getQuery().get(1);
    assertTrue(query2.getTypeName().equals(sampleFeatures.get(1)));
    // this should only have 1 filter which is a comparison
    assertTrue(query2.getFilter().isSetComparisonOps());
    assertTrue(query2.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
    PropertyIsLikeType pilt2 = (PropertyIsLikeType) query2.getFilter().getComparisonOps().getValue();
    assertEquals(ORDER_DOG, pilt2.getPropertyName().getContent());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) PropertyIsLikeType(ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 49 with GetFeatureType

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

the class TestWfsSource method testTwoIDQuery.

@Test
public void testTwoIDQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(NO_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
    Filter idFilter1 = builder.attribute(Core.ID).is().text(ORDER_PERSON);
    Filter idFilter2 = builder.attribute(Core.ID).is().text(ORDER_DOG);
    QueryImpl twoIDQuery = new QueryImpl(builder.anyOf(Arrays.asList(idFilter1, idFilter2)));
    ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
    source.query(new QueryRequestImpl(twoIDQuery));
    verify(mockWfs).getFeature(captor.capture());
    GetFeatureType getFeatureType = captor.getValue();
    assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().get(0).getFilter().getFeatureId().size());
    assertTrue(ORDER_PERSON.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(0).getFid()) || ORDER_PERSON.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(1).getFid()));
    assertTrue(ORDER_DOG.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(0).getFid()) || ORDER_DOG.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(1).getFid()));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 50 with GetFeatureType

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

the class WfsSource method query.

@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
    Wfs wfs = factory.getClient();
    Query query = request.getQuery();
    if (query == null) {
        LOGGER.debug("WFS Source {}: Incoming query is null.", getId());
        return null;
    }
    LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
    SourceResponseImpl simpleResponse = null;
    GetFeatureType getFeature = buildGetFeatureRequest(query);
    try {
        LOGGER.debug("WFS Source {}: Sending query ...", getId());
        Wfs20FeatureCollection featureCollection = wfs.getFeature(getFeature);
        int numResults = -1;
        if (featureCollection == null) {
            throw new UnsupportedQueryException("Invalid results returned from server");
        }
        numResults = featureCollection.getMembers().size();
        if (featureCollection.getNumberReturned() == null) {
            LOGGER.debug("Number Returned Attribute was not added to the response");
        } else if (!featureCollection.getNumberReturned().equals(BigInteger.valueOf(numResults))) {
            LOGGER.debug("Number Returned Attribute ({}) did not match actual number returned ({})", featureCollection.getNumberReturned(), numResults);
        }
        availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
        LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), numResults);
        List<Result> results = new ArrayList<>(numResults);
        for (int i = 0; i < numResults; i++) {
            Metacard mc = featureCollection.getMembers().get(i);
            mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
            Result result = new ResultImpl(mc);
            results.add(result);
            debugResult(result);
        }
        // Fetch total results available
        long totalResults = 0;
        if (featureCollection.getNumberMatched() == null) {
            totalResults = numResults;
        } else if (featureCollection.getNumberMatched().equals(UNKNOWN)) {
            totalResults = numResults;
        } else if (StringUtils.isNumeric(featureCollection.getNumberMatched())) {
            totalResults = Long.parseLong(featureCollection.getNumberMatched());
        }
        simpleResponse = new SourceResponseImpl(request, results, totalResults);
    } 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);
    }
    return simpleResponse;
}
Also used : Query(ddf.catalog.operation.Query) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) 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) Metacard(ddf.catalog.data.Metacard) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType)

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