Search in sources :

Example 36 with GetFeatureType

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

the class WfsSource method buildGetFeatureRequest.

private 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();
            wfsQuery.setTypeName(filterDelegateEntry.getKey());
            FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
            if (filter != null) {
                if (areAnyFiltersSet(filter)) {
                    wfsQuery.setFilter(filter);
                }
                queries.add(wfsQuery);
            } else {
                LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
            }
        }
    }
    if (queries != null && !queries.isEmpty()) {
        GetFeatureType getFeatureType = new GetFeatureType();
        getFeatureType.setMaxFeatures(BigInteger.valueOf(query.getPageSize()));
        getFeatureType.getQuery().addAll(queries);
        getFeatureType.setService(Wfs10Constants.WFS);
        getFeatureType.setVersion(Wfs10Constants.VERSION_1_0_0);
        logMessage(getFeatureType);
        return getFeatureType;
    } else {
        throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
    }
}
Also used : FilterType(ogc.schema.opengis.filter.v_1_0_0.FilterType) ContentType(ddf.catalog.data.ContentType) QName(javax.xml.namespace.QName) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 37 with GetFeatureType

use of net.opengis.wfs.v_2_0_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 38 with GetFeatureType

use of net.opengis.wfs.v_2_0_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 39 with GetFeatureType

use of net.opengis.wfs.v_2_0_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 40 with GetFeatureType

use of net.opengis.wfs.v_2_0_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)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)43 Test (org.junit.Test)42 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)32 Filter (org.opengis.filter.Filter)24 QueryType (net.opengis.wfs.v_2_0_0.QueryType)21 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)19 ArrayList (java.util.ArrayList)17 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)16 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 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)8 Query (ddf.catalog.operation.Query)7 QName (javax.xml.namespace.QName)7 JAXBElement (javax.xml.bind.JAXBElement)5 SortByType (net.opengis.filter.v_2_0_0.SortByType)5 PropertyIsLikeType (ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)5 Metacard (ddf.catalog.data.Metacard)4 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)4