Skip to content

Commit 1f3b245

Browse files
committed
Add the ability to list available layers in a datastore like PostGIS
1 parent 13c4f7d commit 1f3b245

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ Commands
204204

205205
* featuretype list topp --datastore taz_shapes
206206

207+
* featuretype list --workspace post --datastore postgis --list available
208+
207209
* featuretype get --workspace topp --datastore taz_shapes --featuretype tasmania_cities
208210

209211
* featuretype publish --workspace postgis --datastore tables --featuretype table

src/main/java/org/geoserver/shell/FeatureTypeCommands.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,23 @@ public boolean isCommandAvailable() {
3737
@CliCommand(value = "featuretype list", help = "List feature types.")
3838
public String list(
3939
@CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
40-
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore
40+
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore,
41+
@CliOption(key = "list", mandatory = false, unspecifiedDefaultValue = "configured", help = "The list parameter (configured, available, available_with_geom, all)") String list
4142
) throws Exception {
42-
String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/datastores/" + URLUtil.encode(datastore) + "/featuretypes.xml";
43+
String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/datastores/" + URLUtil.encode(datastore) + "/featuretypes.xml?list=" + list;
4344
String xml = HTTPUtils.get(url, geoserver.getUser(), geoserver.getPassword());
4445
Element element = JDOMBuilder.buildElement(xml);
45-
List<Element> elements = element.getChildren("featureType");
4646
List<String> names = new ArrayList<String>();
47-
for (Element elem : elements) {
48-
names.add(elem.getChildText("name"));
47+
if (element.getName().equalsIgnoreCase("featureTypes")) {
48+
List<Element> elements = element.getChildren("featureType");
49+
for (Element elem : elements) {
50+
names.add(elem.getChildText("name"));
51+
}
52+
} else {
53+
List<Element> elements = element.getChildren("featureTypeName");
54+
for (Element elem : elements) {
55+
names.add(elem.getTextTrim());
56+
}
4957
}
5058
Collections.sort(names);
5159
StringBuilder builder = new StringBuilder();

src/test/java/org/geoserver/shell/FeatureTypeCommandsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ public void listFeatureTypes() throws Exception {
2222
Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
2323
FeatureTypeCommands commands = new FeatureTypeCommands();
2424
commands.setGeoserver(geoserver);
25-
String actual = commands.list("topp", "taz_shapes");
25+
String actual = commands.list("topp", "taz_shapes", "configured");
2626
String expected = "tasmania_cities" + OsUtils.LINE_SEPARATOR + "tasmania_hydro" + OsUtils.LINE_SEPARATOR + "tasmania_parcels" + OsUtils.LINE_SEPARATOR;
2727
assertEquals(expected, actual);
28+
assertEquals("configured", server.getCalls().get(0).getParameters().get("list")[0]);
2829
verifyHttp(server).once(method(Method.GET), uri(url));
2930
}
3031

0 commit comments

Comments
 (0)