Compare commits

...

11 Commits

24 changed files with 1948 additions and 962 deletions

58
pom.xml
View File

@ -23,15 +23,12 @@
* THE SOFTWARE.
-->
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.2-SNAPSHOT</version>
<version>1.2.1</version>
<packaging>jar</packaging>
@ -62,6 +59,18 @@
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>ccancellieri</id>
<name>Carlo Cancellieri</name>
<email>carlo.cancellieri AT geosolutions.it</email>
<organization>GeoSolutions</organization>
<organizationUrl>http://www.geo-solutions.it</organizationUrl>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>
<licenses>
@ -88,9 +97,9 @@
</mailingLists>
<scm>
<connection>scm:git:https://github.com/geosolutions-it/geoserver-manager.git</connection>
<connection>scm:git:[fetch=]https://github.com/geosolutions-it/geoserver-manager.git[push=]git@github.com:geosolutions-it/geoserver-manager.git</connection>
<!--developerConnection>scm:git</developerConnection-->
<tag>master</tag>
<!--tag>master</tag-->
<url>https://github.com/geosolutions-it/geoserver-manager</url>
</scm>
@ -130,7 +139,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<detectLinks/>
<detectLinks />
<!-- <links>
<link>http://commons.apache.org/dbcp/apidocs/</link>
<link>http://commons.apache.org/fileupload/apidocs/</link>
@ -158,7 +167,15 @@
</execution>
</executions>
</plugin>
<!-- versioning -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
<!-- ======================================================== -->
@ -177,19 +194,18 @@
</build>
<reporting>
<plugins>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
<link>http://commons.apache.org/lang/api</link>
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
<link>http://www.jdom.org/docs/apidocs</link>
</links>
</configuration>
</plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
<link>http://commons.apache.org/lang/api</link>
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
<link>http://www.jdom.org/docs/apidocs</link>
</links>
</configuration>
</plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>

View File

