Skip to content

Commit

Permalink
Add FeatureTypeTests; Set FTController to produce HTML first.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkrusz committed Mar 31, 2017
1 parent df8e1eb commit 810e459
Show file tree
Hide file tree
Showing 3 changed files with 588 additions and 32 deletions.
5 changes: 0 additions & 5 deletions doc/en/src/main/resources/api/featureTypes.yaml
Expand Up @@ -315,11 +315,6 @@ paths:
] ]
} }
} }





application/xml: '<featureType> application/xml: '<featureType>
<name>poi</name> <name>poi</name>
<nativeName>poi</nativeName> <nativeName>poi</nativeName>
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.geoserver.rest.ResourceNotFoundException; import org.geoserver.rest.ResourceNotFoundException;
import org.geoserver.rest.RestBaseController; import org.geoserver.rest.RestBaseController;
import org.geoserver.rest.RestException; import org.geoserver.rest.RestException;
import org.geoserver.rest.converters.FreemarkerHTMLMessageConverter;
import org.geoserver.rest.converters.XStreamMessageConverter; import org.geoserver.rest.converters.XStreamMessageConverter;
import org.geoserver.rest.wrapper.RestWrapper; import org.geoserver.rest.wrapper.RestWrapper;
import org.geotools.data.DataAccess; import org.geotools.data.DataAccess;
Expand Down Expand Up @@ -67,7 +66,6 @@
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;


import freemarker.template.SimpleHash; import freemarker.template.SimpleHash;
import freemarker.template.Template;


