Merge pull request #46 from geosolutions-it/master-45-featureTypeEncoder-attributes
Master 45 feature type encoder attributes
This commit is contained in:
commit
852cabbd8c
@ -27,6 +27,7 @@ package it.geosolutions.geoserver.rest.decoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMListIterator;
|
||||
|
||||
import java.util.Iterator;
|
||||
import org.jdom.Element;
|
||||
|
||||
|
||||
@ -26,6 +26,14 @@
|
||||
package it.geosolutions.geoserver.rest.decoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.Namespace;
|
||||
|
||||
@ -76,7 +84,8 @@ public class RESTResource {
|
||||
|
||||
public String getStoreUrl() {
|
||||
Element store = rootElem.getChild("store");
|
||||
Element atom = store.getChild("link", Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||
Element atom = store.getChild("link",
|
||||
Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||
return atom.getAttributeValue("href");
|
||||
}
|
||||
|
||||
@ -93,13 +102,95 @@ public class RESTResource {
|
||||
public double getMinX() {
|
||||
return getLatLonEdge("minx");
|
||||
}
|
||||
|
||||
public double getMaxX() {
|
||||
return getLatLonEdge("maxx");
|
||||
}
|
||||
|
||||
public double getMinY() {
|
||||
return getLatLonEdge("miny");
|
||||
}
|
||||
|
||||
public double getMaxY() {
|
||||
return getLatLonEdge("maxy");
|
||||
}
|
||||
|
||||
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
|
||||
List<Map<FeatureTypeAttribute, String>> attrsList = null;
|
||||
|
||||
final Element attrsRoot = rootElem.getChild("attributes");
|
||||
final List<Element> attrs = attrsRoot.getChildren();
|
||||
if (attrs != null) {
|
||||
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
|
||||
for (Element attr : attrs) {
|
||||
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
|
||||
attrsList.add(attrsMap);
|
||||
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||
String key = at.toString();
|
||||
attrsMap.put(at, attr.getChildText(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return attrsList;
|
||||
}
|
||||
|
||||
public List<GSAttributeEncoder> getEncodedAttributeList() {
|
||||
List<GSAttributeEncoder> attrsList = null;
|
||||
|
||||
final Element attrsRoot = rootElem.getChild("attributes");
|
||||
final List<Element> attrs = attrsRoot.getChildren();
|
||||
if (attrs != null) {
|
||||
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
|
||||
for (Element attr : attrs) {
|
||||
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
|
||||
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||
String key = at.toString();
|
||||
attrEnc.setAttribute(at, attr.getChildText(key));
|
||||
}
|
||||
attrsList.add(attrEnc);
|
||||
}
|
||||
|
||||
}
|
||||
return attrsList;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return the list of available attribute names
|
||||
// */
|
||||
// public List<String> getAttributeNames() {
|
||||
// return getAttributes("name");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return a list of object which are String representation of Classes
|
||||
// */
|
||||
// public List<String> getAttributeBinding() {
|
||||
// return getAttributes("binding");
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * <attribute><br>
|
||||
// * <name>NATION</name><br>
|
||||
// * <minOccurs>0</minOccurs><br>
|
||||
// * <maxOccurs>1</maxOccurs><br>
|
||||
// * <nillable>true</nillable><br>
|
||||
// * <binding>java.lang.Integer</binding><br>
|
||||
// * <length>3</length><br>
|
||||
// * </attribute><br>
|
||||
// *
|
||||
// * @param name
|
||||
// * @return
|
||||
// */
|
||||
// private List<String> getAttributes(String name) {
|
||||
// final Element attrsRoot = rootElem.getChild("attributes");
|
||||
// final List<Element> attrs = attrsRoot.getChildren();
|
||||
// List<String> attrNames = null;
|
||||
// if (attrs != null) {
|
||||
// attrNames = new ArrayList<String>(attrs.size());
|
||||
// for (Element attr : attrs) {
|
||||
// attrNames.add(attr.getChildText(name));
|
||||
// }
|
||||
// }
|
||||
// return attrNames;
|
||||
// }
|
||||
}
|
||||
|
||||
@ -61,20 +61,20 @@ public class GSLayerEncoder extends PropertyXMLEncoder {
|
||||
set("enabled","false");
|
||||
}
|
||||
|
||||
private final static String DESCRIPTION = "description";
|
||||
/**
|
||||
* Add the 'description' node with a text value from 'description'
|
||||
*
|
||||
*/
|
||||
protected void addDescription(final String description) {
|
||||
add(DESCRIPTION, description);
|
||||
}
|
||||
/**
|
||||
* Set or modify the 'description' node with a text value from 'description'
|
||||
*/
|
||||
public void setDescription(final String description) {
|
||||
set(DESCRIPTION, description);
|
||||
}
|
||||
// private final static String DESCRIPTION = "description";
|
||||
// /**
|
||||
// * Add the 'description' node with a text value from 'description'
|
||||
// *
|
||||
// */
|
||||
// protected void addDescription(final String description) {
|
||||
// add(DESCRIPTION, description);
|
||||
// }
|
||||
// /**
|
||||
// * Set or modify the 'description' node with a text value from 'description'
|
||||
// */
|
||||
// public void setDescription(final String description) {
|
||||
// set(DESCRIPTION, description);
|
||||
// }
|
||||
|
||||
// queryable
|
||||
private final static String QUERYABLE = "queryable";
|
||||
|
||||
@ -29,6 +29,7 @@ import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.XmlElement;
|
||||
@ -188,7 +189,7 @@ public abstract class GSResourceEncoder
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
final Element nameNode = get(NAME);
|
||||
final Element nameNode = ElementUtils.contains(getRoot(), NAME, 1);
|
||||
if (nameNode != null)
|
||||
return nameNode.getText();
|
||||
else
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2012 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.feature;
|
||||
|
||||
/**
|
||||
* Enumeration of featureType attribute members
|
||||
*/
|
||||
public enum FeatureTypeAttribute {
|
||||
name, minOccurs, maxOccurs, nillable, binding, length
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2012 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.feature;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.filter.Filter;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author carlo cancellieri - GeoSolutions
|
||||
*
|
||||
*/
|
||||
public class GSAttributeEncoder extends PropertyXMLEncoder {
|
||||
|
||||
public static class filterByName implements Filter {
|
||||
|
||||
final private String key;
|
||||
|
||||
public filterByName(String keyword){
|
||||
this.key=keyword;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public boolean matches(Object obj) {
|
||||
Element el=((Element) obj).getChild(FeatureTypeAttribute.name.toString());
|
||||
if (el!=null && el.getTextTrim().equals(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Filter getFilterByName(String name){
|
||||
return new filterByName(name);
|
||||
}
|
||||
|
||||
public GSAttributeEncoder() {
|
||||
super("attribute");
|
||||
}
|
||||
|
||||
public void setup(Map<FeatureTypeAttribute, String> attributes){
|
||||
for (Entry<FeatureTypeAttribute,String> attr:attributes.entrySet()){
|
||||
set(attr.getKey().toString(),attr.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void setAttribute(FeatureTypeAttribute type, String value){
|
||||
set(type.toString(),value);
|
||||
}
|
||||
|
||||
public void delAttribute(FeatureTypeAttribute type){
|
||||
ElementUtils.remove(this.getRoot(), get(type.toString()));
|
||||
}
|
||||
|
||||
public String getAttribute(FeatureTypeAttribute type){
|
||||
Element el = get(type.toString());
|
||||
if (el!=null)
|
||||
return el.getTextTrim();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
*
|
||||
* Encode a GeoServer resource as FeatureType
|
||||
@ -37,8 +39,13 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEnc
|
||||
*/
|
||||
public class GSFeatureTypeEncoder extends GSResourceEncoder {
|
||||
|
||||
public final static String ATTRIBUTES = "attributes";
|
||||
|
||||
final private Element attributes = new Element(ATTRIBUTES);
|
||||
|
||||
public GSFeatureTypeEncoder() {
|
||||
super("featureType");
|
||||
addContent(attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,4 +59,33 @@ public class GSFeatureTypeEncoder extends GSResourceEncoder {
|
||||
public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
||||
super.setMetadata(key, dimensionInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a keyword from the list
|
||||
*
|
||||
* @param keyword
|
||||
* @return true if something is removed, false otherwise
|
||||
*/
|
||||
public boolean delAttribute(final String keyword) {
|
||||
final Element el = new Element("string");
|
||||
el.setText(keyword);
|
||||
return (attributes.removeContent(GSAttributeEncoder.getFilterByName(keyword))).size() == 0 ? false
|
||||
: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute the attribute to add
|
||||
*/
|
||||
protected void addAttribute(GSAttributeEncoder attribute) {
|
||||
attributes.addContent(attribute.getRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute the attribute to set (overriding an attribute with the same name if present)
|
||||
*/
|
||||
public void setAttribute(GSAttributeEncoder attribute) {
|
||||
delAttribute(attribute.getAttribute(FeatureTypeAttribute.name));
|
||||
addAttribute(attribute);
|
||||
}
|
||||
|
||||
}
|
||||
@ -93,7 +93,7 @@ public abstract class ElementUtils {
|
||||
final Filter filter, final int depth)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (root == null || filter == null || depth < 0) {
|
||||
if (root == null || filter == null) {
|
||||
throw new IllegalArgumentException("Bad arguments: root=" + root
|
||||
+ " filter=" + filter + " depth=" + depth);
|
||||
}
|
||||
@ -106,7 +106,7 @@ public abstract class ElementUtils {
|
||||
ret.add(root);
|
||||
}
|
||||
// check my children
|
||||
if (depth > 1) {
|
||||
if (depth != 0) {
|
||||
final List<?> childrenList = root.getContent();
|
||||
final Iterator<?> it = childrenList.iterator();
|
||||
while (it.hasNext()) {
|
||||
@ -201,6 +201,7 @@ public abstract class ElementUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* return the FIRST element with name equals to the passed key
|
||||
*
|
||||
@ -208,7 +209,18 @@ public abstract class ElementUtils {
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Element contains(final Element root, final String name)
|
||||
public static Element contains(final Element root, final String name){
|
||||
return contains(root, name, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the FIRST element with name equals to the passed key
|
||||
*
|
||||
* @param root
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static Element contains(final Element root, final String name, final int deep)
|
||||
throws IllegalArgumentException {
|
||||
if (root == null || name == null) {
|
||||
throw new IllegalArgumentException("Bad arguments: root=" + root
|
||||
@ -228,7 +240,7 @@ public abstract class ElementUtils {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
final Iterator<Element> it = search(root, filter).iterator();
|
||||
final Iterator<Element> it = search(root, filter, deep).iterator();
|
||||
if (it.hasNext())
|
||||
return it.next();
|
||||
else
|
||||
|
||||
@ -57,8 +57,8 @@ public class PropertyXMLEncoder extends XmlElement {
|
||||
super(rootName);
|
||||
}
|
||||
|
||||
protected void get(final String key, final String value) {
|
||||
|
||||
protected Element get(final String key, int deep) {
|
||||
return get(getRoot(), key);
|
||||
}
|
||||
|
||||
protected Element get(final String key) {
|
||||
|
||||
@ -54,24 +54,24 @@ public class ConfigTest extends GeoserverRESTTest {
|
||||
|
||||
private static final String DEFAULT_WS = "geosolutions";
|
||||
|
||||
@Test
|
||||
public void testEtj() throws FileNotFoundException, IOException {
|
||||
if(!enabled()){
|
||||
LOGGER.info("Skipping test "+"testEtj"+"for class:"+this.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
deleteAll();
|
||||
|
||||
assertTrue(reader.getWorkspaces().isEmpty());
|
||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||
|
||||
insertStyles();
|
||||
insertExternalGeotiff();
|
||||
insertExternalShape();
|
||||
|
||||
boolean ok = publisher.publishDBLayer(DEFAULT_WS, "pg_kids", "easia_gaul_0_aggr", "EPSG:4326", "default_polygon");
|
||||
// assertTrue(ok);
|
||||
}
|
||||
// @Test
|
||||
// public void testEtj() throws FileNotFoundException, IOException {
|
||||
// if(!enabled()){
|
||||
// LOGGER.info("Skipping test "+"testEtj"+"for class:"+this.getClass().getSimpleName());
|
||||
// return;
|
||||
// }
|
||||
// deleteAll();
|
||||
//
|
||||
// assertTrue(reader.getWorkspaces().isEmpty());
|
||||
// assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||
//
|
||||
// insertStyles();
|
||||
// insertExternalGeotiff();
|
||||
// insertExternalShape();
|
||||
//
|
||||
// boolean ok = publisher.publishDBLayer(DEFAULT_WS, "pg_kids", "easia_gaul_0_aggr", "EPSG:4326", "default_polygon");
|
||||
//// assertTrue(ok);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void insertStyles() throws FileNotFoundException, IOException {
|
||||
@ -79,6 +79,8 @@ public class ConfigTest extends GeoserverRESTTest {
|
||||
LOGGER.info("Skipping test "+"insertStyles"+"for class:"+this.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
deleteAllStyles();
|
||||
|
||||
File sldDir = new ClassPathResource("testdata").getFile();
|
||||
for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) {
|
||||
LOGGER.info("Existing styles: " + reader.getStyles().getNames());
|
||||
@ -94,20 +96,31 @@ public class ConfigTest extends GeoserverRESTTest {
|
||||
LOGGER.info("Skipping test "+"insertExternalGeotiff"+"for class:"+this.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
deleteAll();
|
||||
|
||||
String storeName = "testRESTStoreGeotiff";
|
||||
String layerName = "resttestdem";
|
||||
|
||||
publisher.createWorkspace(DEFAULT_WS);
|
||||
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),"raster.sld"));
|
||||
|
||||
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||
boolean pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, layerName,"EPSG:4326",ProjectionPolicy.FORCE_DECLARED,"raster");
|
||||
|
||||
assertTrue(pc);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertExternalShape() throws FileNotFoundException, IOException {
|
||||
if(!enabled()){
|
||||
LOGGER.info("Skipping test "+"insertExternalShape"+"for class:"+this.getClass().getSimpleName());
|
||||
return;
|
||||
}
|
||||
deleteAll();
|
||||
|
||||
publisher.createWorkspace(DEFAULT_WS);
|
||||
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),"default_point.sld"));
|
||||
|
||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||
|
||||
boolean published = publisher.publishShp(DEFAULT_WS, "anyname", "cities", zipFile, "EPSG:41001", "default_point");
|
||||
|
||||
@ -37,8 +37,6 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
@ -47,32 +45,39 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* Initializes REST params.
|
||||
* <P>
|
||||
* <B>These tests are destructive, so you have to explicitly enable them</B>
|
||||
* by setting the env var <TT>resttest</TT> to <TT>true</TT>.
|
||||
* <B>These tests are destructive, so you have to explicitly enable them</B> by setting the env var <TT>resttest</TT> to <TT>true</TT>.
|
||||
* <P>
|
||||
* The target geoserver instance can be customized by defining the following env vars: <ul>
|
||||
* The target geoserver instance can be customized by defining the following env vars:
|
||||
* <ul>
|
||||
* <LI><TT>resturl</TT> (default <TT>http://localhost:8080/geoserver</TT>)</LI>
|
||||
* <LI><TT>restuser</TT> (default: <TT>admin</TT>)</LI>
|
||||
* <LI><TT>restpw</TT> (default: <TT>geoserver</TT>)</LI>
|
||||
* </ul>
|
||||
*
|
||||
* @author etj
|
||||
* @author carlo cancellieri - GeoSolutions
|
||||
*/
|
||||
public abstract class GeoserverRESTTest extends Assert {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTTest.class);
|
||||
|
||||
protected static final String DEFAULT_WS = "geosolutions";
|
||||
public static final String DEFAULT_WS = "geosolutions";
|
||||
|
||||
public static final String RESTURL;
|
||||
|
||||
public static final String RESTUSER;
|
||||
|
||||
public static final String RESTPW;
|
||||
|
||||
public static URL URL;
|
||||
|
||||
public static GeoServerRESTManager manager;
|
||||
|
||||
public static GeoServerRESTReader reader;
|
||||
|
||||
public static GeoServerRESTPublisher publisher;
|
||||
|
||||
private static boolean enabled = false;
|
||||
|
||||
private static Boolean existgs = null;
|
||||
|
||||
static {
|
||||
@ -105,14 +110,15 @@ public abstract class GeoserverRESTTest extends Assert {
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
||||
|
||||
if (enabled) {
|
||||
if (existgs == null) {
|
||||
existgs = reader.existGeoserver();
|
||||
if (!existgs) {
|
||||
LOGGER.error("TESTS WILL FAIL BECAUSE NO GEOSERVER WAS FOUND AT " + RESTURL + " ("+ RESTUSER+":"+RESTPW+")");
|
||||
LOGGER.error("TESTS WILL FAIL BECAUSE NO GEOSERVER WAS FOUND AT " + RESTURL
|
||||
+ " (" + RESTUSER + ":" + RESTPW + ")");
|
||||
} else {
|
||||
LOGGER.info("Using geoserver instance " + RESTUSER+":"+RESTPW+ " @ " + RESTURL);
|
||||
LOGGER.info("Using geoserver instance " + RESTUSER + ":" + RESTPW + " @ "
|
||||
+ RESTURL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,11 +241,11 @@ public abstract class GeoserverRESTTest extends Assert {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteAllStyles() {
|
||||
protected void deleteAllStyles() {
|
||||
List<String> styles = reader.getStyles().getNames();
|
||||
for (String style : styles) {
|
||||
LOGGER.warn("Deleting Style " + style);
|
||||
boolean removed = publisher.removeStyle(style);
|
||||
boolean removed = publisher.removeStyle(style,true);
|
||||
assertTrue("Style not removed " + style, removed);
|
||||
|
||||
}
|
||||
@ -249,18 +255,14 @@ public abstract class GeoserverRESTTest extends Assert {
|
||||
RESTFeatureType featureType = reader.getFeatureType(layer);
|
||||
RESTDataStore datastore = reader.getDatastore(featureType);
|
||||
|
||||
LOGGER.warn("Deleting FeatureType"
|
||||
+ datastore.getWorkspaceName() + " : "
|
||||
+ datastore.getName() + " / "
|
||||
+ featureType.getName()
|
||||
);
|
||||
LOGGER.warn("Deleting FeatureType" + datastore.getWorkspaceName() + " : "
|
||||
+ datastore.getName() + " / " + featureType.getName());
|
||||
|
||||
boolean removed = publisher.unpublishFeatureType(datastore.getWorkspaceName(), datastore.getName(), layer.getName());
|
||||
assertTrue("FeatureType not removed:"
|
||||
+ datastore.getWorkspaceName() + " : "
|
||||
+ datastore.getName() + " / "
|
||||
+ featureType.getName(),
|
||||
removed);
|
||||
boolean removed = publisher.unpublishFeatureType(datastore.getWorkspaceName(),
|
||||
datastore.getName(), layer.getName());
|
||||
assertTrue(
|
||||
"FeatureType not removed:" + datastore.getWorkspaceName() + " : "
|
||||
+ datastore.getName() + " / " + featureType.getName(), removed);
|
||||
|
||||
}
|
||||
|
||||
@ -268,19 +270,13 @@ public abstract class GeoserverRESTTest extends Assert {
|
||||
RESTCoverage coverage = reader.getCoverage(layer);
|
||||
RESTCoverageStore coverageStore = reader.getCoverageStore(coverage);
|
||||
|
||||
LOGGER.warn("Deleting Coverage "
|
||||
+ coverageStore.getWorkspaceName() + " : "
|
||||
+ coverageStore.getName() + " / "
|
||||
+ coverage.getName());
|
||||
LOGGER.warn("Deleting Coverage " + coverageStore.getWorkspaceName() + " : "
|
||||
+ coverageStore.getName() + " / " + coverage.getName());
|
||||
|
||||
boolean removed = publisher.unpublishCoverage(coverageStore.getWorkspaceName(),
|
||||
coverageStore.getName(),
|
||||
coverage.getName());
|
||||
assertTrue("Coverage not deleted "
|
||||
+ coverageStore.getWorkspaceName() + " : "
|
||||
+ coverageStore.getName() + " / "
|
||||
+ coverage.getName(),
|
||||
removed);
|
||||
coverageStore.getName(), coverage.getName());
|
||||
assertTrue("Coverage not deleted " + coverageStore.getWorkspaceName() + " : "
|
||||
+ coverageStore.getName() + " / " + coverage.getName(), removed);
|
||||
}
|
||||
|
||||
protected boolean existsLayer(String layername) {
|
||||
|
||||
@ -19,33 +19,90 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.feature;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import it.geosolutions.geoserver.rest.publisher.GeoserverRESTPublisherTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
*/
|
||||
public class GSFeatureEncoderTest extends TestCase {
|
||||
public class GSFeatureEncoderTest extends GeoserverRESTPublisherTest {
|
||||
protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class);
|
||||
|
||||
@Test
|
||||
public void testAll() {
|
||||
public void testIntegration() throws IOException {
|
||||
|
||||
if (!enabled())
|
||||
return;
|
||||
deleteAll();
|
||||
|
||||
GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(RESTURL, RESTUSER, RESTPW);
|
||||
|
||||
String storeName = "resttestshp";
|
||||
String layerName = "cities";
|
||||
|
||||
GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder();
|
||||
fte.setName(layerName + "_NEW");
|
||||
fte.setTitle("title");
|
||||
// fte.addKeyword("TODO");
|
||||
fte.setNativeCRS("EPSG:4326");
|
||||
fte.setDescription("desc");
|
||||
fte.setEnabled(true);
|
||||
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setEnabled(true);
|
||||
layerEncoder.setQueryable(true);
|
||||
|
||||
layerEncoder.setDefaultStyle("point");
|
||||
|
||||
publisher.createWorkspace(DEFAULT_WS);
|
||||
|
||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||
|
||||
// test insert
|
||||
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
|
||||
assertTrue("publish() failed", published);
|
||||
assertTrue(existsLayer(layerName));
|
||||
|
||||
publisher.publishStyle(new File(new ClassPathResource("testdata").getFile(),
|
||||
"default_point.sld"));
|
||||
|
||||
// optionally select the attributes to publish
|
||||
RESTLayer layer = reader.getLayer(layerName);
|
||||
RESTResource resource = reader.getResource(layer);
|
||||
List<GSAttributeEncoder> attrs = resource.getEncodedAttributeList();
|
||||
assertNotNull(attrs);
|
||||
for (GSAttributeEncoder enc : attrs) {
|
||||
fte.setAttribute(enc);
|
||||
}
|
||||
|
||||
assertTrue(publisher.publishDBLayer(DEFAULT_WS, storeName, fte, layerEncoder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFeatureTypeEncoder() {
|
||||
|
||||
GSFeatureTypeEncoder encoder = new GSFeatureTypeEncoder();
|
||||
encoder.addKeyword("KEYWORD_1");
|
||||
@ -53,35 +110,48 @@ public class GSFeatureEncoderTest extends TestCase {
|
||||
encoder.addKeyword("...");
|
||||
encoder.addKeyword("KEYWORD_N");
|
||||
|
||||
encoder.setName("Layername");
|
||||
|
||||
encoder.setTitle("title");
|
||||
encoder.addKeyword("TODO");
|
||||
encoder.setNativeCRS("EPSG:4326");
|
||||
encoder.setDescription("desc");
|
||||
encoder.setEnabled(true);
|
||||
|
||||
GSAttributeEncoder attribute = new GSAttributeEncoder();
|
||||
attribute.setAttribute(FeatureTypeAttribute.name, "NAME");
|
||||
attribute.setAttribute(FeatureTypeAttribute.binding, "java.lang.String");
|
||||
attribute.setAttribute(FeatureTypeAttribute.maxOccurs, "1");
|
||||
attribute.setAttribute(FeatureTypeAttribute.minOccurs, "0");
|
||||
attribute.setAttribute(FeatureTypeAttribute.nillable, "true");
|
||||
|
||||
encoder.setAttribute(attribute);
|
||||
|
||||
encoder.delAttribute("NAME");
|
||||
|
||||
attribute.setAttribute(FeatureTypeAttribute.name, "NEW_NAME");
|
||||
|
||||
encoder.setAttribute(attribute);
|
||||
|
||||
// TODO encoder.getAttribute("NAME");
|
||||
|
||||
GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder("ELE");
|
||||
|
||||
if (LOGGER.isInfoEnabled())
|
||||
LOGGER.info(encoder.toString());
|
||||
|
||||
encoder.addMetadata("elevation", dim2);
|
||||
|
||||
dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
|
||||
BigDecimal.valueOf(10));
|
||||
|
||||
dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(10));
|
||||
Element el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION);
|
||||
Assert.assertNotNull(el);
|
||||
|
||||
|
||||
LOGGER.info("contains_key:" + el.toString());
|
||||
|
||||
dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
|
||||
BigDecimal.valueOf(12));
|
||||
|
||||
dim2.setPresentation(PresentationDiscrete.DISCRETE_INTERVAL, BigDecimal.valueOf(12));
|
||||
el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION);
|
||||
Assert.assertNotNull(el);
|
||||
Assert.assertEquals("12", el.getText());
|
||||
|
||||
dim2.setPresentation(Presentation.CONTINUOUS_INTERVAL);
|
||||
|
||||
|
||||
|
||||
encoder.setMetadata("time", new GSFeatureDimensionInfoEncoder("time"));
|
||||
|
||||
el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.PRESENTATION);
|
||||
Assert.assertNotNull(el);
|
||||
el = ElementUtils.contains(encoder.getRoot(), GSDimensionInfoEncoder.RESOLUTION);
|
||||
@ -100,6 +170,10 @@ public class GSFeatureEncoderTest extends TestCase {
|
||||
if (el == null)
|
||||
LOGGER.info("REMOVED");
|
||||
|
||||
if (LOGGER.isInfoEnabled())
|
||||
LOGGER.info(encoder.toString());
|
||||
|
||||
assertEquals(encoder.getName(),"Layername");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -113,7 +187,8 @@ public class GSFeatureEncoderTest extends TestCase {
|
||||
Assert.assertTrue(encoder.delKeyword("KEYWORD_2"));
|
||||
Assert.assertFalse(encoder.delKeyword("KEYWORD_M"));
|
||||
|
||||
final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder("elevation_field");
|
||||
final GSFeatureDimensionInfoEncoder elevationDimension = new GSFeatureDimensionInfoEncoder(
|
||||
"elevation_field");
|
||||
|
||||
// if (LOGGER.isInfoEnabled())
|
||||
// LOGGER.info(encoder.toString());
|
||||
@ -132,7 +207,8 @@ public class GSFeatureEncoderTest extends TestCase {
|
||||
if (LOGGER.isInfoEnabled())
|
||||
LOGGER.info(encoder.toString());
|
||||
|
||||
final Element el=ElementUtils.contains(encoder.getRoot(),GSDimensionInfoEncoder.DIMENSIONINFO);
|
||||
final Element el = ElementUtils.contains(encoder.getRoot(),
|
||||
GSDimensionInfoEncoder.DIMENSIONINFO);
|
||||
Assert.assertNull(el);
|
||||
if (el == null)
|
||||
LOGGER.info("REMOVED");
|
||||
|
||||
@ -63,7 +63,7 @@ public class ElementUtilsTest {
|
||||
public void containsFilterDepthTest(){
|
||||
LOGGER.info("STARTING-> containsFilterDepthTest");
|
||||
|
||||
final List<Element> list=ElementUtils.search(this.root, filter, 1);
|
||||
final List<Element> list=ElementUtils.search(this.root, filter, 0);
|
||||
Assert.assertEquals(1,list.size());
|
||||
|
||||
final List<Element> list2=ElementUtils.search(this.root, filter, 6);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user