Adding worldfile method.

This commit is contained in:
Joergen Schoeyen Nicolaysen 2012-01-18 16:05:02 +01:00
parent aca15380ea
commit ee75f7138e
2 changed files with 70 additions and 6 deletions

View File

@ -491,8 +491,8 @@ public class GeoServerRESTPublisher {
/**
* The configure parameter is used to control how the data store is
* configured upon file upload. It can take one of the three values first,
* none, or all. <br>
* configured upon file upload. It can take one of the three values <i>first</i>,
* <i>none</i>, or <i>all</i>. <br>
* first - Only setup the first feature type available in the data store.
* This is the default. <br>
* none - Do not configure any feature types.<br>
@ -516,7 +516,7 @@ public class GeoServerRESTPublisher {
* The update parameter is used to control how existing data is handled when
* the file is PUT into a datastore that (a) already exists and (b) already
* contains a schema that matches the content of the file. It can take one
* of the two values append, or overwrite.<br>
* of the two values <i>append</i>, or <i>overwrite</i>.<br>
* append - Data being uploaded is appended to the existing data. This is
* the default.<br>
* overwrite - Data being uploaded replaces any existing data.<br>
@ -1173,8 +1173,8 @@ public class GeoServerRESTPublisher {
* The recurse parameter is used to recursively delete all
* resources contained by the specified workspace. This includes
* data stores, coverage stores, feature types, etc... Allowable
* values for this parameter are true or false. The default
* value is false.
* values for this parameter are âœtrueâ<EFBFBD> or âœfalseâ<EFBFBD>. The default
* value is âœfalseâ<EFBFBD>.
* @return <TT>true</TT> if the WorkSpace was successfully removed.
*/
public boolean removeWorkspace(String workspace, boolean recurse) throws IllegalArgumentException {
@ -1503,7 +1503,52 @@ public class GeoServerRESTPublisher {
cname = ce.getName();
return configureCoverage(ce, wsname, csname);
}
// ==========================================================================
// === WORLDIMAGE
// ==========================================================================
/**
* Publish a zipped worldimage file.
*
* It is assumed that the the zip-file contain the *.prj to set the srs.
*
* <P>This is equivalent call with cUrl:
* <PRE>{@code
*curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
* --data-binary @$ZIPFILE \
* http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
* </PRE>
*
* @param workspace Workspace to use
* @param coveragestore Name of the coveragestore
* @param zipFile zip file to upload
* @param configure Configure parameter. It may be null.
* @param coverageName coverageName parameter to append. Only works if configure is set. It may be null.
* @return true if the operation completed successfully.
*/
public boolean publishWorldimage(String workspace, String coveragestore, File zipFile, String configure, String coverageName) throws FileNotFoundException {
// build full URL
StringBuilder sbUrl = new StringBuilder(restURL).append("/rest/workspaces/").append(workspace).append("/coveragestores/").append(coveragestore)
.append("/file.worldimage");
if ( configure != null && coverageName != null) {
sbUrl.append("?configure").append(configure);
if ( coverageName != null) {
sbUrl.append("&coverageName=").append(coverageName);
}
}
String sentResult = HTTPUtils.put(sbUrl.toString(), zipFile, "application/zip", gsuser, gspass);
boolean fileSent = sentResult != null;
if (fileSent) {
LOGGER.info("Zipfile successfully uploaded ( zip:" + zipFile + ")");
} else {
LOGGER.warn("Error in sending zipfile " + zipFile);
}
return fileSent;
}
/**
*
*/

View File

@ -463,6 +463,25 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
assertTrue("removeDatastore() failed", dsRemoved);
}
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/worldimagetest.zip").getFile();
// test publish
boolean wp = publisher.publishWorldimage(DEFAULT_WS, storeName, worldImageFile, null, null);
assertTrue("Publish worldfile failed.",wp);
}
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
// String wsName = "this_ws_does_not_exist";
@ -470,7 +489,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
// String layerName = "this_layer_does_not_exist";
//
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
// assertFalse("unpublished not existing layer", ok);
// assertFalse("unpublished not existing layer", ok);
// }
private boolean existsLayer(String layername) {
return reader.getLayer(layername) != null;