Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d518e9e5a4 | ||
|
|
cf24d45760 | ||
|
|
f10f027fb8 | ||
|
|
25759e86a5 | ||
|
|
febd28bc3a | ||
|
|
ad6fe87e81 | ||
|
|
318be5853e | ||
|
|
c44eece1f1 | ||
|
|
c588f2c66b | ||
|
|
0ec95f03f9 | ||
|
|
415df68d4b | ||
|
|
12c2e09c0e | ||
|
|
8f0efbc5de | ||
|
|
baf27a6ed7 | ||
|
|
b12342007b | ||
|
|
e6c77e9508 | ||
|
|
88668158f6 | ||
|
|
c6d6c3d2b9 | ||
|
|
61b914c610 | ||
|
|
ebee7276b2 | ||
|
|
10bf4971b2 | ||
|
|
9a736d2d7e | ||
|
|
8968e36673 | ||
|
|
224061257f | ||
|
|
9e0e9490c2 | ||
|
|
62d34ac345 | ||
|
|
7490529d2d | ||
|
|
7fdf019cd6 | ||
|
|
a8412ea7e9 | ||
|
|
098999b9b2 |
49
README.md
49
README.md
@ -7,23 +7,62 @@
|
||||
* Stable on Windows + OracleJDK7 [](http://winbuild.geo-solutions.it/jenkins/view/GeoServer-Manager/job/GeoServer-Manager-Stable/)
|
||||
|
||||
|
||||
## Intro
|
||||
Client library written in Java to interact with [GeoServer](http://www.geoserver.org) through its REst administration interface.
|
||||
|
||||
The purpose of this project is to hold a REST client library to interact with GeoServer; a requirement for this library is to depend as less as possible on external libraries. This library aims at being lean and mean.
|
||||
## Intro
|
||||
Client library written in Java to interact with [GeoServer](http://www.geoserver.org) through its [ReST administration interface](http://docs.geoserver.org/stable/en/user/rest/api/index.html).
|
||||
|
||||
The purpose of this project is to hold a ReST client library to interact with GeoServer; a requirement for this library is to depend as less as possible on external libraries. This library aims at being lean and mean.
|
||||
|
||||
For general questions about this project feel free to use the mailing lists.
|
||||
|
||||
## Using the library
|
||||
|
||||
### Working with Maven
|
||||
In order to include the lib and its dependencies in a Maven project, the repository to point at is this one:
|
||||
|
||||
```xml
|
||||
<repository>
|
||||
<id>GeoSolutions</id>
|
||||
<url>http://maven.geo-solutions.it/</url>
|
||||
</repository>
|
||||
```
|
||||
|
||||
and the dependency tag for your pom is as follows:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>it.geosolutions</groupId>
|
||||
<artifactId>geoserver-manager</artifactId>
|
||||
<version>1.7.0</version>
|
||||
</dependency>
|
||||
```
|
||||
### Direct Link to JAR
|
||||
If you are simply looking for the JAR to download and use you can find it [here](http://maven.geo-solutions.it/it/geosolutions/geoserver-manager/1.7.0/geoserver-manager-1.7.0.jar).
|
||||
|
||||
### GeoServer Compatibility Matrix
|
||||
|
||||
**GeoServer-Manager/GeoServer** | **2.6.x** |**2.7.x** |**2.8.x** |**2.9.x**
|
||||
-------------------------------- | ----------|----------|----------|---------
|
||||
**1.6.0** | Y | Y | P | P
|
||||
**1.7.0** | N | P | Y | Y
|
||||
|
||||
### Documentation
|
||||
You can find some examples in the wiki.
|
||||
## License
|
||||
|
||||
geoserver-manager is released under a permissinve [MIT](https://opensource.org/licenses/MIT) license. See [wikipedia](https://en.wikipedia.org/wiki/MIT_License) for more information.
|
||||
geoserver-manager is released under a permissive [MIT](https://opensource.org/licenses/MIT) license. See [wikipedia](https://en.wikipedia.org/wiki/MIT_License) for more information.
|
||||
|
||||
|
||||
## Mailing Lists
|
||||
|
||||
* [USERS](https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-users]https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-users)
|
||||
* [USERS](https://groups.google.com/group/geoserver-manager-users)
|
||||
* [DEVELOPERS](https://groups.google.com/forum/?fromgroups#!forum/geoserver-manager-devs)
|
||||
|
||||
For more information see [this](https://github.com/geosolutions-it/geoserver-manager/wiki) page.
|
||||
|
||||
## Version
|
||||
Current stable version is [1.7.0](https://github.com/geosolutions-it/geoserver-manager/releases/tag/v1.7.0) ([Changelog](https://github.com/geosolutions-it/geoserver-manager/wiki/Changelog)).
|
||||
|
||||
## Credits
|
||||
The work on this library has been initiated by GeoSolutions. Over the years it has been funded by various organizations like UN FAO, German Space Agency (DLR) and others.
|
||||
|
||||
|
||||
68
pom.xml
68
pom.xml
@ -30,13 +30,13 @@
|
||||
|
||||
<groupId>it.geosolutions</groupId>
|
||||
<artifactId>geoserver-manager</artifactId>
|
||||
<version>1.7.0</version>
|
||||
<version>1.8-SNAPSHOT</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>GeoServer 2 Manager - REST based</name>
|
||||
<name>GeoServer Manager - REST based</name>
|
||||
<description>
|
||||
GeoServer Manager is a library to interact with GeoServer 2.x.
|
||||
GeoServer Manager is a library to interact with GeoServer
|
||||
The scope of this library is to have a simple API, and use as few external
|
||||
libs as possible.
|
||||
</description>
|
||||
@ -108,6 +108,53 @@
|
||||
<url>http://build.geo-solutions.it/jenkins/view/GeoServer-manager/</url>
|
||||
</ciManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>boundless</id>
|
||||
<name>Boundless Maven Repository</name>
|
||||
<url>https://repo.boundlessgeo.com/main/</url>
|
||||
<!-- contains snapshot and release (including third-party-dependences) -->
|
||||
<!-- Restlet maven Repository (http://maven.restlet.org) -->
|
||||
<!-- ucar (https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases) -->
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>osgeo</id>
|
||||
<name>Open Source Geospatial Foundation Repository</name>
|
||||
<url>http://download.osgeo.org/webdav/geotools/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>maven-restlet</id>
|
||||
<name>Restlet Maven Repository</name>
|
||||
<url>http://maven.restlet.org</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>geosolutions</id>
|
||||
<name>geosolutions repository</name>
|
||||
<url>http://maven.geo-solutions.it/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<downloadUrl>http://maven.geo-solutions.it</downloadUrl>
|
||||
<repository>
|
||||
@ -204,8 +251,6 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>2.2</version> </plugin> -->
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
@ -239,6 +284,19 @@
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.4</version>
|
||||
<classifier>jdk15</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.servicemix.bundles</groupId>
|
||||
<artifactId>org.apache.servicemix.bundles.restlet</artifactId>
|
||||
<version>1.1.10_3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||
*
|
||||
* Copyright (C) 2007,2013 GeoSolutions S.A.S.
|
||||
* Copyright (C) 2007,2016 GeoSolutions S.A.S.
|
||||
* http://www.geo-solutions.it
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
||||
@ -42,6 +42,7 @@ import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager.ConfigureCoveragesOption;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -58,6 +59,8 @@ import org.apache.commons.io.FilenameUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Connect to a GeoServer instance to publish or modify its contents via REST API.
|
||||
* <P>
|
||||
@ -91,6 +94,9 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
|
||||
private final GeoServerRESTStyleManager styleManager;
|
||||
|
||||
private final GeoServerRESTImporterManager importerManager;
|
||||
|
||||
/**
|
||||
* Creates a <TT>GeoServerRESTPublisher</TT> to connect against a GeoServer instance with the given URL and user credentials.
|
||||
*
|
||||
@ -110,6 +116,7 @@ public class GeoServerRESTPublisher {
|
||||
LOGGER.error("Bad URL: Calls to GeoServer are going to fail" , ex);
|
||||
}
|
||||
styleManager = new GeoServerRESTStyleManager(url, username, password);
|
||||
importerManager = new GeoServerRESTImporterManager(url, username, password);
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
@ -3145,4 +3152,58 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#postNewImport() postNewImport} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewImport() throws Exception {
|
||||
return importerManager.postNewImport();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#postNewTaskAsMultiPartForm(int, String) postNewTaskAsMultiPartForm} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewTaskAsMultiPartForm(int i, String data) throws Exception {
|
||||
return importerManager.postNewTaskAsMultiPartForm(i, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#getTask(int, int) getTask} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public JSONObject getTask(int i, int t) throws Exception {
|
||||
return importerManager.getTask(i, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#putTask(int, int, String) putTask} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTask(int i, int t, String json) throws Exception {
|
||||
importerManager.putTask(i, t, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#putTaskLayer(int, int, String) putTaskLayer} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTaskLayer(int i, int t, String json) throws Exception {
|
||||
importerManager.putTaskLayer(i, t, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#postImport(int) postImport} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void postImport(int i) throws Exception {
|
||||
importerManager.postImport(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -33,6 +34,11 @@ import java.net.ConnectException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONSerializer;
|
||||
|
||||
import org.apache.commons.httpclient.Credentials;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
@ -48,6 +54,9 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.PutMethod;
|
||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -117,6 +126,22 @@ public class HTTPUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a request using the GET method and parses the result as a json object.
|
||||
*
|
||||
* @param path The path to request.
|
||||
*
|
||||
* @return The result parsed as json.
|
||||
*/
|
||||
public static JSON getAsJSON(String url, String username, String pw) throws Exception {
|
||||
String response = get(url, username, pw);
|
||||
return json(response);
|
||||
}
|
||||
|
||||
public static JSON json(String content) {
|
||||
return JSONSerializer.toJSON(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUTs a File to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
@ -175,6 +200,23 @@ public class HTTPUtils {
|
||||
return put(url, content, "text/xml", username, pw);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUTs a String representing an JSON Object to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
*
|
||||
* @param url The URL where to connect to.
|
||||
* @param content The JSON Object to be sent as a String.
|
||||
* @param username Basic auth credential. No basic auth if null.
|
||||
* @param pw Basic auth credential. No basic auth if null.
|
||||
* @return The HTTP response as a String if the HTTP response code was 200
|
||||
* (OK).
|
||||
* @throws MalformedURLException
|
||||
* @return the HTTP response or <TT>null</TT> on errors.
|
||||
*/
|
||||
public static String putJson(String url, String content, String username, String pw) {
|
||||
return put(url, content, "application/json", username, pw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a PUT to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
@ -233,6 +275,38 @@ public class HTTPUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POSTs a list of files as attachments to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
*
|
||||
* @param url The URL where to connect to.
|
||||
* @param dir The folder containing the attachments.
|
||||
* @param username Basic auth credential. No basic auth if null.
|
||||
* @param pw Basic auth credential. No basic auth if null.
|
||||
* @return The HTTP response as a String if the HTTP response code was 200
|
||||
* (OK).
|
||||
* @throws MalformedURLException
|
||||
* @return the HTTP response or <TT>null</TT> on errors.
|
||||
*/
|
||||
public static String postMultipartForm(String url, File dir, String username, String pw) {
|
||||
try {
|
||||
List<Part> parts = new ArrayList<Part>();
|
||||
for (File f : dir.listFiles()) {
|
||||
parts.add(new FilePart(f.getName(), f));
|
||||
}
|
||||
MultipartRequestEntity multipart = new MultipartRequestEntity(
|
||||
parts.toArray(new Part[parts.size()]), new PostMethod().getParams());
|
||||
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
multipart.writeRequest(bout);
|
||||
|
||||
return post(url, multipart, username, pw);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Cannot POST " + url, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POSTs a String representing an XML document to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
@ -250,6 +324,23 @@ public class HTTPUtils {
|
||||
return post(url, content, "text/xml", username, pw);
|
||||
}
|
||||
|
||||
/**
|
||||
* POSTs a String representing an JSON Object to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
*
|
||||
* @param url The URL where to connect to.
|
||||
* @param content The JSON content to be sent as a String.
|
||||
* @param username Basic auth credential. No basic auth if null.
|
||||
* @param pw Basic auth credential. No basic auth if null.
|
||||
* @return The HTTP response as a String if the HTTP response code was 200
|
||||
* (OK).
|
||||
* @throws MalformedURLException
|
||||
* @return the HTTP response or <TT>null</TT> on errors.
|
||||
*/
|
||||
public static String postJson(String url, String content, String username, String pw) {
|
||||
return post(url, content, "application/json", username, pw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a POST to the given URL. <BR>
|
||||
* Basic auth is used if both username and pw are not null.
|
||||
@ -293,6 +384,7 @@ public class HTTPUtils {
|
||||
httpMethod.setRequestEntity(requestEntity);
|
||||
int status = client.executeMethod(httpMethod);
|
||||
|
||||
InputStream responseBody;
|
||||
switch (status) {
|
||||
case HttpURLConnection.HTTP_OK:
|
||||
case HttpURLConnection.HTTP_CREATED:
|
||||
@ -303,9 +395,10 @@ public class HTTPUtils {
|
||||
LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response);
|
||||
return response;
|
||||
default:
|
||||
responseBody = httpMethod.getResponseBodyAsStream();
|
||||
LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]"
|
||||
+ " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName()
|
||||
+ "]: " + IOUtils.toString(httpMethod.getResponseBodyAsStream()));
|
||||
+ "]: " + (responseBody != null ? IOUtils.toString(responseBody) : ""));
|
||||
return null;
|
||||
}
|
||||
} catch (ConnectException e) {
|
||||
|
||||
@ -37,7 +37,7 @@ import org.jdom.filter.Filter;
|
||||
* {@code
|
||||
* final GSCoverageDimensionEncoder gsCoverageDimensionEncoder =
|
||||
* new GSCoverageDimensionEncoder("GRAY_INDEX", "GridSampleDimension[-2.147483648E9,-2.147483648E9]",
|
||||
* String.valueOf(Integer.MIN_VALUE), String.valueOf(Integer.MAX_VALUE), "dobson units³", "REAL_32BITS");
|
||||
* String.valueOf(Integer.MIN_VALUE), String.valueOf(Integer.MAX_VALUE), "dobson units", "REAL_32BITS");
|
||||
* coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
|
||||
* }
|
||||
* </pre>
|
||||
@ -53,7 +53,7 @@ import org.jdom.filter.Filter;
|
||||
* <min>-2.147483648E9</min>
|
||||
* <max>2.147483647E9</max>
|
||||
* </range>
|
||||
* <unit>dobson units³</unit>
|
||||
* <unit>dobson units</unit>
|
||||
* <dimensionType>
|
||||
* <name>REAL_32BITS</name>
|
||||
* </dimensionType>
|
||||
@ -390,4 +390,4 @@ public class GSCoverageDimensionEncoder extends XmlElement {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,321 @@
|
||||
/*
|
||||
* 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.manager;
|
||||
|
||||
import it.geosolutions.geoserver.rest.HTTPUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import net.sf.json.JSON;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.restlet.data.MediaType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Alessio Fabiani, GeoSolutions S.A.S.
|
||||
*
|
||||
*/
|
||||
public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTImporterManager.class);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param restURL GeoServer REST API endpoint
|
||||
* @param username GeoServer REST API authorized username
|
||||
* @param password GeoServer REST API password for the former username
|
||||
*/
|
||||
public GeoServerRESTImporterManager(URL restURL, String username, String password)
|
||||
throws IllegalArgumentException {
|
||||
super(restURL, username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Import JSON Object given its identifier
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
*/
|
||||
public JSONObject getImport(int imp) throws Exception {
|
||||
JSON json = HTTPUtils.getAsJSON(String.format(buildUrl()+"/%d", imp), gsuser , gspass);
|
||||
return ((JSONObject)json).getJSONObject("import");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Import Task JSON Object given its identifier and task number
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param task int: Task number
|
||||
*/
|
||||
public JSONObject getTask(int imp, int task) throws Exception {
|
||||
JSON json = HTTPUtils.getAsJSON(String.format(buildUrl()+"/%d/tasks/%d?expand=all", imp, task), gsuser , gspass);
|
||||
return ((JSONObject)json).getJSONObject("task");
|
||||
}
|
||||
|
||||
/**
|
||||
* Example usage:
|
||||
* <pre>
|
||||
* // Creates a new Importer Context and gets back the ID
|
||||
* int i = postNewImport();
|
||||
*
|
||||
* // Attaches to the new Importer Context a Task pointing to a shapefile's zip archive
|
||||
* int t = postNewTaskAsMultiPartForm(i, "/path_to/shape/archsites_no_crs.zip");
|
||||
*
|
||||
* // Check that the Task was actually created and that the CRS has not recognized in this case
|
||||
* JSONObject task = getTask(i, t);
|
||||
* assertEquals("NO_CRS", task.getString("state"));
|
||||
*
|
||||
* // Prepare the JSON String instructing the Task about the SRS to use
|
||||
* String json =
|
||||
* "{" +
|
||||
* "\"task\": {" +
|
||||
* "\"layer\": {" +
|
||||
* "\"srs\": \"EPSG:4326\"" +
|
||||
* "}" +
|
||||
* "}" +
|
||||
* "}";
|
||||
*
|
||||
* // Performing the Task update
|
||||
* putTask(i, t, json);
|
||||
*
|
||||
* // Double check that the Task is in the READY state
|
||||
* task = getTask(i, t);
|
||||
* assertEquals("READY", task.getString("state"));
|
||||
* assertEquals("gs_archsites", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
*
|
||||
* // Prepare the JSON String instructing the Task avout the SLD to use for the new Layer
|
||||
* json =
|
||||
* "{" +
|
||||
* "\"task\": {" +
|
||||
* "\"layer\": {" +
|
||||
* "\"style\": {" +
|
||||
* "\"name\": \"point\"" +
|
||||
* "}" +
|
||||
* "}" +
|
||||
* "}" +
|
||||
* "}";
|
||||
*
|
||||
* // Performing the Task update
|
||||
* putTask(i, t,json);
|
||||
*
|
||||
* // Double check that the Task is in the READY state and that the Style has been correctly updated
|
||||
* task = getTask(i, t);
|
||||
* assertEquals("READY", task.getString("state"));
|
||||
* assertEquals("point", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
*
|
||||
* // Finally starts the Import ...
|
||||
* postImport(i);
|
||||
* </pre>
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param task int: Task number
|
||||
* @param json String: JSON containing the Task properties to be updated
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTask(int imp, int task, final String json) throws Exception {
|
||||
//HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, gsuser, gspass);
|
||||
HTTPUtils.put(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, "text/plain", gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just update the Layers properties associated to a Task (t) in the Importer Context (i).
|
||||
*
|
||||
* e.g.:
|
||||
* <pre>
|
||||
* putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");
|
||||
* </pre>
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param task int: Task number
|
||||
* @param json String: JSON containing the Layer properties to be updated
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTaskLayer(int imp, int task, final String json) throws Exception {
|
||||
HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d/layer", imp, task), json, gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just update the Layers properties associated to a Task (t) in the Importer Context (i).
|
||||
*
|
||||
* e.g.:
|
||||
* <pre>
|
||||
* putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");
|
||||
* </pre>
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param task int: Task number
|
||||
* @param json String: JSON containing the Layer properties to be updated
|
||||
* @throws Exception
|
||||
*/
|
||||
public void postTaskTransform(int imp, int task, final String json) throws Exception {
|
||||
HTTPUtils.postJson(String.format(buildUrl()+"/%d/tasks/%d/transforms", imp, task), json, gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty Importer Context.
|
||||
*
|
||||
* @return The new Importer Context ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewImport() throws Exception {
|
||||
return postNewImport(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* e.g.:
|
||||
* <pre>
|
||||
* String body =
|
||||
* "{" +
|
||||
* "\"import\": { " +
|
||||
* "\"data\": {" +
|
||||
* "\"type\": \"mosaic\", " +
|
||||
* "\"time\": {" +
|
||||
* " \"mode\": \"auto\"" +
|
||||
* "}" +
|
||||
* "}" +
|
||||
* "}" +
|
||||
* "}";
|
||||
* </pre>
|
||||
*
|
||||
* @param body JSON String representing the Importer Context definition
|
||||
* @return The new Importer Context ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewImport(String body) throws Exception {
|
||||
String resp = body == null ? HTTPUtils.post(buildUrl(), "", "text/plain", gsuser, gspass)
|
||||
: HTTPUtils.postJson(buildUrl(), body, gsuser, gspass);
|
||||
|
||||
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||
JSONObject imprt = json.getJSONObject("import");
|
||||
return imprt.getInt("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually starts the READY State Import.
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public void postImport(int imp) throws Exception {
|
||||
HTTPUtils.post(buildUrl()+"/" + imp + "?exec=true", "", "text/plain", gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param data
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewTaskAsMultiPartForm(int imp, String data) throws Exception {
|
||||
String resp = HTTPUtils.postMultipartForm(buildUrl()+"/" + imp + "/tasks", unpack(data), gsuser, gspass);
|
||||
|
||||
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||
|
||||
JSONObject task = json.getJSONObject("task");
|
||||
return task.getInt("id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to attach a new zip file to an existing Importer Context.
|
||||
*
|
||||
* @param imp int: Import context number ID
|
||||
* @param path
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int putNewTask(int imp, String path) throws Exception {
|
||||
File zip = new File(path);
|
||||
|
||||
String resp = HTTPUtils.put(buildUrl()+"/" + imp + "/tasks/" + zip.getName(), zip, MediaType.APPLICATION_ZIP.toString(), gsuser, gspass);
|
||||
|
||||
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||
|
||||
JSONObject task = json.getJSONObject("task");
|
||||
return task.getInt("id");
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Util methods
|
||||
//=========================================================================
|
||||
|
||||
/**
|
||||
* Creates the base REST URL for the imports
|
||||
*/
|
||||
protected String buildUrl() {
|
||||
StringBuilder sUrl = new StringBuilder(gsBaseUrl.toString()).append("/rest/imports");
|
||||
|
||||
return sUrl.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a temporary file
|
||||
*
|
||||
* @return Path to the temporary file
|
||||
* @throws Exception
|
||||
*/
|
||||
public static File tmpDir() throws Exception {
|
||||
File dir = File.createTempFile("importer", "data", new File("target"));
|
||||
dir.delete();
|
||||
dir.mkdirs();
|
||||
return dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands a zip archive into the temporary folder.
|
||||
*
|
||||
* @param path The absolute path to the source zip file
|
||||
* @return Path to the temporary folder containing the expanded files
|
||||
* @throws Exception
|
||||
*/
|
||||
public static File unpack(String path) throws Exception {
|
||||
return unpack(path, tmpDir());
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands a zip archive into the target folder.
|
||||
*
|
||||
* @param path The absolute path to the source zip file
|
||||
* @param dir Full path of the target folder where to expand the archive
|
||||
* @return Path to the temporary folder containing the expanded files
|
||||
* @throws Exception
|
||||
*/
|
||||
public static File unpack(String path, File dir) throws Exception {
|
||||
|
||||
File file = new File(path);
|
||||
|
||||
//new VFSWorker().extractTo(file, dir);
|
||||
if (!file.delete()) {
|
||||
// fail early as tests will expect it's deleted
|
||||
throw new IOException("deletion failed during extraction");
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
package it.geosolutions.geoserver.decoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer21;
|
||||
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||
@ -14,6 +13,8 @@ import junit.framework.Assert;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
@ -24,7 +25,9 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*
|
||||
*/
|
||||
public class LayerDecoder21Test{
|
||||
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(LayerDecoder21Test.class);
|
||||
|
||||
RESTLayer21 layer;
|
||||
|
||||
@Before
|
||||
@ -43,7 +46,7 @@ public class LayerDecoder21Test{
|
||||
public void testAuthorityURLs() {
|
||||
List<GSAuthorityURLInfoEncoder> authorityURLs = layer
|
||||
.getEncodedAuthorityURLInfoList();
|
||||
System.out.println(authorityURLs.size());
|
||||
LOGGER.debug("Number of authority URLs: " + authorityURLs.size());
|
||||
Assert.assertEquals("authority1", authorityURLs.get(0).getName());
|
||||
Assert.assertEquals("http://www.authority1.org", authorityURLs.get(0)
|
||||
.getHref());
|
||||
|
||||
@ -23,7 +23,6 @@ package it.geosolutions.geoserver.decoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverage;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTDimensionInfo;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -156,7 +156,8 @@ public class ResourceDecoderTest {
|
||||
coverageDimension1.getDescription());
|
||||
Assert.assertEquals("-inf", coverageDimension1.getRangeMin());
|
||||
Assert.assertEquals("inf", coverageDimension1.getRangeMax());
|
||||
Assert.assertEquals("dobson units³", coverageDimension1.getUnit());
|
||||
// Assert.assertEquals("dobson units", coverageDimension1.getUnit());
|
||||
Assert.assertTrue(coverageDimension1.getUnit().startsWith("dobson units"));
|
||||
Assert.assertEquals("REAL_32BITS", coverageDimension1.getDimensionTypeName());
|
||||
}
|
||||
|
||||
|
||||
@ -21,11 +21,8 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.decoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTReader;
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
@ -25,12 +25,10 @@
|
||||
package it.geosolutions.geoserver.rest;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayerGroup;
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -35,6 +35,9 @@ import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
@ -44,6 +47,8 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTReaderTest.class);
|
||||
|
||||
/**
|
||||
* Test of getLayers method, of class GeoServerRESTReader.
|
||||
*/
|
||||
@ -56,16 +61,16 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
// assertEquals(/*CHANGEME*/19, result.getChildren("layer").size()); // value in default gs installation
|
||||
|
||||
// System.out.println("Layers:" + result.getChildren("layer").size());
|
||||
System.out.println("Layers:" + result.size());
|
||||
System.out.print("Layers:" );
|
||||
LOGGER.debug("Layers: " + result.size());
|
||||
// LOGGER.debug("Layers:" );
|
||||
for (NameLinkElem shlayer : result) {
|
||||
assertNotNull(shlayer.getName());
|
||||
System.out.print(shlayer.getName() + " ");
|
||||
LOGGER.debug(shlayer.getName() + " ");
|
||||
}
|
||||
// for (Element layer : (List<Element>)result.getChildren("layer")) {
|
||||
// System.out.print(layer.getChildText("name") + " ");
|
||||
// }
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,25 +84,25 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
assertNotNull(wslist);
|
||||
// assertEquals(7, wslist.size()); // value in default gs installation
|
||||
|
||||
System.out.println("Workspaces: " + wslist.size());
|
||||
LOGGER.debug("Workspaces: " + wslist.size());
|
||||
int dsnum = 0;
|
||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||
System.out.println("Getting DSlist for WS " + ws.getName() + "..." );
|
||||
LOGGER.debug("Getting DSlist for WS " + ws.getName() + "..." );
|
||||
RESTDataStoreList result = reader.getDatastores(ws.getName());
|
||||
assertNotNull(result);
|
||||
dsnum += result.size();
|
||||
for (NameLinkElem ds : result) {
|
||||
assertNotNull(ds.getName());
|
||||
System.out.print(ds.getName() + " " );
|
||||
LOGGER.debug(ds.getName() + " " );
|
||||
RESTDataStore datastore = reader.getDatastore(ws.getName(), ds.getName());
|
||||
assertNotNull(datastore);
|
||||
assertEquals(ds.getName(), datastore.getName());
|
||||
assertEquals(ws.getName(), datastore.getWorkspaceName());
|
||||
}
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
}
|
||||
System.out.println();
|
||||
System.out.println("Datastores:" + dsnum); // value in default gs installation
|
||||
LOGGER.debug("");
|
||||
LOGGER.debug("Datastores:" + dsnum); // value in default gs installation
|
||||
// assertEquals(4, dsnum); // value in default gs installation
|
||||
|
||||
}
|
||||
@ -116,7 +121,6 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
// assertEquals(7, wsnames.size()); // value in default gs installation
|
||||
|
||||
// System.out.println("Workspaces: " + wslist.size());
|
||||
int dsnum = 0;
|
||||
int wscnt = 0;
|
||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||
String wsname = wsnames.get(wscnt++);
|
||||
@ -158,14 +162,14 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
assertNotNull(names);
|
||||
assertEquals(names.size(), result.size()); // value in default gs installation
|
||||
|
||||
System.out.println("Namespaces:" + result.size());
|
||||
System.out.print("Namespaces:" );
|
||||
LOGGER.debug("Namespaces:" + result.size());
|
||||
LOGGER.debug("Namespaces:" );
|
||||
int namesIdx = 0;
|
||||
for (RESTNamespaceList.RESTShortNamespace ns : result) {
|
||||
assertEquals("namespace mismatch", names.get(namesIdx++), ns.getName());
|
||||
System.out.print(ns.getName() + " " );
|
||||
LOGGER.debug(ns.getName() + " " );
|
||||
}
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,12 +183,12 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
assertNotNull(names);
|
||||
// assertEquals(7, names.size()); // value in default gs installation
|
||||
|
||||
System.out.println("Namespaces:" + names.size());
|
||||
System.out.print("Namespaces:");
|
||||
LOGGER.debug("Namespaces:" + names.size());
|
||||
LOGGER.debug("Namespaces:");
|
||||
for (String name : names) {
|
||||
System.out.print(name + " ");
|
||||
LOGGER.debug(name + " ");
|
||||
}
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,12 +202,12 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
assertNotNull(wslist);
|
||||
// assertEquals(7, wslist.size()); // value in default gs installation
|
||||
|
||||
System.out.println("Workspaces:" + wslist.size());
|
||||
System.out.print("Workspaces:");
|
||||
LOGGER.debug("Workspaces:" + wslist.size());
|
||||
LOGGER.debug("Workspaces:");
|
||||
for (RESTWorkspaceList.RESTShortWorkspace ws : wslist) {
|
||||
System.out.print(ws.getName() + " ");
|
||||
LOGGER.debug(ws.getName() + " ");
|
||||
}
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
|
||||
assertEquals(wslist.size(), reader.getWorkspaceNames().size());
|
||||
}
|
||||
@ -218,12 +222,12 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
|
||||
assertNotNull(names);
|
||||
// assertEquals(7, names.size()); // value in default gs installation
|
||||
|
||||
System.out.println("Workspaces:" + names.size());
|
||||
System.out.print("Workspaces:");
|
||||
LOGGER.debug("Workspaces:" + names.size());
|
||||
LOGGER.debug("Workspaces:");
|
||||
for (String name : names) {
|
||||
System.out.print(name + " ");
|
||||
LOGGER.debug(name + " ");
|
||||
}
|
||||
System.out.println();
|
||||
LOGGER.debug("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -135,17 +135,17 @@ public abstract class GeoserverRESTTest {
|
||||
+ RESTURL);
|
||||
}
|
||||
} else if (existgs == false){
|
||||
System.out.println("Failing tests : geoserver not found");
|
||||
LOGGER.debug("Failing tests : geoserver not found");
|
||||
fail("GeoServer not found");
|
||||
}
|
||||
|
||||
GSVersionDecoder v=reader.getGeoserverVersion();
|
||||
if (v.compareTo(VERSION.getVersion(GS_VERSION))!=0){
|
||||
System.out.println("Failing tests : geoserver version does not match.\nAccepted versions: "+VERSION.print());
|
||||
LOGGER.debug("Failing tests : geoserver version does not match.\nAccepted versions: "+VERSION.print());
|
||||
fail("GeoServer version ("+v.getVersion()+") does not match the desired one ("+GS_VERSION+")");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Skipping tests ");
|
||||
LOGGER.debug("Skipping tests ");
|
||||
LOGGER.warn("Tests are disabled. Please read the documentation to enable them.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,16 +24,15 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest;
|
||||
|
||||
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.publisher;
|
||||
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.reader;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
@ -81,7 +80,7 @@ public class UtilTest extends GeoserverRESTTest {
|
||||
|
||||
for(RESTStyle style : Util.searchStyles(reader, STYLENAME))
|
||||
{
|
||||
System.out.println(style.getWorkspace() + " :: " + style.getName());
|
||||
LOGGER.debug(style.getWorkspace() + " :: " + style.getName());
|
||||
}
|
||||
|
||||
// there's a bug in geoserver here: the global style will include workspace info
|
||||
|
||||
@ -19,8 +19,6 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
|
||||
@ -128,7 +126,7 @@ public class GSCoverageEncoderTest extends TestCase {
|
||||
// setting dimensions (since gs-2.4.x)
|
||||
GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||
"GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf",
|
||||
"dobson units³", "REAL_32BITS");
|
||||
"dobson units", "REAL_32BITS");
|
||||
encoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
|
||||
|
||||
encoder.setNativeCoverageName("Sample native name");
|
||||
|
||||
@ -19,12 +19,6 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.encoder.dimensions;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -39,14 +33,14 @@ public class GSCoverageDimensionEncoderTest {
|
||||
@Test
|
||||
public void coverageDimensionTest() {
|
||||
GSCoverageDimensionEncoder encoder = new GSCoverageDimensionEncoder("GRAY_INDEX",
|
||||
"GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units³",
|
||||
"GridSampleDimension[-Infinity,Infinity]", "-inf", "inf", "dobson units",
|
||||
"REAL_32BITS");
|
||||
|
||||
Assert.assertEquals("GRAY_INDEX", encoder.getName());
|
||||
Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription());
|
||||
Assert.assertEquals("-inf", encoder.getRangeMin());
|
||||
Assert.assertEquals("inf", encoder.getRangeMax());
|
||||
Assert.assertEquals("dobson units³", encoder.getUnit());
|
||||
Assert.assertEquals("dobson units", encoder.getUnit());
|
||||
Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName());
|
||||
|
||||
Assert.assertTrue(encoder.delName());
|
||||
@ -65,15 +59,15 @@ public class GSCoverageDimensionEncoderTest {
|
||||
encoder.setName("GRAY_INDEX");
|
||||
encoder.setDescription("GridSampleDimension[-Infinity,Infinity]");
|
||||
encoder.setRange("-inf", "inf");
|
||||
encoder.setUnit("dobson units³");
|
||||
encoder.setUnit("dobson units");
|
||||
encoder.setDimensionType("REAL_32BITS");
|
||||
|
||||
Assert.assertEquals("GRAY_INDEX", encoder.getName());
|
||||
Assert.assertEquals("GridSampleDimension[-Infinity,Infinity]", encoder.getDescription());
|
||||
Assert.assertEquals("-inf", encoder.getRangeMin());
|
||||
Assert.assertEquals("inf", encoder.getRangeMax());
|
||||
Assert.assertEquals("dobson units³", encoder.getUnit());
|
||||
Assert.assertEquals("dobson units", encoder.getUnit());
|
||||
Assert.assertEquals("REAL_32BITS", encoder.getDimensionTypeName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,14 +23,11 @@ import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTFeatureType;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTResource;
|
||||
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder;
|
||||
import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder.VERSION;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder21;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.dimensions.GSCoverageDimensionEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
|
||||
|
||||
@ -116,7 +116,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
|
||||
if (v.compareTo(GSVersionDecoder.VERSION.v24)>=0){
|
||||
GSCoverageDimensionEncoder gsCoverageDimensionEncoder = new GSCoverageDimensionEncoder(
|
||||
"GRAY_INDEX", "GridSampleDimension[-Infinity,Infinity]", "-inf", "inf",
|
||||
"dobson units³", "REAL_32BITS");
|
||||
"dobson units", "REAL_32BITS");
|
||||
coverageEncoder.addCoverageDimensionInfo(gsCoverageDimensionEncoder);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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 Alessio Fabiani, GeoSolutions S.A.S.
|
||||
*
|
||||
*/
|
||||
public class GeoserverRESTImporterTest extends GeoserverRESTTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImporterTest.class);
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShapeFileImport() throws Exception {
|
||||
if (!enabled())
|
||||
return;
|
||||
|
||||
// Creates a new Importer Context and gets back the ID
|
||||
int i = publisher.postNewImport();
|
||||
|
||||
// Attaches to the new Importer Context a Task pointing to a shapefile's zip archive
|
||||
String data = new ClassPathResource("testdata/test_noepsg.zip").getFile().getAbsolutePath();
|
||||
int t = publisher.postNewTaskAsMultiPartForm(i, data);
|
||||
|
||||
// Check that the Task was actually created and that the CRS has not recognized in this case
|
||||
JSONObject task = publisher.getTask(i, t);
|
||||
//assertEquals("NO_CRS", task.getString("state"));
|
||||
assertEquals("READY", task.getString("state"));
|
||||
|
||||
// Prepare the JSON String instructing the Task about the SRS to use
|
||||
String json = "{\"layer\":{\"srs\":\"EPSG:26713\"}}";
|
||||
|
||||
// Performing the Task update
|
||||
publisher.putTaskLayer(i, t, json);
|
||||
|
||||
// Double check that the Task is in the READY state
|
||||
task = publisher.getTask(i, t);
|
||||
assertEquals("READY", task.getString("state"));
|
||||
assertEquals("nurc_10m_populated_places", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
|
||||
// Prepare the JSON String instructing the Task avout the SLD to use for the new Layer
|
||||
json = "{\"layer\":{\"style\":{\"name\": \"point\"}}}";
|
||||
|
||||
// Performing the Task update
|
||||
publisher.putTaskLayer(i, t,json);
|
||||
|
||||
// Double check that the Task is in the READY state and that the Style has been correctly updated
|
||||
task = publisher.getTask(i, t);
|
||||
assertEquals("READY", task.getString("state"));
|
||||
assertEquals("point", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
|
||||
// Finally starts the Import ...
|
||||
publisher.postImport(i);
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,8 +26,6 @@
|
||||
package it.geosolutions.geoserver.rest.publisher;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.publisher;
|
||||
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.reader;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTStyle;
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||
|
||||
@ -33,8 +33,6 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
@ -47,8 +45,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*/
|
||||
public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorkspaceTest.class);
|
||||
|
||||
@Test
|
||||
public void testWorkspaces() {
|
||||
if (!enabled()) return;
|
||||
|
||||
@ -35,8 +35,6 @@ import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
/**
|
||||
@ -48,8 +46,6 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*/
|
||||
public class GeoserverRESTWorldImageTest extends GeoserverRESTTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorldImageTest.class);
|
||||
|
||||
@Test
|
||||
public void testPublishWorldImage() throws IOException {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user