Merge pull request #101 from wumpz/master

FeatureTypeList included
This commit is contained in:
Carlo Cancellieri 2013-10-19 10:49:45 -07:00
commit 8073671631
4 changed files with 148 additions and 0 deletions

View File

@ -32,6 +32,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStoreList;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
import it.geosolutions.geoserver.rest.decoder.RESTFeatureTypeList;
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroupList;
@ -524,6 +525,19 @@ public class GeoServerRESTReader {
}
return RESTLayerList.build(load(url));
}
/**
* Get summary info about all FeatureTypes of a workspace.
*
* @return summary info about Layers as a {@link RESTLayerList}
*/
public RESTFeatureTypeList getFeatureTypes(String workspace) {
String url = "/rest/workspaces/" + workspace + "/featuretypes.xml";
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("### Retrieving featuretypes from " + url);
}
return RESTFeatureTypeList.build(load(url));
}
/**
* Get detailed info about a given Layer.

View File

@ -0,0 +1,62 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2011 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 it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import org.jdom.Element;
/**
* Parses list of summary data about FeatureTypes.
*
*
* FeatureType summary info.
* <BR>This is an XML fragment:
* <PRE>
*{@code
<featureType>
<name>states</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate"
href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/states.xml"
type="application/xml"/>
</featureType>
* }
* </PRE>
*
* @author wumpz
*/
public class RESTFeatureTypeList extends RESTAbstractList<NameLinkElem> {
public static RESTFeatureTypeList build(String response) {
Element elem = JDOMBuilder.buildElement(response);
return elem == null? null : new RESTFeatureTypeList(elem);
}
protected RESTFeatureTypeList(Element list) {
super(list);
}
}

View File

@ -0,0 +1,50 @@
package it.geosolutions.geoserver.rest.decoder;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author toben
*/
public class RESTFeatureTypeListTest {
public RESTFeatureTypeListTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testBuild() throws IOException {
InputStream is = RESTFeatureTypeListTest.class.getResourceAsStream("/testdata/featureTypeListExample.xml");
String response = IOUtils.toString(is);
is.close();
RESTFeatureTypeList result = RESTFeatureTypeList.build(response);
List<String> list = result.getNames();
assertArrayEquals(new String[]{"states", "tasmania_cities", "tasmania_roads", "tasmania_state_boundaries", "tasmania_water_bodies"}
, list.toArray());
}
}

View File

@ -0,0 +1,22 @@
<featureTypes>
<featureType>
<name>states</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/states.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_cities</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_cities.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_roads</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_roads.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_state_boundaries</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_state_boundaries.xml" type="application/xml"/>
</featureType>
<featureType>
<name>tasmania_water_bodies</name>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/featuretypes/tasmania_water_bodies.xml" type="application/xml"/>
</featureType>
</featureTypes>