@Test public void testCopy() throws Exception { MockGeoServer.get().catalog() .workspace("foo", "http: .map("map") .defaults() .info("The map", "This map is cool!") .layer("one").style().point().layer().featureType().defaults().store("shape").map() .layer("two").style().point().layer().featureType().defaults().store("shape") .geoServer().build(geoServer); Catalog cat = geoServer.getCatalog(); JSONObj obj = new JSONObj(); obj.put("name", "bar"); obj.put("copylayers", "false"); MockHttpServletRequestBuilder req = put("/app/api/maps/foo/map/copy") .contentType(MediaType.APPLICATION_JSON) .content(obj.toString()); mvc.perform(req) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); verify(cat, times(1)).add(isA(LayerGroupInfo.class)); }
@RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) public @ResponseBody JSONObj copy(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); String nameCopy = obj.str("name"); JSONObj map = get(wsName, name, req).put("name", nameCopy); if (!obj.has("copylayers") || obj.bool("copylayers")) { JSONArr layers = new JSONArr(); Map<String, Integer> renames = new HashMap<String, Integer>(); if (obj.has("layers")) { layers = obj.array("layers"); for (int i = 0; i < layers.size(); i++) { JSONObj layer = layers.object(i); renames.put(layer.object("layer").str("name"), i); } } JSONArr oldLayers = map.array("layers"); JSONArr newLayers = new JSONArr(); for (JSONObj layer : oldLayers.objects()) { String layerName = layer.str("name"); if (renames.containsKey(layerName)) { newLayers.add(layerController.create(wsName, layers.object(renames.get(layerName)), req)); renames.remove(layerName); } else { JSONObj newLayer = new JSONObj() .put("name", layerName + "-" + nameCopy.substring(0, 3)) .put("layer", layer); newLayers.add(layerController.create(wsName, newLayer, req)); } } if (renames.size() > 0) { for (Integer i : renames.values()) { LOG.log(Level.FINE, wsName+"."+name+" unrecognized layers:" +layers.object(renames.get(i)).str("name")); } } map.put("layers", newLayers); } return create(wsName, map, req); }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) public @ResponseBody JSONObj copy(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); String nameCopy = obj.str("name"); JSONObj map = get(wsName, name, req).put("name", nameCopy); if (!obj.has("copylayers") || obj.bool("copylayers")) { JSONArr layers = new JSONArr(); Map<String, Integer> renames = new HashMap<String, Integer>(); if (obj.has("layers")) { layers = obj.array("layers"); for (int i = 0; i < layers.size(); i++) { JSONObj layer = layers.object(i); renames.put(layer.object("layer").str("name"), i); } } JSONArr oldLayers = map.array("layers"); JSONArr newLayers = new JSONArr(); for (JSONObj layer : oldLayers.objects()) { String layerName = layer.str("name"); if (renames.containsKey(layerName)) { newLayers.add(layerController.create(wsName, layers.object(renames.get(layerName)), req)); renames.remove(layerName); } else { JSONObj newLayer = new JSONObj() .put("name", layerName + "-" + nameCopy.substring(0, 3)) .put("layer", layer); newLayers.add(layerController.create(wsName, newLayer, req)); } } if (renames.size() > 0) { for (Integer i : renames.values()) { LOG.log(Level.FINE, wsName+"."+name+" unrecognized layers:" +layers.object(renames.get(i)).str("name")); } } map.put("layers", newLayers); } return create(wsName, map, req); } }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) public @ResponseBody JSONObj copy(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); String nameCopy = obj.str("name"); JSONObj map = get(wsName, name, req).put("name", nameCopy); if (!obj.has("copylayers") || obj.bool("copylayers")) { JSONArr layers = new JSONArr(); Map<String, Integer> renames = new HashMap<String, Integer>(); if (obj.has("layers")) { layers = obj.array("layers"); for (int i = 0; i < layers.size(); i++) { JSONObj layer = layers.object(i); renames.put(layer.object("layer").str("name"), i); } } JSONArr oldLayers = map.array("layers"); JSONArr newLayers = new JSONArr(); for (JSONObj layer : oldLayers.objects()) { String layerName = layer.str("name"); if (renames.containsKey(layerName)) { newLayers.add(layerController.create(wsName, layers.object(renames.get(layerName)), req)); renames.remove(layerName); } else { JSONObj newLayer = new JSONObj() .put("name", layerName + "-" + nameCopy.substring(0, 3)) .put("layer", layer); newLayers.add(layerController.create(wsName, newLayer, req)); } } if (renames.size() > 0) { for (Integer i : renames.values()) { LOG.log(Level.FINE, wsName+"."+name+" unrecognized layers:" +layers.object(renames.get(i)).str("name")); } } map.put("layers", newLayers); } return create(wsName, map, req); } @Autowired  MapController(GeoServer geoServer, RecentObjectCache recentCache); }
MapController extends ApiController { @RequestMapping(value = "/{wsName}/{name}/copy", method = RequestMethod.PUT) public @ResponseBody JSONObj copy(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); String nameCopy = obj.str("name"); JSONObj map = get(wsName, name, req).put("name", nameCopy); if (!obj.has("copylayers") || obj.bool("copylayers")) { JSONArr layers = new JSONArr(); Map<String, Integer> renames = new HashMap<String, Integer>(); if (obj.has("layers")) { layers = obj.array("layers"); for (int i = 0; i < layers.size(); i++) { JSONObj layer = layers.object(i); renames.put(layer.object("layer").str("name"), i); } } JSONArr oldLayers = map.array("layers"); JSONArr newLayers = new JSONArr(); for (JSONObj layer : oldLayers.objects()) { String layerName = layer.str("name"); if (renames.containsKey(layerName)) { newLayers.add(layerController.create(wsName, layers.object(renames.get(layerName)), req)); renames.remove(layerName); } else { JSONObj newLayer = new JSONObj() .put("name", layerName + "-" + nameCopy.substring(0, 3)) .put("layer", layer); newLayers.add(layerController.create(wsName, newLayer, req)); } } if (renames.size() > 0) { for (Integer i : renames.values()) { LOG.log(Level.FINE, wsName+"."+name+" unrecognized layers:" +layers.object(renames.get(i)).str("name")); } } map.put("layers", newLayers); } return create(wsName, map, 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}/copy", method = RequestMethod.PUT) public @ResponseBody JSONObj copy(@PathVariable String wsName, @PathVariable String name, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); String nameCopy = obj.str("name"); JSONObj map = get(wsName, name, req).put("name", nameCopy); if (!obj.has("copylayers") || obj.bool("copylayers")) { JSONArr layers = new JSONArr(); Map<String, Integer> renames = new HashMap<String, Integer>(); if (obj.has("layers")) { layers = obj.array("layers"); for (int i = 0; i < layers.size(); i++) { JSONObj layer = layers.object(i); renames.put(layer.object("layer").str("name"), i); } } JSONArr oldLayers = map.array("layers"); JSONArr newLayers = new JSONArr(); for (JSONObj layer : oldLayers.objects()) { String layerName = layer.str("name"); if (renames.containsKey(layerName)) { newLayers.add(layerController.create(wsName, layers.object(renames.get(layerName)), req)); renames.remove(layerName); } else { JSONObj newLayer = new JSONObj() .put("name", layerName + "-" + nameCopy.substring(0, 3)) .put("layer", layer); newLayers.add(layerController.create(wsName, newLayer, req)); } } if (renames.size() > 0) { for (Integer i : renames.values()) { LOG.log(Level.FINE, wsName+"."+name+" unrecognized layers:" +layers.object(renames.get(i)).str("name")); } } map.put("layers", newLayers); } return create(wsName, map, 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);  }