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.");
}
}
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);
}
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());
}
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());
}
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()));
}
Aggregations