use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testQuerySendsHitsRequestBeforeResultsRequest.
@Test
public void testQuerySendsHitsRequestBeforeResultsRequest() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
final QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("literal"));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
final ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
final ExtendedGetFeatureType getHits = captor.getAllValues().get(0);
assertThat(getHits.getResultType(), is(ResultTypeType.HITS));
assertThat(getHits.getMaxFeatures(), is(nullValue()));
final ExtendedGetFeatureType getResults = captor.getAllValues().get(1);
assertThat(getResults.getResultType(), is(ResultTypeType.RESULTS));
assertMaxFeatures(getResults, propertyIsLikeQuery);
for (final ExtendedGetFeatureType getFeatureType : captor.getAllValues()) {
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
final QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testTwoPropertyQuery.
@Test
public void testTwoPropertyQuery() throws Exception {
mapSchemaToFeatures(TWO_TEXT_PROPERTY_SCHEMA, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
// The Text Properties should be ORed
assertThat(query.getFilter().isSetLogicOps(), is(true));
assertThat(query.getFilter().getLogicOps().getValue(), is(instanceOf(BinaryLogicOpType.class)));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testContentTypeQuery.
@Test
public void testContentTypeQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, ONE_FEATURE);
setUpMocks(null, null, ONE_FEATURE, ONE_FEATURE);
Filter propertyIsLikeFilter = builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL);
Filter contentTypeFilter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(// .text(SAMPLE_FEATURE[0].getLocalPart());
sampleFeatures.get(0).getLocalPart());
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.allOf(propertyIsLikeFilter, contentTypeFilter));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(ONE_FEATURE));
QueryType query = getFeatureType.getQuery().get(0);
// SAMPLE_FEATURE[0]));
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testTwoFeatureTypesQuery.
@Test
public void testTwoFeatureTypesQuery() throws Exception {
mapSchemaToFeatures(ONE_TEXT_PROPERTY_SCHEMA_PERSON, TWO_FEATURES);
setUpMocks(null, null, TWO_FEATURES, TWO_FEATURES);
QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(LITERAL));
propertyIsLikeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<ExtendedGetFeatureType> captor = ArgumentCaptor.forClass(ExtendedGetFeatureType.class);
source.query(new QueryRequestImpl(propertyIsLikeQuery));
verify(mockWfs, times(2)).getFeature(captor.capture());
ExtendedGetFeatureType getFeatureType = captor.getAllValues().get(1);
assertMaxFeatures(getFeatureType, propertyIsLikeQuery);
assertThat(getFeatureType.getQuery().size(), is(TWO_FEATURES));
Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName().get(0), is(sampleFeatures.get(0)));
assertThat(query.getFilter().isSetComparisonOps(), is(true));
assertThat(query.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
QueryType query2 = getFeatureType.getQuery().get(1);
assertThat(query2.getTypeName().get(0), is(sampleFeatures.get(1)));
assertThat(query2.getFilter().isSetComparisonOps(), is(true));
assertThat(query2.getFilter().getComparisonOps().getValue(), is(instanceOf(PropertyIsLikeType.class)));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSource method buildGetFeatureRequest.
protected GetFeatureType buildGetFeatureRequest(Query query) 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();
String typeName = null;
if (StringUtils.isEmpty(filterDelegateEntry.getKey().getPrefix())) {
typeName = filterDelegateEntry.getKey().getLocalPart();
} else {
typeName = filterDelegateEntry.getKey().getPrefix() + ":" + filterDelegateEntry.getKey().getLocalPart();
}
if (StringUtils.isNotBlank(srsName)) {
wfsQuery.setSrsName(srsName);
}
wfsQuery.setTypeNames(Arrays.asList(typeName));
wfsQuery.setHandle(filterDelegateEntry.getKey().getLocalPart());
FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
if (filter != null) {
if (areAnyFiltersSet(filter)) {
wfsQuery.setAbstractSelectionClause(new net.opengis.filter.v_2_0_0.ObjectFactory().createFilter(filter));
}
if (!this.disableSorting) {
if (query.getSortBy() != null) {
SortOrder sortOrder = query.getSortBy().getSortOrder();
if (filterDelegateEntry.getValue().isSortingSupported() && filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortBy != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Sorting using sort order of [{}].", sortOrder.identifier());
}
wfsQuery.setAbstractSortingClause(sortBy);
}
} else if (filterDelegateEntry.getValue().isSortingSupported() && CollectionUtils.isEmpty(filterDelegateEntry.getValue().getAllowedSortOrders())) {
JAXBElement<SortByType> sortBy = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortBy != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No sort orders defined in getCapabilities. Attempting to sort using sort order of [{}].", sortOrder.identifier());
}
wfsQuery.setAbstractSortingClause(sortBy);
}
} else if (filterDelegateEntry.getValue().isSortingSupported() && !filterDelegateEntry.getValue().getAllowedSortOrders().contains(sortOrder)) {
LOGGER.debug("Unsupported sort order of [{}]. Supported sort orders are {}.", sortOrder, filterDelegateEntry.getValue().getAllowedSortOrders());
} else if (!filterDelegateEntry.getValue().isSortingSupported()) {
LOGGER.debug("Sorting is not supported.");
}
}
} else {
LOGGER.debug("Sorting is disabled.");
}
queries.add(wfsQuery);
} else {
LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
}
}
}
if (!queries.isEmpty()) {
GetFeatureType getFeatureType = new GetFeatureType();
int pageSize = query.getPageSize();
if (pageSize < 0) {
LOGGER.debug("Page size has a negative value");
throw new UnsupportedQueryException("Unable to build query. Page size has a negative value.");
}
int startIndex = query.getStartIndex();
if (startIndex < 0) {
LOGGER.debug("Start index has a negative value");
throw new UnsupportedQueryException("Unable to build query. Start index has a negative value.");
} else if (startIndex != 0) {
// Convert DDF index of 1 back to index of 0 for WFS 2.0
startIndex = query.getStartIndex() - 1;
} else {
LOGGER.debug("Query already has a start index of 0");
}
getFeatureType.setCount(BigInteger.valueOf(query.getPageSize()));
getFeatureType.setStartIndex(BigInteger.valueOf(startIndex));
List<JAXBElement<?>> incomingQueries = getFeatureType.getAbstractQueryExpression();
for (QueryType queryType : queries) {
incomingQueries.add(new net.opengis.wfs.v_2_0_0.ObjectFactory().createQuery(queryType));
}
logMessage(getFeatureType);
return getFeatureType;
} else {
throw new UnsupportedQueryException("Unable to build query. No filters could be created from query criteria.");
}
}
Aggregations