Skip to content

Commit

Permalink
Make RequestMapping path syntax and PathVariable names consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarsballe committed Apr 6, 2017
1 parent 637663d commit c6a929e
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 305 deletions.
Expand Up @@ -16,12 +16,11 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = RestBaseController.ROOT_PATH, produces = { MediaType.APPLICATION_JSON_VALUE,
@RequestMapping(path = RestBaseController.ROOT_PATH + "/fonts", produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE })
public class FontListController extends RestBaseController {

@GetMapping(value = "/fonts", produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE })
@GetMapping
public Map<String, Set<String>> getFonts() {
FontCache cache = FontCache.getDefaultInstance();

Expand Down
Expand Up @@ -6,7 +6,7 @@
/**
* Base controller implementation for geoserver info requests
*/
public class GeoServerController extends RestBaseController {
public abstract class GeoServerController extends RestBaseController {
protected final GeoServer geoServer;

public GeoServerController(GeoServer geoServer) {
Expand Down
Expand Up @@ -27,38 +27,38 @@
*/
@RestController
@ControllerAdvice
@RequestMapping(path = RestBaseController.ROOT_PATH)
@RequestMapping(path = RestBaseController.ROOT_PATH + "/workspaces/{workspaceName}/settings")
public class LocalSettingsController extends GeoServerController {

@Autowired
public LocalSettingsController(GeoServer geoServer) {
super(geoServer);
}

@GetMapping(value = "/workspaces/{wsName}/settings", produces = { MediaType.APPLICATION_JSON_VALUE,
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE })
public RestWrapper<SettingsInfo> getLocalSettings(@PathVariable String wsName) {
if (wsName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(wsName);
public RestWrapper<SettingsInfo> getLocalSettings(@PathVariable String workspaceName) {
if (workspaceName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(workspaceName);
SettingsInfo settingsInfo = geoServer.getSettings(workspaceInfo);
if (settingsInfo == null) {
settingsInfo = new SettingsInfoImpl();
settingsInfo.setVerbose(false);
}
return wrapObject(settingsInfo, SettingsInfo.class);
}
throw new RestException("Workspace " + wsName + " not found", HttpStatus.BAD_REQUEST);
throw new RestException("Workspace " + workspaceName + " not found", HttpStatus.BAD_REQUEST);
}

@PostMapping(value = "/workspaces/{wsName}/settings", consumes = {
@PostMapping(consumes = {
MediaType.APPLICATION_JSON_VALUE, CatalogController.TEXT_JSON,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
@ResponseStatus(HttpStatus.CREATED)
public String createLocalSettings(@PathVariable String wsName, @RequestBody SettingsInfo settingsInfo) {
public String createLocalSettings(@PathVariable String workspaceName, @RequestBody SettingsInfo settingsInfo) {
String name = "";
if (wsName != null) {
if (workspaceName != null) {
Catalog catalog = geoServer.getCatalog();
WorkspaceInfo workspaceInfo = catalog.getWorkspaceByName(wsName);
WorkspaceInfo workspaceInfo = catalog.getWorkspaceByName(workspaceName);
settingsInfo.setWorkspace(workspaceInfo);
geoServer.add(settingsInfo);
geoServer.save(geoServer.getSettings(workspaceInfo));
Expand All @@ -67,12 +67,12 @@ public String createLocalSettings(@PathVariable String wsName, @RequestBody Sett
return name;
}

@PutMapping(value = "/workspaces/{wsName}/settings", consumes = {
@PutMapping(consumes = {
MediaType.APPLICATION_JSON_VALUE, CatalogController.TEXT_JSON,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void setLocalSettings(@PathVariable String wsName, @RequestBody SettingsInfo settingsInfo) {
if (wsName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(wsName);
public void setLocalSettings(@PathVariable String workspaceName, @RequestBody SettingsInfo settingsInfo) {
if (workspaceName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(workspaceName);
SettingsInfo original = geoServer.getSettings(workspaceInfo);
if (original == null) {
settingsInfo.setWorkspace(workspaceInfo);
Expand All @@ -86,10 +86,10 @@ public void setLocalSettings(@PathVariable String wsName, @RequestBody SettingsI
}
}

@DeleteMapping(value = "/workspaces/{wsName}/settings")
public void deleteLocalSetings(@PathVariable String wsName) {
if (wsName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(wsName);
@DeleteMapping
public void deleteLocalSetings(@PathVariable String workspaceName) {
if (workspaceName != null) {
WorkspaceInfo workspaceInfo = geoServer.getCatalog().getWorkspaceByName(workspaceName);
SettingsInfo settingsInfo = geoServer.getSettings(workspaceInfo);
geoServer.remove(settingsInfo);
}
Expand Down
Expand Up @@ -23,21 +23,21 @@
*/
@RestController
@ControllerAdvice
@RequestMapping(path = RestBaseController.ROOT_PATH)
@RequestMapping(path = RestBaseController.ROOT_PATH + "/settings")
public class SettingsController extends GeoServerController {

@Autowired
public SettingsController(GeoServer geoServer) {
super(geoServer);
}

@GetMapping(value = "/settings", produces = { MediaType.APPLICATION_JSON_VALUE,
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE })
public RestWrapper<GeoServerInfo> getGlobalSettings() {
return wrapObject(geoServer.getGlobal(), GeoServerInfo.class);
}

@PutMapping(value = "/settings", consumes = {
@PutMapping(consumes = {
MediaType.APPLICATION_JSON_VALUE, CatalogController.TEXT_JSON,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void setGlobalSettings(@RequestBody GeoServerInfo geoServerInfo) {
Expand All @@ -46,7 +46,7 @@ public void setGlobalSettings(@RequestBody GeoServerInfo geoServerInfo) {
geoServer.save(original);
}

@GetMapping(value = "/settings/contact", produces = { MediaType.APPLICATION_JSON_VALUE,
@GetMapping(value = "/contact", produces = { MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE })
public RestWrapper<ContactInfo> getContact() {
if (geoServer.getSettings().getContact() == null) {
Expand All @@ -55,7 +55,7 @@ public RestWrapper<ContactInfo> getContact() {
return wrapObject(geoServer.getGlobal().getSettings().getContact(), ContactInfo.class);
}

@PutMapping(value = "/settings/contact", consumes = {
@PutMapping(value = "/contact", consumes = {
MediaType.APPLICATION_JSON_VALUE, CatalogController.TEXT_JSON,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE })
public void setContact(@RequestBody ContactInfo contactInfo) {
Expand Down
Expand Up @@ -46,12 +46,12 @@
import freemarker.template.Template;

@RestController
@RequestMapping(path = RestBaseController.ROOT_PATH, produces = { MediaType.TEXT_HTML_VALUE,
@RequestMapping(path = RestBaseController.ROOT_PATH + "/about", produces = { MediaType.TEXT_HTML_VALUE,
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ControllerAdvice
public class AboutController extends RestBaseController {

@GetMapping(value = "/about/manifest")
@GetMapping(value = "/manifest")
public RestWrapper<AboutModel> getManifest(
@RequestParam(name = "manifest", required = false) String regex,
@RequestParam(required = false) String from, @RequestParam(required = false) String to,
Expand All @@ -61,7 +61,7 @@ public RestWrapper<AboutModel> getManifest(
AboutModel.class);
}

@GetMapping(value = "/about/version")
@GetMapping(value = "/version")
public RestWrapper<AboutModel> getVersion(
@RequestParam(name = "manifest", required = false) String regex,
@RequestParam(required = false) String from, @RequestParam(required = false) String to,
Expand Down
Expand Up @@ -40,18 +40,18 @@
import freemarker.template.TemplateModelException;

@RestController
@RequestMapping(path = RestBaseController.ROOT_PATH, produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
@RequestMapping(path = RestBaseController.ROOT_PATH + "/about/status", produces = { MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE })
public class AboutStatusController extends RestBaseController {

@GetMapping(value = "/about/status")
@GetMapping
protected RestWrapper<ModuleStatus> getStatus() throws Exception {
List<ModuleStatus> applicationStatus = GeoServerExtensions.extensions(ModuleStatus.class)
.stream().map(ModuleStatusImpl::new).collect(Collectors.toList());
return wrapList(applicationStatus, ModuleStatus.class);
}

@GetMapping(value = "/about/status/{target}")
@GetMapping(value = "/{target}")
protected RestWrapper<ModuleStatus> getStatus(@PathVariable String target) throws Exception {
List<ModuleStatus> applicationStatus = GeoServerExtensions.extensions(ModuleStatus.class)
.stream().map(ModuleStatusImpl::new).filter(getModule(target))
Expand Down
Expand Up @@ -55,7 +55,7 @@

@RestController
@ControllerAdvice
@RequestMapping(path = RestBaseController.ROOT_PATH + "/workspaces/{workspace}")
@RequestMapping(path = RestBaseController.ROOT_PATH + "/workspaces/{workspaceName}")
public class CoverageController extends CatalogController {

private static final Logger LOGGER = Logging.getLogger(CoverageController.class);
Expand All @@ -65,14 +65,14 @@ public CoverageController(@Qualifier("catalog") Catalog catalog) {
super(catalog);
}

@GetMapping(path = "coveragestores/{store}/coverages", produces = {
@GetMapping(path = "coveragestores/{storeName}/coverages", produces = {
MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE})
public Object getCoverages(@RequestParam(name = "list", required = false) String list,
@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "store") String storeName) {
@PathVariable String workspaceName,
@PathVariable String storeName) {
// find the coverage store
CoverageStoreInfo coverageStore = getExistingCoverageStore(workspaceName, storeName);
if (list != null && list.equalsIgnoreCase("all")) {
Expand All @@ -92,7 +92,7 @@ public Object getCoverages(@RequestParam(name = "list", required = false) String
MediaType.TEXT_HTML_VALUE,
TEXT_JSON})
public Object getCoverages(@RequestParam(name = "list", required = false) String list,
@PathVariable(name = "workspace") String workspaceName) {
@PathVariable String workspaceName) {
// get the workspace name space
NamespaceInfo nameSpace = catalog.getNamespaceByPrefix(workspaceName);
if (nameSpace == null) {
Expand All @@ -111,15 +111,15 @@ public Object getCoverages(@RequestParam(name = "list", required = false) String
return wrapList(coverages, CoverageInfo.class);
}

@GetMapping(path = "coveragestores/{store}/coverages/{coverage}", produces = {
@GetMapping(path = "coveragestores/{storeName}/coverages/{coverageName}", produces = {
MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE,
TEXT_JSON})
public RestWrapper<CoverageInfo> getCoverage(@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "store") String storeName,
@PathVariable(name = "coverage") String coverageName) {
public RestWrapper<CoverageInfo> getCoverage(@PathVariable String workspaceName,
@PathVariable String storeName,
@PathVariable String coverageName) {
CoverageStoreInfo coverageStore = getExistingCoverageStore(workspaceName, storeName);
List<CoverageInfo> coverages = catalog.getCoveragesByCoverageStore(coverageStore);
Optional<CoverageInfo> optCoverage = coverages.stream()
Expand All @@ -133,14 +133,14 @@ public RestWrapper<CoverageInfo> getCoverage(@PathVariable(name = "workspace") S
return wrapObject(coverage, CoverageInfo.class);
}

@GetMapping(path = "coverages/{coverage}", produces = {
@GetMapping(path = "coverages/{coverageName}", produces = {
MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE,
TEXT_JSON})
public RestWrapper<CoverageInfo> getCoverage(@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "coverage") String coverageName) {
public RestWrapper<CoverageInfo> getCoverage(@PathVariable String workspaceName,
@PathVariable String coverageName) {
// get the workspace name space
NamespaceInfo nameSpace = catalog.getNamespaceByPrefix(workspaceName);
if (nameSpace == null) {
Expand All @@ -153,37 +153,37 @@ public RestWrapper<CoverageInfo> getCoverage(@PathVariable(name = "workspace") S
return wrapObject(coverage, CoverageInfo.class);
}

@PostMapping(path = {"coverages", "coveragestores/{store}/coverages"}, consumes = {
@PostMapping(path = {"coverages", "coveragestores/{storeName}/coverages"}, consumes = {
MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> postCoverage(@RequestBody CoverageInfo coverage,
@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "store", required = false) String storeName,
@PathVariable String workspaceName,
@PathVariable(required = false) String storeName,
UriComponentsBuilder builder) throws Exception {
String coverageName = handleObjectPost(coverage, workspaceName, storeName);
UriComponents uriComponents;
if (storeName == null) {
uriComponents = builder.path("/workspaces/{workspaceName}/coverages/{coverage}")
uriComponents = builder.path("/workspaces/{workspaceName}/coverages/{coverageName}")
.buildAndExpand(workspaceName, storeName, coverageName);
} else {
uriComponents = builder.path("/workspaces/{workspaceName}/coveragestores/{store}/coverages/{coverage}")
uriComponents = builder.path("/workspaces/{workspaceName}/coveragestores/{storeName}/coverages/{coverageName}")
.buildAndExpand(workspaceName, storeName, coverageName);
}
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uriComponents.toUri());
return new ResponseEntity<>(coverageName, headers, HttpStatus.CREATED);
}

@PutMapping(path = "coveragestores/{store}/coverages/{coverage}", consumes = {
@PutMapping(path = "coveragestores/{storeName}/coverages/{coverageName}", consumes = {
MediaType.TEXT_XML_VALUE,
MediaType.APPLICATION_XML_VALUE,
MediaType.APPLICATION_JSON_VALUE})
public void putCoverage(@RequestBody CoverageInfo coverage,
@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "store") String storeName,
@PathVariable(name = "coverage") String coverageName,
@RequestParam(name = "calculate", required = false) String calculate) throws Exception {
@PathVariable String workspaceName,
@PathVariable String storeName,
@PathVariable String coverageName,
@RequestParam(required = false) String calculate) throws Exception {
CoverageStoreInfo cs = catalog.getCoverageStoreByName(workspaceName, storeName);
CoverageInfo original = catalog.getCoverageByCoverageStore(cs, coverageName);
checkCoverageExists(original, workspaceName, coverageName);
Expand All @@ -196,10 +196,10 @@ public void putCoverage(@RequestBody CoverageInfo coverage,
}


@DeleteMapping(path = "coveragestores/{store}/coverages/{coverage}")
protected void deleteCoverage(@PathVariable(name = "workspace") String workspaceName,
@PathVariable(name = "store") String storeName,
@PathVariable(name = "coverage") String coverageName,
@DeleteMapping(path = "coveragestores/{storeName}/coverages/{coverageName}")
protected void deleteCoverage(@PathVariable String workspaceName,
@PathVariable String storeName,
@PathVariable String coverageName,
@RequestParam(name = "recurse", defaultValue = "false") boolean recurse) {
CoverageStoreInfo ds = catalog.getCoverageStoreByName(workspaceName, storeName);
CoverageInfo c = catalog.getCoverageByCoverageStore(ds, coverageName);
Expand Down Expand Up @@ -347,9 +347,9 @@ protected Class<CoverageInfo> getObjectClass() {
protected CatalogInfo getCatalogObject() {
Map<String, String> uriTemplateVars = (Map<String, String>) RequestContextHolder.getRequestAttributes()
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
String workspace = uriTemplateVars.get("workspace");
String coveragestore = uriTemplateVars.get("store");
String coverage = uriTemplateVars.get("coverage");
String workspace = uriTemplateVars.get("workspaceName");
String coveragestore = uriTemplateVars.get("storeName");
String coverage = uriTemplateVars.get("coverageName");

if (workspace == null || coveragestore == null || coverage == null) {
return null;
Expand Down

0 comments on commit c6a929e

Please sign in to comment.