@ -68,7 +68,9 @@ public class RESTCoverageStore {
public static RESTCoverageStore build(String response) {
if(response == null)
return null;
if(response.isEmpty())
return new RESTCoverageStore(new Element("coverageStore")); // TODO check how to response
Element pb = JDOMBuilder.buildElement(response);
if(pb != null)
return new RESTCoverageStore(pb);

View File

@ -41,9 +41,10 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
public GSPostGISDatastoreEncoder() {
super("dataStore");
addContent(connectionParameters.getRoot());
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
addDatabaseType("postgis");
addContent(connectionParameters.getRoot());
}
/**

View File

@ -48,10 +48,11 @@ import org.jdom.filter.Filter;
*/
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
extends PropertyXMLEncoder {
private final static String NAME="name";
private final static String NAME = "name";
final private GSMetadataEncoder<T> metadata = new GSMetadataEncoder<T>();
final private Element keywordsListEncoder = new Element("keywords");
/**
* @param rootName
* Actually 'feature' or 'coverage'
@ -66,9 +67,9 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
addContent(metadata.getRoot());
addContent(keywordsListEncoder);
}
public void setEnabled(boolean enabled){
set("enabled",(enabled)?"true":"false");
public void setEnabled(boolean enabled) {
set("enabled", (enabled) ? "true" : "false");
}
/**
@ -79,28 +80,29 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
public void addMetadata(String key, T dimensionInfo) {
metadata.add(key, dimensionInfo.getRoot());
}
/**
* @param key the name of the metadata to add (f.e.: elevation, time)
* @param key
* the name of the metadata to add (f.e.: elevation, time)
* @return true if something is removed, false otherwise
*/
public boolean delMetadata(String key) {
return metadata.remove(key);
}
public void setMetadata(String key, T dimensionInfo) {
metadata.set(key, dimensionInfo.getRoot());
}
public void addKeyword(String keyword) {
final Element el = new Element("string");
el.setText(keyword);
keywordsListEncoder.addContent(el);
}
/**
* delete a keyword from the list
*
* @param keyword
* @return true if something is removed, false otherwise
*/
@ -109,13 +111,14 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
el.setText(keyword);
return (keywordsListEncoder.removeContent(new Filter() {
private static final long serialVersionUID = 1L;
public boolean matches(Object obj) {
if (((Element)obj).getText().equals(keyword)){
if (((Element) obj).getText().equals(keyword)) {
return true;
}
return false;
}
})).size()==0?false:true;
})).size() == 0 ? false : true;
}
/**
@ -125,7 +128,8 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
}
private final static String PROJECTIONPOLICY="projectionPolicy";
private final static String PROJECTIONPOLICY = "projectionPolicy";
/**
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
*
@ -153,6 +157,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
public void addName(final String name) {
add(NAME, name);
}
/**
* Set or modify the 'name' node with a text value from 'name'
*
@ -162,7 +167,16 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
set(NAME, name);
}
private final static String TITLE="title";
public String getName() {
final Element nameNode = get(NAME);
if (nameNode != null)
return nameNode.getText();
else
return null;
}
private final static String TITLE = "title";
/**
* Add the 'title' node with a text value from 'title'
*
@ -172,7 +186,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
public void addTitle(final String title) {
add(TITLE, title);
}
/**
* Set or modify the 'title' node with a text value from 'title'
*/
@ -180,7 +194,8 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
set(TITLE, title);
}
private final static String SRS="srs";
private final static String SRS = "srs";
/**
* Add the 'SRS' node with a text value from 'srs'
*
@ -190,7 +205,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
public void addSRS(final String srs) {
add(SRS, srs);
}
/**
* Set or modify the 'SRS' node with a text value from 'srs'
*/
@ -198,67 +213,67 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
set(SRS, srs);
}
private final static String LATLONBBMINX="latLonBoundingBox/minx";
private final static String LATLONBBMAXX="latLonBoundingBox/maxx";
private final static String LATLONBBMINY="latLonBoundingBox/miny";
private final static String LATLONBBMAXY="latLonBoundingBox/maxy";
private final static String LATLONBBCRS="latLonBoundingBox/crs";
private final static String LATLONBBMINX = "latLonBoundingBox/minx";
private final static String LATLONBBMAXX = "latLonBoundingBox/maxx";
private final static String LATLONBBMINY = "latLonBoundingBox/miny";
private final static String LATLONBBMAXY = "latLonBoundingBox/maxy";
private final static String LATLONBBCRS = "latLonBoundingBox/crs";
/**
* @deprecated use the setSRS. <br>
* This method will be set as protected in the next release
*
*
* @param minx
* @param maxy
* @param maxx
* @param miny
* @param crs
*/
public void addLatLonBoundingBox(double minx, double maxy, double maxx,
double miny, final String crs) {
public void addLatLonBoundingBox(double minx, double miny, double maxx,
double maxy, final String crs) {
add(LATLONBBMINX, String.valueOf(minx));
add(LATLONBBMINY, String.valueOf(miny));
add(LATLONBBMAXY, String.valueOf(maxy));
add(LATLONBBMAXX, String.valueOf(maxx));
add(LATLONBBMINY, String.valueOf(miny));
add(LATLONBBCRS, crs);
}
public void setLatLonBoundingBox(double minx, double maxy, double maxx,
double miny, final String crs) {
public void setLatLonBoundingBox(double minx, double miny, double maxx,
double maxy, final String crs) {
set(LATLONBBMINX, String.valueOf(minx));
set(LATLONBBMAXY, String.valueOf(maxy));
set(LATLONBBMAXX, String.valueOf(maxx));
set(LATLONBBMINY, String.valueOf(miny));
set(LATLONBBCRS, crs);
}
private final static String NATIVEBBMINX="nativeBoundingBox/minx";
private final static String NATIVEBBMAXX="nativeBoundingBox/maxx";
private final static String NATIVEBBMINY="nativeBoundingBox/miny";
private final static String NATIVEBBMAXY="nativeBoundingBox/maxy";
private final static String NATIVEBBCRS="nativeBoundingBox/crs";
private final static String NATIVEBBMINX = "nativeBoundingBox/minx";
private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx";
private final static String NATIVEBBMINY = "nativeBoundingBox/miny";
private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy";
private final static String NATIVEBBCRS = "nativeBoundingBox/crs";
/**
* @deprecated use the setSRS. <br>
* This method will be set as protected in the next release
*
*
* @param minx
* @param maxy
* @param maxx
* @param miny
* @param crs
*/
public void addNativeBoundingBox(double minx, double maxy, double maxx,
double miny, final String crs) {
public void addNativeBoundingBox(double minx, double miny, double maxx,
double maxy, final String crs) {
add(NATIVEBBMINX, String.valueOf(minx));
add(NATIVEBBMAXY, String.valueOf(maxy));
add(NATIVEBBMAXX, String.valueOf(maxx));
add(NATIVEBBMINY, String.valueOf(miny));
add(NATIVEBBCRS, crs);
}
public void setNativeBoundingBox(double minx, double maxy, double maxx,
double miny, final String crs) {
public void setNativeBoundingBox(double minx, double miny, double maxx,
double maxy, final String crs) {
set(NATIVEBBMINX, String.valueOf(minx));
set(NATIVEBBMAXY, String.valueOf(maxy));
set(NATIVEBBMAXX, String.valueOf(maxx));

View File

@ -43,6 +43,9 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
super(WORKSPACE);
}
/**
* @param name the workspace name
*/
public GSWorkspaceEncoder(String name) {
super(WORKSPACE);
addName(name);
@ -54,7 +57,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
* @throws IllegalStateException if name is already set
* @deprecated will be set to protected in the next release
*/
public void addName(String name) {
public void addName(final String name) {
final Element el=ElementUtils.contains(getRoot(),NAME);
if (el==null)
add(NAME, name);
@ -66,7 +69,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
* add or change (if already set) the workspace name
* @param name
*/
public void setName(String name) {
public void setName(final String name) {
final Element el=ElementUtils.contains(getRoot(),NAME);
if (el==null)
add(NAME, name);

View File

@ -27,7 +27,9 @@ package it.geosolutions.geoserver.rest.encoder.coverage;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;
import org.jdom.filter.Filter;
@ -60,6 +62,8 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
if (obj instanceof Element) {
if (((Element)obj).getName().equals(ENTRY)){
final Element el=((Element)obj).getChild(STRING);
if (el==null)
return false;
if (el.getText().equals(this.name)){
return true;
}
@ -87,10 +91,11 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addAllowMultithreading(final boolean val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(allowMultithreading));
param.addContent(new Element(STRING).setText((val)?"true":"false"));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(allowMultithreading));
list.add(new Element(STRING).setText((val)?"true":"false"));
parameters.add(null,list);
}
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
@ -105,10 +110,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addFilter(final String val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(filter));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(filter));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter filterFilter=new parametersFilter(filter);
@ -123,10 +128,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addMaxAllowedTiles(final int val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(maxAllowedTiles));
param.addContent(new Element(STRING).setText(String.valueOf(val)));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(maxAllowedTiles));
list.add(new Element(STRING).setText(String.valueOf(val)));
parameters.add(null,list);
}
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
@ -141,10 +146,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addInputTransparentColor(final String val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(inputTransparentColor));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(inputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
@ -159,10 +164,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addOutputTransparentColor(final String val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(outputTransparentColor));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(outputTransparentColor));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
@ -178,10 +183,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @deprecated will be set to protected in the next release
*/
public void addSUGGESTED_TILE_SIZE(final String val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
@ -196,10 +201,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addUSE_JAI_IMAGEREAD(final boolean val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(USE_JAI_IMAGEREAD));
param.addContent(new Element(STRING).setText((val)?"true":"false"));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
list.add(new Element(STRING).setText((val)?"true":"false"));
parameters.add(null,list);
}
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
@ -214,10 +219,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
* @param val
*/
public void addBackgroundValues(final String val){
final Element param=new Element(ENTRY);
param.addContent(new Element(STRING).setText(backgroundValues));
param.addContent(new Element(STRING).setText(val));
parameters.addContent(param);
final List<Element> list=new ArrayList<Element>(2);
list.add(new Element(STRING).setText(backgroundValues));
list.add(new Element(STRING).setText(val));
parameters.add(null,list);
}
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);

View File

@ -25,6 +25,9 @@
package it.geosolutions.geoserver.rest.encoder.utils;
import java.util.Iterator;
import java.util.List;
import org.jdom.Content;
import org.jdom.Element;
import org.jdom.filter.Filter;
@ -63,6 +66,22 @@ import org.jdom.filter.Filter;
* </entry>
* </listName>}
*
* This can be also add list of compounded Elements <br/>
*
* <listName>
* <entry>
* <String>AllowMultithreading</String>
* <enabled>false</enabled>
* </entry>
* <entry>
*
* <enabled>true</enabled>
* <attribute>ele</attribute>
* <presentation>LIST</presentation>
* </dimensionInfo>
* </entry>
* </listName>}
*
* <PRE>
*
* @author ETj (etj at geo-solutions.it)
@ -72,100 +91,145 @@ import org.jdom.filter.Filter;
public class NestedElementEncoder extends XmlElement {
public final static String ENTRY = "entry";
public final static String KEY = "key";
static class NestedElementFilter implements Filter {
private static final long serialVersionUID = 1L;
private final String key;
private final String value;
private final Element root;
public NestedElementFilter(Element root, String key) {
this.key=key;
this.root=root;
/**
* if key is null we only check for children name if value is null we
* only check for key attribute
*
* @param root
* @param key
* @param value
*/
public NestedElementFilter(Element root, String key, String value) {
this.key = key;
this.root = root;
this.value = value;
}
public boolean matches(Object obj) {
if (obj instanceof Element) {
final Element el = ((Element) obj);
if (root.isAncestor(el)){
if (root.isAncestor(el)) {
if (el.getName().equals(ENTRY)/* && el.getText().equals(value) */) {
boolean keyCheck=true;
if (key != null) {
if (el.getAttribute(KEY).getValue().equals(key))
return true;
else
return false;
if (el.getAttribute(KEY).getValue().equals(key)) {
keyCheck=true;
} else {
keyCheck=false;
}
}
return true;
if (value != null)
return keyCheck&&checkChilds(el, value);
else
return keyCheck;
}
}
}
return false;
}
private static boolean checkChilds(Element el, String value) {
final List<Element> childList = el.getChildren();
final Iterator<Element> childIt = childList.iterator();
while (childIt.hasNext()) {
final Element child = childIt.next();
if (child.getName().equals(value)) {
return true;
}
}
return false;
}
};
public NestedElementEncoder(String listName) {
super(listName);
}
// public void set(final String key, final String value) {
// // if some previous similar object is found
// final Element search;
// if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
// // remove it
// ElementUtils.remove(getRoot(), search);
// }
// // add the new entry
// add(key,value);
// }
public void set(final String key, final String value) {
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
getRoot(), key, value))) != null) {
// remove it
ElementUtils.remove(getRoot(), search);
}
// add the new entry
add(key, value);
}
// public void add(final String key, final Element value) {
// final Element entryElem = new Element(ENTRY);
// if (key != null)
// entryElem.setAttribute(KEY, key);
//
// entryElem.addContent(value);
//
// this.addContent(entryElem);
// }
// public void add(final String key, final String value) {
// final Element entryElem = new Element(ENTRY);
//
// if (key != null)
// entryElem.setAttribute(KEY, key);
//
// entryElem.setText(value);
//
// this.addContent(entryElem);
// }
public void set(final String key, final Element value) {
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
getRoot(), key, value.getName()))) != null) {
// remove it
ElementUtils.remove(getRoot(), search);
}
// add the new entry
add(key, value);
}
public void add(final String key, final Content value) {
public void add(final String key, final Element value) {
final Element entryElem = new Element(ENTRY);
if (key != null)
entryElem.setAttribute(KEY, key);
entryElem.setContent(value);
entryElem.addContent(value);
this.addContent(entryElem);
}
public void set(final String key, final Content value) {
public void add(final String key, final String value) {
final Element entryElem = new Element(ENTRY);
if (key != null)
entryElem.setAttribute(KEY, key);
entryElem.setText(value);
this.addContent(entryElem);
}
public void add(final String key, final List<Element> list) {
final Element entryElem = new Element(ENTRY);
if (key != null)
entryElem.setAttribute(KEY, key);
// final Iterator<Element> it=list.iterator();
// while (it.hasNext()){
// final Element child=it.next();
entryElem.addContent(list);
// }
this.addContent(entryElem);
}
public void set(final String key, final List<Element> value) {
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
getRoot(), key, value.get(0).getValue()))) != null) {
// remove it
ElementUtils.remove(search, search);
}
// add the new entry
add(key,value);
add(key, value);
}
public boolean remove(final String key){
public boolean remove(final String key) {
// if some previous similar object is found
final Element search;
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
return ElementUtils.remove(search,search);
}
else
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
getRoot(), key, null))) != null) {
return ElementUtils.remove(search, search);
} else
return false;
}
}

