@Test public void testList() throws Exception { MockGeoServer.get().catalog() .workspace("foo", "http: .workspace("bar", "http: .geoServer().build(geoServer); GeoServerResourceLoader resourceLoader = mock(GeoServerResourceLoader.class); when(resourceLoader.get("workspaces/foo/workspace.xml")).thenAnswer(mockResource()); when(resourceLoader.get("workspaces/bar/workspace.xml")).thenAnswer(mockResource()); Catalog catalog = geoServer.getCatalog(); when(catalog.getResourceLoader()).thenReturn(resourceLoader); MvcResult result = mvc.perform(get("/app/api/workspaces")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); JSONArr arr = JSONWrapper.read(result.getResponse().getContentAsString()).toArray(); assertEquals(2, arr.size()); JSONObj obj = arr.object(0); assertEquals("foo", obj.str("name")); assertTrue(obj.bool("default")); assertEquals("http: assertTrue(obj.has("modified")); assertTrue(obj.object("modified").has("timestamp")); assertTrue(obj.object("modified").has("pretty")); obj = arr.object(1); assertEquals("bar", obj.str("name")); assertFalse(obj.bool("default")); assertEquals("http: assertTrue(obj.has("modified")); assertTrue(obj.object("modified").has("timestamp")); assertTrue(obj.object("modified").has("pretty")); }
@RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { JSONArr arr = new JSONArr(); Catalog cat = geoServer.getCatalog(); WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { workspace(arr.addObject(), def, namespaceFor(def), true); } try ( CloseableIterator<WorkspaceInfo> list = cat.list(WorkspaceInfo.class, Predicates.acceptAll()); ) { while(list.hasNext()) { WorkspaceInfo ws = list.next(); if (def != null && ws.getName().equals(def.getName())) { continue; } NamespaceInfo ns = namespaceFor(ws); workspace(arr.addObject(), ws, ns, false); } } return arr; }
WorkspaceController extends ApiController { @RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { JSONArr arr = new JSONArr(); Catalog cat = geoServer.getCatalog(); WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { workspace(arr.addObject(), def, namespaceFor(def), true); } try ( CloseableIterator<WorkspaceInfo> list = cat.list(WorkspaceInfo.class, Predicates.acceptAll()); ) { while(list.hasNext()) { WorkspaceInfo ws = list.next(); if (def != null && ws.getName().equals(def.getName())) { continue; } NamespaceInfo ns = namespaceFor(ws); workspace(arr.addObject(), ws, ns, false); } } return arr; } }
WorkspaceController extends ApiController { @RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { JSONArr arr = new JSONArr(); Catalog cat = geoServer.getCatalog(); WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { workspace(arr.addObject(), def, namespaceFor(def), true); } try ( CloseableIterator<WorkspaceInfo> list = cat.list(WorkspaceInfo.class, Predicates.acceptAll()); ) { while(list.hasNext()) { WorkspaceInfo ws = list.next(); if (def != null && ws.getName().equals(def.getName())) { continue; } NamespaceInfo ns = namespaceFor(ws); workspace(arr.addObject(), ws, ns, false); } } return arr; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); }
WorkspaceController extends ApiController { @RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { JSONArr arr = new JSONArr(); Catalog cat = geoServer.getCatalog(); WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { workspace(arr.addObject(), def, namespaceFor(def), true); } try ( CloseableIterator<WorkspaceInfo> list = cat.list(WorkspaceInfo.class, Predicates.acceptAll()); ) { while(list.hasNext()) { WorkspaceInfo ws = list.next(); if (def != null && ws.getName().equals(def.getName())) { continue; } NamespaceInfo ns = namespaceFor(ws); workspace(arr.addObject(), ws, ns, false); } } return arr; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(method = RequestMethod.GET) @ResponseBody JSONArr list(); @RequestMapping(value = "/recent", method = RequestMethod.GET) @ResponseBody JSONArr recent(); @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/export", method = RequestMethod.POST, produces = APPLICATION_ZIP_VALUE) @ResponseStatus(value = HttpStatus.OK) void export(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/import", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(value = HttpStatus.OK) void inport(@PathVariable String wsName, HttpServletRequest request, HttpServletResponse response); }
WorkspaceController extends ApiController { @RequestMapping(method = RequestMethod.GET) public @ResponseBody JSONArr list() { JSONArr arr = new JSONArr(); Catalog cat = geoServer.getCatalog(); WorkspaceInfo def = cat.getDefaultWorkspace(); if (def != null) { workspace(arr.addObject(), def, namespaceFor(def), true); } try ( CloseableIterator<WorkspaceInfo> list = cat.list(WorkspaceInfo.class, Predicates.acceptAll()); ) { while(list.hasNext()) { WorkspaceInfo ws = list.next(); if (def != null && ws.getName().equals(def.getName())) { continue; } NamespaceInfo ns = namespaceFor(ws); workspace(arr.addObject(), ws, ns, false); } } return arr; } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); @RequestMapping(method = RequestMethod.GET) @ResponseBody JSONArr list(); @RequestMapping(value = "/recent", method = RequestMethod.GET) @ResponseBody JSONArr recent(); @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody JSONObj create(@RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.GET) @ResponseBody JSONObj get(@PathVariable String wsName); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PATCH) @ResponseBody JSONObj patch(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj); @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.NO_CONTENT) void delete(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/export", method = RequestMethod.POST, produces = APPLICATION_ZIP_VALUE) @ResponseStatus(value = HttpStatus.OK) void export(@PathVariable String wsName, HttpServletResponse response); @RequestMapping(value = "/{wsName}/import", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(value = HttpStatus.OK) void inport(@PathVariable String wsName, HttpServletRequest request, HttpServletResponse response); static final String APPLICATION_ZIP_VALUE; }