@Test public void testPut() throws Exception { MockGeoServer.get().catalog() .workspace("foo", "http: .workspace("bar", "http: .geoServer().build(geoServer); JSONObj obj = new JSONObj().put("name", "blah"); MockHttpServletRequestBuilder request = put("/app/api/workspaces/foo") .contentType(MediaType.APPLICATION_JSON) .content(obj.toString()); mvc.perform(request) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); Catalog cat = geoServer.getCatalog(); verify(cat, times(1)).save(isA(NamespaceInfo.class)); verify(cat, times(1)).save(isA(NamespaceInfo.class)); WorkspaceInfo ws = cat.getWorkspaceByName("foo"); verify(ws, times(1)).setName("blah"); verify(recent, times(1)).add(eq(WorkspaceInfo.class), isA(WorkspaceInfo.class)); }
@RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); NamespaceInfo ns = namespaceFor(ws); String name = obj.str("name"); if (name != null) { ws.setName(name); ns.setPrefix(name); } String uri = obj.str("uri"); if (uri != null) { ns.setURI(uri); } Metadata.modified(ws, new Date()); cat.save(ws); cat.save(ns); recent.add(WorkspaceInfo.class, ws); Boolean isDefault = obj.bool("default"); if (Boolean.TRUE.equals(isDefault)) { cat.setDefaultWorkspace(ws); cat.setDefaultNamespace(ns); } else if (Boolean.FALSE.equals(isDefault)) { WorkspaceInfo defaultWorkspace = cat.getDefaultWorkspace(); if( defaultWorkspace != null && defaultWorkspace.getId().equals( ws.getId())){ cat.setDefaultWorkspace(null); cat.setDefaultNamespace(null); } } return IO.workspace(new JSONObj(), ws, ns, isDefault == Boolean.TRUE); }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); NamespaceInfo ns = namespaceFor(ws); String name = obj.str("name"); if (name != null) { ws.setName(name); ns.setPrefix(name); } String uri = obj.str("uri"); if (uri != null) { ns.setURI(uri); } Metadata.modified(ws, new Date()); cat.save(ws); cat.save(ns); recent.add(WorkspaceInfo.class, ws); Boolean isDefault = obj.bool("default"); if (Boolean.TRUE.equals(isDefault)) { cat.setDefaultWorkspace(ws); cat.setDefaultNamespace(ns); } else if (Boolean.FALSE.equals(isDefault)) { WorkspaceInfo defaultWorkspace = cat.getDefaultWorkspace(); if( defaultWorkspace != null && defaultWorkspace.getId().equals( ws.getId())){ cat.setDefaultWorkspace(null); cat.setDefaultNamespace(null); } } return IO.workspace(new JSONObj(), ws, ns, isDefault == Boolean.TRUE); } }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); NamespaceInfo ns = namespaceFor(ws); String name = obj.str("name"); if (name != null) { ws.setName(name); ns.setPrefix(name); } String uri = obj.str("uri"); if (uri != null) { ns.setURI(uri); } Metadata.modified(ws, new Date()); cat.save(ws); cat.save(ns); recent.add(WorkspaceInfo.class, ws); Boolean isDefault = obj.bool("default"); if (Boolean.TRUE.equals(isDefault)) { cat.setDefaultWorkspace(ws); cat.setDefaultNamespace(ns); } else if (Boolean.FALSE.equals(isDefault)) { WorkspaceInfo defaultWorkspace = cat.getDefaultWorkspace(); if( defaultWorkspace != null && defaultWorkspace.getId().equals( ws.getId())){ cat.setDefaultWorkspace(null); cat.setDefaultNamespace(null); } } return IO.workspace(new JSONObj(), ws, ns, isDefault == Boolean.TRUE); } @Autowired  WorkspaceController(GeoServer geoServer, RecentObjectCache recentCache); }
WorkspaceController extends ApiController { @RequestMapping(value = "/{wsName:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); NamespaceInfo ns = namespaceFor(ws); String name = obj.str("name"); if (name != null) { ws.setName(name); ns.setPrefix(name); } String uri = obj.str("uri"); if (uri != null) { ns.setURI(uri); } Metadata.modified(ws, new Date()); cat.save(ws); cat.save(ns); recent.add(WorkspaceInfo.class, ws); Boolean isDefault = obj.bool("default"); if (Boolean.TRUE.equals(isDefault)) { cat.setDefaultWorkspace(ws); cat.setDefaultNamespace(ns); } else if (Boolean.FALSE.equals(isDefault)) { WorkspaceInfo defaultWorkspace = cat.getDefaultWorkspace(); if( defaultWorkspace != null && defaultWorkspace.getId().equals( ws.getId())){ cat.setDefaultWorkspace(null); cat.setDefaultNamespace(null); } } return IO.workspace(new JSONObj(), ws, ns, isDefault == Boolean.TRUE); } @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(value = "/{wsName:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @RequestBody JSONObj obj) { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); NamespaceInfo ns = namespaceFor(ws); String name = obj.str("name"); if (name != null) { ws.setName(name); ns.setPrefix(name); } String uri = obj.str("uri"); if (uri != null) { ns.setURI(uri); } Metadata.modified(ws, new Date()); cat.save(ws); cat.save(ns); recent.add(WorkspaceInfo.class, ws); Boolean isDefault = obj.bool("default"); if (Boolean.TRUE.equals(isDefault)) { cat.setDefaultWorkspace(ws); cat.setDefaultNamespace(ns); } else if (Boolean.FALSE.equals(isDefault)) { WorkspaceInfo defaultWorkspace = cat.getDefaultWorkspace(); if( defaultWorkspace != null && defaultWorkspace.getId().equals( ws.getId())){ cat.setDefaultWorkspace(null); cat.setDefaultNamespace(null); } } return IO.workspace(new JSONObj(), ws, ns, isDefault == Boolean.TRUE); } @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; }