Class GeoServerRESTImporterManager
- java.lang.Object
-
- it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager
-
- it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager
-
public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager
GeoServerRESTImporterManager class.
- Version:
- $Id: $
- Author:
- Alessio Fabiani, GeoSolutions S.A.S.
-
-
Field Summary
-
Fields inherited from class it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager
gsBaseUrl, gspass, gsuser
-
-
Constructor Summary
Constructors Constructor Description GeoServerRESTImporterManager(java.net.URL restURL, java.lang.String username, java.lang.String password)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbuildUrl()Creates the base REST URL for the importsnet.sf.json.JSONObjectgetImport(int imp)Retrieves the Import JSON Object given its identifiernet.sf.json.JSONObjectgetTask(int imp, int task)Retrieves the Import Task JSON Object given its identifier and task numbervoidpostImport(int imp)Actually starts the READY State Import.intpostNewImport()Creates an empty Importer Context.intpostNewImport(java.lang.String body)e.g.:intpostNewTaskAsMultiPartForm(int imp, java.lang.String data)postNewTaskAsMultiPartFormvoidpostTaskTransform(int imp, int task, java.lang.String json)Just update the Layers properties associated to a Task (t) in the Importer Context (i).intputNewTask(int imp, java.lang.String path)Allows to attach a new zip file to an existing Importer Context.voidputTask(int imp, int task, java.lang.String json)Example usage:voidputTaskLayer(int imp, int task, java.lang.String json)Just update the Layers properties associated to a Task (t) in the Importer Context (i).static java.io.FiletmpDir()Creates a temporary filestatic java.io.Fileunpack(java.lang.String path)Expands a zip archive into the temporary folder.static java.io.Fileunpack(java.lang.String path, java.io.File dir)Expands a zip archive into the target folder.
-
-
-
Constructor Detail
-
GeoServerRESTImporterManager
public GeoServerRESTImporterManager(java.net.URL restURL, java.lang.String username, java.lang.String password) throws java.lang.IllegalArgumentExceptionDefault constructor.- Parameters:
restURL- GeoServer REST API endpointusername- GeoServer REST API authorized usernamepassword- GeoServer REST API password for the former username- Throws:
java.lang.IllegalArgumentException- if any.
-
-
Method Detail
-
getImport
public net.sf.json.JSONObject getImport(int imp) throws java.lang.ExceptionRetrieves the Import JSON Object given its identifier- Parameters:
imp- int: Import context number ID- Returns:
- a
JSONObjectobject. - Throws:
java.lang.Exception- if any.
-
getTask
public net.sf.json.JSONObject getTask(int imp, int task) throws java.lang.ExceptionRetrieves the Import Task JSON Object given its identifier and task number- Parameters:
imp- int: Import context number IDtask- int: Task number- Returns:
- a
JSONObjectobject. - Throws:
java.lang.Exception- if any.
-
putTask
public void putTask(int imp, int task, java.lang.String json) throws java.lang.ExceptionExample usage:// 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);- Parameters:
imp- int: Import context number IDtask- int: Task numberjson- String: JSON containing the Task properties to be updated- Throws:
java.lang.Exception- if any.
-
putTaskLayer
public void putTaskLayer(int imp, int task, java.lang.String json) throws java.lang.ExceptionJust update the Layers properties associated to a Task (t) in the Importer Context (i). e.g.:putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");- Parameters:
imp- int: Import context number IDtask- int: Task numberjson- String: JSON containing the Layer properties to be updated- Throws:
java.lang.Exception- if any.
-
postTaskTransform
public void postTaskTransform(int imp, int task, java.lang.String json) throws java.lang.ExceptionJust update the Layers properties associated to a Task (t) in the Importer Context (i). e.g.:putTaskLayer(i, t, "{\"title\":\"Archsites\", \"abstract\":\"Archeological Sites\"}");- Parameters:
imp- int: Import context number IDtask- int: Task numberjson- String: JSON containing the Layer properties to be updated- Throws:
java.lang.Exception- if any.
-
postNewImport
public int postNewImport() throws java.lang.ExceptionCreates an empty Importer Context.- Returns:
- The new Importer Context ID
- Throws:
java.lang.Exception- if any.
-
postNewImport
public int postNewImport(java.lang.String body) throws java.lang.Exceptione.g.:String body = "{" + "\"import\": { " + "\"data\": {" + "\"type\": \"mosaic\", " + "\"time\": {" + " \"mode\": \"auto\"" + "}" + "}" + "}" + "}";- Parameters:
body- JSON String representing the Importer Context definition- Returns:
- The new Importer Context ID
- Throws:
java.lang.Exception- if any.
-
postImport
public void postImport(int imp) throws java.lang.ExceptionActually starts the READY State Import.- Parameters:
imp- int: Import context number ID- Throws:
java.lang.Exception- if any.
-
postNewTaskAsMultiPartForm
public int postNewTaskAsMultiPartForm(int imp, java.lang.String data) throws java.lang.ExceptionpostNewTaskAsMultiPartForm
- Parameters:
imp- int: Import context number IDdata- aStringobject.- Returns:
- a int.
- Throws:
java.lang.Exception- if any.
-
putNewTask
public int putNewTask(int imp, java.lang.String path) throws java.lang.ExceptionAllows to attach a new zip file to an existing Importer Context.- Parameters:
imp- int: Import context number IDpath- aStringobject.- Returns:
- a int.
- Throws:
java.lang.Exception- if any.
-
buildUrl
protected java.lang.String buildUrl()
Creates the base REST URL for the imports- Returns:
- a
Stringobject.
-
tmpDir
public static java.io.File tmpDir() throws java.lang.ExceptionCreates a temporary file- Returns:
- Path to the temporary file
- Throws:
java.lang.Exception- if any.
-
unpack
public static java.io.File unpack(java.lang.String path) throws java.lang.ExceptionExpands a zip archive into the temporary folder.- Parameters:
path- The absolute path to the source zip file- Returns:
- Path to the temporary folder containing the expanded files
- Throws:
java.lang.Exception- if any.
-
unpack
public static java.io.File unpack(java.lang.String path, java.io.File dir) throws java.lang.ExceptionExpands a zip archive into the target folder.- Parameters:
path- The absolute path to the source zip filedir- Full path of the target folder where to expand the archive- Returns:
- Path to the temporary folder containing the expanded files
- Throws:
java.lang.Exception- if any.
-
-