View File

@ -56,15 +56,35 @@ public class PropertyXMLEncoder extends XmlElement {
public PropertyXMLEncoder(final String rootName) {
super(rootName);
}
protected void get(final String key, final String value) {
}
protected Element get(final String key) {
return get(getRoot(), key);
}
public void set(final String key, final String value) {
private Element get(final Element el, final String key) {
if (el==null)
return null;
if (key.contains("/")) {
final int i = key.indexOf("/");
final String parentName = key.substring(0, i);
final String newkey = key.substring(i + 1);
return get(ElementUtils.contains(el, parentName),newkey);
} else {
return ElementUtils.contains(el, key);
}
}
protected void set(final String key, final String value) {
if (key != null && value != null) {
set(getRoot(), key, value);
}
}
private void set(final Element e, final String key, final String value){
private void set(final Element e, final String key, final String value) {
if (key.contains("/")) {
final int i = key.indexOf("/");
final String childName = key.substring(0, i);
@ -74,21 +94,21 @@ public class PropertyXMLEncoder extends XmlElement {
if (child == null) {
child = new Element(childName);
e.addContent(child);
add(child,newkey,value);
add(child, newkey, value);
}
set(child, newkey, value);
set(child, newkey, value);
} else {
Element pp = null;
if ((pp = ElementUtils.contains(e,key)) == null)
add(e,key, value);
if ((pp = ElementUtils.contains(e, key)) == null)
add(e, key, value);
else {
ElementUtils.remove(e,pp);
add(e,key, value);
ElementUtils.remove(pp, pp);
add(e, key, value);
}
}
}
public void add(final String key, final String value) {
protected void add(final String key, final String value) {
if (key != null && value != null) {
add(this.getRoot(), key, value);
}
@ -113,60 +133,60 @@ public class PropertyXMLEncoder extends XmlElement {
}
}
// public void set(final String key, final String value) {
// if (key != null && value != null) {
// set(getRoot(), key, value);
// }
// }
//
// private void set(final Element e, final String key, final String value){
// if (!key.contains("/")) {
// Element pp = null;
// if ((pp = contains(key)) == null)
// add(e,key, value);
// else {
// remove(pp);
// add(e,key, value);
// }
// } else {
// final int i = key.indexOf("/");
// final String childName = key.substring(0, i);
// final String newkey = key.substring(i + 1);
//
// Element child = e.getChild(childName);
// if (child == null) {
// child = new Element(childName);
// e.addContent(child);
// add(child,newkey,value);
// }
// set(child, newkey, value);
// }
// }
//
// public void add(final String key, final String value) {
// if (key != null && value != null) {
// add(this.getRoot(), key, value);
// }
// }
//
// private void add(Element e, String key, String value) {
// if (!key.contains("/")) {
// e.addContent(new Element(key).setText(value));
// } else {
// final int i = key.indexOf("/");
// final String childName = key.substring(0, i);
// final String newkey = key.substring(i + 1);
//
// Element child = e.getChild(childName);
// if (child == null) {
// child = new Element(childName);
// e.addContent(child);
// }
//
// add(child, newkey, value);
// }
//
// }
// public void set(final String key, final String value) {
// if (key != null && value != null) {
// set(getRoot(), key, value);
// }
// }
//
// private void set(final Element e, final String key, final String value){
// if (!key.contains("/")) {
// Element pp = null;
// if ((pp = contains(key)) == null)
// add(e,key, value);
// else {
// remove(pp);
// add(e,key, value);
// }
// } else {
// final int i = key.indexOf("/");
// final String childName = key.substring(0, i);
// final String newkey = key.substring(i + 1);
//
// Element child = e.getChild(childName);
// if (child == null) {
// child = new Element(childName);
// e.addContent(child);
// add(child,newkey,value);
// }
// set(child, newkey, value);
// }
// }
//
// public void add(final String key, final String value) {
// if (key != null && value != null) {
// add(this.getRoot(), key, value);
// }
// }
//
// private void add(Element e, String key, String value) {
// if (!key.contains("/")) {
// e.addContent(new Element(key).setText(value));
// } else {
// final int i = key.indexOf("/");
// final String childName = key.substring(0, i);
// final String newkey = key.substring(i + 1);
//
// Element child = e.getChild(childName);
// if (child == null) {
// child = new Element(childName);
// e.addContent(child);
// }
//
// add(child, newkey, value);
// }
//
// }
}

View File

@ -56,21 +56,21 @@ public class XmlElement{
@SuppressWarnings("unused")
private XmlElement(){root=null;};
public void add(final String nodename, final String nodetext) {
protected void add(final String nodename, final String nodetext) {
add(nodename,new Text(nodetext));
}
public void add(final String nodename, final Content nodetext) {
protected void add(final String nodename, final Content nodetext) {
final Element el=new Element(nodename);
el.setContent(nodetext);
this.addContent(el);
}
public void set(final String nodename, final String nodetext) {
protected void set(final String nodename, final String nodetext) {
set(nodename,new Text(nodetext));
}
public void set(final String nodename, final Content nodeContent) {
protected void set(final String nodename, final Content nodeContent) {
final Element el=ElementUtils.contains(getRoot(),nodename);
if (el==null){
add(nodename,nodeContent);
@ -80,7 +80,7 @@ public class XmlElement{
}
}
public Element addContent(Content child){
protected Element addContent(Content child){
return root.addContent(child);
}

View File

@ -50,7 +50,7 @@ import org.springframework.core.io.ClassPathResource;
public class ConfigTest extends GeoserverRESTTest {
private final static Logger LOGGER = Logger.getLogger(ConfigTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
private static final String DEFAULT_WS = "geosolutions";
public ConfigTest(String testName) {

View File

@ -0,0 +1,169 @@
/*
* 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;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
import it.geosolutions.geoserver.rest.encoder.coverage.GSImageMosaicEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
/**
* Testcase for creating postgis-based resources on geoserver.
* <P>
* Since these tests require a running postgis instance, this is more like integration tests.<br/>
* You may skip them by defining<tt> <pre>
* -DpgIgnore=true </pre></tt>
* When <tt>pgIgnore</tt> is defined that way, failing tests will not break
* the build: they will be logged as errors instead.
*
* <P>
* The target postgis instance can be customized by defining the following env vars: <ul>
* <LI><TT>pgHost</TT> (default <TT>localhost</TT>)</LI>
* <LI><TT>pgPort</TT> (default: <TT>5432</TT>)</LI>
* <LI><TT>pgDatabase</TT> (default: <TT>test</TT>)</LI>
* <LI><TT>pgSchema</TT> (default: <TT>public</TT>)</LI>
* <LI><TT>pgUser</TT> (default: <TT>utest</TT>)</LI>
* <LI><TT>pgPassword</TT> (default: <TT>ptest</TT>)</LI>
* </ul>
*
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*
* @see GeoserverRESTTest
*/
public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTImageMosaicTest.class);
public GeoserverRESTImageMosaicTest(String testName) {
super(testName);
}
public void testCreateDeleteImageMosaicDatastore() {
if (!enabled()) {
return;
}
deleteAll();
final String wsName = "geosolutions";
final String coverageStoreName = "resttestImageMosaic";
final GSImageMosaicEncoder coverageEncoder = new GSImageMosaicEncoder();
/*
* unused in mosaic creation
* this is only useful if you want to modify an existing coverage:
* publisher.configureCoverage(ce, wsname, csname);
* or create a new one from an existing store:
* publisher.createCoverage(ce, wsname, csname);
*/
coverageEncoder.setName("CoverageName");
coverageEncoder.setAllowMultithreading(true);
coverageEncoder.setBackgroundValues("");
coverageEncoder.setFilter("");
coverageEncoder.setInputTransparentColor("");
coverageEncoder.setLatLonBoundingBox(-180, -90, 180, 90, "EPSG:4326");
coverageEncoder.setMaxAllowedTiles(6000);
coverageEncoder.setNativeBoundingBox(-180, -90, 180, 90, "EPSG:4326");
coverageEncoder.setOutputTransparentColor("");
coverageEncoder.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
coverageEncoder.setSRS("EPSG:4326");
coverageEncoder.setSUGGESTED_TILE_SIZE("256,256");
coverageEncoder.setUSE_JAI_IMAGEREAD(true);
// activate time
final GSDimensionInfoEncoder time=new GSDimensionInfoEncoder(true);
time.setPresentation(Presentation.LIST);
// set time metadata
coverageEncoder.setMetadata("time", time);
// not active elevation
coverageEncoder.setMetadata("elevation", new GSDimensionInfoEncoder());
assertTrue(publisher.createWorkspace(wsName));
LOGGER.info(coverageEncoder.toString());
final String styleName = "raster";
File sldFile;
try {
sldFile = new ClassPathResource("testdata/raster.sld").getFile();
// insert style
assertTrue(publisher.publishStyle(sldFile));
} catch (IOException e1) {
assertFalse(e1.getLocalizedMessage(),Boolean.FALSE);
e1.printStackTrace();
}
GSLayerEncoder layerEncoder=new GSLayerEncoder();
layerEncoder.setDefaultStyle(styleName);
LOGGER.info(layerEncoder.toString());
// creation test
RESTCoverageStore coverageStore =null;
try {
final File mosaicFile = new ClassPathResource("testdata/time_geotiff/").getFile();
if (!publisher.createExternalMosaic(wsName,coverageStoreName,mosaicFile,coverageEncoder,layerEncoder)){
fail();
}
coverageStore = reader.getCoverageStore(wsName,coverageStoreName);
if (coverageStore==null){
LOGGER.error("*** coveragestore " + coverageStoreName + " has not been created.");
fail("*** coveragestore " + coverageStoreName + " has not been created.");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
} catch (IOException e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
// removing recursively coveragestore
boolean removed = publisher.removeCoverageStore(coverageStore.getWorkspaceName(), coverageStore.getName(), true);
if( ! removed ){
LOGGER.error("*** CoverageStore " + coverageStoreName + " has not been removed.");
fail("*** CoverageStore " + coverageStoreName + " has not been removed.");
}
assertTrue(publisher.removeStyle(styleName));
assertTrue(publisher.removeWorkspace(wsName));
}
}

View File

@ -34,6 +34,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.jdom.Element;
@ -175,7 +176,6 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
// String ns = "it.geosolutions";
String storeName = "resttestshp";
String layerName = "cities";
@ -251,6 +251,46 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse(reader.existsStyle(styleName));
}
public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException {
if (!enabled()) {
return;
}
// Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp";
String layerName = "cities";
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// known state?
cleanupTestFT(layerName, DEFAULT_WS, storeName);
// test insert
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile,"EPSG:4326",new NameValuePair("charset","UTF-8"));
assertTrue("publish() failed", published);
assertTrue(existsLayer(layerName));
RESTLayer layer = reader.getLayer(layerName);
LOGGER.info("Layer style is " + layer.getDefaultStyle());
//test delete
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
assertTrue("Unpublish() failed", ok);
assertFalse(existsLayer(layerName));
// remove also datastore
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
assertTrue("removeDatastore() failed", dsRemoved);
}
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
if (!enabled()) {
return;

View File

@ -44,13 +44,8 @@ public class GSWorkspaceEncoderTest extends TestCase {
final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder("WS1");
LOGGER.info(wsenc.toString());
try{
wsenc.addName("test_name");
// NEVER HERE
Assert.assertTrue(false);
}catch (IllegalStateException e){
Assert.assertTrue(true);
}
wsenc.setName("test_name");
LOGGER.info(wsenc.toString());
wsenc.setName("new_name");
LOGGER.info(wsenc.toString());

View File

@ -0,0 +1,3 @@
TimeAttribute=time
Schema= the_geom:Polygon,location:String,time:java.util.Date
PropertyCollectors=TimestampFileNameExtractorSPI[timeregex](time)

View File

@ -0,0 +1 @@
regex=[a-z]{5,5}

View File

@ -0,0 +1 @@
regex=[0-9]{6}