use of ddf.catalog.data.impl.ResultImpl 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<Result>(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 = Long.valueOf(numResults);
} else if (featureCollection.getNumberMatched().equals(UNKNOWN)) {
totalResults = Long.valueOf(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;
}
Aggregations