use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testSortingNoSortBySortingSupported.
@Test
public void testSortingNoSortBySortingSupported() throws Exception {
// Setup
final String searchPhrase = "*";
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 0);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
// Perform Test
GetFeatureType featureType = source.buildGetFeatureRequest(query);
// Verify
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
assertFalse(queryType.isSetAbstractSortingClause());
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties.
@Test
public void testSourceUsesMetacardMapperToMapMetacardAttributesToFeatureProperties() throws Exception {
final MetacardMapperImpl metacardMapper = new MetacardMapperImpl();
metacardMapper.setFeatureType("{http://example.com}SampleFeature0");
metacardMapper.setResourceUriMapping("title");
metacardMappers.add(metacardMapper);
final WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 1);
final Filter filter = builder.attribute(Core.RESOURCE_URI).is().equalTo().text("anything");
final Query query = new QueryImpl(filter);
final QueryRequest queryRequest = new QueryRequestImpl(query);
source.query(queryRequest);
final ArgumentCaptor<GetFeatureType> getFeatureCaptor = ArgumentCaptor.forClass(GetFeatureType.class);
verify(mockWfs).getFeature(getFeatureCaptor.capture());
final GetFeatureType getFeatureType = getFeatureCaptor.getValue();
final String getFeatureXml = marshal(getFeatureType);
assertThat(getFeatureXml, hasXPath("/wfs:GetFeature/wfs:Query/ogc:Filter/ogc:PropertyIsEqualTo[ogc:ValueReference='title' and ogc:Literal='anything']").withNamespaceContext(NAMESPACE_CONTEXT));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testSrsNameProvided.
@Test
public void testSrsNameProvided() throws Exception {
int pageSize = 10;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 10, false);
source.setSrsName(GeospatialUtil.EPSG_4326);
Filter filter = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "0");
QueryImpl query = new QueryImpl(filter);
query.setPageSize(pageSize);
// Execute
GetFeatureType featureType = source.buildGetFeatureRequest(query);
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
assertThat(queryType.getSrsName(), is(GeospatialUtil.EPSG_4326));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSource method buildGetFeatureRequest.
private ExtendedGetFeatureType buildGetFeatureRequest(Query query, ResultTypeType resultType, BigInteger maxFeatures) 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();
wfsQuery.setTypeName(Collections.singletonList(filterDelegateEntry.getKey()));
if (StringUtils.isNotBlank(srsName)) {
wfsQuery.setSrsName(srsName);
}
FilterType filter = filterAdapter.adapt(query, filterDelegateEntry.getValue());
if (filter != null) {
if (areAnyFiltersSet(filter)) {
wfsQuery.setFilter(filter);
}
if (!this.disableSorting && query.getSortBy() != null && query.getSortBy().getPropertyName() != null && query.getSortBy().getPropertyName().getPropertyName() != null) {
SortByType sortByType = buildSortBy(filterDelegateEntry.getKey(), query.getSortBy());
if (sortByType != null && sortByType.getSortProperty() != null && sortByType.getSortProperty().size() > 0) {
LOGGER.debug("Sorting using sort property [{}] and sort order [{}].", sortByType.getSortProperty().get(0).getPropertyName(), sortByType.getSortProperty().get(0).getSortOrder());
wfsQuery.setSortBy(sortByType);
} else {
throw new UnsupportedQueryException("Source " + this.getId() + " does not support specified sort property " + query.getSortBy().getPropertyName().getPropertyName());
}
} else {
LOGGER.debug("Sorting is disabled or sort not specified.");
}
queries.add(wfsQuery);
} else {
LOGGER.debug("WFS Source {}: {} has an invalid filter.", getId(), filterDelegateEntry.getKey());
}
}
}
if (!queries.isEmpty()) {
ExtendedGetFeatureType getFeatureType = new ExtendedGetFeatureType();
getFeatureType.setMaxFeatures(maxFeatures);
getFeatureType.getQuery().addAll(queries);
getFeatureType.setService(Wfs11Constants.WFS);
getFeatureType.setVersion(Wfs11Constants.VERSION_1_1_0);
getFeatureType.setResultType(resultType);
if (supportsStartIndex && resultType.equals(ResultTypeType.RESULTS)) {
// Convert DDF index of 1 back to index of 0 for WFS
getFeatureType.setStartIndex(BigInteger.valueOf(query.getStartIndex() - 1));
}
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_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSource method logMessage.
private void logMessage(GetFeatureType getFeature) {
if (LOGGER.isDebugEnabled()) {
try {
StringWriter writer = new StringWriter();
JAXBContext contextObj = JAXBContext.newInstance(GetFeatureType.class);
Marshaller marshallerObj = contextObj.createMarshaller();
marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshallerObj.marshal(new ObjectFactory().createGetFeature(getFeature), writer);
LOGGER.debug("WfsSource {}: {}", getId(), writer);
} catch (JAXBException e) {
LOGGER.debug("An error occurred debugging the GetFeature request", e);
}
}
}
Aggregations