/** /**
* Feature type controller * Feature type controller
Expand All @@ -86,9 +84,9 @@ public FeatureTypeController(Catalog catalog) {


@GetMapping(path = { "/workspaces/{workspaceName}/featuretypes", @GetMapping(path = { "/workspaces/{workspaceName}/featuretypes",
"/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes" }, produces = { "/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes" }, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE }) MediaType.APPLICATION_XML_VALUE })
public RestWrapper getFeatureTypes( public Object getFeatureTypes(
@PathVariable(name = "workspaceName", required = true) String workspaceName, @PathVariable(name = "workspaceName", required = true) String workspaceName,
@PathVariable(name = "datastoreName", required = false) String datastoreName, @PathVariable(name = "datastoreName", required = false) String datastoreName,
@RequestParam(name = "list", required = true, defaultValue = "configured") String list) { @RequestParam(name = "list", required = true, defaultValue = "configured") String list) {
Expand Down Expand Up @@ -136,7 +134,7 @@ public RestWrapper getFeatureTypes(
throw new ResourceNotFoundException("Could not load datastore: " + datastoreName); throw new ResourceNotFoundException("Could not load datastore: " + datastoreName);
} }


return wrapList(available, String.class); return new StringsList(available, "featureTypeName");
} else { } else {
List<FeatureTypeInfo> fts; List<FeatureTypeInfo> fts;


Expand All @@ -155,8 +153,8 @@ public RestWrapper getFeatureTypes(


@PostMapping(path = { "/workspaces/{workspaceName}/featuretypes", @PostMapping(path = { "/workspaces/{workspaceName}/featuretypes",
"/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes" }, consumes = { "/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes" }, consumes = {
MediaType.APPLICATION_JSON_VALUE, CatalogController.TEXT_JSON, CatalogController.TEXT_JSON, MediaType.APPLICATION_JSON_VALUE,
MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE }) MediaType.TEXT_XML_VALUE, MediaType.APPLICATION_XML_VALUE })
public ResponseEntity postFeatureType( public ResponseEntity postFeatureType(
@PathVariable(name = "workspaceName", required = true) String workspace, @PathVariable(name = "workspaceName", required = true) String workspace,
@PathVariable(name = "datastoreName", required = false) String dataStore, @PathVariable(name = "datastoreName", required = false) String dataStore,
Expand Down Expand Up @@ -274,8 +272,8 @@ public ResponseEntity postFeatureType(


@GetMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}", @GetMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}",
"/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = { "/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE }) MediaType.APPLICATION_XML_VALUE })
public RestWrapper getFeatureType( public RestWrapper getFeatureType(
@PathVariable(name = "workspaceName", required = true) String workspaceName, @PathVariable(name = "workspaceName", required = true) String workspaceName,
@PathVariable(name = "datastoreName", required = false) String datastoreName, @PathVariable(name = "datastoreName", required = false) String datastoreName,
Expand Down Expand Up @@ -331,8 +329,8 @@ public RestWrapper getFeatureType(


@PutMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}", @PutMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}",
"/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = { "/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE }) MediaType.APPLICATION_XML_VALUE })
public void putFeatureType( public void putFeatureType(
@PathVariable(name = "workspaceName", required = true) String workspaceName, @PathVariable(name = "workspaceName", required = true) String workspaceName,
@PathVariable(name = "datastoreName", required = false) String datastoreName, @PathVariable(name = "datastoreName", required = false) String datastoreName,
Expand All @@ -341,7 +339,7 @@ public void putFeatureType(
@RequestParam(name = "recalculate", required = false) String recalculate) { @RequestParam(name = "recalculate", required = false) String recalculate) {


ensureResourcesExist(workspaceName, datastoreName); ensureResourcesExist(workspaceName, datastoreName);

if (datastoreName != null if (datastoreName != null
&& catalog.getFeatureTypeByDataStore(catalog.getDataStoreByName(workspaceName), && catalog.getFeatureTypeByDataStore(catalog.getDataStoreByName(workspaceName),
featureTypeName) == null) { featureTypeName) == null) {
Expand Down Expand Up @@ -387,8 +385,8 @@ public void putFeatureType(


@DeleteMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}", @DeleteMapping(path = { "/workspaces/{workspaceName}/featuretypes/{featureTypeName}",
"/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = { "/workspaces/{workspaceName}/datastores/{datastoreName}/featuretypes/{featureTypeName}" }, produces = {
MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_JSON_VALUE,
MediaType.TEXT_HTML_VALUE }) MediaType.APPLICATION_XML_VALUE })
public void deleteFeatureType( public void deleteFeatureType(
@PathVariable(name = "workspaceName", required = true) String workspaceName, @PathVariable(name = "workspaceName", required = true) String workspaceName,
@PathVariable(name = "datastoreName", required = false) String datastoreName, @PathVariable(name = "datastoreName", required = false) String datastoreName,
Expand Down Expand Up @@ -436,29 +434,25 @@ public void deleteFeatureType(
} }


/** /**
* Check if the provided workspace and datastore exist. * Check if the provided workspace and datastore exist. <br/>
* * <br/>
* If the parameter is null, no check is performed. * If the parameter is null, no check is performed. <br/>
* * <br/>
* If the workspaceName / datastoreName parameter is provided but the corresponding * If the workspaceName / datastoreName parameter is provided but the corresponding resource does not exist, throws a 404 exception.
* resource does not exist, throws a 404 exception.
*
* Implementation Note: Does not throw the explicit {@link ResourceNotFoundException}, because
* that gets silenced by quietOnNotFound parameters, but these exceptions should not be.
* *
* @param workspaceName * @param workspaceName
* @param datastoreName * @param datastoreName
*/ */
public void ensureResourcesExist(String workspaceName, String datastoreName) { public void ensureResourcesExist(String workspaceName, String datastoreName) {
// ensure referenced resources exist // ensure referenced resources exist
if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) { if (workspaceName != null && catalog.getWorkspaceByName(workspaceName) == null) {
throw new RestException("No such workspace: " + workspaceName, HttpStatus.NOT_FOUND); throw new ResourceNotFoundException("No such workspace: " + workspaceName);
} }


if (datastoreName != null if (datastoreName != null
&& catalog.getDataStoreByName(workspaceName, datastoreName) == null) { && catalog.getDataStoreByName(workspaceName, datastoreName) == null) {
throw new RestException("No such datastore: " + workspaceName + "," + datastoreName, throw new ResourceNotFoundException(
HttpStatus.NOT_FOUND); "No such datastore: " + workspaceName + "," + datastoreName);
} }
} }


Expand Down

0 comments on commit 810e459

Please sign in to comment.