* Allows subclasses to alter the result generation
*/
protected FeatureCollectionResponse buildResults(GetFeatureRequest request, int offset, int maxFeatures,
int count, int total, List results, String lockId) {
FeatureCollectionResponse result = request.createResponse();
result.setNumberOfFeatures(BigInteger.valueOf(count));
result.setTotalNumberOfFeatures(BigInteger.valueOf(total));
result.setTimeStamp(Calendar.getInstance());
result.setLockId(lockId);
result.getFeature().addAll(results);
if (offset > 0 || count < Integer.MAX_VALUE) {
//paged request, set the values of previous and next
//get the Request thread local since we need to know about the request, whether it is
// GET or POST some kvp information if the former
Request req = Dispatcher.REQUEST.get();
//grab the original kvp params if this is a GET request
//for POST, do nothing, make the client post the same content
//TODO: try to encode the request as best we can in a GET request, only issue should
// be the filter and encoding it property... especially for joins that might be
// tricky, and it also may cause the request to be too large for a get request
//TODO: figure out what the spec says about this...
Map<String,String> kvp = null;
if (req.isGet()) {
kvp = new KvpMap(req.getRawKvp());
}
else {
//generate kvp map from request object
kvp = buildKvpFromRequest(request);
}
if (offset > 0) {
//previous
//previous offset calculated as the current offset - maxFeatures, or 0 if this is a
// negative value
int prevOffset = Math.max(offset - maxFeatures, 0);
kvp.put("startIndex", String.valueOf(prevOffset));
//previous count should be current offset - previousOffset
kvp.put("count", String.valueOf(offset - prevOffset));
result.setPrevious(buildURL(request.getBaseUrl(), "wfs", kvp, URLType.SERVICE));
}
if (count > 0 && offset > -1) {
//next
//calculate the count of the next result set
int nextCount = total - (offset + count);
if (nextCount > 0) {
kvp.put("startIndex", String.valueOf(offset > 0 ? offset + count : count));
//kvp.put("count", String.valueOf(nextCount));
kvp.put("count", String.valueOf(maxFeatures));
result.setNext(buildURL(request.getBaseUrl(), "wfs", kvp, URLType.SERVICE));
}
}
}
return result;