Skip to content

Commit 83355f8

Browse files
committed
Allow publishing of an existing layer such a table from a PostGIS database
1 parent 90dbb99 commit 83355f8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,21 @@ public String list(
5555
return builder.toString();
5656
}
5757

58-
@CliCommand(value = "featuretype create", help = "Create a feature type.")
58+
@CliCommand(value = "featuretype publish", help = "Publish a feature type from an existing dataset.")
59+
public boolean publish(
60+
@CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
61+
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore,
62+
@CliOption(key = "featuretype", mandatory = true, help = "The featuretype") String featuretype
63+
) throws Exception {
64+
Element rootElement = new Element("featureType");
65+
rootElement.addContent(new Element("name").setText(featuretype));
66+
String xml = JDOMUtil.toString(rootElement);
67+
String url = geoserver.getUrl() + "/rest/workspaces/" + URLUtil.encode(workspace) + "/datastores/" + URLUtil.encode(datastore) + "/featuretypes.xml";
68+
String response = HTTPUtils.postXml(url, xml, geoserver.getUser(), geoserver.getPassword());
69+
return response != null;
70+
}
71+
72+
@CliCommand(value = "featuretype create", help = "Create a new feature type.")
5973
public boolean create(
6074
@CliOption(key = "workspace", mandatory = true, help = "The workspace") String workspace,
6175
@CliOption(key = "datastore", mandatory = true, help = "The datastore") String datastore,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ public void deleteFeatureType() throws Exception {
115115
verifyHttp(server).once(method(Method.DELETE), uri(url));
116116
}
117117

118+
@Test
119+
public void publishFeatureType() throws Exception {
120+
String url = "/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes.xml";
121+
whenHttp(server).match(post(url)).then(stringContent(getResourceString("featuretypes.xml")), status(HttpStatus.OK_200));
122+
Geoserver geoserver = new Geoserver("http://00.0.0.0:8888/geoserver", "admin", "geoserver");
123+
FeatureTypeCommands commands = new FeatureTypeCommands();
124+
commands.setGeoserver(geoserver);
125+
String workspace = "topp";
126+
String dataStore = "taz_shapes";
127+
String featureType = "taz_soils";
128+
boolean result = commands.publish(workspace, dataStore, featureType);
129+
assertTrue(result);
130+
String actual = server.getCalls().get(0).getPostBody();
131+
String expected = "<featureType><name>taz_soils</name></featureType>";
132+
assertEquals(expected, actual);
133+
verifyHttp(server).once(method(Method.POST), uri(url));
134+
}
135+
118136
@Test
119137
public void createFeatureType() throws Exception {
120138
String url = "/geoserver/rest/workspaces/topp/datastores/taz_shapes/featuretypes.xml";

0 commit comments

Comments
 (0)