@Test public void testPut() throws Exception { @SuppressWarnings("unused") GeoServer gs = MockGeoServer.get().catalog() .workspace("foo", "http: .map("map").info("title", "map title") .defaults() .layer("one") .style().ysld("one.ysld").layer() .featureType().defaults().store("store").map() .layer("two") .style().ysld("two.ysld").layer() .featureType().defaults().store("store") .geoServer().build(geoServer); JSONObj obj = new JSONObj().put("title", "new title").put("proj", "EPSG:4326").put("timeout", 1000); MockHttpServletRequestBuilder req = put("/app/api/maps/foo/map") .contentType(MediaType.APPLICATION_JSON) .content(obj.toString()); mvc.perform(req).andExpect(status().isOk()).andReturn(); LayerGroupInfo l = gs.getCatalog().getLayerGroupByName("map"); verify(l, times(1)).setTitle("new title"); assertEquals(1000L, l.getMetadata().get("timeout")); }
@RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws Exception { Catalog cat = geoServer.getCatalog(); LayerGroupInfo map = findMap(wsName, name, cat); WorkspaceInfo ws = map.getWorkspace(); if(obj.has("name")){ map.setName( obj.str("name")); } if(obj.has("title")){ map.setTitle(obj.str("title")); } if(obj.has("description")){ map.setAbstract(obj.str("description")); } if(obj.has("proj")) { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); String srs = obj.str("proj"); try { crs = CRS.decode(srs); } catch (FactoryException e) { throw new BadRequestException("Unknown spatial reference identifier: " + srs); } if (obj.has("bbox")){ Envelope envelope = IO.bounds(obj.object("bbox")); ReferencedEnvelope bounds = new ReferencedEnvelope( envelope, crs ); map.setBounds(bounds); } else { new CatalogBuilder( cat ).calculateLayerGroupBounds( map, crs ); } } if(obj.has("layers")){ List<LayerInfo> layers = new ArrayList<LayerInfo>(); for(Iterator<Object> i = obj.array("layers").iterator();i.hasNext();){ JSONObj l = (JSONObj) i.next(); String n = l.str("workspace")+":"+l.str("name"); LayerInfo layer = cat.getLayerByName(n); layers.add(layer); } map.layers().clear(); map.layers().addAll(layers); } if (obj.has("timeout")) { map.getMetadata().put("timeout", (Serializable)obj.get("timeout")); } String user = SecurityContextHolder.getContext().getAuthentication().getName(); map.getMetadata().put("user", user ); Date modified = new Date(); Metadata.modified(map, modified); Metadata.modified(ws, modified); if(obj.has("change")){ map.getMetadata().put("change", obj.str("change") ); } else { map.getMetadata().put("change", "modified "+obj.keys() ); } cat.save(map); cat.save(ws); recent.add(LayerGroupInfo.class, map); recent.add(WorkspaceInfo.class, ws); return mapDetails(new JSONObj(), map, wsName, req); }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws Exception { Catalog cat = geoServer.getCatalog(); LayerGroupInfo map = findMap(wsName, name, cat); WorkspaceInfo ws = map.getWorkspace(); if(obj.has("name")){ map.setName( obj.str("name")); } if(obj.has("title")){ map.setTitle(obj.str("title")); } if(obj.has("description")){ map.setAbstract(obj.str("description")); } if(obj.has("proj")) { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); String srs = obj.str("proj"); try { crs = CRS.decode(srs); } catch (FactoryException e) { throw new BadRequestException("Unknown spatial reference identifier: " + srs); } if (obj.has("bbox")){ Envelope envelope = IO.bounds(obj.object("bbox")); ReferencedEnvelope bounds = new ReferencedEnvelope( envelope, crs ); map.setBounds(bounds); } else { new CatalogBuilder( cat ).calculateLayerGroupBounds( map, crs ); } } if(obj.has("layers")){ List<LayerInfo> layers = new ArrayList<LayerInfo>(); for(Iterator<Object> i = obj.array("layers").iterator();i.hasNext();){ JSONObj l = (JSONObj) i.next(); String n = l.str("workspace")+":"+l.str("name"); LayerInfo layer = cat.getLayerByName(n); layers.add(layer); } map.layers().clear(); map.layers().addAll(layers); } if (obj.has("timeout")) { map.getMetadata().put("timeout", (Serializable)obj.get("timeout")); } String user = SecurityContextHolder.getContext().getAuthentication().getName(); map.getMetadata().put("user", user ); Date modified = new Date(); Metadata.modified(map, modified); Metadata.modified(ws, modified); if(obj.has("change")){ map.getMetadata().put("change", obj.str("change") ); } else { map.getMetadata().put("change", "modified "+obj.keys() ); } cat.save(map); cat.save(ws); recent.add(LayerGroupInfo.class, map); recent.add(WorkspaceInfo.class, ws); return mapDetails(new JSONObj(), map, wsName, req); } }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws Exception { Catalog cat = geoServer.getCatalog(); LayerGroupInfo map = findMap(wsName, name, cat); WorkspaceInfo ws = map.getWorkspace(); if(obj.has("name")){ map.setName( obj.str("name")); } if(obj.has("title")){ map.setTitle(obj.str("title")); } if(obj.has("description")){ map.setAbstract(obj.str("description")); } if(obj.has("proj")) { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); String srs = obj.str("proj"); try { crs = CRS.decode(srs); } catch (FactoryException e) { throw new BadRequestException("Unknown spatial reference identifier: " + srs); } if (obj.has("bbox")){ Envelope envelope = IO.bounds(obj.object("bbox")); ReferencedEnvelope bounds = new ReferencedEnvelope( envelope, crs ); map.setBounds(bounds); } else { new CatalogBuilder( cat ).calculateLayerGroupBounds( map, crs ); } } if(obj.has("layers")){ List<LayerInfo> layers = new ArrayList<LayerInfo>(); for(Iterator<Object> i = obj.array("layers").iterator();i.hasNext();){ JSONObj l = (JSONObj) i.next(); String n = l.str("workspace")+":"+l.str("name"); LayerInfo layer = cat.getLayerByName(n); layers.add(layer); } map.layers().clear(); map.layers().addAll(layers); } if (obj.has("timeout")) { map.getMetadata().put("timeout", (Serializable)obj.get("timeout")); } String user = SecurityContextHolder.getContext().getAuthentication().getName(); map.getMetadata().put("user", user ); Date modified = new Date(); Metadata.modified(map, modified); Metadata.modified(ws, modified); if(obj.has("change")){ map.getMetadata().put("change", obj.str("change") ); } else { map.getMetadata().put("change", "modified "+obj.keys() ); } cat.save(map); cat.save(ws); recent.add(LayerGroupInfo.class, map); recent.add(WorkspaceInfo.class, ws); return mapDetails(new JSONObj(), map, wsName, req); } @Autowired  MapController(GeoServer geoServer, RecentObjectCache recentCache); }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws Exception { Catalog cat = geoServer.getCatalog(); LayerGroupInfo map = findMap(wsName, name, cat); WorkspaceInfo ws = map.getWorkspace(); if(obj.has("name")){ map.setName( obj.str("name")); } if(obj.has("title")){ map.setTitle(obj.str("title")); } if(obj.has("description")){ map.setAbstract(obj.str("description")); } if(obj.has("proj")) { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); String srs = obj.str("proj"); try { crs = CRS.decode(srs); } catch (FactoryException e) { throw new BadRequestException("Unknown spatial reference identifier: " + srs); } if (obj.has("bbox")){ Envelope envelope = IO.bounds(obj.object("bbox")); ReferencedEnvelope bounds = new ReferencedEnvelope( envelope, crs ); map.setBounds(bounds); } else { new CatalogBuilder( cat ).calculateLayerGroupBounds( map, crs ); } } if(obj.has("layers")){ List<LayerInfo> layers = new ArrayList<LayerInfo>(); for(Iterator<Object> i = obj.array("layers").iterator();i.hasNext();){ JSONObj l = (JSONObj) i.next(); String n = l.str("workspace")+":"+l.str("name"); LayerInfo layer = cat.getLayerByName(n); layers.add(layer); } map.layers().clear(); map.layers().addAll(layers); } if (obj.has("timeout")) { map.getMetadata().put("timeout", (Serializable)obj.get("timeout")); } String user = SecurityContextHolder.getContext().getAuthentication().getName(); map.getMetadata().put("user", user ); Date modified = new Date(); Metadata.modified(map, modified); Metadata.modified(ws, modified); if(obj.has("change")){ map.getMetadata().put("change", obj.str("change") ); } else { map.getMetadata().put("change", "modified "+obj.keys() ); } cat.save(map); cat.save(ws); recent.add(LayerGroupInfo.class, map); recent.add(WorkspaceInfo.class, ws); return mapDetails(new JSONObj(), map, wsName, req); } @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}/{name:.+}", method = RequestMethod.PUT) public @ResponseBody JSONObj put(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws Exception { Catalog cat = geoServer.getCatalog(); LayerGroupInfo map = findMap(wsName, name, cat); WorkspaceInfo ws = map.getWorkspace(); if(obj.has("name")){ map.setName( obj.str("name")); } if(obj.has("title")){ map.setTitle(obj.str("title")); } if(obj.has("description")){ map.setAbstract(obj.str("description")); } if(obj.has("proj")) { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); String srs = obj.str("proj"); try { crs = CRS.decode(srs); } catch (FactoryException e) { throw new BadRequestException("Unknown spatial reference identifier: " + srs); } if (obj.has("bbox")){ Envelope envelope = IO.bounds(obj.object("bbox")); ReferencedEnvelope bounds = new ReferencedEnvelope( envelope, crs ); map.setBounds(bounds); } else { new CatalogBuilder( cat ).calculateLayerGroupBounds( map, crs ); } } if(obj.has("layers")){ List<LayerInfo> layers = new ArrayList<LayerInfo>(); for(Iterator<Object> i = obj.array("layers").iterator();i.hasNext();){ JSONObj l = (JSONObj) i.next(); String n = l.str("workspace")+":"+l.str("name"); LayerInfo layer = cat.getLayerByName(n); layers.add(layer); } map.layers().clear(); map.layers().addAll(layers); } if (obj.has("timeout")) { map.getMetadata().put("timeout", (Serializable)obj.get("timeout")); } String user = SecurityContextHolder.getContext().getAuthentication().getName(); map.getMetadata().put("user", user ); Date modified = new Date(); Metadata.modified(map, modified); Metadata.modified(ws, modified); if(obj.has("change")){ map.getMetadata().put("change", obj.str("change") ); } else { map.getMetadata().put("change", "modified "+obj.keys() ); } cat.save(map); cat.save(ws); recent.add(LayerGroupInfo.class, map); recent.add(WorkspaceInfo.class, ws); return mapDetails(new JSONObj(), map, wsName, req); } @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);  }