@Test public void testList() throws Exception { MockGeoServer.get().catalog() .resources() .resource("workspaces/foo/layergroups/map1.xml", "layergroup placeholder") .resource("workspaces/foo/layergroups/map2.xml", "layergroup placeholder") .geoServer() .catalog() .workspace("foo", "http: .map("map1") .defaults() .layer("one").featureType().defaults().map() .layer("two").featureType().defaults().map().workspace() .map("map2") .defaults() .layer("three").featureType().defaults().map() .layer("four").featureType().defaults() .geoServer().build(geoServer); MvcResult result = mvc.perform(get("/app/api/maps/foo")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); JSONObj obj = JSONWrapper.read(result.getResponse().getContentAsString()).toObject(); assertEquals(2, obj.integer("total").intValue()); JSONArr arr = obj.array("maps"); assertEquals(2,arr.size()); Iterables.find(arr, new Predicate<Object>() { @Override public boolean apply(@Nullable Object o) { return "map1".equals(JSONWrapper.wrap(o).toObject().str("name")); } }); Iterables.find(arr, new Predicate<Object>() { @Override public boolean apply(@Nullable Object o) { return "map2".equals(JSONWrapper.wrap(o).toObject().str("name")); } }); }
@RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj list(@PathVariable String wsName, @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) { Catalog cat = geoServer.getCatalog(); if ("default".equals(wsName)) { WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { wsName = def.getName(); } } Filter filter = equal("workspace.name", wsName); if (textFilter != null) { filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter)); } SortBy sortBy = parseSort(sort); Integer total = cat.count(LayerGroupInfo.class, filter); JSONObj obj = new JSONObj(); JSONArr arr = obj.putArray("maps"); try ( CloseableIterator<LayerGroupInfo> it = cat.list(LayerGroupInfo.class, filter, offset(page, count), count, sortBy); ) { while (it.hasNext()) { LayerGroupInfo map = it.next(); if( checkMap( map ) ){ map(arr.addObject(), map, wsName); } else { total--; } } } obj.put("total", total); obj.put("page", page != null ? page : 0); obj.put("count", Math.min(total, count != null ? count : total)); return obj; }
MapController extends ApiController { @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj list(@PathVariable String wsName, @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) { Catalog cat = geoServer.getCatalog(); if ("default".equals(wsName)) { WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { wsName = def.getName(); } } Filter filter = equal("workspace.name", wsName); if (textFilter != null) { filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter)); } SortBy sortBy = parseSort(sort); Integer total = cat.count(LayerGroupInfo.class, filter); JSONObj obj = new JSONObj(); JSONArr arr = obj.putArray("maps"); try ( CloseableIterator<LayerGroupInfo> it = cat.list(LayerGroupInfo.class, filter, offset(page, count), count, sortBy); ) { while (it.hasNext()) { LayerGroupInfo map = it.next(); if( checkMap( map ) ){ map(arr.addObject(), map, wsName); } else { total--; } } } obj.put("total", total); obj.put("page", page != null ? page : 0); obj.put("count", Math.min(total, count != null ? count : total)); return obj; } }
MapController extends ApiController { @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj list(@PathVariable String wsName, @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) { Catalog cat = geoServer.getCatalog(); if ("default".equals(wsName)) { WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { wsName = def.getName(); } } Filter filter = equal("workspace.name", wsName); if (textFilter != null) { filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter)); } SortBy sortBy = parseSort(sort); Integer total = cat.count(LayerGroupInfo.class, filter); JSONObj obj = new JSONObj(); JSONArr arr = obj.putArray("maps"); try ( CloseableIterator<LayerGroupInfo> it = cat.list(LayerGroupInfo.class, filter, offset(page, count), count, sortBy); ) { while (it.hasNext()) { LayerGroupInfo map = it.next(); if( checkMap( map ) ){ map(arr.addObject(), map, wsName); } else { total--; } } } obj.put("total", total); obj.put("page", page != null ? page : 0); obj.put("count", Math.min(total, count != null ? count : total)); return obj; } @Autowired  MapController(GeoServer geoServer, RecentObjectCache recentCache); }
MapController extends ApiController { @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj list(@PathVariable String wsName, @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) { Catalog cat = geoServer.getCatalog(); if ("default".equals(wsName)) { WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { wsName = def.getName(); } } Filter filter = equal("workspace.name", wsName); if (textFilter != null) { filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter)); } SortBy sortBy = parseSort(sort); Integer total = cat.count(LayerGroupInfo.class, filter); JSONObj obj = new JSONObj(); JSONArr arr = obj.putArray("maps"); try ( CloseableIterator<LayerGroupInfo> it = cat.list(LayerGroupInfo.class, filter, offset(page, count), count, sortBy); ) { while (it.hasNext()) { LayerGroupInfo map = it.next(); if( checkMap( map ) ){ map(arr.addObject(), map, wsName); } else { total--; } } } obj.put("total", total); obj.put("page", page != null ? page : 0); obj.put("count", Math.min(total, count != null ? count : total)); return obj; } @Autowired  MapController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, @PathVariable String name); @RequestMapping(value="/{wsName}/{name:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName,
                                     @PathVariable String name, HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName,
                                       @PathVariable String name,
                                       @RequestBody JSONObj obj,HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}/bounds", method = RequestMethod.PUT) @ResponseBody JSONObj bounds(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) @ResponseBody JSONObj copy(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj list(@PathVariable String wsName,
      @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); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.GET) @ResponseBody JSONArr mapLayerListGet(@PathVariable String wsName,
                            @PathVariable String name, HttpServletRequest req); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.PUT) @ResponseBody JSONArr mapLayerListPut(@PathVariable String wsName,
                                                 @PathVariable String name,
                                                 @RequestBody JSONArr layers, HttpServletRequest req); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.POST) @ResponseBody JSONArr mapLayerListPost(@PathVariable String wsName,
                                                  @PathVariable String name,
                                                  @RequestBody JSONArr layers, HttpServletRequest req); @RequestMapping(value="/{wsName}/{mpName}/layers/{name:.+}", method = RequestMethod.GET) @ResponseBody JSONObj mapLayerGet(@PathVariable String wsName,
                                             @PathVariable String mpName,
                                             @PathVariable String name, HttpServletRequest req); @RequestMapping(value="/recent", method = RequestMethod.GET) @ResponseBody JSONArr listRecentMaps(); @RequestMapping(value="/{wsName}/{mapName}/layers/{name:.+}", method = RequestMethod.DELETE) @ResponseBody JSONObj mapLayerDelete(@PathVariable String wsName,
                                                @PathVariable String mapName,
                                                @PathVariable String name, HttpServletRequest req); }
