This commit is contained in:
Davide Savazzi 2013-01-23 13:06:20 -08:00
commit 5c01d71e8d
9 changed files with 780 additions and 11 deletions

View File

@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder; import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSLayerGroupEncoder;
import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder; import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
@ -2150,12 +2151,20 @@ public class GeoServerRESTPublisher {
/** /**
* Remove a layer group. * Remove a layer group.
* *
* @param workspace the layer group workspace.
* @param name the layer group name. * @param name the layer group name.
* @return true if succeeded. * @return true if succeeded.
*/ */
public boolean removeLayerGroup(String name) { public boolean removeLayerGroup(String workspace, String name) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/" + name;
} else {
url += "/workspaces/" + workspace + "/layergroups/" + name;
}
try { try {
URL deleteUrl = new URL(restURL + "/rest/layergroups/" + name); URL deleteUrl = new URL(url);
boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass); boolean deleted = HTTPUtils.delete(deleteUrl.toExternalForm(), gsuser, gspass);
if (!deleted) { if (!deleted) {
if (LOGGER.isWarnEnabled()) if (LOGGER.isWarnEnabled())
@ -2170,7 +2179,17 @@ public class GeoServerRESTPublisher {
if (LOGGER.isErrorEnabled()) if (LOGGER.isErrorEnabled())
LOGGER.error(ex.getLocalizedMessage(), ex); LOGGER.error(ex.getLocalizedMessage(), ex);
return false; return false;
} }
}
/**
* Remove a layer group.
*
* @param name the layer group name.
* @return true if succeeded.
*/
public boolean removeLayerGroup(String name) {
return removeLayerGroup(null, name);
} }
/** /**
@ -2334,6 +2353,89 @@ public class GeoServerRESTPublisher {
return sendResult != null; return sendResult != null;
} }
/**
* Create a new LayerGroup using the specified encoder
*
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean createLayerGroup(String name, GSLayerGroupEncoder group) {
return createLayerGroup(null, name, group);
}
/**
* Create a new LayerGroup using the specified encoder
*
* @param workspace name of the workspace
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean createLayerGroup(String workspace, String name, GSLayerGroupEncoder group) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/";
} else {
group.setWorkspace(workspace);
url += "/workspaces/" + workspace + "/layergroups/";
}
group.setName(name);
String sendResult = HTTPUtils.postXml(url, group.toString(), gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("LayerGroup successfully configured: " + name);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring LayerGroup " + name + " (" + sendResult + ")");
}
return sendResult != null;
}
/**
* Update a LayerGroup using the specified encoder
*
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean configureLayerGroup(String name, GSLayerGroupEncoder group) {
return configureLayerGroup(null, name, group);
}
/**
* Update a LayerGroup using the specified encoder
*
* @param workspace name of the workspace
* @param name name of the layer group
* @param group group encoder
* @return true if operation was successful
*/
public boolean configureLayerGroup(String workspace, String name, GSLayerGroupEncoder group) {
String url = restURL + "/rest";
if (workspace == null) {
url += "/layergroups/" + name;
} else {
url += "/workspaces/" + workspace + "/layergroups/" + name;
}
String sendResult = HTTPUtils.putXml(url, group.toString(), gsuser, gspass);
if (sendResult != null) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("LayerGroup successfully configured: " + name);
}
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Error configuring LayerGroup " + name + " (" + sendResult + ")");
}
return sendResult != null;
}
/** /**
* Configure an existent coverage in a given workspace and coverage store * Configure an existent coverage in a given workspace and coverage store
* *

View File

@ -396,12 +396,19 @@ public class GeoServerRESTReader {
//========================================================================== //==========================================================================
/** /**
* Get summary info about all LayerGroups. * Get summary info about all LayerGroups in the given workspace.
* *
* @param workspace name of the workspace
* @return summary info about LayerGroups as a {@link RESTLayerGroupList} * @return summary info about LayerGroups as a {@link RESTLayerGroupList}
*/ */
public RESTLayerGroupList getLayerGroups() { public RESTLayerGroupList getLayerGroups(String workspace) {
String url = "/rest/layergroups.xml"; String url;
if (workspace == null) {
url = "/rest/layergroups.xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups.xml";
}
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroups from " + url); LOGGER.debug("### Retrieving layergroups from " + url);
} }
@ -411,17 +418,45 @@ public class GeoServerRESTReader {
/** /**
* Get detailed info about a given LayerGroup. * Get detailed info about a given LayerGroup.
* *
* @param name The name of the LayerGroup * @param workspace name of the workspace
* @param name the name of the LayerGroup
* @return LayerGroup details as a {@link RESTLayerGroup} * @return LayerGroup details as a {@link RESTLayerGroup}
*/ */
public RESTLayerGroup getLayerGroup(String name) { public RESTLayerGroup getLayerGroup(String workspace, String name) {
String url = "/rest/layergroups/" + name + ".xml"; String url;
if (workspace == null) {
url = "/rest/layergroups/" + name + ".xml";
} else {
url = "/rest/workspaces/" + workspace + "/layergroups/" + name + ".xml";
}
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving layergroup from " + url); LOGGER.debug("### Retrieving layergroup from " + url);
} }
return RESTLayerGroup.build(load(url)); return RESTLayerGroup.build(load(url));
} }
/**
* Get summary info about all LayerGroups.
*
* @return summary info about LayerGroups as a {@link RESTLayerGroupList}
*/
public RESTLayerGroupList getLayerGroups() {
return getLayerGroups(null);
}
/**
* Get detailed info about a given LayerGroup.
*
* @param name The name of the LayerGroup
* @return LayerGroup details as a {@link RESTLayerGroup}
*/
public RESTLayerGroup getLayerGroup(String name) {
return getLayerGroup(null, name);
}
//========================================================================== //==========================================================================
//=== LAYERS //=== LAYERS
//========================================================================== //==========================================================================

