Class GeoServerRESTImporterManager


  • public class GeoServerRESTImporterManager
    extends GeoServerRESTAbstractManager

    GeoServerRESTImporterManager class.

    Version:
    $Id: $
    Author:
    Alessio Fabiani, GeoSolutions S.A.S.
    • 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.String buildUrl()
      Creates the base REST URL for the imports
      net.sf.json.JSONObject getImport​(int imp)
      Retrieves the Import JSON Object given its identifier
      net.sf.json.JSONObject getTask​(int imp, int task)
      Retrieves the Import Task JSON Object given its identifier and task number
      void postImport​(int imp)
      Actually starts the READY State Import.
      int postNewImport()
      Creates an empty Importer Context.
      int postNewImport​(java.lang.String body)
      e.g.:
      int postNewTaskAsMultiPartForm​(int imp, java.lang.String data)
      postNewTaskAsMultiPartForm
      void postTaskTransform​(int imp, int task, java.lang.String json)
      Just update the Layers properties associated to a Task (t) in the Importer Context (i).
      int putNewTask​(int imp, java.lang.String path)
      Allows to attach a new zip file to an existing Importer Context.
      void putTask​(int imp, int task, java.lang.String json)
      Example usage:
      void putTaskLayer​(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.File tmpDir()
      Creates a temporary file
      static java.io.File unpack​(java.lang.String path)
      Expands a zip archive into the temporary folder.
      static java.io.File unpack​(java.lang.String path, java.io.File dir)
      Expands a zip archive into the target folder.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GeoServerRESTImporterManager

        public GeoServerRESTImporterManager​(java.net.URL restURL,
                                            java.lang.String username,
                                            java.lang.String password)
                                     throws java.lang.IllegalArgumentException
        Default constructor.
        Parameters:
        restURL - GeoServer REST API endpoint
        username - GeoServer REST API authorized username
        password - 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.Exception
        Retrieves the Import JSON Object given its identifier
        Parameters:
        imp - int: Import context number ID
        Returns:
        a JSONObject object.
        Throws:
        java.lang.Exception - if any.
      • getTask

        public net.sf.json.JSONObject getTask​(int imp,
                                              int task)
                                       throws java.lang.Exception
        Retrieves the Import Task JSON Object given its identifier and task number
        Parameters:
        imp - int: Import context number ID
        task - int: Task number
        Returns:
        a JSONObject object.
        Throws:
        java.lang.Exception - if any.
      • putTask

        public void putTask​(int imp,
                            int task,
                            java.lang.String json)
                     throws java.lang.Exception
        Example 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 ID
        task - int: Task number
        json - 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.Exception
        Just 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 ID
        task - int: Task number
        json - 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.Exception
        Just 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 ID
        task - int: Task number
        json - String: JSON containing the Layer properties to be updated
        Throws:
        java.lang.Exception - if any.
      • postNewImport

        public int postNewImport()
                          throws java.lang.Exception
        Creates 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.Exception
        e.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.Exception
        Actually 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.Exception

        postNewTaskAsMultiPartForm

        Parameters:
        imp - int: Import context number ID
        data - a String object.
        Returns:
        a int.
        Throws:
        java.lang.Exception - if any.
      • putNewTask

        public int putNewTask​(int imp,
                              java.lang.String path)
                       throws java.lang.Exception
        Allows to attach a new zip file to an existing Importer Context.
        Parameters:
        imp - int: Import context number ID
        path - a String object.
        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 String object.
      • tmpDir

        public static java.io.File tmpDir()
                                   throws java.lang.Exception
        Creates 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.Exception
        Expands 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.Exception
        Expands a zip archive into the target folder.
        Parameters:
        path - The absolute path to the source zip file
        dir - 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.