Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Handle upload of geotiffs generated by the R backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bpross-52n committed Mar 7, 2019
1 parent 7dec59e commit 9cc4157
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
Expand All @@ -60,6 +61,7 @@
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.io.FileUtils;

public class GeoServerUploader {

Expand All @@ -78,18 +80,22 @@ public GeoServerUploader(String username, String password, String host,

public String uploadGeotiff(File file, String storeName)
throws HttpException, IOException {
String target = "http://" + host + ":" + port
+ "/geoserver/rest/workspaces/N52/coveragestores/" + storeName
+ "/external.geotiff?configure=first&coverageName=" + storeName;
String request;
if (file.getAbsolutePath().startsWith("/")) { // tried with

File copyOfFile = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + UUID.randomUUID().toString().substring(0, 5) + file.getName());

FileUtils.copyFile(file, copyOfFile);

String target = "http://" + host + ":" + port + "/geoserver/rest/workspaces/N52/coveragestores/" + storeName
+ "/external.geotiff?configure=first&coverageName=" + storeName;
String request;
if (copyOfFile.getAbsolutePath().startsWith("/")) { // tried with
// request.replaceAll("//","/");
// but didn't seem to
// work...
request = "file:" + file.getAbsolutePath();
} else {
request = "file:/" + file.getAbsolutePath();
}
request = "file:" + copyOfFile.getAbsolutePath();
} else {
request = "file:/" + copyOfFile.getAbsolutePath();
}
String result = sendRasterRequest(target, request, "PUT", username,
password);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.n52.wps.io.IOUtils;
import org.n52.wps.io.data.GenericFileData;
import org.n52.wps.io.data.GenericFileDataConstants;
Expand Down Expand Up @@ -412,13 +413,17 @@ public IData parseOutput(RConnection connection,
String rType = currentAnnotation.getStringValue(RAttribute.TYPE);
mimeType = dataTypeRegistry.getType(rType).getMimeType();

File copyOfFile = new File(System.getProperty("java.io.tmpdir") + File.separatorChar + UUID.randomUUID().toString().substring(0, 5) + outputFile.getName());

FileUtils.copyFile(outputFile, copyOfFile);

if(iClass.equals(GenericFileDataBinding.class)){
GenericFileData out = new GenericFileData(outputFile, mimeType);
GenericFileData out = new GenericFileData(copyOfFile, mimeType);

return new GenericFileDataBinding(out);

}else if(iClass.equals(GenericFileDataWithGTBinding.class)){
GenericFileDataWithGT out = new GenericFileDataWithGT(outputFile, mimeType);
GenericFileDataWithGT out = new GenericFileDataWithGT(copyOfFile, mimeType);

return new GenericFileDataWithGTBinding(out);
}
Expand Down

0 comments on commit 9cc4157

Please sign in to comment.