@Test public void testCreate() throws Exception { MockGeoServer.get().catalog() .workspace("foo", "http: .layer("one").style().point().layer().featureType().defaults().store("sample") .geoServer().build(geoServer); JSONObj obj = new JSONObj(); obj.put("name", "foo"); obj.put("title", "Foo"); obj.putObject("proj").put("srs", "EPSG:4326"); obj.putArray("layers").addObject().put("name", "one"); MockHttpServletRequestBuilder req = post("/app/api/maps/foo") .contentType(MediaType.APPLICATION_JSON) .content(obj.toString()); mvc.perform(req) .andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); Catalog cat = geoServer.getCatalog(); verify(cat, times(1)).add(isA(LayerGroupInfo.class)); }
@RequestMapping(value = "/{wsName:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); String name = obj.str("name"); if (name == null) { throw new BadRequestException("Map object requires name"); } try { findMap(wsName, name, cat); throw new BadRequestException("Map named '" + name + "' already exists"); } catch(NotFoundException e) { } String title = obj.str("title"); String description = obj.str("abstract"); Date created = new Date(); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); JSONObj proj = obj.object("proj"); if (proj != null) { try { crs = IO.crs(proj); } catch (Exception e) { throw new BadRequestException("Error parsing proj: " + proj.toString()); } } else { throw new BadRequestException("Map object requires projection"); } ReferencedEnvelope bounds = null; boolean updateBounds = false; if (obj.has("bbox")) { Envelope envelope = IO.bounds(obj.object("bbox")); bounds = new ReferencedEnvelope( envelope, crs ); } else { bounds = new ReferencedEnvelope(crs); updateBounds = true; } if (!obj.has("layers")) { throw new BadRequestException("Map object requires layers array"); } LayerGroupInfo map = cat.getFactory().createLayerGroup(); map.setName( name ); map.setAbstract( description ); map.setTitle( title ); map.setMode( Mode.SINGLE ); map.setWorkspace(ws); for (Object o : obj.array("layers")) { JSONObj l = (JSONObj) o; LayerInfo layer = findLayer(wsName, l.str("name"), cat); map.getLayers().add(layer); map.getStyles().add(null); if (updateBounds) { try { updateBounds(bounds, layer); } catch (Exception e) { throw new RuntimeException("Error calculating map bounds ", e); } } } map.setBounds( bounds ); Metadata.created(map, created); Metadata.modified(map, created); Metadata.modified(ws, created); cat.add( 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:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); String name = obj.str("name"); if (name == null) { throw new BadRequestException("Map object requires name"); } try { findMap(wsName, name, cat); throw new BadRequestException("Map named '" + name + "' already exists"); } catch(NotFoundException e) { } String title = obj.str("title"); String description = obj.str("abstract"); Date created = new Date(); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); JSONObj proj = obj.object("proj"); if (proj != null) { try { crs = IO.crs(proj); } catch (Exception e) { throw new BadRequestException("Error parsing proj: " + proj.toString()); } } else { throw new BadRequestException("Map object requires projection"); } ReferencedEnvelope bounds = null; boolean updateBounds = false; if (obj.has("bbox")) { Envelope envelope = IO.bounds(obj.object("bbox")); bounds = new ReferencedEnvelope( envelope, crs ); } else { bounds = new ReferencedEnvelope(crs); updateBounds = true; } if (!obj.has("layers")) { throw new BadRequestException("Map object requires layers array"); } LayerGroupInfo map = cat.getFactory().createLayerGroup(); map.setName( name ); map.setAbstract( description ); map.setTitle( title ); map.setMode( Mode.SINGLE ); map.setWorkspace(ws); for (Object o : obj.array("layers")) { JSONObj l = (JSONObj) o; LayerInfo layer = findLayer(wsName, l.str("name"), cat); map.getLayers().add(layer); map.getStyles().add(null); if (updateBounds) { try { updateBounds(bounds, layer); } catch (Exception e) { throw new RuntimeException("Error calculating map bounds ", e); } } } map.setBounds( bounds ); Metadata.created(map, created); Metadata.modified(map, created); Metadata.modified(ws, created); cat.add( 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:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); String name = obj.str("name"); if (name == null) { throw new BadRequestException("Map object requires name"); } try { findMap(wsName, name, cat); throw new BadRequestException("Map named '" + name + "' already exists"); } catch(NotFoundException e) { } String title = obj.str("title"); String description = obj.str("abstract"); Date created = new Date(); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); JSONObj proj = obj.object("proj"); if (proj != null) { try { crs = IO.crs(proj); } catch (Exception e) { throw new BadRequestException("Error parsing proj: " + proj.toString()); } } else { throw new BadRequestException("Map object requires projection"); } ReferencedEnvelope bounds = null; boolean updateBounds = false; if (obj.has("bbox")) { Envelope envelope = IO.bounds(obj.object("bbox")); bounds = new ReferencedEnvelope( envelope, crs ); } else { bounds = new ReferencedEnvelope(crs); updateBounds = true; } if (!obj.has("layers")) { throw new BadRequestException("Map object requires layers array"); } LayerGroupInfo map = cat.getFactory().createLayerGroup(); map.setName( name ); map.setAbstract( description ); map.setTitle( title ); map.setMode( Mode.SINGLE ); map.setWorkspace(ws); for (Object o : obj.array("layers")) { JSONObj l = (JSONObj) o; LayerInfo layer = findLayer(wsName, l.str("name"), cat); map.getLayers().add(layer); map.getStyles().add(null); if (updateBounds) { try { updateBounds(bounds, layer); } catch (Exception e) { throw new RuntimeException("Error calculating map bounds ", e); } } } map.setBounds( bounds ); Metadata.created(map, created); Metadata.modified(map, created); Metadata.modified(ws, created); cat.add( 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:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); String name = obj.str("name"); if (name == null) { throw new BadRequestException("Map object requires name"); } try { findMap(wsName, name, cat); throw new BadRequestException("Map named '" + name + "' already exists"); } catch(NotFoundException e) { } String title = obj.str("title"); String description = obj.str("abstract"); Date created = new Date(); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); JSONObj proj = obj.object("proj"); if (proj != null) { try { crs = IO.crs(proj); } catch (Exception e) { throw new BadRequestException("Error parsing proj: " + proj.toString()); } } else { throw new BadRequestException("Map object requires projection"); } ReferencedEnvelope bounds = null; boolean updateBounds = false; if (obj.has("bbox")) { Envelope envelope = IO.bounds(obj.object("bbox")); bounds = new ReferencedEnvelope( envelope, crs ); } else { bounds = new ReferencedEnvelope(crs); updateBounds = true; } if (!obj.has("layers")) { throw new BadRequestException("Map object requires layers array"); } LayerGroupInfo map = cat.getFactory().createLayerGroup(); map.setName( name ); map.setAbstract( description ); map.setTitle( title ); map.setMode( Mode.SINGLE ); map.setWorkspace(ws); for (Object o : obj.array("layers")) { JSONObj l = (JSONObj) o; LayerInfo layer = findLayer(wsName, l.str("name"), cat); map.getLayers().add(layer); map.getStyles().add(null); if (updateBounds) { try { updateBounds(bounds, layer); } catch (Exception e) { throw new RuntimeException("Error calculating map bounds ", e); } } } map.setBounds( bounds ); Metadata.created(map, created); Metadata.modified(map, created); Metadata.modified(ws, created); cat.add( 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:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.CREATED) public @ResponseBody JSONObj create(@PathVariable String wsName, @RequestBody JSONObj obj, HttpServletRequest req) throws NoSuchAuthorityCodeException, FactoryException { Catalog cat = catalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); String name = obj.str("name"); if (name == null) { throw new BadRequestException("Map object requires name"); } try { findMap(wsName, name, cat); throw new BadRequestException("Map named '" + name + "' already exists"); } catch(NotFoundException e) { } String title = obj.str("title"); String description = obj.str("abstract"); Date created = new Date(); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); JSONObj proj = obj.object("proj"); if (proj != null) { try { crs = IO.crs(proj); } catch (Exception e) { throw new BadRequestException("Error parsing proj: " + proj.toString()); } } else { throw new BadRequestException("Map object requires projection"); } ReferencedEnvelope bounds = null; boolean updateBounds = false; if (obj.has("bbox")) { Envelope envelope = IO.bounds(obj.object("bbox")); bounds = new ReferencedEnvelope( envelope, crs ); } else { bounds = new ReferencedEnvelope(crs); updateBounds = true; } if (!obj.has("layers")) { throw new BadRequestException("Map object requires layers array"); } LayerGroupInfo map = cat.getFactory().createLayerGroup(); map.setName( name ); map.setAbstract( description ); map.setTitle( title ); map.setMode( Mode.SINGLE ); map.setWorkspace(ws); for (Object o : obj.array("layers")) { JSONObj l = (JSONObj) o; LayerInfo layer = findLayer(wsName, l.str("name"), cat); map.getLayers().add(layer); map.getStyles().add(null); if (updateBounds) { try { updateBounds(bounds, layer); } catch (Exception e) { throw new RuntimeException("Error calculating map bounds ", e); } } } map.setBounds( bounds ); Metadata.created(map, created); Metadata.modified(map, created); Metadata.modified(ws, created); cat.add( 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);  }