Skip to content

Commit

Permalink
Add the ability to list available layers in a datastore like PostGIS
Browse files Browse the repository at this point in the history
  • Loading branch information
jericks committed Jul 4, 2013
1 parent 13c4f7d commit 1f3b245
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ Commands

* featuretype list topp --datastore taz_shapes

* featuretype list --workspace post --datastore postgis --list available

* featuretype get --workspace topp --datastore taz_shapes --featuretype tasmania_cities

* featuretype publish --workspace postgis --datastore tables --featuretype table
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/geoserver/shell/FeatureTypeCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,23 @@ public boolean isCommandAvailable() {
@CliCommand(value = "featuretype list", help = "List feature types.")
public String list(
@CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore,
@CliOption(key = "list", mandatory = false, unspecifiedDefaultValue = "configured", help = "The list parameter (configured, available, available_with_geom, all)") String list
) throws Exception {
String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/datastores/" + URLUtil.encode(datastore) + "/featuretypes.xml";
String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/datastores/" + URLUtil.encode(datastore) + "/featuretypes.xml?list=" + list;
String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
Element element = JDOMBuilder.buildElement(xml);
List<Element> elements = element.getChildren("featureType");
List<String> names = new ArrayList<String>();
for (Element elem : elements) {
names.add(elem.getChildText("name"));
if (element.getName().equalsIgnoreCase("featureTypes")) {
List<Element> elements = element.getChildren("featureType");
for (Element elem : elements) {
names.add(elem.getChildText("name"));
}
} else {
List<Element> elements = element.getChildren("featureTypeName");
for (Element elem : elements) {
names.add(elem.getTextTrim());
}
}
Collections.sort(names);
StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public void listFeatureTypes() throws Exception {
Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
FeatureTypeCommands commands = new FeatureTypeCommands();
commands.setGeoserver(geoserver);
String actual = commands.list("topp", "taz_shapes");
String actual = commands.list("topp", "taz_shapes", "configured");
String expected = "tasmania_cities" + OsUtils.LINE_SEPARATOR + "tasmania_hydro" + OsUtils.LINE_SEPARATOR + "tasmania_parcels" + OsUtils.LINE_SEPARATOR;
assertEquals(expected, actual);
assertEquals("configured", server.getCalls().get(0).getParameters().get("list")[0]);
verifyHttp(server).once(method(Method.GET), uri(url));
}

Expand Down

0 comments on commit 1f3b245

Please sign in to comment.