@RequestParam(value="page", required=false) Integer page,
@RequestParam(value="count", required=false, defaultValue=""+DEFAULT_PAGESIZE) Integer count,
@RequestParam(value="sort", required=false) String sort,
@RequestParam(value="filter", required=false) String textFilter,
HttpServletRequest req) {
JSONObj obj = new JSONObj();
Catalog cat = geoServer.getCatalog();
if ("default".equals(wsName)) {
WorkspaceInfo def = cat.getDefaultWorkspace();
if (def != null) {
wsName = def.getName();
}
}
Filter filter = equal("resource.namespace.prefix", wsName);
if (textFilter != null) {
filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter));
}
Integer total = cat.count(LayerInfo.class, filter);
SortBy sortBy = null;
if (sort != null) {
String[] sortArr = sort.split(":", 2);
if (sortArr.length == 2) {
if (sortArr[1].equals("asc")) {
sortBy = Predicates.asc(sortArr[0]);
} else if (sortArr[1].equals("desc")) {
sortBy = Predicates.desc(sortArr[0]);
} else {
throw new BadRequestException("Sort order must be \"asc\" or \"desc\"");
}
} else {
sortBy = Predicates.asc(sortArr[0]);
}
}
obj.put("total", total);
obj.put("page", page != null ? page : 0);
obj.put("count", Math.min(total, count != null ? count : total));
JSONArr arr = obj.putArray("layers");
try (
CloseableIterator<LayerInfo> it = cat.list(LayerInfo.class, filter, offset(page, count), count, sortBy);
) {
while (it.hasNext()) {
layer(arr.addObject(), it.next(), req);