View File

@ -91,10 +91,52 @@ public class RESTLayerGroup {
return rootElem.getChildText("name"); return rootElem.getChildText("name");
} }
public String getWorkspace() {
Element rootLayer = rootElem.getChild("workspace");
if (rootLayer != null) {
return rootLayer.getChildText("name");
} else {
return null;
}
}
public String getMode() {
return rootElem.getChildText("mode");
}
public String getTitle() {
return rootElem.getChildText("title");
}
public String getAbstract() {
return rootElem.getChildText("abstractTxt");
}
public String getRootLayer() {
Element rootLayer = rootElem.getChild("rootLayer");
if (rootLayer != null) {
return rootLayer.getChildText("name");
} else {
return null;
}
}
public RESTLayerList getLayerList() { public RESTLayerList getLayerList() {
return new RESTLayerList(rootElem.getChild("layers")); if (rootElem.getChild("layers") != null) {
return new RESTLayerList(rootElem.getChild("layers"));
} else {
return null;
}
} }
public RESTPublishedList getPublishedList() {
if (rootElem.getChild("publishables") != null) {
return new RESTPublishedList(rootElem.getChild("publishables"));
} else {
return null;
}
}
public String getCRS() { public String getCRS() {
Element bounds = rootElem.getChild("bounds"); Element bounds = rootElem.getChild("bounds");
return bounds.getChildText("crs"); return bounds.getChildText("crs");

View File

@ -0,0 +1,59 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.decoder;
import org.jdom.Element;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
/**
* Parse a <TT>published</TT> returned as XML REST objects.
*
* This is the XML REST representation:
* <pre>{@code
<published type="layer">
<name>sfdem</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
</published>
* }</pre>
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class RESTPublished extends NameLinkElem {
private final String type;
public RESTPublished(Element elem) {
super(elem);
type = elem.getAttributeValue("type");
}
public String getType() {
return type;
}
}

View File

@ -0,0 +1,66 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import org.jdom.Element;
/**
* Parse <TT>published</TT>s returned as XML REST objects.
*
* This is the XML REST representation:
* <pre>{@code
<publishables>
<published type="layer">
<name>sfdem</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/sfdem.xml" type="application/xml"/>
</published>
<published type="layer">
<name>bugsites</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/layers/bugsites.xml" type="application/xml"/>
</published>
</publishables>
* }</pre>
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class RESTPublishedList extends RESTAbstractList<RESTPublished> {
public static RESTPublishedList build(String response) {
Element elem = JDOMBuilder.buildElement(response);
return elem == null ? null : new RESTPublishedList(elem);
}
protected RESTPublishedList(Element list) {
super(list);
}
protected RESTPublished createElement(Element el) {
return new RESTPublished(el);
}
}

View File

@ -0,0 +1,123 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
import org.jdom.Element;
/**
* LayerGroup encoder for GeoServer < 2.3
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class GSLayerGroupEncoder extends PropertyXMLEncoder {
protected Element nameElem;
protected Element workspaceElem;
protected Element boundsElem;
protected Element publishablesElem;
protected Element stylesElem;
public GSLayerGroupEncoder() {
super("layerGroup");
}
public void setWorkspace(String workspace) {
workspaceElem = elem("workspace", elem("name", workspace));
}
public void setName(String name) {
nameElem = elem("name", name);
}
public void addLayer(String layer) {
addLayer(layer, null);
}
public void addLayer(String layer, String styleName) {
initPublishables("layers");
publishablesElem.addContent(elem("layer", elem("name", layer)));
Element style = new Element("style");
stylesElem.addContent(style);
if (styleName != null) {
style.addContent(elem("name", styleName));
}
}
public void setBounds(String crs, double minx, double maxx, double miny, double maxy) {
boundsElem = elem("bounds",
elem("minx", Double.toString(minx)),
elem("maxx", Double.toString(maxx)),
elem("miny", Double.toString(miny)),
elem("maxy", Double.toString(maxy)),
elem("crs", "class", "projected").setText(crs));
}
protected void initPublishables(String publishablesTag) {
if (publishablesElem == null) {
publishablesElem = new Element(publishablesTag);
}
if (stylesElem == null) {
stylesElem = new Element("styles");
}
}
protected void addToRoot(Element ... elements) {
for (Element e : elements) {
if (e != null) {
getRoot().addContent(e);
}
}
}
protected Element elem(String tag, String attributeName, String attributeValue) {
return new Element(tag).setAttribute(attributeName, attributeValue);
}
protected Element elem(String tag, String text) {
return new Element(tag).setText(text);
}
protected Element elem(String tag, Element ... children) {
Element parent = new Element(tag);
for (Element child : children) {
parent.addContent(child);
}
return parent;
}
@Override
public String toString() {
addToRoot(nameElem, workspaceElem, boundsElem, publishablesElem, stylesElem);
return super.toString();
}
}

View File

@ -0,0 +1,110 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2013 GeoSolutions S.A.S.
* http://www.geo-solutions.it
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package it.geosolutions.geoserver.rest.encoder;
import java.util.HashSet;
import java.util.Set;
import org.jdom.Element;
/**
* LayerGroup encoder for GeoServer >= 2.3
*
* @author Davide Savazzi (geo-solutions.it)
*/
public class GSLayerGroupEncoder23 extends GSLayerGroupEncoder {
public static final String MODE_SINGLE = "SINGLE";
public static final String MODE_NAMED = "NAMED";
public static final String MODE_CONTAINER = "CONTAINER";
public static final String MODE_EO = "EO";
private static final Set<String> modes;
static {
modes = new HashSet<String>();
modes.add(MODE_SINGLE);
modes.add(MODE_NAMED);
modes.add(MODE_CONTAINER);
modes.add(MODE_EO);
}
private Element titleElem;
private Element abstractElem;
private Element modeElem;
private Element rootLayerElem;
private Element rootLayerStyleElem;
public void setTitle(String title) {
titleElem = elem("title", title);
}
public void setAbstract(String abstractTxt) {
abstractElem = elem("abstractTxt", abstractTxt);
}
public void setMode(String mode) {
if (!modes.contains(mode)) {
throw new IllegalArgumentException("Invalid mode: " + mode);
}
modeElem = elem("mode", mode);
}
public void setRootLayer(String layer, String style) {
rootLayerElem = elem("rootLayer", elem("name", layer));
rootLayerStyleElem = elem("rootLayerStyle", elem("name", style));
}
@Override
public void addLayer(String layer, String styleName) {
initPublishables("publishables");
publishablesElem.addContent(
new Element("published").setAttribute("type", "layer").addContent(
elem("name", layer)));
Element style = new Element("style");
stylesElem.addContent(style);
if (styleName != null) {
style.addContent(elem("name", styleName));
}
}
public void addLayerGroup(String group) {
initPublishables("publishables");
publishablesElem.addContent(
new Element("published").setAttribute("type", "layerGroup").addContent(
elem("name", group)));
stylesElem.addContent(new Element("style"));
}
@Override
public String toString() {
addToRoot(titleElem, abstractElem, modeElem, rootLayerElem, rootLayerStyleElem);
return super.toString();
}
}

View File

@ -0,0 +1,232 @@
package it.geosolutions.geoserver.rest.encoder;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
import it.geosolutions.geoserver.rest.decoder.RESTPublished;
import it.geosolutions.geoserver.rest.decoder.RESTPublishedList;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import org.junit.Test;
public class GSLayerGroupEncoderTest extends GeoserverRESTTest {
@Test
public void testCreateLayerGroup() throws Exception {
String groupName = "my-tasmania";
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:tasmania_roads");
groupWriter.addLayer("topp:tasmania_cities");
assertTrue(publisher.createLayerGroup(groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("tasmania_roads".equals(published.getName()) || "tasmania_cities".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(2, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("tasmania_roads".equals(layer.getName()) || "tasmania_cities".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
@Test
public void testCreateLayerGroupInWorkspace() throws Exception {
String groupName = "my-tasmania-in-ws";
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:tasmania_roads");
groupWriter.addLayer("topp:tasmania_cities");
assertTrue(publisher.createLayerGroup("topp", groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup("topp", groupName);
assertEquals("topp", groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("tasmania_roads".equals(published.getName()) || "tasmania_cities".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(2, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("tasmania_roads".equals(layer.getName()) || "tasmania_cities".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup("topp", groupName));
}
}
private void createTestLayerGroup(String workspace, String groupName) {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:tasmania_roads");
groupWriter.addLayer("topp:tasmania_cities");
assertTrue(publisher.createLayerGroup(workspace, groupName, groupWriter));
}
@Test
public void testConfigureLayerGroup() throws Exception {
String groupName = "my-tasmania";
createTestLayerGroup(null, groupName);
try {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.addLayer("topp:tasmania_roads");
assertTrue(publisher.configureLayerGroup(groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("tasmania_roads".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(1, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("tasmania_roads".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
@Test
public void testConfigureLayerGroupInWorkspace() throws Exception {
String groupName = "my-tasmania-in-ws";
createTestLayerGroup("topp", groupName);
try {
GSLayerGroupEncoder groupWriter = new GSLayerGroupEncoder();
groupWriter.addLayer("topp:tasmania_roads");
assertTrue(publisher.configureLayerGroup("topp", groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup("topp", groupName);
assertEquals("topp", groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
RESTPublishedList publishedList = groupReader.getPublishedList();
if (publishedList != null) {
// GeoServer >= 2.3
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("tasmania_roads".equals(published.getName()));
}
} else {
RESTLayerList layerList = groupReader.getLayerList();
assertEquals(1, layerList.size());
for (NameLinkElem layer : layerList) {
assertTrue("tasmania_roads".equals(layer.getName()));
}
}
} finally {
assertTrue(publisher.removeLayerGroup("topp", groupName));
}
}
@Test
public void testConfigureLayerGroup23() throws Exception {
String groupName = "my-tasmania-23";
createTestLayerGroup(null, groupName);
try {
GSLayerGroupEncoder23 groupWriter = new GSLayerGroupEncoder23();
groupWriter.addLayer("topp:tasmania_roads");
groupWriter.setMode(GSLayerGroupEncoder23.MODE_NAMED);
groupWriter.setTitle("my title");
groupWriter.setAbstract("my abstract");
assertTrue(publisher.configureLayerGroup(groupName, groupWriter));
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
assertEquals("my title", groupReader.getTitle());
assertEquals("my abstract", groupReader.getAbstract());
assertEquals(GSLayerGroupEncoder23.MODE_NAMED, groupReader.getMode());
RESTPublishedList publishedList = groupReader.getPublishedList();
assertEquals(1, publishedList.size());
for (RESTPublished published : publishedList) {
assertEquals("layer", published.getType());
assertTrue("tasmania_roads".equals(published.getName()));
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
/**
* This test only works with GeoServer >= 2.3
*/
@Test
public void testCreateNestedLayerGroup23() throws Exception {
String groupName = "my-tasmania-eo";
GSLayerGroupEncoder23 groupWriter = new GSLayerGroupEncoder23();
groupWriter.setTitle("my title");
groupWriter.setAbstract("my abstract");
groupWriter.setMode(GSLayerGroupEncoder23.MODE_EO);
groupWriter.setRootLayer("topp:tasmania_roads", "simple_roads");
groupWriter.setBounds("EPSG:26713", 589425.93423656, 609518.6719560538, 4913959.224611808, 4928082.949945881);
groupWriter.addLayer("topp:tasmania_cities");
groupWriter.addLayerGroup("tasmania");
assertTrue(publisher.createLayerGroup(groupName, groupWriter));
try {
RESTLayerGroup groupReader = reader.getLayerGroup(groupName);
assertNull(groupReader.getWorkspace());
assertEquals(groupName, groupReader.getName());
assertEquals("my title", groupReader.getTitle());
assertEquals("my abstract", groupReader.getAbstract());
assertEquals(GSLayerGroupEncoder23.MODE_EO, groupReader.getMode());
assertEquals("tasmania_roads", groupReader.getRootLayer());
RESTPublishedList publishedList = groupReader.getPublishedList();
assertEquals(2, publishedList.size());
for (RESTPublished published : publishedList) {
if ("layer".equals(published.getType())) {
assertEquals("tasmania_cities", published.getName());
} else {
assertEquals("layerGroup", published.getType());
assertEquals("tasmania", published.getName());
}
}
} finally {
assertTrue(publisher.removeLayerGroup(groupName));
}
}
}