Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f0e6ccb05 | ||
|
|
c26ac38cac | ||
|
|
c0f73dfc52 | ||
|
|
757660eaf7 | ||
|
|
e0a033ea71 | ||
|
|
1961ecd8b7 | ||
|
|
0ef0251619 | ||
|
|
9375c07ea3 | ||
|
|
9514399b77 | ||
|
|
514679990d | ||
|
|
c24cbd9a83 | ||
|
|
92932151ea | ||
|
|
64502efd0e | ||
|
|
395859124a | ||
|
|
3f0d61f86f | ||
|
|
ffa19fefba | ||
|
|
10c6fcbb1f | ||
|
|
2b23e3be82 | ||
|
|
69f4abd849 | ||
|
|
3fa1545019 |
2
README
2
README
@ -4,4 +4,4 @@ The purpose of this project is to hold a REST client library to interact with Ge
|
|||||||
|
|
||||||
For more information see this page:
|
For more information see this page:
|
||||||
|
|
||||||
http://code.google.com/p/geoserver-manager/
|
https://github.com/geosolutions-it/geoserver-manager
|
||||||
62
pom.xml
62
pom.xml
@ -23,15 +23,12 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<project
|
<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">
|
||||||
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>it.geosolutions</groupId>
|
<groupId>it.geosolutions</groupId>
|
||||||
<artifactId>geoserver-manager</artifactId>
|
<artifactId>geoserver-manager</artifactId>
|
||||||
<version>1.2-SNAPSHOT</version>
|
<version>1.2.4-SNAPSHOT</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
@ -62,6 +59,18 @@
|
|||||||
</roles>
|
</roles>
|
||||||
<timezone>+1</timezone>
|
<timezone>+1</timezone>
|
||||||
</developer>
|
</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>
|
</developers>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
@ -88,9 +97,9 @@
|
|||||||
</mailingLists>
|
</mailingLists>
|
||||||
|
|
||||||
<scm>
|
<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-->
|
<!--developerConnection>scm:git</developerConnection-->
|
||||||
<tag>master</tag>
|
<!--tag>master</tag-->
|
||||||
<url>https://github.com/geosolutions-it/geoserver-manager</url>
|
<url>https://github.com/geosolutions-it/geoserver-manager</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
@ -120,8 +129,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.5</source>
|
<source>1.6</source>
|
||||||
<target>1.5</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
@ -130,7 +139,7 @@
|
|||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>2.7</version>
|
<version>2.7</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<detectLinks/>
|
<detectLinks />
|
||||||
<!-- <links>
|
<!-- <links>
|
||||||
<link>http://commons.apache.org/dbcp/apidocs/</link>
|
<link>http://commons.apache.org/dbcp/apidocs/</link>
|
||||||
<link>http://commons.apache.org/fileupload/apidocs/</link>
|
<link>http://commons.apache.org/fileupload/apidocs/</link>
|
||||||
@ -158,7 +167,15 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
|
|
||||||
<!-- ======================================================== -->
|
<!-- ======================================================== -->
|
||||||
@ -177,19 +194,18 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<links>
|
<links>
|
||||||
<link>http://commons.apache.org/lang/api</link>
|
<link>http://commons.apache.org/lang/api</link>
|
||||||
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
|
<link>http://java.sun.com/j2se/1.5.0/docs/api</link>
|
||||||
<link>http://www.jdom.org/docs/apidocs</link>
|
<link>http://www.jdom.org/docs/apidocs</link>
|
||||||
</links>
|
</links>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- <plugin>
|
<!-- <plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -68,7 +68,9 @@ public class RESTCoverageStore {
|
|||||||
public static RESTCoverageStore build(String response) {
|
public static RESTCoverageStore build(String response) {
|
||||||
if(response == null)
|
if(response == null)
|
||||||
return null;
|
return null;
|
||||||
|
if(response.isEmpty())
|
||||||
|
return new RESTCoverageStore(new Element("coverageStore")); // TODO check how to response
|
||||||
|
|
||||||
Element pb = JDOMBuilder.buildElement(response);
|
Element pb = JDOMBuilder.buildElement(response);
|
||||||
if(pb != null)
|
if(pb != null)
|
||||||
return new RESTCoverageStore(pb);
|
return new RESTCoverageStore(pb);
|
||||||
|
|||||||
@ -41,9 +41,10 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
|||||||
|
|
||||||
public GSPostGISDatastoreEncoder() {
|
public GSPostGISDatastoreEncoder() {
|
||||||
super("dataStore");
|
super("dataStore");
|
||||||
|
addContent(connectionParameters.getRoot());
|
||||||
|
|
||||||
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
|
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
|
||||||
addDatabaseType("postgis");
|
addDatabaseType("postgis");
|
||||||
addContent(connectionParameters.getRoot());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -48,10 +48,11 @@ import org.jdom.filter.Filter;
|
|||||||
*/
|
*/
|
||||||
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
||||||
extends PropertyXMLEncoder {
|
extends PropertyXMLEncoder {
|
||||||
private final static String NAME="name";
|
private final static String NAME = "name";
|
||||||
|
|
||||||
final private GSMetadataEncoder<T> metadata = new GSMetadataEncoder<T>();
|
final private GSMetadataEncoder<T> metadata = new GSMetadataEncoder<T>();
|
||||||
final private Element keywordsListEncoder = new Element("keywords");
|
final private Element keywordsListEncoder = new Element("keywords");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param rootName
|
* @param rootName
|
||||||
* Actually 'feature' or 'coverage'
|
* Actually 'feature' or 'coverage'
|
||||||
@ -66,9 +67,9 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
|||||||
addContent(metadata.getRoot());
|
addContent(metadata.getRoot());
|
||||||
addContent(keywordsListEncoder);
|
addContent(keywordsListEncoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnabled(boolean enabled){
|
public void setEnabled(boolean enabled) {
|
||||||
set("enabled",(enabled)?"true":"false");
|
set("enabled", (enabled) ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,28 +80,29 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
|||||||
public void addMetadata(String key, T dimensionInfo) {
|
public void addMetadata(String key, T dimensionInfo) {
|
||||||
metadata.add(key, dimensionInfo.getRoot());
|
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
|
* @return true if something is removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean delMetadata(String key) {
|
public boolean delMetadata(String key) {
|
||||||
return metadata.remove(key);
|
return metadata.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetadata(String key, T dimensionInfo) {
|
public void setMetadata(String key, T dimensionInfo) {
|
||||||
metadata.set(key, dimensionInfo.getRoot());
|
metadata.set(key, dimensionInfo.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addKeyword(String keyword) {
|
public void addKeyword(String keyword) {
|
||||||
final Element el = new Element("string");
|
final Element el = new Element("string");
|
||||||
el.setText(keyword);
|
el.setText(keyword);
|
||||||
keywordsListEncoder.addContent(el);
|
keywordsListEncoder.addContent(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a keyword from the list
|
* delete a keyword from the list
|
||||||
|
*
|
||||||
* @param keyword
|
* @param keyword
|
||||||
* @return true if something is removed, false otherwise
|
* @return true if something is removed, false otherwise
|
||||||
*/
|
*/
|
||||||
@ -109,13 +111,14 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
|||||||
el.setText(keyword);
|
el.setText(keyword);
|
||||||
return (keywordsListEncoder.removeContent(new Filter() {
|
return (keywordsListEncoder.removeContent(new Filter() {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public boolean matches(Object obj) {
|
public boolean matches(Object obj) {
|
||||||
if (((Element)obj).getText().equals(keyword)){
|
if (((Element) obj).getText().equals(keyword)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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
|
REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String PROJECTIONPOLICY="projectionPolicy";
|
private final static String PROJECTIONPOLICY = "projectionPolicy";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
* NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED
|
||||||
*
|
*
|
||||||
@ -153,6 +157,7 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
|||||||
public void addName(final String name) {
|
public void addName(final String name) {
|
||||||
add(NAME, name);
|
add(NAME, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or modify the 'name' node with a text value from '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);
|
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'
|
* 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) {
|
public void addTitle(final String title) {
|
||||||
add(TITLE, title);
|
add(TITLE, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or modify the 'title' node with a text value from '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);
|
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'
|
* 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) {
|
public void addSRS(final String srs) {
|
||||||
add(SRS, srs);
|
add(SRS, srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or modify the 'SRS' node with a text value from '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);
|
set(SRS, srs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String LATLONBBMINX="latLonBoundingBox/minx";
|
private final static String LATLONBBMINX = "latLonBoundingBox/minx";
|
||||||
private final static String LATLONBBMAXX="latLonBoundingBox/maxx";
|
private final static String LATLONBBMAXX = "latLonBoundingBox/maxx";
|
||||||
private final static String LATLONBBMINY="latLonBoundingBox/miny";
|
private final static String LATLONBBMINY = "latLonBoundingBox/miny";
|
||||||
private final static String LATLONBBMAXY="latLonBoundingBox/maxy";
|
private final static String LATLONBBMAXY = "latLonBoundingBox/maxy";
|
||||||
private final static String LATLONBBCRS="latLonBoundingBox/crs";
|
private final static String LATLONBBCRS = "latLonBoundingBox/crs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use the setSRS. <br>
|
* @deprecated use the setSRS. <br>
|
||||||
* This method will be set as protected in the next release
|
* This method will be set as protected in the next release
|
||||||
*
|
*
|
||||||
* @param minx
|
* @param minx
|
||||||
* @param maxy
|
* @param maxy
|
||||||
* @param maxx
|
* @param maxx
|
||||||
* @param miny
|
* @param miny
|
||||||
* @param crs
|
* @param crs
|
||||||
*/
|
*/
|
||||||
public void addLatLonBoundingBox(double minx, double maxy, double maxx,
|
public void addLatLonBoundingBox(double minx, double miny, double maxx,
|
||||||
double miny, final String crs) {
|
double maxy, final String crs) {
|
||||||
add(LATLONBBMINX, String.valueOf(minx));
|
add(LATLONBBMINX, String.valueOf(minx));
|
||||||
|
add(LATLONBBMINY, String.valueOf(miny));
|
||||||
add(LATLONBBMAXY, String.valueOf(maxy));
|
add(LATLONBBMAXY, String.valueOf(maxy));
|
||||||
add(LATLONBBMAXX, String.valueOf(maxx));
|
add(LATLONBBMAXX, String.valueOf(maxx));
|
||||||
add(LATLONBBMINY, String.valueOf(miny));
|
|
||||||
add(LATLONBBCRS, crs);
|
add(LATLONBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatLonBoundingBox(double minx, double maxy, double maxx,
|
public void setLatLonBoundingBox(double minx, double miny, double maxx,
|
||||||
double miny, final String crs) {
|
double maxy, final String crs) {
|
||||||
set(LATLONBBMINX, String.valueOf(minx));
|
set(LATLONBBMINX, String.valueOf(minx));
|
||||||
set(LATLONBBMAXY, String.valueOf(maxy));
|
set(LATLONBBMAXY, String.valueOf(maxy));
|
||||||
set(LATLONBBMAXX, String.valueOf(maxx));
|
set(LATLONBBMAXX, String.valueOf(maxx));
|
||||||
set(LATLONBBMINY, String.valueOf(miny));
|
set(LATLONBBMINY, String.valueOf(miny));
|
||||||
set(LATLONBBCRS, crs);
|
set(LATLONBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static String NATIVEBBMINX="nativeBoundingBox/minx";
|
private final static String NATIVEBBMINX = "nativeBoundingBox/minx";
|
||||||
private final static String NATIVEBBMAXX="nativeBoundingBox/maxx";
|
private final static String NATIVEBBMAXX = "nativeBoundingBox/maxx";
|
||||||
private final static String NATIVEBBMINY="nativeBoundingBox/miny";
|
private final static String NATIVEBBMINY = "nativeBoundingBox/miny";
|
||||||
private final static String NATIVEBBMAXY="nativeBoundingBox/maxy";
|
private final static String NATIVEBBMAXY = "nativeBoundingBox/maxy";
|
||||||
private final static String NATIVEBBCRS="nativeBoundingBox/crs";
|
private final static String NATIVEBBCRS = "nativeBoundingBox/crs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use the setSRS. <br>
|
* @deprecated use the setSRS. <br>
|
||||||
* This method will be set as protected in the next release
|
* This method will be set as protected in the next release
|
||||||
*
|
*
|
||||||
* @param minx
|
* @param minx
|
||||||
* @param maxy
|
* @param maxy
|
||||||
* @param maxx
|
* @param maxx
|
||||||
* @param miny
|
* @param miny
|
||||||
* @param crs
|
* @param crs
|
||||||
*/
|
*/
|
||||||
public void addNativeBoundingBox(double minx, double maxy, double maxx,
|
public void addNativeBoundingBox(double minx, double miny, double maxx,
|
||||||
double miny, final String crs) {
|
double maxy, final String crs) {
|
||||||
add(NATIVEBBMINX, String.valueOf(minx));
|
add(NATIVEBBMINX, String.valueOf(minx));
|
||||||
add(NATIVEBBMAXY, String.valueOf(maxy));
|
add(NATIVEBBMAXY, String.valueOf(maxy));
|
||||||
add(NATIVEBBMAXX, String.valueOf(maxx));
|
add(NATIVEBBMAXX, String.valueOf(maxx));
|
||||||
add(NATIVEBBMINY, String.valueOf(miny));
|
add(NATIVEBBMINY, String.valueOf(miny));
|
||||||
add(NATIVEBBCRS, crs);
|
add(NATIVEBBCRS, crs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNativeBoundingBox(double minx, double maxy, double maxx,
|
public void setNativeBoundingBox(double minx, double miny, double maxx,
|
||||||
double miny, final String crs) {
|
double maxy, final String crs) {
|
||||||
set(NATIVEBBMINX, String.valueOf(minx));
|
set(NATIVEBBMINX, String.valueOf(minx));
|
||||||
set(NATIVEBBMAXY, String.valueOf(maxy));
|
set(NATIVEBBMAXY, String.valueOf(maxy));
|
||||||
set(NATIVEBBMAXX, String.valueOf(maxx));
|
set(NATIVEBBMAXX, String.valueOf(maxx));
|
||||||
|
|||||||
@ -43,6 +43,9 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
|||||||
super(WORKSPACE);
|
super(WORKSPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name the workspace name
|
||||||
|
*/
|
||||||
public GSWorkspaceEncoder(String name) {
|
public GSWorkspaceEncoder(String name) {
|
||||||
super(WORKSPACE);
|
super(WORKSPACE);
|
||||||
addName(name);
|
addName(name);
|
||||||
@ -54,7 +57,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
|||||||
* @throws IllegalStateException if name is already set
|
* @throws IllegalStateException if name is already set
|
||||||
* @deprecated will be set to protected in the next release
|
* @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);
|
final Element el=ElementUtils.contains(getRoot(),NAME);
|
||||||
if (el==null)
|
if (el==null)
|
||||||
add(NAME, name);
|
add(NAME, name);
|
||||||
@ -66,7 +69,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
|||||||
* add or change (if already set) the workspace name
|
* add or change (if already set) the workspace name
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public void setName(String name) {
|
public void setName(final String name) {
|
||||||
final Element el=ElementUtils.contains(getRoot(),NAME);
|
final Element el=ElementUtils.contains(getRoot(),NAME);
|
||||||
if (el==null)
|
if (el==null)
|
||||||
add(NAME, name);
|
add(NAME, name);
|
||||||
|
|||||||
@ -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.ElementUtils;
|
||||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.filter.Filter;
|
import org.jdom.filter.Filter;
|
||||||
@ -60,6 +62,8 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
if (obj instanceof Element) {
|
if (obj instanceof Element) {
|
||||||
if (((Element)obj).getName().equals(ENTRY)){
|
if (((Element)obj).getName().equals(ENTRY)){
|
||||||
final Element el=((Element)obj).getChild(STRING);
|
final Element el=((Element)obj).getChild(STRING);
|
||||||
|
if (el==null)
|
||||||
|
return false;
|
||||||
if (el.getText().equals(this.name)){
|
if (el.getText().equals(this.name)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -87,10 +91,11 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addAllowMultithreading(final boolean val){
|
public void addAllowMultithreading(final boolean val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(allowMultithreading));
|
list.add(new Element(STRING).setText(allowMultithreading));
|
||||||
param.addContent(new Element(STRING).setText((val)?"true":"false"));
|
list.add(new Element(STRING).setText((val)?"true":"false"));
|
||||||
parameters.addContent(param);
|
|
||||||
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
|
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
|
||||||
@ -105,10 +110,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addFilter(final String val){
|
public void addFilter(final String val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(filter));
|
list.add(new Element(STRING).setText(filter));
|
||||||
param.addContent(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter filterFilter=new parametersFilter(filter);
|
private final static Filter filterFilter=new parametersFilter(filter);
|
||||||
@ -123,10 +128,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addMaxAllowedTiles(final int val){
|
public void addMaxAllowedTiles(final int val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(maxAllowedTiles));
|
list.add(new Element(STRING).setText(maxAllowedTiles));
|
||||||
param.addContent(new Element(STRING).setText(String.valueOf(val)));
|
list.add(new Element(STRING).setText(String.valueOf(val)));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
|
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
|
||||||
@ -141,10 +146,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addInputTransparentColor(final String val){
|
public void addInputTransparentColor(final String val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(inputTransparentColor));
|
list.add(new Element(STRING).setText(inputTransparentColor));
|
||||||
param.addContent(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
|
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
|
||||||
@ -159,10 +164,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addOutputTransparentColor(final String val){
|
public void addOutputTransparentColor(final String val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(outputTransparentColor));
|
list.add(new Element(STRING).setText(outputTransparentColor));
|
||||||
param.addContent(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
|
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
|
* @deprecated will be set to protected in the next release
|
||||||
*/
|
*/
|
||||||
public void addSUGGESTED_TILE_SIZE(final String val){
|
public void addSUGGESTED_TILE_SIZE(final String val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
||||||
param.addContent(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
|
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
|
||||||
@ -196,10 +201,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addUSE_JAI_IMAGEREAD(final boolean val){
|
public void addUSE_JAI_IMAGEREAD(final boolean val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
||||||
param.addContent(new Element(STRING).setText((val)?"true":"false"));
|
list.add(new Element(STRING).setText((val)?"true":"false"));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
|
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
|
||||||
@ -214,10 +219,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
|||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
public void addBackgroundValues(final String val){
|
public void addBackgroundValues(final String val){
|
||||||
final Element param=new Element(ENTRY);
|
final List<Element> list=new ArrayList<Element>(2);
|
||||||
param.addContent(new Element(STRING).setText(backgroundValues));
|
list.add(new Element(STRING).setText(backgroundValues));
|
||||||
param.addContent(new Element(STRING).setText(val));
|
list.add(new Element(STRING).setText(val));
|
||||||
parameters.addContent(param);
|
parameters.add(null,list);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);
|
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);
|
||||||
|
|||||||
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.jdom.Content;
|
import org.jdom.Content;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.filter.Filter;
|
import org.jdom.filter.Filter;
|
||||||
@ -63,6 +66,22 @@ import org.jdom.filter.Filter;
|
|||||||
* </entry>
|
* </entry>
|
||||||
* </listName>}
|
* </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>
|
* <PRE>
|
||||||
*
|
*
|
||||||
* @author ETj (etj at geo-solutions.it)
|
* @author ETj (etj at geo-solutions.it)
|
||||||
@ -72,100 +91,145 @@ import org.jdom.filter.Filter;
|
|||||||
public class NestedElementEncoder extends XmlElement {
|
public class NestedElementEncoder extends XmlElement {
|
||||||
public final static String ENTRY = "entry";
|
public final static String ENTRY = "entry";
|
||||||
public final static String KEY = "key";
|
public final static String KEY = "key";
|
||||||
|
|
||||||
static class NestedElementFilter implements Filter {
|
static class NestedElementFilter implements Filter {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private final String key;
|
private final String key;
|
||||||
|
private final String value;
|
||||||
private final Element root;
|
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) {
|
public boolean matches(Object obj) {
|
||||||
if (obj instanceof Element) {
|
if (obj instanceof Element) {
|
||||||
final Element el = ((Element) obj);
|
final Element el = ((Element) obj);
|
||||||
if (root.isAncestor(el)){
|
if (root.isAncestor(el)) {
|
||||||
if (el.getName().equals(ENTRY)/* && el.getText().equals(value) */) {
|
if (el.getName().equals(ENTRY)/* && el.getText().equals(value) */) {
|
||||||
|
boolean keyCheck=true;
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
if (el.getAttribute(KEY).getValue().equals(key))
|
if (el.getAttribute(KEY).getValue().equals(key)) {
|
||||||
return true;
|
keyCheck=true;
|
||||||
else
|
} else {
|
||||||
return false;
|
keyCheck=false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
if (value != null)
|
||||||
|
return keyCheck&&checkChilds(el, value);
|
||||||
|
else
|
||||||
|
return keyCheck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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) {
|
public NestedElementEncoder(String listName) {
|
||||||
super(listName);
|
super(listName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void set(final String key, final String value) {
|
public void set(final String key, final String value) {
|
||||||
// // if some previous similar object is found
|
// if some previous similar object is found
|
||||||
// final Element search;
|
final Element search;
|
||||||
// if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
|
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||||
// // remove it
|
getRoot(), key, value))) != null) {
|
||||||
// ElementUtils.remove(getRoot(), search);
|
// remove it
|
||||||
// }
|
ElementUtils.remove(getRoot(), search);
|
||||||
// // add the new entry
|
}
|
||||||
// add(key,value);
|
// add the new entry
|
||||||
// }
|
add(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
// public void add(final String key, final Element value) {
|
public void set(final String key, final Element value) {
|
||||||
// final Element entryElem = new Element(ENTRY);
|
// if some previous similar object is found
|
||||||
// if (key != null)
|
final Element search;
|
||||||
// entryElem.setAttribute(KEY, key);
|
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||||
//
|
getRoot(), key, value.getName()))) != null) {
|
||||||
// entryElem.addContent(value);
|
// remove it
|
||||||
//
|
ElementUtils.remove(getRoot(), search);
|
||||||
// this.addContent(entryElem);
|
}
|
||||||
// }
|
// add the new entry
|
||||||
|
add(key, 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 Content value) {
|
public void add(final String key, final Element value) {
|
||||||
final Element entryElem = new Element(ENTRY);
|
final Element entryElem = new Element(ENTRY);
|
||||||
if (key != null)
|
if (key != null)
|
||||||
entryElem.setAttribute(KEY, key);
|
entryElem.setAttribute(KEY, key);
|
||||||
|
|
||||||
entryElem.setContent(value);
|
entryElem.addContent(value);
|
||||||
|
|
||||||
this.addContent(entryElem);
|
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
|
// if some previous similar object is found
|
||||||
final Element search;
|
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
|
// remove it
|
||||||
ElementUtils.remove(search, search);
|
ElementUtils.remove(search, search);
|
||||||
}
|
}
|
||||||
// add the new entry
|
// 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
|
// if some previous similar object is found
|
||||||
final Element search;
|
final Element search;
|
||||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
|
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||||
return ElementUtils.remove(search,search);
|
getRoot(), key, null))) != null) {
|
||||||
}
|
return ElementUtils.remove(search, search);
|
||||||
else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,15 +56,35 @@ public class PropertyXMLEncoder extends XmlElement {
|
|||||||
public PropertyXMLEncoder(final String rootName) {
|
public PropertyXMLEncoder(final String rootName) {
|
||||||
super(rootName);
|
super(rootName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void get(final String key, final String value) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Element get(final String key) {
|
||||||
|
return get(getRoot(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element get(final Element el, final String key) {
|
||||||
public void set(final String key, final String value) {
|
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) {
|
if (key != null && value != null) {
|
||||||
set(getRoot(), key, value);
|
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("/")) {
|
if (key.contains("/")) {
|
||||||
final int i = key.indexOf("/");
|
final int i = key.indexOf("/");
|
||||||
final String childName = key.substring(0, i);
|
final String childName = key.substring(0, i);
|
||||||
@ -74,21 +94,21 @@ public class PropertyXMLEncoder extends XmlElement {
|
|||||||
if (child == null) {
|
if (child == null) {
|
||||||
child = new Element(childName);
|
child = new Element(childName);
|
||||||
e.addContent(child);
|
e.addContent(child);
|
||||||
add(child,newkey,value);
|
add(child, newkey, value);
|
||||||
}
|
}
|
||||||
set(child, newkey, value);
|
set(child, newkey, value);
|
||||||
} else {
|
} else {
|
||||||
Element pp = null;
|
Element pp = null;
|
||||||
if ((pp = ElementUtils.contains(e,key)) == null)
|
if ((pp = ElementUtils.contains(e, key)) == null)
|
||||||
add(e,key, value);
|
add(e, key, value);
|
||||||
else {
|
else {
|
||||||
ElementUtils.remove(e,pp);
|
ElementUtils.remove(pp, pp);
|
||||||
add(e,key, value);
|
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) {
|
if (key != null && value != null) {
|
||||||
add(this.getRoot(), key, value);
|
add(this.getRoot(), key, value);
|
||||||
}
|
}
|
||||||
@ -113,60 +133,60 @@ public class PropertyXMLEncoder extends XmlElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void set(final String key, final String value) {
|
// public void set(final String key, final String value) {
|
||||||
// if (key != null && value != null) {
|
// if (key != null && value != null) {
|
||||||
// set(getRoot(), key, value);
|
// 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("/")) {
|
// if (!key.contains("/")) {
|
||||||
// Element pp = null;
|
// Element pp = null;
|
||||||
// if ((pp = contains(key)) == null)
|
// if ((pp = contains(key)) == null)
|
||||||
// add(e,key, value);
|
// add(e,key, value);
|
||||||
// else {
|
// else {
|
||||||
// remove(pp);
|
// remove(pp);
|
||||||
// add(e,key, value);
|
// add(e,key, value);
|
||||||
// }
|
// }
|
||||||
// } else {
|
// } else {
|
||||||
// final int i = key.indexOf("/");
|
// final int i = key.indexOf("/");
|
||||||
// final String childName = key.substring(0, i);
|
// final String childName = key.substring(0, i);
|
||||||
// final String newkey = key.substring(i + 1);
|
// final String newkey = key.substring(i + 1);
|
||||||
//
|
//
|
||||||
// Element child = e.getChild(childName);
|
// Element child = e.getChild(childName);
|
||||||
// if (child == null) {
|
// if (child == null) {
|
||||||
// child = new Element(childName);
|
// child = new Element(childName);
|
||||||
// e.addContent(child);
|
// e.addContent(child);
|
||||||
// add(child,newkey,value);
|
// add(child,newkey,value);
|
||||||
// }
|
// }
|
||||||
// set(child, newkey, value);
|
// set(child, newkey, value);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// public void add(final String key, final String value) {
|
// public void add(final String key, final String value) {
|
||||||
// if (key != null && value != null) {
|
// if (key != null && value != null) {
|
||||||
// add(this.getRoot(), key, value);
|
// add(this.getRoot(), key, value);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// private void add(Element e, String key, String value) {
|
// private void add(Element e, String key, String value) {
|
||||||
// if (!key.contains("/")) {
|
// if (!key.contains("/")) {
|
||||||
// e.addContent(new Element(key).setText(value));
|
// e.addContent(new Element(key).setText(value));
|
||||||
// } else {
|
// } else {
|
||||||
// final int i = key.indexOf("/");
|
// final int i = key.indexOf("/");
|
||||||
// final String childName = key.substring(0, i);
|
// final String childName = key.substring(0, i);
|
||||||
// final String newkey = key.substring(i + 1);
|
// final String newkey = key.substring(i + 1);
|
||||||
//
|
//
|
||||||
// Element child = e.getChild(childName);
|
// Element child = e.getChild(childName);
|
||||||
// if (child == null) {
|
// if (child == null) {
|
||||||
// child = new Element(childName);
|
// child = new Element(childName);
|
||||||
// e.addContent(child);
|
// e.addContent(child);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// add(child, newkey, value);
|
// add(child, newkey, value);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,21 +56,21 @@ public class XmlElement{
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private XmlElement(){root=null;};
|
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));
|
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);
|
final Element el=new Element(nodename);
|
||||||
el.setContent(nodetext);
|
el.setContent(nodetext);
|
||||||
this.addContent(el);
|
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));
|
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);
|
final Element el=ElementUtils.contains(getRoot(),nodename);
|
||||||
if (el==null){
|
if (el==null){
|
||||||
add(nodename,nodeContent);
|
add(nodename,nodeContent);
|
||||||
@ -80,7 +80,7 @@ public class XmlElement{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element addContent(Content child){
|
protected Element addContent(Content child){
|
||||||
return root.addContent(child);
|
return root.addContent(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ import org.springframework.core.io.ClassPathResource;
|
|||||||
public class ConfigTest extends GeoserverRESTTest {
|
public class ConfigTest extends GeoserverRESTTest {
|
||||||
private final static Logger LOGGER = Logger.getLogger(ConfigTest.class);
|
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) {
|
public ConfigTest(String testName) {
|
||||||
|
|||||||
@ -1,416 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.RESTLayer;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.jdom.Element;
|
|
||||||
import org.jdom.Namespace;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Testcase for publishing layers on geoserver.
|
|
||||||
* We need a running GeoServer to properly run the tests.
|
|
||||||
* If such geoserver instance cannot be contacted, tests will be skipped.
|
|
||||||
*
|
|
||||||
* @author etj
|
|
||||||
*/
|
|
||||||
public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
|
|
||||||
|
|
||||||
public GeoserverRESTPublisherTest(String testName) {
|
|
||||||
super(testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWorkspaces() {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
assertEquals(0, reader.getWorkspaces().size());
|
|
||||||
|
|
||||||
assertTrue(publisher.createWorkspace("WS1"));
|
|
||||||
assertTrue(publisher.createWorkspace("WS2"));
|
|
||||||
assertEquals(2, reader.getWorkspaces().size());
|
|
||||||
|
|
||||||
assertFalse(publisher.createWorkspace("WS2"));
|
|
||||||
assertEquals(2, reader.getWorkspaces().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testStyles() throws IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
assertEquals(0, reader.getStyles().size());
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// insert style
|
|
||||||
assertTrue(publisher.publishStyle(sldFile));
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
assertFalse(publisher.publishStyle(sldFile));
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
String sld = reader.getSLD(styleName);
|
|
||||||
assertNotNull(sld);
|
|
||||||
|
|
||||||
Element styleEl = JDOMBuilder.buildElement(sld);
|
|
||||||
assertNotNull(styleEl);
|
|
||||||
|
|
||||||
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS).getChild("Name",SLDNS).getText());
|
|
||||||
assertEquals("STYLE FOR TESTING PURPOSES", styleEl.getChild("NamedLayer", SLDNS).getChild("UserStyle", SLDNS).getChild("Title", SLDNS).getText());
|
|
||||||
} catch(NullPointerException npe) {
|
|
||||||
fail("Error in SLD");
|
|
||||||
}
|
|
||||||
|
|
||||||
// assertEquals(1475, sld.length());
|
|
||||||
|
|
||||||
assertEquals(1, reader.getStyles().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testExternalGeotiff() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
String storeName = "testRESTStoreGeotiff";
|
|
||||||
String layerName = "resttestdem";
|
|
||||||
|
|
||||||
assertTrue(reader.getWorkspaces().isEmpty());
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
assertFalse("Cleanup failed", existsLayer(layerName));
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
|
||||||
assertNotNull("publish() failed", pc);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
LOGGER.info(pc);
|
|
||||||
RESTCoverageStore reloadedCS = reader.getCoverageStore(DEFAULT_WS, storeName);
|
|
||||||
|
|
||||||
assertEquals(pc.getName(), reloadedCS.getName());
|
|
||||||
assertEquals(pc.getWorkspaceName(), reloadedCS.getWorkspaceName());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
assertTrue("Unpublish() failed", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
|
||||||
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName));
|
|
||||||
assertFalse("Bad unpublish()", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanupTestFT(String layerName, String ns, String storeName) {
|
|
||||||
// dry run delete to work in a known state
|
|
||||||
RESTLayer testLayer = reader.getLayer(layerName);
|
|
||||||
if (testLayer != null) {
|
|
||||||
LOGGER.info("Clearing stale test layer " + layerName);
|
|
||||||
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
|
||||||
if (!ok) {
|
|
||||||
fail("Could not unpublish layer " + layerName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (publisher.removeDatastore(ns, storeName)) {
|
|
||||||
LOGGER.info("Cleared stale datastore " + storeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse("Cleanup failed", existsLayer(layerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanupTestStyle(final String styleName) {
|
|
||||||
// dry run delete to work in a known state
|
|
||||||
if (reader.existsStyle(styleName)) {
|
|
||||||
LOGGER.info("Clearing stale test style " + styleName);
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
if (!ok) {
|
|
||||||
fail("Could not unpublish style " + styleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertFalse("Cleanup failed", reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
deleteAllWorkspaces();
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
// String ns = "it.geosolutions";
|
|
||||||
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);
|
|
||||||
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 testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String ns = "geosolutions";
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
|
||||||
cleanupTestFT(layerName, ns, storeName);
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// insert style
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
// RESTLayer layerDecoder = new RESTLayer(layer);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals("Style not assigned properly", styleName, layer.getDefaultStyle());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
|
|
||||||
// remove also datastore
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(ns, storeName);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
|
|
||||||
//test delete style
|
|
||||||
boolean oksld = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", oksld);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteStyleString() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
String sldContent = IOUtils.toString(new FileInputStream(sldFile));
|
|
||||||
|
|
||||||
boolean published = publisher.publishStyle(sldContent); // Will take the name from sld contents
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
String layerName = "this_layer_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.unpublishCoverage(wsName, storeName, layerName);
|
|
||||||
assertFalse("unpublished not existing layer", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
String layerName = "this_layer_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.unpublishFeatureType(wsName, storeName, layerName);
|
|
||||||
assertFalse("unpublished not existing layer", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.removeDatastore(wsName, storeName);
|
|
||||||
assertFalse("removed not existing datastore", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testUpdateDefaultStyle() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
{
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String styleName2 = "restteststyle2";
|
|
||||||
{
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName2);
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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", styleName);
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
{
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals(styleName, layer.getDefaultStyle());
|
|
||||||
}
|
|
||||||
|
|
||||||
GSLayerEncoder le = new GSLayerEncoder();
|
|
||||||
le.addDefaultStyle(styleName2);
|
|
||||||
publisher.configureLayer(DEFAULT_WS, layerName, le);
|
|
||||||
|
|
||||||
{
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals(styleName2, layer.getDefaultStyle());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remove layer and datastore
|
|
||||||
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
|
||||||
// String wsName = "this_ws_does_not_exist";
|
|
||||||
// String storeName = "this_store_does_not_exist";
|
|
||||||
// String layerName = "this_layer_does_not_exist";
|
|
||||||
//
|
|
||||||
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
|
||||||
// assertFalse("unpublished not existing layer", ok);
|
|
||||||
// }
|
|
||||||
private boolean existsLayer(String layername) {
|
|
||||||
return reader.getLayer(layername) != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -190,7 +190,7 @@ public abstract class GeoserverRESTTest extends TestCase {
|
|||||||
// RESTCoverageStore store = reader.getCoverageStore(workspace, storename);
|
// RESTCoverageStore store = reader.getCoverageStore(workspace, storename);
|
||||||
|
|
||||||
LOGGER.warn("Deleting CoverageStore " + workspace + " : " + storename);
|
LOGGER.warn("Deleting CoverageStore " + workspace + " : " + storename);
|
||||||
boolean removed = publisher.removeCoverageStore(workspace, storename);
|
boolean removed = publisher.removeCoverageStore(workspace, storename, false);
|
||||||
assertTrue("CoverageStore not removed " + workspace + " : " + storename, removed);
|
assertTrue("CoverageStore not removed " + workspace + " : " + storename, removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,17 +210,27 @@ public abstract class GeoserverRESTTest extends TestCase {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
LOGGER.warn("Deleting DataStore " + workspace + " : " + storename);
|
LOGGER.warn("Deleting DataStore " + workspace + " : " + storename);
|
||||||
boolean removed = publisher.removeDatastore(workspace, storename);
|
boolean removed = publisher.removeDatastore(workspace, storename, false);
|
||||||
assertTrue("DataStore not removed " + workspace + " : " + storename, removed);
|
assertTrue("DataStore not removed " + workspace + " : " + storename, removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void deleteAllWorkspacesRecursively() {
|
||||||
|
List<String> workspaces = reader.getWorkspaceNames();
|
||||||
|
for (String workspace : workspaces) {
|
||||||
|
LOGGER.warn("Deleting Workspace " + workspace );
|
||||||
|
boolean removed = publisher.removeWorkspace(workspace,true);
|
||||||
|
assertTrue("Workspace not removed " + workspace, removed );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void deleteAllWorkspaces() {
|
protected void deleteAllWorkspaces() {
|
||||||
List<String> workspaces = reader.getWorkspaceNames();
|
List<String> workspaces = reader.getWorkspaceNames();
|
||||||
for (String workspace : workspaces) {
|
for (String workspace : workspaces) {
|
||||||
LOGGER.warn("Deleting Workspace " + workspace );
|
LOGGER.warn("Deleting Workspace " + workspace );
|
||||||
boolean removed = publisher.removeWorkspace(workspace);
|
boolean removed = publisher.removeWorkspace(workspace,false);
|
||||||
assertTrue("Workspace not removed " + workspace, removed );
|
assertTrue("Workspace not removed " + workspace, removed );
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -273,5 +283,9 @@ public abstract class GeoserverRESTTest extends TestCase {
|
|||||||
+ coverage.getName(),
|
+ coverage.getName(),
|
||||||
removed);
|
removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean existsLayer(String layername) {
|
||||||
|
return reader.getLayer(layername) != null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -44,13 +44,8 @@ public class GSWorkspaceEncoderTest extends TestCase {
|
|||||||
final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder("WS1");
|
final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder("WS1");
|
||||||
LOGGER.info(wsenc.toString());
|
LOGGER.info(wsenc.toString());
|
||||||
|
|
||||||
try{
|
wsenc.setName("test_name");
|
||||||
wsenc.addName("test_name");
|
LOGGER.info(wsenc.toString());
|
||||||
// NEVER HERE
|
|
||||||
Assert.assertTrue(false);
|
|
||||||
}catch (IllegalStateException e){
|
|
||||||
Assert.assertTrue(true);
|
|
||||||
}
|
|
||||||
wsenc.setName("new_name");
|
wsenc.setName("new_name");
|
||||||
LOGGER.info(wsenc.toString());
|
LOGGER.info(wsenc.toString());
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
|
|
||||||
|
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 publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTGeoTiffTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTGeoTiffTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExternalGeotiff() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
||||||
|
assertNotNull("publish() failed", pc);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
LOGGER.info(pc);
|
||||||
|
RESTCoverageStore reloadedCS = reader.getCoverageStore(DEFAULT_WS, storeName);
|
||||||
|
|
||||||
|
assertEquals(pc.getName(), reloadedCS.getName());
|
||||||
|
assertEquals(pc.getWorkspaceName(), reloadedCS.getWorkspaceName());
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
assertTrue("Unpublish() failed", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName));
|
||||||
|
assertFalse("Bad unpublish()", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
||||||
|
assertFalse(existsLayer(layerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGeotiff() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean pub = publisher.publishGeoTIFF(DEFAULT_WS, storeName, geotiff);
|
||||||
|
|
||||||
|
assertNotNull("publish() failed", pub);
|
||||||
|
|
||||||
|
//delete
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName,true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,222 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure;
|
||||||
|
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.commons.httpclient.NameValuePair;
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishImageMosaic() throws IOException {
|
||||||
|
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testImageMosaic";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File imageMosaicFile = new ClassPathResource(
|
||||||
|
"testdata/mosaic_geotiff.zip").getFile();
|
||||||
|
|
||||||
|
// test publish
|
||||||
|
boolean wp = publisher.publishImageMosaic(DEFAULT_WS, storeName,
|
||||||
|
imageMosaicFile, ParameterConfigure.NONE, (NameValuePair) null);
|
||||||
|
|
||||||
|
assertTrue("Publish imagemosaic with no layer configured, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed",
|
||||||
|
publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
// create default style
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
|
||||||
|
.getFile();
|
||||||
|
assertTrue(publisher.publishStyle(sldFile, "raster"));
|
||||||
|
|
||||||
|
wp = publisher.publishImageMosaic(DEFAULT_WS, storeName, imageMosaicFile,
|
||||||
|
ParameterConfigure.FIRST, new NameValuePair("coverageName",
|
||||||
|
"imageMosaic_test"));
|
||||||
|
|
||||||
|
assertTrue("Publish imagemosaic configuring layer name, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed",
|
||||||
|
publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
wp = publisher.publishImageMosaic(DEFAULT_WS, storeName,
|
||||||
|
imageMosaicFile, ParameterConfigure.ALL, (NameValuePair) null);
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
"Publish imagemosaic configuring all available layers, failed.",
|
||||||
|
wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed",
|
||||||
|
publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -23,9 +23,10 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTPublisherTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanupTestFT(String layerName, String ns, String storeName) {
|
||||||
|
// dry run delete to work in a known state
|
||||||
|
RESTLayer testLayer = reader.getLayer(layerName);
|
||||||
|
if (testLayer != null) {
|
||||||
|
LOGGER.info("Clearing stale test layer " + layerName);
|
||||||
|
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
||||||
|
if (!ok) {
|
||||||
|
fail("Could not unpublish layer " + layerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (publisher.removeDatastore(ns, storeName)) {
|
||||||
|
LOGGER.info("Cleared stale datastore " + storeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
String layerName = "this_layer_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.unpublishCoverage(wsName, storeName, layerName);
|
||||||
|
assertFalse("unpublished not existing layer", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
String layerName = "this_layer_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.unpublishFeatureType(wsName, storeName, layerName);
|
||||||
|
assertFalse("unpublished not existing layer", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.removeDatastore(wsName, storeName);
|
||||||
|
assertFalse("removed not existing datastore", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
||||||
|
// String wsName = "this_ws_does_not_exist";
|
||||||
|
// String storeName = "this_store_does_not_exist";
|
||||||
|
// String layerName = "this_layer_does_not_exist";
|
||||||
|
//
|
||||||
|
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
||||||
|
// assertFalse("unpublished not existing layer", ok);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTShapeTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTShapeTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTShapeTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteShapeZip() 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();
|
||||||
|
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
|
||||||
|
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,false);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String ns = "geosolutions";
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
publisher.removeDatastore(DEFAULT_WS, storeName,true);
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
|
||||||
|
// insert style
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
// RESTLayer layerDecoder = new RESTLayer(layer);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals("Style not assigned properly", styleName, layer.getDefaultStyle());
|
||||||
|
|
||||||
|
// remove also datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(ns, storeName,true);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
|
||||||
|
//test delete style
|
||||||
|
boolean oksld = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", oksld);
|
||||||
|
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?
|
||||||
|
publisher.removeDatastore(DEFAULT_WS, storeName,true);
|
||||||
|
|
||||||
|
// 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 testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
||||||
|
// String wsName = "this_ws_does_not_exist";
|
||||||
|
// String storeName = "this_store_does_not_exist";
|
||||||
|
// String layerName = "this_layer_does_not_exist";
|
||||||
|
//
|
||||||
|
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
||||||
|
// assertFalse("unpublished not existing layer", ok);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,260 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.Namespace;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver. We need a running GeoServer to
|
||||||
|
* properly run the tests. If such geoserver instance cannot be contacted, tests
|
||||||
|
* will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTStyleTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger
|
||||||
|
.getLogger(GeoserverRESTStyleTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTStyleTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStyles() throws IOException {
|
||||||
|
if (!enabled())
|
||||||
|
return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
assertEquals(0, reader.getStyles().size());
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
|
||||||
|
.getFile();
|
||||||
|
|
||||||
|
// insert style
|
||||||
|
assertTrue(publisher.publishStyle(sldFile));
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
assertFalse(publisher.publishStyle(sldFile));
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
String sld = reader.getSLD(styleName);
|
||||||
|
assertNotNull(sld);
|
||||||
|
|
||||||
|
Element styleEl = JDOMBuilder.buildElement(sld);
|
||||||
|
assertNotNull(styleEl);
|
||||||
|
|
||||||
|
Namespace SLDNS = Namespace.getNamespace("sld",
|
||||||
|
"http://www.opengis.net/sld");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS)
|
||||||
|
.getChild("Name", SLDNS).getText());
|
||||||
|
assertEquals(
|
||||||
|
"STYLE FOR TESTING PURPOSES",
|
||||||
|
styleEl.getChild("NamedLayer", SLDNS)
|
||||||
|
.getChild("UserStyle", SLDNS)
|
||||||
|
.getChild("Title", SLDNS).getText());
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
fail("Error in SLD");
|
||||||
|
}
|
||||||
|
|
||||||
|
// assertEquals(1475, sld.length());
|
||||||
|
|
||||||
|
assertEquals(1, reader.getStyles().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanupTestStyle(final String styleName) {
|
||||||
|
// dry run delete to work in a known state
|
||||||
|
if (reader.existsStyle(styleName)) {
|
||||||
|
LOGGER.info("Clearing stale test style " + styleName);
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
if (!ok) {
|
||||||
|
fail("Could not unpublish style " + styleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse("Cleanup failed", reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyleFile() throws FileNotFoundException,
|
||||||
|
IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
|
||||||
|
.getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishStyle(sldFile); // Will take the
|
||||||
|
// name from sld
|
||||||
|
// contents
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
|
||||||
|
published = publisher.updateStyle(sldFile, styleName); // update
|
||||||
|
assertTrue("update() failed", published);
|
||||||
|
|
||||||
|
// test delete
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyleString() throws FileNotFoundException,
|
||||||
|
IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
String styleName = "restteststyle";
|
||||||
|
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
|
||||||
|
.getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
String sldContent = IOUtils.toString(new FileInputStream(sldFile));
|
||||||
|
|
||||||
|
boolean published = publisher.publishStyle(sldContent); // Will take the
|
||||||
|
// name from sld
|
||||||
|
// contents
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
// test delete
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
styleName = "restteststyle_with_name";
|
||||||
|
// test insert with name
|
||||||
|
published = publisher.publishStyle(sldContent, styleName); // Will set
|
||||||
|
// the name
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
String newSldContent = sldContent.replace(
|
||||||
|
"<sld:Title>STYLE FOR TESTING PURPOSES</sld:Title>",
|
||||||
|
"<sld:Title>MODIFIED STYLE FOR TESTING</sld:Title>");
|
||||||
|
published = publisher.updateStyle(newSldContent, styleName); // update
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
|
||||||
|
// test delete
|
||||||
|
ok = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testUpdateDefaultStyle() throws FileNotFoundException,
|
||||||
|
IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
|
||||||
|
.getFile();
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take
|
||||||
|
// the name
|
||||||
|
// from sld
|
||||||
|
// contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String styleName2 = "restteststyle2";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle2.sld")
|
||||||
|
.getFile();
|
||||||
|
cleanupTestStyle(styleName2);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile, styleName2);
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName2));
|
||||||
|
}
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip")
|
||||||
|
.getFile();
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(DEFAULT_WS, storeName,
|
||||||
|
layerName, zipFile, "EPSG:4326", styleName);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
GSLayerEncoder le = new GSLayerEncoder();
|
||||||
|
le.setDefaultStyle(styleName2);
|
||||||
|
publisher.configureLayer(DEFAULT_WS, layerName, le);
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName2, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove layer and datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName,
|
||||||
|
true);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTWorkspaceTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTWorkspaceTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWorkspaces() {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
assertEquals(0, reader.getWorkspaces().size());
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace("WS1"));
|
||||||
|
assertTrue(publisher.createWorkspace("WS2"));
|
||||||
|
assertEquals(2, reader.getWorkspaces().size());
|
||||||
|
|
||||||
|
assertFalse(publisher.createWorkspace("WS2"));
|
||||||
|
assertEquals(2, reader.getWorkspaces().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove workspace and all of its contents
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void testWorkspaceRemoval() throws IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
||||||
|
|
||||||
|
// remove workspace and all of its contents
|
||||||
|
assertTrue(publisher.removeWorkspace(DEFAULT_WS,true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* 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.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTWorldImageTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTWorldImageTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTWorldImageTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishWorldImage() throws IOException {
|
||||||
|
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
String storeName = "testWorldimage";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File worldImageFile = new ClassPathResource(
|
||||||
|
"testdata/sw.zip").getFile();
|
||||||
|
|
||||||
|
// test publish
|
||||||
|
|
||||||
|
boolean wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.NONE, null);
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile with no layer configured, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
// create default style
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
assertTrue(publisher.publishStyle(sldFile,"raster"));
|
||||||
|
|
||||||
|
wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.FIRST, new NameValuePair("coverageName", "worldImage_test"));
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile configuring layer name, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.ALL,null);
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile configuring all available layers, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
src/test/resources/testdata/mosaic_geotiff.zip
vendored
Normal file
BIN
src/test/resources/testdata/mosaic_geotiff.zip
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/sw.zip
vendored
Normal file
BIN
src/test/resources/testdata/sw.zip
vendored
Normal file
Binary file not shown.
3
src/test/resources/testdata/time_geotiff/indexer.properties
vendored
Normal file
3
src/test/resources/testdata/time_geotiff/indexer.properties
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
TimeAttribute=time
|
||||||
|
Schema= the_geom:Polygon,location:String,time:java.util.Date
|
||||||
|
PropertyCollectors=TimestampFileNameExtractorSPI[timeregex](time)
|
||||||
1
src/test/resources/testdata/time_geotiff/stringregex.properties
vendored
Normal file
1
src/test/resources/testdata/time_geotiff/stringregex.properties
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
regex=[a-z]{5,5}
|
||||||
1
src/test/resources/testdata/time_geotiff/timeregex.properties
vendored
Normal file
1
src/test/resources/testdata/time_geotiff/timeregex.properties
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
regex=[0-9]{6}
|
||||||
BIN
src/test/resources/testdata/time_geotiff/world.200401.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200401.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200402.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200402.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200403.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200403.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200404.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200404.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200405.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200405.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200406.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200406.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
BIN
src/test/resources/testdata/time_geotiff/world.200407.3x5400x2700.tiff
vendored
Normal file
BIN
src/test/resources/testdata/time_geotiff/world.200407.3x5400x2700.tiff
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user