MapController extends ApiController { @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) public @ResponseBody JSONObj list(@PathVariable String wsName, @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) { Catalog cat = geoServer.getCatalog(); if ("default".equals(wsName)) { WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { wsName = def.getName(); } } Filter filter = equal("workspace.name", wsName); if (textFilter != null) { filter = Predicates.and(filter, Predicates.fullTextSearch(textFilter)); } SortBy sortBy = parseSort(sort); Integer total = cat.count(LayerGroupInfo.class, filter); JSONObj obj = new JSONObj(); JSONArr arr = obj.putArray("maps"); try ( CloseableIterator<LayerGroupInfo> it = cat.list(LayerGroupInfo.class, filter, offset(page, count), count, sortBy); ) { while (it.hasNext()) { LayerGroupInfo map = it.next(); if( checkMap( map ) ){ map(arr.addObject(), map, wsName); } else { total--; } } } obj.put("total", total); obj.put("page", page != null ? page : 0); obj.put("count", Math.min(total, count != null ? count : total)); return obj; } @Autowired  MapController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, @PathVariable String name); @RequestMapping(value="/{wsName}/{name:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName,
                                     @PathVariable String name, HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName,
                                       @PathVariable String name,
                                       @RequestBody JSONObj obj,HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name:.+}/bounds", method = RequestMethod.PUT) @ResponseBody JSONObj bounds(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) @ResponseBody JSONObj copy(@PathVariable String wsName,
                                     @PathVariable String name, 
                                     @RequestBody JSONObj obj,
                                     HttpServletRequest req); @RequestMapping(value="/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj list(@PathVariable String wsName,
      @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); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.GET) @ResponseBody JSONArr mapLayerListGet(@PathVariable String wsName,
                            @PathVariable String name, HttpServletRequest req); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.PUT) @ResponseBody JSONArr mapLayerListPut(@PathVariable String wsName,
                                                 @PathVariable String name,
                                                 @RequestBody JSONArr layers, HttpServletRequest req); @RequestMapping(value="/{wsName}/{name}/layers", method = RequestMethod.POST) @ResponseBody JSONArr mapLayerListPost(@PathVariable String wsName,
                                                  @PathVariable String name,
                                                  @RequestBody JSONArr layers, HttpServletRequest req); @RequestMapping(value="/{wsName}/{mpName}/layers/{name:.+}", method = RequestMethod.GET) @ResponseBody JSONObj mapLayerGet(@PathVariable String wsName,
                                             @PathVariable String mpName,
                                             @PathVariable String name, HttpServletRequest req); @RequestMapping(value="/recent", method = RequestMethod.GET) @ResponseBody JSONArr listRecentMaps(); @RequestMapping(value="/{wsName}/{mapName}/layers/{name:.+}", method = RequestMethod.DELETE) @ResponseBody JSONObj mapLayerDelete(@PathVariable String wsName,
                                                @PathVariable String mapName,
                                                @PathVariable String name, HttpServletRequest req);  }