use of net.opengis.wfs.v_2_0_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;
}
use of net.opengis.wfs.v_2_0_0.GetFeatureType in project ddf by codice.
the class WfsSource method initProviders.
private List<? extends Object> initProviders() {
// We need to tell the JAXBElementProvider to marshal the GetFeatureType
// class as an element
// because it is missing the @XmlRootElement Annotation
JAXBElementProvider<GetFeatureType> provider = new Wfs20JaxbElementProvider<>();
Map<String, String> jaxbClassMap = new HashMap<>();
// Ensure a namespace is used when the GetFeature request is generated
String expandedName = new QName(Wfs20Constants.WFS_2_0_NAMESPACE, Wfs20Constants.GET_FEATURE).toString();
jaxbClassMap.put(GetFeatureType.class.getName(), expandedName);
provider.setJaxbElementClassMap(jaxbClassMap);
provider.setMarshallAsJaxbElement(true);
featureCollectionReader = new FeatureCollectionMessageBodyReaderWfs20();
return Arrays.asList(provider, new XmlSchemaMessageBodyReaderWfs20(), featureCollectionReader);
}
use of net.opengis.wfs.v_2_0_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testTypeNameHasNoPrefix.
@Test
public void testTypeNameHasNoPrefix() throws Exception {
// Setup
final String TITLE = "title";
final String searchPhrase = "*";
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 3, false, false, 3);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
query.setSortBy(sortBy);
// Perform test
GetFeatureType featureType = source.buildGetFeatureRequest(query);
// Validate
List<JAXBElement<?>> queryList = featureType.getAbstractQueryExpression();
for (JAXBElement<?> queryType : queryList) {
Object val = queryType.getValue();
QueryType queryTypeVal = (QueryType) val;
assertThat(queryTypeVal.getTypeNames().get(0), containsString("SampleFeature"));
assertThat(queryTypeVal.getTypeNames().get(0), is(not(containsString("Prefix"))));
assertThat(queryTypeVal.getTypeNames().get(0), is(not(containsString(":"))));
}
}
use of net.opengis.wfs.v_2_0_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testSrsNameNotProvided.
@Test
public void testSrsNameNotProvided() throws Exception {
int pageSize = 10;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 10, false);
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(), nullValue());
}
use of net.opengis.wfs.v_2_0_0.GetFeatureType in project ddf by codice.
the class WfsSourceTest method testSortingAscendingSortingSupported.
/**
* Verify that the SortBy is set with the mapped Feature Property and a ASC sort order. In this
* case, the incoming sort property of TEMPORAL is mapped to myTemporalFeatureProperty.
*
* <p><?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ns5:GetFeature startIndex="1"
* count="1" service="WFS" version="2.0.0" xmlns:ns2="http://www.opengis.net/ows/1.1"
* xmlns="http://www.opengis.net/fes/2.0" xmlns:ns4="http://www.opengis.net/gml"
* xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.opengis.net/wfs/2.0"> <ns5:Query
* typeNames="SampleFeature0" handle="SampleFeature0"> <Filter> <PropertyIsLike wildCard="*"
* singleChar="?" escapeChar="!"> <Literal>*</Literal> <ValueReference>title</ValueReference>
* </PropertyIsLike> </Filter> <SortBy> <SortProperty>
* <ValueReference>myTemporalFeatureProperty</ValueReference> <SortOrder>ASC</SortOrder>
* </SortProperty> </SortBy> </ns5:Query> </ns5:GetFeature>
*/
@Test
public void testSortingAscendingSortingSupported() throws Exception {
// Setup
final String searchPhrase = "*";
final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), 1, false, false, 0);
MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
mappers.add(mockMetacardMapper);
source.setMetacardToFeatureMapper(mappers);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
query.setSortBy(sortBy);
// Perform Test
GetFeatureType featureType = source.buildGetFeatureRequest(query);
// Verify
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
JAXBElement<?> abstractSortingClause = queryType.getAbstractSortingClause();
SortByType sortByType = (SortByType) abstractSortingClause.getValue();
assertThat(sortByType.getSortProperty().get(0).getValueReference(), is(mockTemporalFeatureProperty));
assertThat(sortByType.getSortProperty().get(0).getSortOrder().name(), is(SortOrderType.ASC.value()));
}
Aggregations