public RESTImport createImportJob ( String workSpaceName , String dataStoreName ) throws Exception { if ( StringUtils . isEmpty ( workSpaceName ) ) { throw new GeoServerRESTImporterException ( "No workspace given. Please provide a " + "workspace to import the data in." ) ; } RESTImport importJob = new RESTImport ( ) ; LOG . debug ( "Creating a new import job to import into workspace " + workSpaceName ) ; RESTTargetWorkspace targetWorkspace = new RESTTargetWorkspace ( workSpaceName ) ; importJob . setTargetWorkspace ( targetWorkspace ) ; if ( ! StringUtils . isEmpty ( dataStoreName ) ) { LOG . debug ( "The data will be imported into datastore " + dataStoreName ) ; RESTTargetDataStore targetDataStore = new RESTTargetDataStore ( dataStoreName , null ) ; importJob . setTargetStore ( targetDataStore ) ; } else { LOG . debug ( "No datastore given. A new datastore will be created in relation to the" + "input data." ) ; } Response httpResponse = HttpUtil . post ( this . addEndPoint ( "" ) , this . asJSON ( importJob ) , ContentType . APPLICATION_JSON , this . username , this . password ) ; HttpStatus responseStatus = httpResponse . getStatusCode ( ) ; if ( responseStatus == null || ! responseStatus . is2xxSuccessful ( ) ) { throw new GeoServerRESTImporterException ( "Import job cannot be " + "created. Is the GeoServer Importer extension installed?" ) ; } RESTImport restImport = ( RESTImport ) this . asEntity ( httpResponse . getBody ( ) , RESTImport . class ) ; LOG . debug ( "Successfully created the import job with ID " + restImport . getId ( ) ) ; return restImport ; }
Create a new import job .