From 90c8af21055ad0c7083980a8cc48602d72d4c888 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 10 Jun 2018 15:23:59 -0400 Subject: [PATCH 01/12] Added Nextcloud Module --- pom.xml | 15 +++ .../Exception/NextcloudApiException.java | 13 +++ .../Nextcloud/GenerateTokenTask.java | 75 +++++++++++++++ .../NextCloudFolderdownloadtask.java | 76 +++++++++++++++ .../Nextcloud/NextcloudAdapter.java | 93 +++++++++++++++++++ .../Nextcloud/NextcloudFileDownloadTask.java | 56 +++++++++++ .../Nextcloud/NextcloudFileTask.java | 68 ++++++++++++++ .../Nextcloud/NextcloudFileUploadTask.java | 45 +++++++++ .../Nextcloud/NextcloudFolderUploadTask.java | 75 +++++++++++++++ .../Nextcloud/ValidateTokenTask.java | 61 ++++++++++++ .../seagrid/desktop/util/SEAGridConfig.java | 9 ++ .../seagrid/desktop/util/SEAGridContext.java | 32 +++++++ src/main/resources/seagrid.properties | 12 ++- 13 files changed, 629 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java diff --git a/pom.xml b/pom.xml index c3e3147..cb2a06c 100644 --- a/pom.xml +++ b/pom.xml @@ -388,6 +388,21 @@ vecmath 1.6.0-scijava-2 + + org.apache.httpcomponents + httpclient + 4.5.5 + + + org.json + json + 20180130 + + + com.github.lookfirst + sardine + 5.8 + diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java new file mode 100644 index 0000000..fa24f03 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java @@ -0,0 +1,13 @@ +package org.seagrid.desktop.connectors.Nextcloud.Exception; + +public class NextcloudApiException extends RuntimeException { + private static final long serialVersionUID = 8088239559973590632L; + + public NextcloudApiException(Throwable cause) { + super(cause); + } + + public NextcloudApiException(String message) { + super(message); + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java new file mode 100644 index 0000000..2c40d26 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java @@ -0,0 +1,75 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import org.json.JSONObject; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.LinkedHashMap; +import java.util.Map; + +public class GenerateTokenTask { + + private String client_id; + private String username; + private String password; + private String tokenendpoint; + private String grant_type; + private String client_secret; + + GenerateTokenTask() { + client_id = SEAGridContext.getInstance().getClientID(); + username = SEAGridContext.getInstance().getUserName(); + //Still need to work on this + password = "embedpassword"; + tokenendpoint = SEAGridContext.getInstance().getTokenGenerateEndpoint(); + grant_type = SEAGridContext.getInstance().getGrantType(); + } + + /** + * Generates the token and returns the access_token if the user credentials are valid + * + * @return String + * @throws IOException + */ + public String generateToken() throws IOException { + String access_token; + URL url = new URL(tokenendpoint); + Map params = new LinkedHashMap<>(); + params.put("client_id", client_id); + params.put("username", username); + //Need to check this and work on getting the password as it is required to generate the token + params.put("password", password); + params.put("grant_type", grant_type); + //Need to find a better way to emebed the client-secret + params.put("client_secret",client_secret); + StringBuilder postData = new StringBuilder(); + for (Map.Entry param : params.entrySet()) { + if (postData.length() != 0) postData.append('&'); + postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); + postData.append('='); + postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); + + } + byte[] postDataBytes = postData.toString().getBytes("UTF-8"); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); + conn.setDoOutput(true); + conn.getOutputStream().write(postDataBytes); + Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); + StringBuilder sb = new StringBuilder(); + for (int c; (c = in.read()) >= 0;) + sb.append((char)c); + String response = sb.toString(); + JSONObject myResponse = new JSONObject(response.toString()); + access_token = myResponse.getString("access_token"); + return access_token; + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java new file mode 100644 index 0000000..901c680 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java @@ -0,0 +1,76 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import com.github.sardine.DavResource; +import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.*; +import java.util.LinkedList; +import java.util.List; + +public class NextCloudFolderdownloadtask extends NextcloudFileTask { + + private String rootpath; + private String downloadirpath = SEAGridContext.getInstance().getBaseDownloadPath(); + + /** + * Constructor + */ + NextCloudFolderdownloadtask() { + super(); + rootpath = (isusehttps ? "https" : "http") +"://"+servername+"/"+basepath+SEAGridContext.getInstance().getUserName(); + + } + + /** + * Downloads all the files inside the folder at the specified path + * + * @param remotepath + * @param depth + * @return + * @throws IOException + */ + public void downloadFolder(String remotepath,int depth) throws IOException { + rootpath = rootpath+remotepath ; + System.out.println(rootpath); + int count = 0; + String filepath; + List retVal= new LinkedList<>(); + List resources; + try { + resources = sardine.list(rootpath, depth); + for (DavResource res : resources) { + //Skip the Documents folder which is listed as default as first by the sardine output + if (count != 0) { + if (res.isDirectory()) { + String filename = res.getName(); + File dir = new File(downloadirpath + "/" + filename); + dir.mkdir(); + filepath = rootpath + "/" + filename; + downloadFolder(filepath, depth); + } else { + String filename = res.getName(); + filepath = rootpath + "/" + filename; + retVal.add(res.getName()); + InputStream in = null; + //System.out.println(filepath); + if (sardine.exists(filepath)) { + in = sardine.get(filepath); + byte[] buffer = new byte[in.available()]; + in.read(buffer); + File targetFile = new File(downloadirpath + "/" + filename); + OutputStream outStream = new FileOutputStream(targetFile); + outStream.write(buffer); + in.close(); + outStream.close(); + } + } + } + count++; + } + } catch (IOException e) { + throw new NextcloudApiException(e); + } + } + +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java new file mode 100644 index 0000000..9c92c6b --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java @@ -0,0 +1,93 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +public class NextcloudAdapter { + private final NextcloudFileUploadTask uplfile; + private final NextcloudFileDownloadTask dnlfile; + private final NextCloudFolderdownloadtask dnlfolder; + + /** + * Constructor + */ + public NextcloudAdapter() { + uplfile = new NextcloudFileUploadTask(); + dnlfile = new NextcloudFileDownloadTask(); + dnlfolder = new NextCloudFolderdownloadtask(); + } + + /** + *Upload the file to the remote path of the nextcloud server + * + * @param localpath + * @param remotepath + * @return boolean + * + * Reference: https://github.com/a-schild/nextcloud-java-api + */ + public boolean UploadFile(String localpath, String remotepath) { + boolean status=false; + try { + if(uplfile.AuthenticateSession()) { + status = uplfile.UploadFile(localpath, remotepath); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + return status; + } + } + + /** + * Download the file from the remotepath to the download path specified + * + * @param remotepath + * @return boolean + */ + public boolean downloadFile(String remotepath) { + boolean status = false; + try { + if(dnlfile.AuthenticateSession()) { + status = dnlfile.downloadFile(remotepath); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + return status; + } + } + + /** + * Downloads all the files at the specified folder of the remote server + * @param path + * @throws IOException + */ + public void downloadFolder(String path) throws IOException { + try { + List downloadlist= new LinkedList<>(); + if(dnlfolder.AuthenticateSession()) { + dnlfolder.downloadFolder(path, 2); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + + /** + * Check if the remotepath exists at the nextcloud server + * + * @param rootpath + * @return + * + * Reference: https://github.com/a-schild/nextcloud-java-api + */ + public boolean Exists(String rootpath) { + if(uplfile.Exists(rootpath)) { + return true; + } + return false; + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java new file mode 100644 index 0000000..c623a6d --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java @@ -0,0 +1,56 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.*; + +public class NextcloudFileDownloadTask extends NextcloudFileTask { + + private String remoterootpath; + private String downloadirpath; + NextcloudFileDownloadTask() { + super(); + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); + downloadirpath = SEAGridContext.getInstance().getBaseDownloadPath() + SEAGridContext.getInstance().getUserName(); + } + + /** + * Download the file from the remote nextcloud server using the remotepath to the specified directory + * + * @param remotepath + * @return + * @throws IOException + */ + public boolean downloadFile(String remotepath) throws IOException { + boolean status=false; + String path = remoterootpath + remotepath; + InputStream in = null; + if(Exists(remotepath)) { + //Extract the Filename from the path + String[] segments = path.split("/"); + String filename = segments[segments.length - 1]; + downloadirpath = downloadirpath + "/" + filename; + } + try { + in = sardine.get(path); + byte[] buffer = new byte[in.available()]; + in.read(buffer); + File targetFile = new File(downloadirpath); + OutputStream outStream = new FileOutputStream(targetFile); + outStream.write(buffer); + outStream.close(); + status = true; + } catch (IOException e) { + throw new NextcloudApiException(e); + } finally { + sardine.shutdown(); + in.close(); + return status; + } + } + + + + +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java new file mode 100644 index 0000000..1f0350e --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java @@ -0,0 +1,68 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import com.github.sardine.Sardine; +import com.github.sardine.SardineFactory; +import org.seagrid.desktop.util.SEAGridContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class NextcloudFileTask { + private final static Logger logger = LoggerFactory.getLogger(NextcloudFileTask.class); + + protected Sardine sardine = SardineFactory.begin(); + + protected String servername; + protected String basepath; + protected boolean isusehttps; + private String token; + + /** + * Constructor + */ + NextcloudFileTask() { + servername = SEAGridContext.getInstance().getNextcloudServername(); + basepath = SEAGridContext.getInstance().getDavBasepath(); + isusehttps = SEAGridContext.getInstance().isUseHttps(); + } + + /** + *Authenticate the session with the token and set the credentials to login + * + * @return boolean if the session is authenticated returns true + * @throws IOException + */ + public boolean AuthenticateSession() throws IOException { + GenerateTokenTask t1 = new GenerateTokenTask(); + token = t1.generateToken(); + ValidateTokenTask t2 = new ValidateTokenTask(); + if(t2.ValidateToken(token) == "200") { + sardine.setCredentials(SEAGridContext.getInstance().getUserName(), token); + sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); + return true; + } + return false; + } + + /** + * method to check if a file/folder is already present in the remote path + * + * @param rootpath of the file (full path) + * @return boolean value is returned depending on the existance of the file + * + * Reference: https://github.com/a-schild/nextcloud-java-api + */ + + public boolean Exists(String rootpath){ + String path = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName() + rootpath; + try { + if(sardine.exists(rootpath)) { + return true; + } + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java new file mode 100644 index 0000000..d105313 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java @@ -0,0 +1,45 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NextcloudFileUploadTask extends NextcloudFileTask { + + private String remoterootpath; + /** + * Constructor + */ + NextcloudFileUploadTask() { + super(); + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); + } + + /** + * Upload the inputstream to the remote file path as specified to the nextcloud server + * + * @param localpath + * @param remotepath + * @throws IOException + * + * Reference: https://github.com/a-schild/nextcloud-java-api + */ + protected boolean UploadFile(String localpath, String remotepath) throws IOException { + boolean status = false; + InputStream inputStream = new FileInputStream(localpath); + String path; + try { + path = remoterootpath + remotepath; + sardine.put(path, inputStream); + status = true; + } catch (IOException e) { + throw new NextcloudApiException(e); + } finally { + inputStream.close(); + return status; + } + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java new file mode 100644 index 0000000..5888f02 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java @@ -0,0 +1,75 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NextcloudFolderUploadTask extends NextcloudFileTask { + + private String remoterootpath; + NextcloudFolderUploadTask() { + super(); + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); + } + + /** + * Create the folder at the specified path, if the folder doesn't exist a new folder with + * the specific foldername is created + * + * @param localpath + * @param remotepath + * @throws IOException + */ + public void uploadFolder(String localpath, String remotepath) throws IOException { + String path; + path = remoterootpath + remotepath; + String ip = localpath; + try { + File f = new File(ip); + if (f.exists() && f.isDirectory()) { + //Extract the Foldername from the path + String[] segments = ip.split("/"); + String foldername = segments[segments.length - 1]; + System.out.println(foldername); + path = path + "/" + foldername; + System.out.println(path); + //if the folder doesn't exist in the remote server then create the folder + if (!Exists(remotepath)) { + createFolder(remotepath); + } + + File[] listfil = f.listFiles(); + if (listfil != null) { + for (File child : listfil) { + String filename = child.getName(); + String newpath = path + "/" + filename; + InputStream input = new FileInputStream(child.getAbsolutePath()); + sardine.put(newpath, input); + input.close(); + } + } + } + } catch (IOException e) { + throw new NextcloudApiException(e); + } + + } + + /** + * Create the folder at the specified path + * @param remotepath + */ + public void createFolder(String remotepath) + { + String path= remoterootpath+remotepath; + try { + sardine.createDirectory(path); + } catch (IOException e) { + throw new NextcloudApiException(e); + } + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java new file mode 100644 index 0000000..aa15518 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java @@ -0,0 +1,61 @@ +package org.seagrid.desktop.connectors.Nextcloud; + +import org.json.JSONObject; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.LinkedHashMap; +import java.util.Map; + +public class ValidateTokenTask { + + /** + * Returns 200 status if the token is successfully validated. + * + * @param token + * @return + * @throws IOException + */ + public String ValidateToken(String token) throws IOException { + URL url = null; + try { + url = new URL(SEAGridContext.getInstance().getValidationURL()); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + Map params = new LinkedHashMap<>(); + params.put("username", SEAGridContext.getInstance().getUserName()); + params.put("token", token); + StringBuilder postData = new StringBuilder(); + for (Map.Entry param : params.entrySet()) { + if (postData.length() != 0) postData.append('&'); + try { + postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); + postData.append('='); + postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + byte[] postDataBytes = postData.toString().getBytes("UTF-8"); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); + conn.setDoOutput(true); + conn.getOutputStream().write(postDataBytes); + Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); + StringBuilder sb = new StringBuilder(); + for (int c; (c = in.read()) >= 0;) + sb.append((char)c); + String response = sb.toString(); + System.out.println(response); + JSONObject myResponse = new JSONObject(response.toString()); + return myResponse.get("status").toString(); + } +} diff --git a/src/main/java/org/seagrid/desktop/util/SEAGridConfig.java b/src/main/java/org/seagrid/desktop/util/SEAGridConfig.java index 68cb912..5417bcf 100644 --- a/src/main/java/org/seagrid/desktop/util/SEAGridConfig.java +++ b/src/main/java/org/seagrid/desktop/util/SEAGridConfig.java @@ -27,6 +27,7 @@ public class SEAGridConfig { private final static Logger logger = LoggerFactory.getLogger(SEAGridConfig.class); public static final boolean DEV = false; //true + public static final boolean IS_USE_HTTPS = false; public static final String USER_NAME = "user.name"; public static final String AUTHENTICATED = "authenticated"; @@ -51,4 +52,12 @@ public class SEAGridConfig { public static final java.lang.String DEV_REMOTE_DATA_DIR_ROOT = "dev.remote.data.dir.root"; public static final java.lang.String REMOTE_DATA_DIR_PREFIX = "remote.data.dir.prefix"; public static final java.lang.String DEV_REMOTE_DATA_DIR_PREFIX = "dev.remote.data.dir.prefix"; + + public static final java.lang.String NEXTCLOUD_SERVERNAME = "nextcloud.server"; + public static final java.lang.String NEXTCLOUD_WEBDAV_BASEPATH = "nextcloudwebdav.base.path"; + public static final java.lang.String CLIENT_ID = "nextcloud.client.id"; + public static final java.lang.String TOKEN_ENDPOINT = "nextcloud.token.endpoint"; + public static final java.lang.String TOKEN_GRANTYPE = "nextcloud.grantype"; + public static final java.lang.String TOKEN_VALIDATION_URL = "nextcloud.tokenvalidation.api"; + public static final java.lang.String BASE_DOWNLOAD_PATH = "nextcloud.file.basedownloadpath"; } \ No newline at end of file diff --git a/src/main/java/org/seagrid/desktop/util/SEAGridContext.java b/src/main/java/org/seagrid/desktop/util/SEAGridContext.java index c82597e..c8eb5ef 100644 --- a/src/main/java/org/seagrid/desktop/util/SEAGridContext.java +++ b/src/main/java/org/seagrid/desktop/util/SEAGridContext.java @@ -220,6 +220,38 @@ public void saveUserPrefs() { } + public String getNextcloudServername() { + return SEAGridConfig.NEXTCLOUD_SERVERNAME; + } + + public String getDavBasepath() { + return SEAGridConfig.NEXTCLOUD_WEBDAV_BASEPATH; + } + + public boolean isUseHttps() { + return SEAGridConfig.IS_USE_HTTPS; + } + + public String getClientID() { + return SEAGridConfig.CLIENT_ID; + } + + public String getTokenGenerateEndpoint() { + return SEAGridConfig.TOKEN_ENDPOINT; + } + + public String getGrantType() { + return SEAGridConfig.TOKEN_GRANTYPE; + } + + public String getValidationURL() { + return SEAGridConfig.TOKEN_VALIDATION_URL; + } + + public String getBaseDownloadPath() { + return SEAGridConfig.BASE_DOWNLOAD_PATH; + } + //FIXME - There is an issue in loading file from resources. This is a temporary hack public static final String logoBase64 = "iVBORw0KGgoAAAANSUhEUgAAAdkAAACTCAMAAAD1LZOOAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5" + "ccllPAAAAGxQTFRF1PPxWMW/j9jUx+zqLbqx8fr6LrevSsC6q+LfZc3H4/X0dM/KPLy11fHvgtTPuefkZsrFnd3as+vmnODc9Pz7YM7HNsC36f" + diff --git a/src/main/resources/seagrid.properties b/src/main/resources/seagrid.properties index c1e8ead..8096d72 100644 --- a/src/main/resources/seagrid.properties +++ b/src/main/resources/seagrid.properties @@ -47,4 +47,14 @@ remote.data.dir.prefix=file://pga@seagrid.org: dev.remote.data.dir.prefix=file://pga@dev.seagrid.org: #Default file download location. If not set will be downloaded to use.dir/SEAGrid/ExperimentData -default.file.download.path= \ No newline at end of file +default.file.download.path= + +#Nextcloud configurations, Jetstream instance is specified at present +nextcloud.server=149.165.157.194 +nextcloudwebdav.base.path = remote.php/dav/files +nextcloud.client.id = http://149.165.157.194/index.php/apps/user_saml/saml/metadata +nextcloud.client.secret= +nextcloud.token.endpoint=http://149.165.157.194:8180/auth/realms/realm-nextcloud/protocol/openid-connect/token +nextcloud.grantype=password +nextcloud.tokenvalidation.api=http://149.165.157.194/checkuser.php +nextcloud.file.basedownloadpath= \ No newline at end of file From e29b5f99058876ea81119495710fdcc98041dee6 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Mon, 11 Jun 2018 21:47:29 -0400 Subject: [PATCH 02/12] Updated Changes in downloadfoldertask --- .../NextCloudFolderdownloadtask.java | 26 ++++++++++--------- .../Nextcloud/NextcloudAdapter.java | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java index 901c680..8d99f84 100644 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java @@ -11,7 +11,7 @@ public class NextCloudFolderdownloadtask extends NextcloudFileTask { private String rootpath; - private String downloadirpath = SEAGridContext.getInstance().getBaseDownloadPath(); + private String rootdownloadirpath = SEAGridContext.getInstance().getBaseDownloadPath(); /** * Constructor @@ -31,34 +31,36 @@ public class NextCloudFolderdownloadtask extends NextcloudFileTask { * @throws IOException */ public void downloadFolder(String remotepath,int depth) throws IOException { - rootpath = rootpath+remotepath ; - System.out.println(rootpath); int count = 0; String filepath; + String newrootpath = rootpath + remotepath; + String newdownloadir = rootdownloadirpath + "/" + remotepath ; + File downloadfilepathobject = new File(newdownloadir); + if(!downloadfilepathobject.exists()) { + downloadfilepathobject.mkdir(); + } + List retVal= new LinkedList<>(); List resources; try { - resources = sardine.list(rootpath, depth); + resources = sardine.list(newrootpath, depth); for (DavResource res : resources) { - //Skip the Documents folder which is listed as default as first by the sardine output + //Skip the first folder which is listed as default as first by the sardine output if (count != 0) { if (res.isDirectory()) { String filename = res.getName(); - File dir = new File(downloadirpath + "/" + filename); - dir.mkdir(); - filepath = rootpath + "/" + filename; - downloadFolder(filepath, depth); + String recursefilepath = remotepath + "/" + filename; + downloadFolder(recursefilepath, depth); } else { String filename = res.getName(); - filepath = rootpath + "/" + filename; + filepath = newrootpath + "/" + filename; retVal.add(res.getName()); InputStream in = null; - //System.out.println(filepath); if (sardine.exists(filepath)) { in = sardine.get(filepath); byte[] buffer = new byte[in.available()]; in.read(buffer); - File targetFile = new File(downloadirpath + "/" + filename); + File targetFile = new File(newdownloadir + "/" + filename); OutputStream outStream = new FileOutputStream(targetFile); outStream.write(buffer); in.close(); diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java index 9c92c6b..800b2b8 100644 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java @@ -68,7 +68,7 @@ public void downloadFolder(String path) throws IOException { try { List downloadlist= new LinkedList<>(); if(dnlfolder.AuthenticateSession()) { - dnlfolder.downloadFolder(path, 2); + dnlfolder.downloadFolder(path, 1); } } catch (IOException e) { e.printStackTrace(); From fcc9dfc29fb54961bf30eef96ee961f23572223b Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Tue, 12 Jun 2018 12:50:07 -0400 Subject: [PATCH 03/12] Added recursive folder Upload --- .../Nextcloud/NextcloudAdapter.java | 1 - .../Nextcloud/NextcloudFolderUploadTask.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java index 800b2b8..6c4bee7 100644 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java @@ -75,7 +75,6 @@ public void downloadFolder(String path) throws IOException { } } - /** * Check if the remotepath exists at the nextcloud server * diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java index 5888f02..9cf2859 100644 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java +++ b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java @@ -28,28 +28,34 @@ public void uploadFolder(String localpath, String remotepath) throws IOException String path; path = remoterootpath + remotepath; String ip = localpath; + File f = new File(ip); try { - File f = new File(ip); if (f.exists() && f.isDirectory()) { //Extract the Foldername from the path String[] segments = ip.split("/"); String foldername = segments[segments.length - 1]; - System.out.println(foldername); - path = path + "/" + foldername; - System.out.println(path); + String folderemotepath = remotepath + "/" + foldername; + //if the folder doesn't exist in the remote server then create the folder - if (!Exists(remotepath)) { - createFolder(remotepath); + if (!Exists(folderemotepath)) { + createFolder(folderemotepath); } File[] listfil = f.listFiles(); if (listfil != null) { for (File child : listfil) { - String filename = child.getName(); - String newpath = path + "/" + filename; - InputStream input = new FileInputStream(child.getAbsolutePath()); - sardine.put(newpath, input); - input.close(); + if(child.isDirectory()) { + String childfoldername = child.getName(); + String newremotepath = folderemotepath; + String newlocalpath = localpath + "/" + childfoldername; + uploadFolder(newlocalpath, newremotepath); + } else { + String filename = child.getName(); + String newpath = path + "/" + foldername + "/" + filename; + InputStream input = new FileInputStream(child.getAbsolutePath()); + sardine.put(newpath, input); + input.close(); + } } } } From 17c4f64cf59483ce881188170744d2c1ecee6a87 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 21:27:43 -0400 Subject: [PATCH 04/12] Updated the New Connector for Nextcloud in the valid Task Structure --- .../Exception/NextcloudApiException.java | 13 ++ .../NextCloudFolderdownloadtask.java | 126 ++++++++++++++++++ .../NextcloudStorage/NextcloudFileTask.java | 68 ++++++++++ .../NextcloudFileUploadTask.java | 73 ++++++++++ .../NextcloudFolderUploadTask.java | 77 +++++++++++ .../NextcloudSingleFileUploadTask.java | 64 +++++++++ .../NextcloudStorageManager.java | 95 +++++++++++++ src/main/resources/client_truststore.jks | Bin 2423 -> 0 bytes 8 files changed, 516 insertions(+) create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/Exception/NextcloudApiException.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextCloudFolderdownloadtask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileUploadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFolderUploadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java delete mode 100644 src/main/resources/client_truststore.jks diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/Exception/NextcloudApiException.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/Exception/NextcloudApiException.java new file mode 100644 index 0000000..3b95c92 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/Exception/NextcloudApiException.java @@ -0,0 +1,13 @@ +package org.seagrid.desktop.connectors.NextcloudStorage.Exception; + +public class NextcloudApiException extends RuntimeException { + private static final long serialVersionUID = 8088239559973590632L; + + public NextcloudApiException(Throwable cause) { + super(cause); + } + + public NextcloudApiException(String message) { + super(message); + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextCloudFolderdownloadtask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextCloudFolderdownloadtask.java new file mode 100644 index 0000000..c45a44e --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextCloudFolderdownloadtask.java @@ -0,0 +1,126 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import com.github.sardine.DavResource; +import com.jcraft.jsch.SftpException; +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; +import java.util.LinkedList; +import java.util.List; + +public class NextCloudFolderdownloadtask extends NextcloudFileTask { + + private final static Logger logger = LoggerFactory.getLogger(NextCloudFolderdownloadtask.class); + + private String rootpath; + private String remoteDirPath, localDirPath; + private double totalBytesRead = 0, totalSize = 0; + + public NextCloudFolderdownloadtask(String remoteDirPath, String localDirPath) throws IOException { + super(); + rootpath = (isusehttps ? "https" : "http") +"://"+servername+"/"+basepath+ "/" + SEAGridContext.getInstance().getUserName(); + this.remoteDirPath = remoteDirPath; + this.localDirPath = localDirPath; + } + + @Override + protected Boolean call() throws Exception { + calculateNextcloudTotalSize(remoteDirPath); + boolean status = downloadFolder(remoteDirPath, localDirPath); + return status; + } + + /** + * Downloads the folder at the specified remotepath to the rootdownloadirpath + * + * @param remotepath the path in the nextcloud server with respect to the specific folder + * @param rootdownloadirpath the local path in the system where the folder needs be saved + * @return + * @throws IOException + */ + + public boolean downloadFolder(String remotepath, String rootdownloadirpath) throws IOException { + int depth=1; + String newdownloadir = rootdownloadirpath; + File localDir = new File(newdownloadir); + + if(!localDir.exists()){ + localDir.mkdirs(); + } + + String rootpathnew = rootpath + remotepath ; + + int count = 0; + String filepath; + + List retVal= new LinkedList<>(); + List resources; + try { + resources = sardine.list(rootpathnew, depth); + } catch (IOException e) { + throw new NextcloudApiException(e); + } + + for (DavResource res : resources) + { + if(count != 0) { + if(res.equals(".") || res.equals("..")){ + continue; + } + + else if(res.isDirectory()) { + String subFoldername = res.getName(); + String downloadDirtosend = newdownloadir + "/" + subFoldername; + String pathToSend = remotepath + "/" + subFoldername; + downloadFolder(pathToSend,downloadDirtosend); + } + + else { + String filename = res.getName(); + filepath = rootpathnew + "/" + filename; + retVal.add(res.getName()); + InputStream in = null; + if (sardine.exists(filepath)) { + in = sardine.get(filepath); + byte[] buffer = new byte[in.available()]; + File targetFile = new File(newdownloadir + "/" + filename); + OutputStream outStream = new FileOutputStream(targetFile); + int bytesRead = -1; + while ((bytesRead = in.read(buffer)) != -1) { + outStream.write(buffer); + totalBytesRead += bytesRead; + updateMessage("Downloaded " + totalBytesRead + " bytes"); + updateProgress(totalBytesRead, totalSize); + } + in.close(); + outStream.close(); + } + } + } + count ++; + } + return true; + } + + private void calculateNextcloudTotalSize(String remoteDirPath) throws SftpException, IOException { + List davResource = listDirectories(remoteDirPath); + int count = 0; + for (DavResource res : davResource) { + if(count != 0) { + if (res.getName().equals(".") || res.getName().equals("..")) { + continue; + } + if (res.isDirectory()) { + String tempRemoteDir = remoteDirPath + "/" + res.getName(); + calculateNextcloudTotalSize(tempRemoteDir); + } else { + totalSize += res.getContentLength().intValue(); + } + } + count++; + } + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java new file mode 100644 index 0000000..f0f3a43 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java @@ -0,0 +1,68 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import com.github.sardine.DavResource; +import com.github.sardine.Sardine; +import com.github.sardine.SardineFactory; +import javafx.concurrent.Task; +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.connectors.Nextcloud.ValidateTokenTask; +import org.seagrid.desktop.util.SEAGridContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +public abstract class NextcloudFileTask extends Task { + private final static Logger logger = LoggerFactory.getLogger(org.seagrid.desktop.connectors.Nextcloud.NextcloudFileTask.class); + + protected Sardine sardine = SardineFactory.begin(); + + protected String servername; + protected String basepath; + protected boolean isusehttps; + private String token; + private String rootremotepath; + + public NextcloudFileTask() throws IOException { + servername = SEAGridContext.getInstance().getNextcloudServername(); + basepath = SEAGridContext.getInstance().getDavBasepath(); + isusehttps = SEAGridContext.getInstance().isUseHttps(); + rootremotepath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); + token = SEAGridContext.getInstance().getOAuthToken(); + sardine.setCredentials(SEAGridContext.getInstance().getUserName(), SEAGridContext.getInstance().getClientID()); + sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); + } + + /** + * Create the folder at the specified path + * @param remotepath + */ + public void createFolder(String remotepath){ + String path= rootremotepath+remotepath; + + try { + sardine.createDirectory(path); + } catch (IOException e) { + throw new NextcloudApiException(e); + } + } + + public List listDirectories(String remotepath) throws IOException { + String path = rootremotepath + remotepath; + List resources; + if(sardine.exists(path)) { + try { + resources = sardine.list(path, 1); + return resources; + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } +} + + diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileUploadTask.java new file mode 100644 index 0000000..e0a0052 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileUploadTask.java @@ -0,0 +1,73 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.*; +import java.util.Map; + +public class NextcloudFileUploadTask extends NextcloudFileTask { + + private String remoterootpath; + private Map uploadFiles; + /** + * Constructor + */ + public NextcloudFileUploadTask(Map uploadFiles) throws IOException { + super(); + this.uploadFiles = uploadFiles; + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); + } + + @Override + protected Boolean call() throws Exception { + return uploadToNextcloud(); + } + + public boolean uploadToNextcloud() throws IOException { + for(String remoteFilePath : uploadFiles.keySet()){ + int numberOfFiles = uploadFiles.size(); + int index = 1; + remoteFilePath = remoteFilePath.replace("\\","/"); + File localFile = uploadFiles.get(remoteFilePath); + String localpath = localFile.getPath(); + String remotepath = remoteFilePath; + boolean status = false; + InputStream inputStream = new FileInputStream(localpath); + String path; + try { + //createpath if not exists + String[] segments = remotepath.split("/"); + String appendpath=""; + for(int i = 1; i < segments.length - 1 ; i++) + { + appendpath = appendpath + "/" + segments[i]; + if(!sardine.exists(remoterootpath + "/" + appendpath)) { + createFolder(appendpath); + } + } + path = remoterootpath + remotepath; + long fileSize = localFile.length(); + byte[] buffer = new byte[inputStream.available()]; + int bytesRead = -1; + int totalBytesRead = 0; + double percentCompleted = 0; + while ((bytesRead = inputStream.read(buffer)) != -1) { + totalBytesRead += bytesRead; + sardine.put(path, buffer); + percentCompleted = ((double)totalBytesRead) / fileSize * index / numberOfFiles; + updateMessage("Uploaded " + totalBytesRead + " bytes"); + updateProgress(percentCompleted, 1); + } + status = true; + } catch (IOException e) { + throw new NextcloudApiException(e); + } finally { + inputStream.close(); + return status; + } + } + return true; + } + +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFolderUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFolderUploadTask.java new file mode 100644 index 0000000..98978c6 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFolderUploadTask.java @@ -0,0 +1,77 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NextcloudFolderUploadTask extends NextcloudFileTask { + + private String remoterootpath; + private String remoteDirPath, localDirPath; + + public NextcloudFolderUploadTask(String remoteDirPath, String localDirPath) throws IOException { + super(); + this.remoteDirPath = remoteDirPath; + this.localDirPath = localDirPath; + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); + } + + @Override + protected Boolean call() throws Exception { + return uploadFolder(localDirPath, remoteDirPath); + } + + /** + * Upload the folder at the specified path, if the folder doesn't exist a new folder with + * the specific foldername is created + * + * @param localpath + * @param remotepath + * @throws IOException + */ + public Boolean uploadFolder(String localpath, String remotepath) throws IOException { + String path; + path = remoterootpath + remotepath; + String ip = localpath; + File f = new File(ip); + try { + if (f.exists() && f.isDirectory()) { + //Extract the Foldername from the path + String[] segments = ip.split("/"); + String foldername = segments[segments.length - 1]; + String folderemotepath = remotepath + "/" + foldername; + String checkpath = remoterootpath + "/" + folderemotepath; + + //if the folder doesn't exist in the remote server then create the folder + if (!sardine.exists(checkpath)) { + createFolder(folderemotepath); + } + + File[] listfil = f.listFiles(); + if (listfil != null) { + for (File child : listfil) { + if(child.isDirectory()) { + String childfoldername = child.getName(); + String newremotepath = folderemotepath; + String newlocalpath = localpath + "/" + childfoldername; + uploadFolder(newlocalpath, newremotepath); + } else { + String filename = child.getName(); + String newpath = path + "/" + foldername + "/" + filename; + InputStream input = new FileInputStream(child.getAbsolutePath()); + sardine.put(newpath, input); + input.close(); + } + } + } + } + } catch (IOException e) { + throw new NextcloudApiException(e); + } + return true; + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java new file mode 100644 index 0000000..5e9bdc5 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java @@ -0,0 +1,64 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.connectors.storage.GuiFileUploadTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +public class NextcloudSingleFileUploadTask extends NextcloudFileTask{ + + private final static Logger logger = LoggerFactory.getLogger(NextcloudSingleFileUploadTask.class); + + private String remoteFilePath, localFilePath; + private String remoterootpath; + + public NextcloudSingleFileUploadTask(String remoteFilePath, String localFilePath) throws IOException { + super(); + this.remoteFilePath = remoteFilePath; + this.localFilePath = localFilePath; + } + + + @Override + protected Boolean call() throws Exception { + return uploadFile(remoteFilePath, localFilePath); + } + + /** + * Upload the inputstream to the remote file path as specified to the nextcloud server + * + * @param localpath + * @param remotepath + * @throws IOException + * + */ + protected boolean uploadFile(String localpath, String remotepath) throws IOException { + boolean status = false; + InputStream inputStream = new FileInputStream(localpath); + String path; + try { + //createpath if not exists + String[] segments = remotepath.split("/"); + String appendpath=""; + for(int i = 1; i < segments.length - 1 ; i++) + { + appendpath = appendpath + "/" + segments[i]; + if(!sardine.exists(remoterootpath + "/" + appendpath)) { + createFolder(appendpath); + } + } + path = remoterootpath + remotepath; + sardine.put(path, inputStream); + status = true; + } catch (IOException e) { + throw new NextcloudApiException(e); + } finally { + inputStream.close(); + return status; + } + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java new file mode 100644 index 0000000..81f7a49 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java @@ -0,0 +1,95 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import com.github.sardine.DavResource; +import com.github.sardine.Sardine; +import com.github.sardine.SardineFactory; +import com.jcraft.jsch.JSchException; +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.util.SEAGridContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; + +public class NextcloudStorageManager { + private final static Logger logger = LoggerFactory.getLogger(NextcloudStorageManager.class); + + private static NextcloudStorageManager instance; + + protected Sardine sardine = SardineFactory.begin(); + + private String servername; + private String basepath; + private boolean isusehttps; + private String token; + private String rootremotepath; + + public NextcloudStorageManager() throws IOException, JSchException { + connect(); + } + + private void connect() throws JSchException, IOException { + servername = SEAGridContext.getInstance().getNextcloudServername(); + basepath = SEAGridContext.getInstance().getDavBasepath(); + isusehttps = SEAGridContext.getInstance().isUseHttps(); + rootremotepath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); + token = SEAGridContext.getInstance().getOAuthToken(); + sardine.setCredentials(SEAGridContext.getInstance().getUserName(), SEAGridContext.getInstance().getClientID()); + sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); + } + + public static NextcloudStorageManager getInstance() throws JSchException, IOException { + if(instance==null) { + instance = new NextcloudStorageManager(); + } + return instance; + } + + public List listDirectories(String remotepath) throws IOException { + String path = rootremotepath + remotepath; + List resources; + if(sardine.exists(path)) { + try { + resources = sardine.list(path, 1); + return resources; + } catch (IOException e) { + e.printStackTrace(); + } + } + return null; + } + + /** + * Creates the folder if the folder is not present at the remote path of the nextcloud storage + * @param remotepath + * @throws IOException + */ + public void createFolderifNotExist(String remotepath) throws IOException { + String[] segments = remotepath.split("/"); + + String tempath = ""; + for (int i = 1; i < segments.length; i++) { + tempath = tempath + "/" + segments[i]; + String path = rootremotepath + tempath; + if (!sardine.exists(path)) { + createFolder(tempath); + } + } + } + + /** + * Create the folder at the specified path + * @param remotepath + */ + public void createFolder(String remotepath) + { + String path= rootremotepath+remotepath; + + try { + sardine.createDirectory(path); + } catch (IOException e) { + throw new NextcloudApiException(e); + } + } +} diff --git a/src/main/resources/client_truststore.jks b/src/main/resources/client_truststore.jks deleted file mode 100644 index 21e4e624b22d77d0c7cf9321786c53c3365c0789..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2423 zcmezO_TO6u1_mY|W(Lz-<;D3%$%#ct`FRWsjDA_q?glfkM(CLuSOQg98Z8gPTexp-K@gZ+&Rg$x8hTxK55oc!d(oQ(Y95(7DL zUPA)|BST9Aa|0tIvnX+1V^bj47|NxUwT<(U{m014z}(o&V9?mf)Y!-{W%)1BYhUMl z{_@08qhYU=-i9;hjN8_*XDr>ecY;>W^X_R=#on8KIOV51N&CZQb$`>PQ)a)<;0t76 z&&+X{{kxyFcSGDIX}Q45m2z|R=hPpLJ{D7u{p5L(mDR4@EgRNfo%nXggB6oFivO^@ zZdZQwlT+95>vLB<_B9JT{cWN+k6K$YF*7nSE(Qjc0Ut29Wce8x|Ff_#GqHR?b}}$Z zn1ODMp2P3HUHi%g+0~D<-TRcBLfoFT97-*-ZRzDd#dQAG#sg;Z{fS?m9o^kGUz1l_ z!{GUMOL^TiPfszzUA7HcWcfHyKFzH zeb<>m^;hD~%&Z7y!R^b9`@>2jzn;~+?zWvvJ9XP-r+m>(JF0)be;FHm)g($Ck{=rH z7&P8AkOk!kJ{B<+k+pkgRGDm1`~K^QTF86my$@7Qhe&~o8(Dr(Zee6I;0LJ{2IU@B z17;v)&^Qw$qRi4b(V(%f0jmiMi}@+1CfY?J0X z&X{wvrLys+T(k(gvRP{Xh8yL(*Er_5Co~6c_-SPO{LeQv;o}WrOZP|pX+K|4*{L|| zkqr7cWdzz?!QJm{aaUYp(PNc?0CIMdb5$AZM%)?Ff@m9>FyqUb=@pxMwLa95t*Iup2V|yo!!Acb8m#O z{%4!``S~+^C;v!zdD|;uo|9o_BiZZ_DQ@?_+rq6y&{|4RU55-IuU!eqEP*=mJ;8KR={{{P$%WZoZs1 zC4S5Qs}e0;Mhnr2=h2I>LE<3SW*dOT!06io;_W%F@ From 242893fc2f92186ca7ac3d42c0201b72f602cf76 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 22:17:31 -0400 Subject: [PATCH 05/12] Updated changes in the NextcloudStorage Connector --- src/main/resources/client_truststore.jks | Bin 0 -> 2423 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/client_truststore.jks diff --git a/src/main/resources/client_truststore.jks b/src/main/resources/client_truststore.jks new file mode 100644 index 0000000000000000000000000000000000000000..21e4e624b22d77d0c7cf9321786c53c3365c0789 GIT binary patch literal 2423 zcmezO_TO6u1_mY|W(Lz-<;D3%$%#ct`FRWsjDA_q?glfkM(CLuSOQg98Z8gPTexp-K@gZ+&Rg$x8hTxK55oc!d(oQ(Y95(7DL zUPA)|BST9Aa|0tIvnX+1V^bj47|NxUwT<(U{m014z}(o&V9?mf)Y!-{W%)1BYhUMl z{_@08qhYU=-i9;hjN8_*XDr>ecY;>W^X_R=#on8KIOV51N&CZQb$`>PQ)a)<;0t76 z&&+X{{kxyFcSGDIX}Q45m2z|R=hPpLJ{D7u{p5L(mDR4@EgRNfo%nXggB6oFivO^@ zZdZQwlT+95>vLB<_B9JT{cWN+k6K$YF*7nSE(Qjc0Ut29Wce8x|Ff_#GqHR?b}}$Z zn1ODMp2P3HUHi%g+0~D<-TRcBLfoFT97-*-ZRzDd#dQAG#sg;Z{fS?m9o^kGUz1l_ z!{GUMOL^TiPfszzUA7HcWcfHyKFzH zeb<>m^;hD~%&Z7y!R^b9`@>2jzn;~+?zWvvJ9XP-r+m>(JF0)be;FHm)g($Ck{=rH z7&P8AkOk!kJ{B<+k+pkgRGDm1`~K^QTF86my$@7Qhe&~o8(Dr(Zee6I;0LJ{2IU@B z17;v)&^Qw$qRi4b(V(%f0jmiMi}@+1CfY?J0X z&X{wvrLys+T(k(gvRP{Xh8yL(*Er_5Co~6c_-SPO{LeQv;o}WrOZP|pX+K|4*{L|| zkqr7cWdzz?!QJm{aaUYp(PNc?0CIMdb5$AZM%)?Ff@m9>FyqUb=@pxMwLa95t*Iup2V|yo!!Acb8m#O z{%4!``S~+^C;v!zdD|;uo|9o_BiZZ_DQ@?_+rq6y&{|4RU55-IuU!eqEP*=mJ;8KR={{{P$%WZoZs1 zC4S5Qs}e0;Mhnr2=h2I>LE<3SW*dOT!06io;_W%F@ literal 0 HcmV?d00001 From fa0831289e8b3c2af563ec81bfb4436fb309add2 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 22:54:41 -0400 Subject: [PATCH 06/12] Updated NextcloudStorage Classes --- .../NextcloudAuth/ValidateTokenTask.java | 63 +++++++++++++++++++ .../NextcloudFileDownloadTask.java | 50 +++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java create mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java new file mode 100644 index 0000000..3731dc4 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java @@ -0,0 +1,63 @@ +package org.seagrid.desktop.connectors.NextcloudAuth; + +import org.json.JSONObject; +import org.seagrid.desktop.util.SEAGridContext; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; +import java.util.LinkedHashMap; +import java.util.Map; + +public class ValidateTokenTask { + + /** + * Returns 200 status if the token is successfully validated. + * + * @param token + * @return + * @throws IOException + */ + public int ValidateToken(String token) throws IOException { + URL url = null; + try { + url = new URL(SEAGridContext.getInstance().getValidationURL()); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + Map params = new LinkedHashMap<>(); + params.put("username", SEAGridContext.getInstance().getUserName()); + params.put("token", token); + StringBuilder postData = new StringBuilder(); + for (Map.Entry param : params.entrySet()) { + if (postData.length() != 0) postData.append('&'); + try { + postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); + postData.append('='); + postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + + byte[] postDataBytes = postData.toString().getBytes("UTF-8"); + HttpURLConnection conn = (HttpURLConnection)url.openConnection(); + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); + conn.setDoOutput(true); + conn.getOutputStream().write(postDataBytes); + Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); + StringBuilder sb = new StringBuilder(); + for (int c; (c = in.read()) >= 0;) + sb.append((char)c); + String response = sb.toString(); + System.out.println(response); + JSONObject myResponse = new JSONObject(response.toString()); + String responseString = myResponse.get("status").toString(); + int responseInteger = Integer.parseInt(responseString); + return responseInteger; + } +} diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java new file mode 100644 index 0000000..b91eb41 --- /dev/null +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java @@ -0,0 +1,50 @@ +package org.seagrid.desktop.connectors.NextcloudStorage; + +import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; +import org.seagrid.desktop.connectors.storage.GuiFileDownloadTask; +import org.seagrid.desktop.util.SEAGridContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.*; + +public class NextcloudFileDownloadTask extends NextcloudFileTask { + + private final static Logger logger = LoggerFactory.getLogger(GuiFileDownloadTask.class); + + private String remoteFilePath, localFilePath; + private String remoterootpath; + + public NextcloudFileDownloadTask(String remoteFilePath, String localFilePath) throws IOException { + super(); + this.remoteFilePath = remoteFilePath; + this.localFilePath = localFilePath; + remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); + } + + @Override + protected Boolean call() throws Exception { + return downloadFile(localFilePath, remoteFilePath); + } + + public boolean downloadFile(String sourceFile, String destFile) { + String path = remoterootpath + destFile; + File downloadFilepath = new File(sourceFile); + if(!downloadFilepath.getParentFile().exists()) { + downloadFilepath.getParentFile().mkdirs(); + } + try { + InputStream in = sardine.get(path); + byte[] buffer = new byte[in.available()]; + in.read(buffer); + File targetFile = new File(sourceFile); + OutputStream outStream = new FileOutputStream(targetFile); + outStream.write(buffer); + outStream.close(); + in.close(); + return true; + } catch (IOException e) { + throw new NextcloudApiException(e); + } + } +} From a87514b905a209559edee964660e6e231b99f621 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 22:59:33 -0400 Subject: [PATCH 07/12] Deleted Old Nextcloud connector --- .../Exception/NextcloudApiException.java | 13 --- .../Nextcloud/GenerateTokenTask.java | 75 --------------- .../NextCloudFolderdownloadtask.java | 78 ---------------- .../Nextcloud/NextcloudAdapter.java | 92 ------------------- .../Nextcloud/NextcloudFileDownloadTask.java | 56 ----------- .../Nextcloud/NextcloudFileTask.java | 68 -------------- .../Nextcloud/NextcloudFileUploadTask.java | 45 --------- .../Nextcloud/NextcloudFolderUploadTask.java | 81 ---------------- .../Nextcloud/ValidateTokenTask.java | 61 ------------ 9 files changed, 569 deletions(-) delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java delete mode 100644 src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java deleted file mode 100644 index fa24f03..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/Exception/NextcloudApiException.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud.Exception; - -public class NextcloudApiException extends RuntimeException { - private static final long serialVersionUID = 8088239559973590632L; - - public NextcloudApiException(Throwable cause) { - super(cause); - } - - public NextcloudApiException(String message) { - super(message); - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java deleted file mode 100644 index 2c40d26..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/GenerateTokenTask.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import org.json.JSONObject; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.util.LinkedHashMap; -import java.util.Map; - -public class GenerateTokenTask { - - private String client_id; - private String username; - private String password; - private String tokenendpoint; - private String grant_type; - private String client_secret; - - GenerateTokenTask() { - client_id = SEAGridContext.getInstance().getClientID(); - username = SEAGridContext.getInstance().getUserName(); - //Still need to work on this - password = "embedpassword"; - tokenendpoint = SEAGridContext.getInstance().getTokenGenerateEndpoint(); - grant_type = SEAGridContext.getInstance().getGrantType(); - } - - /** - * Generates the token and returns the access_token if the user credentials are valid - * - * @return String - * @throws IOException - */ - public String generateToken() throws IOException { - String access_token; - URL url = new URL(tokenendpoint); - Map params = new LinkedHashMap<>(); - params.put("client_id", client_id); - params.put("username", username); - //Need to check this and work on getting the password as it is required to generate the token - params.put("password", password); - params.put("grant_type", grant_type); - //Need to find a better way to emebed the client-secret - params.put("client_secret",client_secret); - StringBuilder postData = new StringBuilder(); - for (Map.Entry param : params.entrySet()) { - if (postData.length() != 0) postData.append('&'); - postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); - postData.append('='); - postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); - - } - byte[] postDataBytes = postData.toString().getBytes("UTF-8"); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - conn.setDoOutput(true); - conn.getOutputStream().write(postDataBytes); - Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - StringBuilder sb = new StringBuilder(); - for (int c; (c = in.read()) >= 0;) - sb.append((char)c); - String response = sb.toString(); - JSONObject myResponse = new JSONObject(response.toString()); - access_token = myResponse.getString("access_token"); - return access_token; - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java deleted file mode 100644 index 8d99f84..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextCloudFolderdownloadtask.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import com.github.sardine.DavResource; -import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.*; -import java.util.LinkedList; -import java.util.List; - -public class NextCloudFolderdownloadtask extends NextcloudFileTask { - - private String rootpath; - private String rootdownloadirpath = SEAGridContext.getInstance().getBaseDownloadPath(); - - /** - * Constructor - */ - NextCloudFolderdownloadtask() { - super(); - rootpath = (isusehttps ? "https" : "http") +"://"+servername+"/"+basepath+SEAGridContext.getInstance().getUserName(); - - } - - /** - * Downloads all the files inside the folder at the specified path - * - * @param remotepath - * @param depth - * @return - * @throws IOException - */ - public void downloadFolder(String remotepath,int depth) throws IOException { - int count = 0; - String filepath; - String newrootpath = rootpath + remotepath; - String newdownloadir = rootdownloadirpath + "/" + remotepath ; - File downloadfilepathobject = new File(newdownloadir); - if(!downloadfilepathobject.exists()) { - downloadfilepathobject.mkdir(); - } - - List retVal= new LinkedList<>(); - List resources; - try { - resources = sardine.list(newrootpath, depth); - for (DavResource res : resources) { - //Skip the first folder which is listed as default as first by the sardine output - if (count != 0) { - if (res.isDirectory()) { - String filename = res.getName(); - String recursefilepath = remotepath + "/" + filename; - downloadFolder(recursefilepath, depth); - } else { - String filename = res.getName(); - filepath = newrootpath + "/" + filename; - retVal.add(res.getName()); - InputStream in = null; - if (sardine.exists(filepath)) { - in = sardine.get(filepath); - byte[] buffer = new byte[in.available()]; - in.read(buffer); - File targetFile = new File(newdownloadir + "/" + filename); - OutputStream outStream = new FileOutputStream(targetFile); - outStream.write(buffer); - in.close(); - outStream.close(); - } - } - } - count++; - } - } catch (IOException e) { - throw new NextcloudApiException(e); - } - } - -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java deleted file mode 100644 index 6c4bee7..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -public class NextcloudAdapter { - private final NextcloudFileUploadTask uplfile; - private final NextcloudFileDownloadTask dnlfile; - private final NextCloudFolderdownloadtask dnlfolder; - - /** - * Constructor - */ - public NextcloudAdapter() { - uplfile = new NextcloudFileUploadTask(); - dnlfile = new NextcloudFileDownloadTask(); - dnlfolder = new NextCloudFolderdownloadtask(); - } - - /** - *Upload the file to the remote path of the nextcloud server - * - * @param localpath - * @param remotepath - * @return boolean - * - * Reference: https://github.com/a-schild/nextcloud-java-api - */ - public boolean UploadFile(String localpath, String remotepath) { - boolean status=false; - try { - if(uplfile.AuthenticateSession()) { - status = uplfile.UploadFile(localpath, remotepath); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - return status; - } - } - - /** - * Download the file from the remotepath to the download path specified - * - * @param remotepath - * @return boolean - */ - public boolean downloadFile(String remotepath) { - boolean status = false; - try { - if(dnlfile.AuthenticateSession()) { - status = dnlfile.downloadFile(remotepath); - } - } catch (IOException e) { - e.printStackTrace(); - } finally { - return status; - } - } - - /** - * Downloads all the files at the specified folder of the remote server - * @param path - * @throws IOException - */ - public void downloadFolder(String path) throws IOException { - try { - List downloadlist= new LinkedList<>(); - if(dnlfolder.AuthenticateSession()) { - dnlfolder.downloadFolder(path, 1); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Check if the remotepath exists at the nextcloud server - * - * @param rootpath - * @return - * - * Reference: https://github.com/a-schild/nextcloud-java-api - */ - public boolean Exists(String rootpath) { - if(uplfile.Exists(rootpath)) { - return true; - } - return false; - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java deleted file mode 100644 index c623a6d..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileDownloadTask.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.*; - -public class NextcloudFileDownloadTask extends NextcloudFileTask { - - private String remoterootpath; - private String downloadirpath; - NextcloudFileDownloadTask() { - super(); - remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); - downloadirpath = SEAGridContext.getInstance().getBaseDownloadPath() + SEAGridContext.getInstance().getUserName(); - } - - /** - * Download the file from the remote nextcloud server using the remotepath to the specified directory - * - * @param remotepath - * @return - * @throws IOException - */ - public boolean downloadFile(String remotepath) throws IOException { - boolean status=false; - String path = remoterootpath + remotepath; - InputStream in = null; - if(Exists(remotepath)) { - //Extract the Filename from the path - String[] segments = path.split("/"); - String filename = segments[segments.length - 1]; - downloadirpath = downloadirpath + "/" + filename; - } - try { - in = sardine.get(path); - byte[] buffer = new byte[in.available()]; - in.read(buffer); - File targetFile = new File(downloadirpath); - OutputStream outStream = new FileOutputStream(targetFile); - outStream.write(buffer); - outStream.close(); - status = true; - } catch (IOException e) { - throw new NextcloudApiException(e); - } finally { - sardine.shutdown(); - in.close(); - return status; - } - } - - - - -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java deleted file mode 100644 index 1f0350e..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileTask.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import com.github.sardine.Sardine; -import com.github.sardine.SardineFactory; -import org.seagrid.desktop.util.SEAGridContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -public class NextcloudFileTask { - private final static Logger logger = LoggerFactory.getLogger(NextcloudFileTask.class); - - protected Sardine sardine = SardineFactory.begin(); - - protected String servername; - protected String basepath; - protected boolean isusehttps; - private String token; - - /** - * Constructor - */ - NextcloudFileTask() { - servername = SEAGridContext.getInstance().getNextcloudServername(); - basepath = SEAGridContext.getInstance().getDavBasepath(); - isusehttps = SEAGridContext.getInstance().isUseHttps(); - } - - /** - *Authenticate the session with the token and set the credentials to login - * - * @return boolean if the session is authenticated returns true - * @throws IOException - */ - public boolean AuthenticateSession() throws IOException { - GenerateTokenTask t1 = new GenerateTokenTask(); - token = t1.generateToken(); - ValidateTokenTask t2 = new ValidateTokenTask(); - if(t2.ValidateToken(token) == "200") { - sardine.setCredentials(SEAGridContext.getInstance().getUserName(), token); - sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); - return true; - } - return false; - } - - /** - * method to check if a file/folder is already present in the remote path - * - * @param rootpath of the file (full path) - * @return boolean value is returned depending on the existance of the file - * - * Reference: https://github.com/a-schild/nextcloud-java-api - */ - - public boolean Exists(String rootpath){ - String path = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName() + rootpath; - try { - if(sardine.exists(rootpath)) { - return true; - } - } catch (IOException e) { - e.printStackTrace(); - } - return false; - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java deleted file mode 100644 index d105313..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFileUploadTask.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -public class NextcloudFileUploadTask extends NextcloudFileTask { - - private String remoterootpath; - /** - * Constructor - */ - NextcloudFileUploadTask() { - super(); - remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); - } - - /** - * Upload the inputstream to the remote file path as specified to the nextcloud server - * - * @param localpath - * @param remotepath - * @throws IOException - * - * Reference: https://github.com/a-schild/nextcloud-java-api - */ - protected boolean UploadFile(String localpath, String remotepath) throws IOException { - boolean status = false; - InputStream inputStream = new FileInputStream(localpath); - String path; - try { - path = remoterootpath + remotepath; - sardine.put(path, inputStream); - status = true; - } catch (IOException e) { - throw new NextcloudApiException(e); - } finally { - inputStream.close(); - return status; - } - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java deleted file mode 100644 index 9cf2859..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/NextcloudFolderUploadTask.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import org.seagrid.desktop.connectors.Nextcloud.Exception.NextcloudApiException; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -public class NextcloudFolderUploadTask extends NextcloudFileTask { - - private String remoterootpath; - NextcloudFolderUploadTask() { - super(); - remoterootpath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + SEAGridContext.getInstance().getUserName(); - } - - /** - * Create the folder at the specified path, if the folder doesn't exist a new folder with - * the specific foldername is created - * - * @param localpath - * @param remotepath - * @throws IOException - */ - public void uploadFolder(String localpath, String remotepath) throws IOException { - String path; - path = remoterootpath + remotepath; - String ip = localpath; - File f = new File(ip); - try { - if (f.exists() && f.isDirectory()) { - //Extract the Foldername from the path - String[] segments = ip.split("/"); - String foldername = segments[segments.length - 1]; - String folderemotepath = remotepath + "/" + foldername; - - //if the folder doesn't exist in the remote server then create the folder - if (!Exists(folderemotepath)) { - createFolder(folderemotepath); - } - - File[] listfil = f.listFiles(); - if (listfil != null) { - for (File child : listfil) { - if(child.isDirectory()) { - String childfoldername = child.getName(); - String newremotepath = folderemotepath; - String newlocalpath = localpath + "/" + childfoldername; - uploadFolder(newlocalpath, newremotepath); - } else { - String filename = child.getName(); - String newpath = path + "/" + foldername + "/" + filename; - InputStream input = new FileInputStream(child.getAbsolutePath()); - sardine.put(newpath, input); - input.close(); - } - } - } - } - } catch (IOException e) { - throw new NextcloudApiException(e); - } - - } - - /** - * Create the folder at the specified path - * @param remotepath - */ - public void createFolder(String remotepath) - { - String path= remoterootpath+remotepath; - try { - sardine.createDirectory(path); - } catch (IOException e) { - throw new NextcloudApiException(e); - } - } -} diff --git a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java deleted file mode 100644 index aa15518..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/Nextcloud/ValidateTokenTask.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.seagrid.desktop.connectors.Nextcloud; - -import org.json.JSONObject; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.LinkedHashMap; -import java.util.Map; - -public class ValidateTokenTask { - - /** - * Returns 200 status if the token is successfully validated. - * - * @param token - * @return - * @throws IOException - */ - public String ValidateToken(String token) throws IOException { - URL url = null; - try { - url = new URL(SEAGridContext.getInstance().getValidationURL()); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - Map params = new LinkedHashMap<>(); - params.put("username", SEAGridContext.getInstance().getUserName()); - params.put("token", token); - StringBuilder postData = new StringBuilder(); - for (Map.Entry param : params.entrySet()) { - if (postData.length() != 0) postData.append('&'); - try { - postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); - postData.append('='); - postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - byte[] postDataBytes = postData.toString().getBytes("UTF-8"); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - conn.setDoOutput(true); - conn.getOutputStream().write(postDataBytes); - Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - StringBuilder sb = new StringBuilder(); - for (int c; (c = in.read()) >= 0;) - sb.append((char)c); - String response = sb.toString(); - System.out.println(response); - JSONObject myResponse = new JSONObject(response.toString()); - return myResponse.get("status").toString(); - } -} From a42367b3dde583a98bde93f4b840c78c3ed57779 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 23:00:32 -0400 Subject: [PATCH 08/12] Deleted NextcloudAuth --- .../NextcloudAuth/ValidateTokenTask.java | 63 ------------------- 1 file changed, 63 deletions(-) delete mode 100644 src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java deleted file mode 100644 index 3731dc4..0000000 --- a/src/main/java/org/seagrid/desktop/connectors/NextcloudAuth/ValidateTokenTask.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.seagrid.desktop.connectors.NextcloudAuth; - -import org.json.JSONObject; -import org.seagrid.desktop.util.SEAGridContext; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.LinkedHashMap; -import java.util.Map; - -public class ValidateTokenTask { - - /** - * Returns 200 status if the token is successfully validated. - * - * @param token - * @return - * @throws IOException - */ - public int ValidateToken(String token) throws IOException { - URL url = null; - try { - url = new URL(SEAGridContext.getInstance().getValidationURL()); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - Map params = new LinkedHashMap<>(); - params.put("username", SEAGridContext.getInstance().getUserName()); - params.put("token", token); - StringBuilder postData = new StringBuilder(); - for (Map.Entry param : params.entrySet()) { - if (postData.length() != 0) postData.append('&'); - try { - postData.append(URLEncoder.encode(String.valueOf(param.getKey()), "UTF-8")); - postData.append('='); - postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - } - - byte[] postDataBytes = postData.toString().getBytes("UTF-8"); - HttpURLConnection conn = (HttpURLConnection)url.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - conn.setDoOutput(true); - conn.getOutputStream().write(postDataBytes); - Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); - StringBuilder sb = new StringBuilder(); - for (int c; (c = in.read()) >= 0;) - sb.append((char)c); - String response = sb.toString(); - System.out.println(response); - JSONObject myResponse = new JSONObject(response.toString()); - String responseString = myResponse.get("status").toString(); - int responseInteger = Integer.parseInt(responseString); - return responseInteger; - } -} From 44ed5d29a0967b25f287cc2fae2835bded60094a Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 23:03:04 -0400 Subject: [PATCH 09/12] Updated Changes to connect the NextcloudStorage --- .../ExperimentCreateController.java | 36 ++++++--- .../RemoteFilePickerController.java | 31 +++++--- .../ExperimentSummaryController.java | 37 +++++++-- .../MassStorageBrowserController.java | 78 +++++++++++++------ 4 files changed, 130 insertions(+), 52 deletions(-) diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java index fb83fbf..c487a71 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java @@ -52,9 +52,9 @@ import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.workspace.Project; import org.apache.thrift.TException; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudFileDownloadTask; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudFileUploadTask; import org.seagrid.desktop.connectors.airavata.AiravataManager; -import org.seagrid.desktop.connectors.storage.GuiBulkFileUploadTask; -import org.seagrid.desktop.connectors.storage.GuiFileDownloadTask; import org.seagrid.desktop.ui.commons.ImageButton; import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.seagrid.desktop.util.SEAGridContext; @@ -65,10 +65,7 @@ import org.slf4j.LoggerFactory; import java.awt.*; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Path; @@ -243,6 +240,8 @@ public ApplicationInterfaceDescription fromString(String string) { createExperiment(false); } catch (TException e) { SEAGridDialogHelper.showExceptionDialog(e,"Caught Exception",null, "Unable to create experiment"); + } catch (IOException e) { + e.printStackTrace(); } }); @@ -251,6 +250,8 @@ public ApplicationInterfaceDescription fromString(String string) { createExperiment(true); } catch (TException e) { SEAGridDialogHelper.showExceptionDialog(e, "Caught Exception", null, "Unable to create experiment"); + } catch (IOException e) { + e.printStackTrace(); } }); @@ -796,13 +797,18 @@ private String showSelectRemoteFile() throws IOException { return controller.getSelectedFilePath(); } - private void createExperiment(boolean launch) throws TException { + private void createExperiment(boolean launch) throws TException, IOException { if(validateExperimentFields()){ //FIXME Hardcoded value String projectId = ((Project)expCreateProjField.getSelectionModel().getSelectedItem()).getProjectID(); String randomString = projectId.substring(0,projectId.length()-37).replaceAll("[^A-Za-z0-9 ]", "_") + "/" + expCreateNameField.getText().replaceAll("[^A-Za-z0-9]","_")+"."+System.currentTimeMillis(); String remoteDataDir = SEAGridContext.getInstance().getRemoteDataDirPrefix() + remoteDataDirRoot + randomString + "/"; + + String downlfile = "CreateExperimentLog.txt"; + BufferedWriter writer3 = new BufferedWriter(new FileWriter(downlfile)); + writer3.write("\nRemote Data Directory "+remoteDataDir); + writer3.close(); ExperimentModel experimentModel = assembleExperiment(remoteDataDir, randomString + "/"); Map uploadFiles = new HashMap<>(); for(Iterator> it = experimentInputs.entrySet().iterator(); it.hasNext(); ) { @@ -868,6 +874,7 @@ private void createExperiment(ExperimentModel experimentModel, boolean launch){ } private ExperimentModel assembleExperiment(String remoteDataDir, String experimentDataDir) throws TException { + ExperimentModel experimentModel = new ExperimentModel(); experimentModel.setExperimentName(expCreateNameField.getText()); experimentModel.setDescription(expCreateDescField.getText() == null ? "" : expCreateDescField.getText()); @@ -888,6 +895,7 @@ private ExperimentModel assembleExperiment(String remoteDataDir, String experime userConfigurationDataModel.setAiravataAutoSchedule(false); userConfigurationDataModel.setOverrideManualScheduledParams(false); userConfigurationDataModel.setStorageId(SEAGridContext.getInstance().getGatewayaStorageId()); + userConfigurationDataModel.setExperimentDataDir(remoteDataDirRoot + experimentDataDir); userConfigurationDataModel.setUseUserCRPref(useMyCRAccount.isSelected()); @@ -1026,7 +1034,16 @@ private Service getFileUploadService(Map uploadFiles){ @Override protected Task createTask() { try { - return new GuiBulkFileUploadTask(uploadFiles); + /*for (Map.Entry entry : uploadFiles.entrySet()) { + //System.out.println(entry.getKey() + ":" + entry.getValue().toString()); + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Content of the keys" + entry.getKey() + " ?" +"Value of the key"+entry.getValue(), ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); + alert.showAndWait(); + if (alert.getResult() == ButtonType.YES) { + //do stuff + } + }*/ + //return new GuiBulkFileUploadTask(uploadFiles); + return new NextcloudFileUploadTask(uploadFiles); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", expCreateInputsGridPane.getScene().getWindow(), @@ -1050,7 +1067,8 @@ private void downloadFile(Path remotePath, String destParentPath){ @Override protected Task createTask() { try { - return new GuiFileDownloadTask(remotePath.toString(), localPath); + //return new GuiFileDownloadTask(remotePath.toString(), localPath); + return new NextcloudFileDownloadTask(remotePath.toString(), localPath); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", expCreateNameField.getScene().getWindow(), diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java index 00e9589..448230f 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java @@ -20,6 +20,7 @@ */ package org.seagrid.desktop.ui.experiment.create.controller; +import com.github.sardine.DavResource; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; @@ -37,16 +38,18 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.stage.Stage; -import org.seagrid.desktop.connectors.storage.StorageManager; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudStorageManager; import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.seagrid.desktop.ui.storage.model.FileListModel; import org.seagrid.desktop.util.SEAGridContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; +import java.util.List; import java.util.Vector; public class RemoteFilePickerController { @@ -102,7 +105,7 @@ private void initialiseColumnWidths(){ fbRemoteFileTblLastMod.prefWidthProperty().bind(fbRemoteFileTable.widthProperty().divide(3)); } - private void initializeRemoteFileTable() throws SftpException, JSchException { + private void initializeRemoteFileTable() throws SftpException, JSchException, IOException { String remoteHome = "/"; this.currentRemotePath = Paths.get(remoteHome); @@ -203,8 +206,9 @@ public void updateItem(String item, boolean empty){ populateRemoteFileTable(); } - private void populateRemoteFileTable() throws JSchException, SftpException { + private void populateRemoteFileTable() throws JSchException, SftpException, IOException { currentRemoteFileList.clear(); + int count = 0; fbRemotePath.setText(SEAGridContext.getInstance().getUserName() + currentRemotePath.toString()); FileListModel fileListModel; if(currentRemotePath.getParent() != null){ @@ -212,14 +216,19 @@ private void populateRemoteFileTable() throws JSchException, SftpException { currentRemotePath.getParent().toString()); currentRemoteFileList.add(fileListModel); } - Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); - for(ChannelSftp.LsEntry lsEntry : children){ - if(lsEntry.getFilename().equals(".") || lsEntry.getFilename().equals("..")) continue; - fileListModel = new FileListModel(lsEntry.getFilename(), lsEntry.getAttrs().isDir() == false - ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, lsEntry.getAttrs().getSize(), - lsEntry.getAttrs().getATime() * 1000L, FileListModel.FileLocation.REMOTE, currentRemotePath.toString() - + "/" + lsEntry.getFilename()); - currentRemoteFileList.add(fileListModel); + //Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); + List resources = NextcloudStorageManager.getInstance().listDirectories(currentRemotePath.toString()); + + for (DavResource res : resources) { + if (count != 0) { + if (res.getName().equals(".") || res.getName().equals("..")) continue; + fileListModel = new FileListModel(res.getName(), res.isDirectory() == false + ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, res.getContentLength().intValue(), + res.getModified().getTime(), FileListModel.FileLocation.REMOTE, currentRemotePath.toString() + + "/" + res.getName()); + currentRemoteFileList.add(fileListModel); + } + count++; } } diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java b/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java index 024b428..675645b 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java @@ -53,9 +53,9 @@ import org.apache.airavata.model.status.JobStatus; import org.apache.airavata.model.workspace.Project; import org.apache.thrift.TException; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudFileDownloadTask; +import org.seagrid.desktop.connectors.NextcloudStorage.NextcloudStorageManager; import org.seagrid.desktop.connectors.airavata.AiravataManager; -import org.seagrid.desktop.connectors.storage.GuiFileDownloadTask; -import org.seagrid.desktop.connectors.storage.StorageManager; import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.seagrid.desktop.ui.home.model.ExperimentListModel; import org.seagrid.desktop.ui.storage.MassStorageBrowserWindow; @@ -65,7 +65,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Path; @@ -190,7 +193,12 @@ public void initialize(){ List inputDataObjectTypes = experimentModel.getExperimentInputs(); String experimentDataDir = "/" + experimentModel.getProjectId().substring(0, experimentModel.getProjectId().length()-37).replaceAll("[^A-Za-z0-9 ]", "_") + "/" + experimentNameLabel.getText().replaceAll("[^A-Za-z0-9]","_")+"."+System.currentTimeMillis(); - StorageManager.getInstance().createDirIfNotExists(experimentDataDir); + //StorageManager.getInstance().createDirIfNotExists(experimentDataDir); + String DirectoryListings ="ExpcloneLog.txt"; + BufferedWriter writ = new BufferedWriter(new FileWriter(DirectoryListings)); + writ.write("Experiment Data Directory"+experimentDataDir); + NextcloudStorageManager.getInstance().createFolderifNotExist(experimentDataDir); + writ.close(); String expId = AiravataManager.getInstance().cloneExperiment(experimentModel.getExperimentId(), "Clone of " + experimentModel.getExperimentName(), experimentModel.getProjectId()); ExperimentModel clonedExperimentModel = AiravataManager.getInstance().getExperiment(expId); @@ -217,7 +225,7 @@ public void initialize(){ SEAGridEventBus.getInstance().register(this); } - public void initExperimentInfo(ExperimentModel experimentModel) throws TException, URISyntaxException { + public void initExperimentInfo(ExperimentModel experimentModel) throws TException, URISyntaxException, IOException { if(experimentModel != null){ experimentIdLabel.setText(experimentModel.getExperimentId()); experimentNameLabel.setText(experimentModel.getExperimentName()); @@ -292,7 +300,7 @@ public void initExperimentInfo(ExperimentModel experimentModel) throws TExceptio } } - public void initExperimentInfo(String experimentId) throws TException, URISyntaxException { + public void initExperimentInfo(String experimentId) throws TException, URISyntaxException, IOException { experimentModel = AiravataManager.getInstance().getExperiment(experimentId); initExperimentInfo(experimentModel); } @@ -365,6 +373,7 @@ private void showStatus(ExperimentModel experimentModel) throws TException { } private void showExperimentInputs(ExperimentModel experimentModel) throws TException, URISyntaxException { + List inputDataObjectTypes = experimentModel.getExperimentInputs(); int rowIndex = EXPERIMENT_INPUT_START_ROW; experimentInfoGridPane.add(new Label("Inputs"), 0, rowIndex); @@ -400,6 +409,7 @@ else if(o2.getName().startsWith("Optional-File-Inputs")) String filePath1 = (new URI(fileUri)).getPath(); hyperlink = new Hyperlink(Paths.get(filePath1).getFileName().toString()); uriOutputLabel = new TextFlow(new Text(input.getName() + " : "), hyperlink); + hyperlink.setOnAction(event -> { downloadFile(Paths.get(filePath1.toString().replaceAll(dataRoot, "")), experimentModel); }); @@ -457,8 +467,10 @@ private void showExperimentErrors(ExperimentModel experimentModel) { } } - private void showExperimentOutputs(ExperimentModel experimentModel) throws TException, URISyntaxException { + private void showExperimentOutputs(ExperimentModel experimentModel) throws TException, URISyntaxException, IOException { int rowIndex = experimentInfoGridPane.getRowConstraints().size(); + String downlfile="BufferedOutput.txt"; + BufferedWriter writer3 = new BufferedWriter(new FileWriter(downlfile)); experimentInfoGridPane.add(new Label("Outputs"), 0, rowIndex); List outputDataObjectTypes = experimentModel.getExperimentOutputs(); for(OutputDataObjectType output : outputDataObjectTypes){ @@ -469,6 +481,8 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce case STDERR: case STDOUT: String dataRoot = remoteDataDirRoot; + writer3.write("Output Directory "+dataRoot); + try{ List replicas = AiravataManager.getInstance().getDataReplicas(output.getValue()); String fileUri = ""; @@ -479,9 +493,15 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce } } String filePath = (new URI(fileUri)).getPath(); + writer3.write("\nFilepath "+ filePath); Hyperlink hyperlink = new Hyperlink(Paths.get(filePath).getFileName().toString()); TextFlow uriOutputLabel = new TextFlow(new Text(output.getName()+" : "), hyperlink); hyperlink.setOnAction(event -> { + try { + writer3.write("\nSending the path to the download File"); + } catch (IOException e) { + e.printStackTrace(); + } downloadFile(Paths.get(filePath.toString().replaceAll(dataRoot, "")), experimentModel); }); experimentInfoGridPane.add(uriOutputLabel, 1, rowIndex); @@ -500,6 +520,7 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce rowIndex++; } } + writer3.close(); } private void downloadFile(Path remotePath, ExperimentModel experimentModel){ @@ -510,7 +531,7 @@ private void downloadFile(Path remotePath, ExperimentModel experimentModel){ @Override protected Task createTask() { try { - return new GuiFileDownloadTask(remotePath.toString(), localPath); + return new NextcloudFileDownloadTask(remotePath.toString(), localPath); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", experimentInfoGridPane.getScene().getWindow(), @@ -555,7 +576,7 @@ private void updateButtonOptions(ExperimentModel experimentModel){ @SuppressWarnings("unused") @Subscribe - public void listenSEAGridEvents(SEAGridEvent event) throws TException { + public void listenSEAGridEvents(SEAGridEvent event) throws TException, IOException { if (event.getEventType().equals(SEAGridEvent.SEAGridEventType.EXPERIMENT_UPDATED)) { ExperimentModel updatedExperimentModel = (ExperimentModel) event.getPayload(); if(updatedExperimentModel.getExperimentId().equals(this.experimentModel.getExperimentId())){ diff --git a/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java b/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java index 242927a..1232c97 100644 --- a/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java +++ b/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java @@ -20,6 +20,7 @@ */ package org.seagrid.desktop.ui.storage.controller; +import com.github.sardine.DavResource; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; @@ -42,7 +43,8 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.stage.Stage; -import org.seagrid.desktop.connectors.storage.*; +import org.seagrid.desktop.connectors.Nextcloud.NextcloudAdapter; +import org.seagrid.desktop.connectors.NextcloudStorage.*; import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.seagrid.desktop.ui.storage.model.FileListModel; import org.seagrid.desktop.util.SEAGridContext; @@ -51,10 +53,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.time.LocalDateTime; +import java.util.List; import java.util.Vector; public class MassStorageBrowserController { @@ -98,6 +104,8 @@ public class MassStorageBrowserController { ObservableList currentLocalFileList, currentRemoteFileList; + private NextcloudAdapter next = new NextcloudAdapter(); + @SuppressWarnings("unused") public void initialize(){ try{ @@ -257,7 +265,7 @@ private void populateLocalFileList(){ } } - private void initializeRemoteFileTable() throws SftpException, JSchException { + private void initializeRemoteFileTable() throws SftpException, JSchException, IOException { this.currentRemotePath = "/"; fbRemoteFileTblFileName.setCellValueFactory(cellData-> new SimpleObjectProperty(cellData.getValue())); @@ -379,7 +387,7 @@ public void updateItem(String item, boolean empty){ populateRemoteFileTable(); } - private void populateRemoteFileTable() throws JSchException, SftpException { + private void populateRemoteFileTable() throws JSchException, SftpException, IOException { currentRemoteFileList.clear(); fbRemotePath.setText(SEAGridContext.getInstance().getUserName() + currentRemotePath.toString()); FileListModel fileListModel; @@ -388,14 +396,21 @@ private void populateRemoteFileTable() throws JSchException, SftpException { (new File(currentRemotePath).getParent())); currentRemoteFileList.add(fileListModel); } - Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); - for(ChannelSftp.LsEntry lsEntry : children){ - if(lsEntry.getFilename().equals(".") || lsEntry.getFilename().equals("..")) continue; - fileListModel = new FileListModel(lsEntry.getFilename(), lsEntry.getAttrs().isDir() == false - ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, lsEntry.getAttrs().getSize(), - lsEntry.getAttrs().getATime() * 1000L, FileListModel.FileLocation.REMOTE, currentRemotePath.toString() - + "/" + lsEntry.getFilename()); - currentRemoteFileList.add(fileListModel); + + List resources = NextcloudStorageManager.getInstance().listDirectories(currentRemotePath.toString()); + int count = 0; + if(resources!= null) { + for (DavResource res : resources) { + if(count != 0) { + if (res.getName().equals(".") || res.getName().equals("..")) continue; + fileListModel = new FileListModel(res.getName(), res.isDirectory() == false + ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, res.getContentLength().intValue(), + res.getModified().getTime(), FileListModel.FileLocation.REMOTE, currentRemotePath.toString() + + "/" + res.getName()); + currentRemoteFileList.add(fileListModel); + } + count++; + } } } @@ -404,7 +419,7 @@ private void uploadFile(String localFile, String remotePath, FileListModel upldF @Override protected Task createTask() { try { - return new GuiFileUploadTask(remotePath, localFile); + return new NextcloudSingleFileUploadTask(remotePath, localFile); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", fbRemoteFileTable.getScene().getWindow(), @@ -441,7 +456,7 @@ private void uploadDir(String localDir, String remoteDir, FileListModel upldFile @Override protected Task createTask() { try { - return new GuiDirUploadTask(remoteDir, localDir); + return new NextcloudFolderUploadTask(remoteDir, localDir); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", fbRemoteFileTable.getScene().getWindow(), @@ -478,7 +493,7 @@ private void downloadFile(String remoteFile, String localFile, FileListModel dow @Override protected Task createTask() { try { - return new GuiFileDownloadTask(remoteFile, localFile); + return new NextcloudFileDownloadTask(remoteFile, localFile); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", fbLocalFileTable.getScene().getWindow(), @@ -515,7 +530,7 @@ private void downloadDir(String remoteDir, String localDir, FileListModel downFi @Override protected Task createTask() { try { - return new GuiDirDownloadTask(remoteDir, localDir); + return new NextCloudFolderdownloadtask(remoteDir, localDir); } catch (Exception e) { e.printStackTrace(); SEAGridDialogHelper.showExceptionDialogAndWait(e, "Exception Dialog", fbLocalFileTable.getScene().getWindow(), @@ -547,9 +562,10 @@ protected Task createTask() { service.start(); } - public void gotoRemoteDir(String path) throws JSchException, SftpException { + public void gotoRemoteDir(String path) throws JSchException, SftpException, IOException { currentRemoteFileList.clear(); currentRemotePath = path; + int count = 0; fbRemotePath.setText(SEAGridContext.getInstance().getUserName() + currentRemotePath.toString()); FileListModel fileListModel; if((new File(currentRemotePath)).getParent() != null && !(new File(currentRemotePath)).getParent().isEmpty()){ @@ -557,14 +573,28 @@ public void gotoRemoteDir(String path) throws JSchException, SftpException { (new File(currentRemotePath).getParent())); currentRemoteFileList.add(fileListModel); } - Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); - for(ChannelSftp.LsEntry lsEntry : children){ - if(lsEntry.getFilename().equals(".") || lsEntry.getFilename().equals("..")) continue; - fileListModel = new FileListModel(lsEntry.getFilename(), lsEntry.getAttrs().isDir() == false - ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, lsEntry.getAttrs().getSize(), - lsEntry.getAttrs().getATime() * 1000L, FileListModel.FileLocation.REMOTE, currentRemotePath.toString() - + "/" + lsEntry.getFilename()); - currentRemoteFileList.add(fileListModel); + //Creating Custom Logs + + //Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); + String DirectoryListings ="LogsExperimentStorageDir.txt"; + BufferedWriter writ = new BufferedWriter(new FileWriter(DirectoryListings)); + List resources = NextcloudStorageManager.getInstance().listDirectories(currentRemotePath.toString()); + writ.write("\nPath" +currentRemotePath.toString()); + if(resources!=null) { + for (DavResource res : resources) { + if (count != 0) { + ; + if (res.getName().equals(".") || res.getName().equals("..")) continue; + writ.write("\nName" + res.getName()); + fileListModel = new FileListModel(res.getName(), res.isDirectory() == false + ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, res.getContentLength().intValue(), + res.getModified().getTime(), FileListModel.FileLocation.REMOTE, currentRemotePath.toString() + + "/" + res.getName()); + currentRemoteFileList.add(fileListModel); + } + count++; + } } + writ.close(); } } \ No newline at end of file From 45e0a2275ee03dcdcf8c3d386a69c47d80316f96 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Sun, 12 Aug 2018 23:16:47 -0400 Subject: [PATCH 10/12] Updated changes to connect the NextcloudStorage --- .../NextcloudStorage/NextcloudFileTask.java | 5 ++--- .../NextcloudStorage/NextcloudStorageManager.java | 2 +- .../controller/ExperimentCreateController.java | 6 ------ .../controller/RemoteFilePickerController.java | 1 - .../controller/ExperimentSummaryController.java | 15 --------------- .../controller/MassStorageBrowserController.java | 10 ---------- 6 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java index f0f3a43..0e7bef1 100644 --- a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileTask.java @@ -5,7 +5,6 @@ import com.github.sardine.SardineFactory; import javafx.concurrent.Task; import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; -import org.seagrid.desktop.connectors.Nextcloud.ValidateTokenTask; import org.seagrid.desktop.util.SEAGridContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +15,7 @@ import java.util.List; public abstract class NextcloudFileTask extends Task { - private final static Logger logger = LoggerFactory.getLogger(org.seagrid.desktop.connectors.Nextcloud.NextcloudFileTask.class); + private final static Logger logger = LoggerFactory.getLogger(org.seagrid.desktop.connectors.NextcloudStorage.NextcloudFileTask.class); protected Sardine sardine = SardineFactory.begin(); @@ -32,7 +31,7 @@ public NextcloudFileTask() throws IOException { isusehttps = SEAGridContext.getInstance().isUseHttps(); rootremotepath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); token = SEAGridContext.getInstance().getOAuthToken(); - sardine.setCredentials(SEAGridContext.getInstance().getUserName(), SEAGridContext.getInstance().getClientID()); + sardine.setCredentials(SEAGridContext.getInstance().getUserName(), token); sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); } diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java index 81f7a49..7caa120 100644 --- a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudStorageManager.java @@ -35,7 +35,7 @@ private void connect() throws JSchException, IOException { isusehttps = SEAGridContext.getInstance().isUseHttps(); rootremotepath = (isusehttps ? "https" : "http") + "://" + servername + "/" + basepath + "/" + SEAGridContext.getInstance().getUserName(); token = SEAGridContext.getInstance().getOAuthToken(); - sardine.setCredentials(SEAGridContext.getInstance().getUserName(), SEAGridContext.getInstance().getClientID()); + sardine.setCredentials(SEAGridContext.getInstance().getUserName(), token); sardine.enablePreemptiveAuthentication(SEAGridContext.getInstance().getNextcloudServername()); } diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java index c487a71..09b45c2 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/ExperimentCreateController.java @@ -804,11 +804,6 @@ private void createExperiment(boolean launch) throws TException, IOException { String randomString = projectId.substring(0,projectId.length()-37).replaceAll("[^A-Za-z0-9 ]", "_") + "/" + expCreateNameField.getText().replaceAll("[^A-Za-z0-9]","_")+"."+System.currentTimeMillis(); String remoteDataDir = SEAGridContext.getInstance().getRemoteDataDirPrefix() + remoteDataDirRoot + randomString + "/"; - - String downlfile = "CreateExperimentLog.txt"; - BufferedWriter writer3 = new BufferedWriter(new FileWriter(downlfile)); - writer3.write("\nRemote Data Directory "+remoteDataDir); - writer3.close(); ExperimentModel experimentModel = assembleExperiment(remoteDataDir, randomString + "/"); Map uploadFiles = new HashMap<>(); for(Iterator> it = experimentInputs.entrySet().iterator(); it.hasNext(); ) { @@ -1042,7 +1037,6 @@ protected Task createTask() { //do stuff } }*/ - //return new GuiBulkFileUploadTask(uploadFiles); return new NextcloudFileUploadTask(uploadFiles); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java index 448230f..6a00b9f 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/create/controller/RemoteFilePickerController.java @@ -216,7 +216,6 @@ private void populateRemoteFileTable() throws JSchException, SftpException, IOEx currentRemotePath.getParent().toString()); currentRemoteFileList.add(fileListModel); } - //Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); List resources = NextcloudStorageManager.getInstance().listDirectories(currentRemotePath.toString()); for (DavResource res : resources) { diff --git a/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java b/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java index 675645b..aa991b7 100644 --- a/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java +++ b/src/main/java/org/seagrid/desktop/ui/experiment/summary/controller/ExperimentSummaryController.java @@ -193,12 +193,7 @@ public void initialize(){ List inputDataObjectTypes = experimentModel.getExperimentInputs(); String experimentDataDir = "/" + experimentModel.getProjectId().substring(0, experimentModel.getProjectId().length()-37).replaceAll("[^A-Za-z0-9 ]", "_") + "/" + experimentNameLabel.getText().replaceAll("[^A-Za-z0-9]","_")+"."+System.currentTimeMillis(); - //StorageManager.getInstance().createDirIfNotExists(experimentDataDir); - String DirectoryListings ="ExpcloneLog.txt"; - BufferedWriter writ = new BufferedWriter(new FileWriter(DirectoryListings)); - writ.write("Experiment Data Directory"+experimentDataDir); NextcloudStorageManager.getInstance().createFolderifNotExist(experimentDataDir); - writ.close(); String expId = AiravataManager.getInstance().cloneExperiment(experimentModel.getExperimentId(), "Clone of " + experimentModel.getExperimentName(), experimentModel.getProjectId()); ExperimentModel clonedExperimentModel = AiravataManager.getInstance().getExperiment(expId); @@ -469,8 +464,6 @@ private void showExperimentErrors(ExperimentModel experimentModel) { private void showExperimentOutputs(ExperimentModel experimentModel) throws TException, URISyntaxException, IOException { int rowIndex = experimentInfoGridPane.getRowConstraints().size(); - String downlfile="BufferedOutput.txt"; - BufferedWriter writer3 = new BufferedWriter(new FileWriter(downlfile)); experimentInfoGridPane.add(new Label("Outputs"), 0, rowIndex); List outputDataObjectTypes = experimentModel.getExperimentOutputs(); for(OutputDataObjectType output : outputDataObjectTypes){ @@ -481,7 +474,6 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce case STDERR: case STDOUT: String dataRoot = remoteDataDirRoot; - writer3.write("Output Directory "+dataRoot); try{ List replicas = AiravataManager.getInstance().getDataReplicas(output.getValue()); @@ -493,15 +485,9 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce } } String filePath = (new URI(fileUri)).getPath(); - writer3.write("\nFilepath "+ filePath); Hyperlink hyperlink = new Hyperlink(Paths.get(filePath).getFileName().toString()); TextFlow uriOutputLabel = new TextFlow(new Text(output.getName()+" : "), hyperlink); hyperlink.setOnAction(event -> { - try { - writer3.write("\nSending the path to the download File"); - } catch (IOException e) { - e.printStackTrace(); - } downloadFile(Paths.get(filePath.toString().replaceAll(dataRoot, "")), experimentModel); }); experimentInfoGridPane.add(uriOutputLabel, 1, rowIndex); @@ -520,7 +506,6 @@ private void showExperimentOutputs(ExperimentModel experimentModel) throws TExce rowIndex++; } } - writer3.close(); } private void downloadFile(Path remotePath, ExperimentModel experimentModel){ diff --git a/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java b/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java index 1232c97..62e53cf 100644 --- a/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java +++ b/src/main/java/org/seagrid/desktop/ui/storage/controller/MassStorageBrowserController.java @@ -43,7 +43,6 @@ import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.stage.Stage; -import org.seagrid.desktop.connectors.Nextcloud.NextcloudAdapter; import org.seagrid.desktop.connectors.NextcloudStorage.*; import org.seagrid.desktop.ui.commons.SEAGridDialogHelper; import org.seagrid.desktop.ui.storage.model.FileListModel; @@ -104,8 +103,6 @@ public class MassStorageBrowserController { ObservableList currentLocalFileList, currentRemoteFileList; - private NextcloudAdapter next = new NextcloudAdapter(); - @SuppressWarnings("unused") public void initialize(){ try{ @@ -573,19 +570,13 @@ public void gotoRemoteDir(String path) throws JSchException, SftpException, IOEx (new File(currentRemotePath).getParent())); currentRemoteFileList.add(fileListModel); } - //Creating Custom Logs - //Vector children = StorageManager.getInstance().getDirectoryListing(currentRemotePath.toString()); - String DirectoryListings ="LogsExperimentStorageDir.txt"; - BufferedWriter writ = new BufferedWriter(new FileWriter(DirectoryListings)); List resources = NextcloudStorageManager.getInstance().listDirectories(currentRemotePath.toString()); - writ.write("\nPath" +currentRemotePath.toString()); if(resources!=null) { for (DavResource res : resources) { if (count != 0) { ; if (res.getName().equals(".") || res.getName().equals("..")) continue; - writ.write("\nName" + res.getName()); fileListModel = new FileListModel(res.getName(), res.isDirectory() == false ? FileListModel.FileListModelType.FILE : FileListModel.FileListModelType.DIR, res.getContentLength().intValue(), res.getModified().getTime(), FileListModel.FileLocation.REMOTE, currentRemotePath.toString() @@ -595,6 +586,5 @@ public void gotoRemoteDir(String path) throws JSchException, SftpException, IOEx count++; } } - writ.close(); } } \ No newline at end of file From d49a09e71a617056ec0093d620586ab251dd7ad4 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Tue, 14 Aug 2018 10:53:45 -0400 Subject: [PATCH 11/12] removed unused imports --- .../NextcloudFileDownloadTask.java | 3 +-- .../NextcloudSingleFileUploadTask.java | 1 - src/main/resources/client_truststore.jks | Bin 2423 -> 0 bytes 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 src/main/resources/client_truststore.jks diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java index b91eb41..12e018d 100644 --- a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudFileDownloadTask.java @@ -1,7 +1,6 @@ package org.seagrid.desktop.connectors.NextcloudStorage; import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; -import org.seagrid.desktop.connectors.storage.GuiFileDownloadTask; import org.seagrid.desktop.util.SEAGridContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,7 +9,7 @@ public class NextcloudFileDownloadTask extends NextcloudFileTask { - private final static Logger logger = LoggerFactory.getLogger(GuiFileDownloadTask.class); + private final static Logger logger = LoggerFactory.getLogger(NextcloudFileDownloadTask.class); private String remoteFilePath, localFilePath; private String remoterootpath; diff --git a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java index 5e9bdc5..e24026f 100644 --- a/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java +++ b/src/main/java/org/seagrid/desktop/connectors/NextcloudStorage/NextcloudSingleFileUploadTask.java @@ -1,7 +1,6 @@ package org.seagrid.desktop.connectors.NextcloudStorage; import org.seagrid.desktop.connectors.NextcloudStorage.Exception.NextcloudApiException; -import org.seagrid.desktop.connectors.storage.GuiFileUploadTask; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/resources/client_truststore.jks b/src/main/resources/client_truststore.jks deleted file mode 100644 index 21e4e624b22d77d0c7cf9321786c53c3365c0789..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2423 zcmezO_TO6u1_mY|W(Lz-<;D3%$%#ct`FRWsjDA_q?glfkM(CLuSOQg98Z8gPTexp-K@gZ+&Rg$x8hTxK55oc!d(oQ(Y95(7DL zUPA)|BST9Aa|0tIvnX+1V^bj47|NxUwT<(U{m014z}(o&V9?mf)Y!-{W%)1BYhUMl z{_@08qhYU=-i9;hjN8_*XDr>ecY;>W^X_R=#on8KIOV51N&CZQb$`>PQ)a)<;0t76 z&&+X{{kxyFcSGDIX}Q45m2z|R=hPpLJ{D7u{p5L(mDR4@EgRNfo%nXggB6oFivO^@ zZdZQwlT+95>vLB<_B9JT{cWN+k6K$YF*7nSE(Qjc0Ut29Wce8x|Ff_#GqHR?b}}$Z zn1ODMp2P3HUHi%g+0~D<-TRcBLfoFT97-*-ZRzDd#dQAG#sg;Z{fS?m9o^kGUz1l_ z!{GUMOL^TiPfszzUA7HcWcfHyKFzH zeb<>m^;hD~%&Z7y!R^b9`@>2jzn;~+?zWvvJ9XP-r+m>(JF0)be;FHm)g($Ck{=rH z7&P8AkOk!kJ{B<+k+pkgRGDm1`~K^QTF86my$@7Qhe&~o8(Dr(Zee6I;0LJ{2IU@B z17;v)&^Qw$qRi4b(V(%f0jmiMi}@+1CfY?J0X z&X{wvrLys+T(k(gvRP{Xh8yL(*Er_5Co~6c_-SPO{LeQv;o}WrOZP|pX+K|4*{L|| zkqr7cWdzz?!QJm{aaUYp(PNc?0CIMdb5$AZM%)?Ff@m9>FyqUb=@pxMwLa95t*Iup2V|yo!!Acb8m#O z{%4!``S~+^C;v!zdD|;uo|9o_BiZZ_DQ@?_+rq6y&{|4RU55-IuU!eqEP*=mJ;8KR={{{P$%WZoZs1 zC4S5Qs}e0;Mhnr2=h2I>LE<3SW*dOT!06io;_W%F@ From 0a42c5c3fbf7bade43e64fa048686e9c1f776963 Mon Sep 17 00:00:00 2001 From: Karan Kotabagi Date: Tue, 14 Aug 2018 11:04:04 -0400 Subject: [PATCH 12/12] reverting not used changes --- src/main/resources/client_truststore.jks | Bin 0 -> 2423 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/client_truststore.jks diff --git a/src/main/resources/client_truststore.jks b/src/main/resources/client_truststore.jks new file mode 100644 index 0000000000000000000000000000000000000000..21e4e624b22d77d0c7cf9321786c53c3365c0789 GIT binary patch literal 2423 zcmezO_TO6u1_mY|W(Lz-<;D3%$%#ct`FRWsjDA_q?glfkM(CLuSOQg98Z8gPTexp-K@gZ+&Rg$x8hTxK55oc!d(oQ(Y95(7DL zUPA)|BST9Aa|0tIvnX+1V^bj47|NxUwT<(U{m014z}(o&V9?mf)Y!-{W%)1BYhUMl z{_@08qhYU=-i9;hjN8_*XDr>ecY;>W^X_R=#on8KIOV51N&CZQb$`>PQ)a)<;0t76 z&&+X{{kxyFcSGDIX}Q45m2z|R=hPpLJ{D7u{p5L(mDR4@EgRNfo%nXggB6oFivO^@ zZdZQwlT+95>vLB<_B9JT{cWN+k6K$YF*7nSE(Qjc0Ut29Wce8x|Ff_#GqHR?b}}$Z zn1ODMp2P3HUHi%g+0~D<-TRcBLfoFT97-*-ZRzDd#dQAG#sg;Z{fS?m9o^kGUz1l_ z!{GUMOL^TiPfszzUA7HcWcfHyKFzH zeb<>m^;hD~%&Z7y!R^b9`@>2jzn;~+?zWvvJ9XP-r+m>(JF0)be;FHm)g($Ck{=rH z7&P8AkOk!kJ{B<+k+pkgRGDm1`~K^QTF86my$@7Qhe&~o8(Dr(Zee6I;0LJ{2IU@B z17;v)&^Qw$qRi4b(V(%f0jmiMi}@+1CfY?J0X z&X{wvrLys+T(k(gvRP{Xh8yL(*Er_5Co~6c_-SPO{LeQv;o}WrOZP|pX+K|4*{L|| zkqr7cWdzz?!QJm{aaUYp(PNc?0CIMdb5$AZM%)?Ff@m9>FyqUb=@pxMwLa95t*Iup2V|yo!!Acb8m#O z{%4!``S~+^C;v!zdD|;uo|9o_BiZZ_DQ@?_+rq6y&{|4RU55-IuU!eqEP*=mJ;8KR={{{P$%WZoZs1 zC4S5Qs}e0;Mhnr2=h2I>LE<3SW*dOT!06io;_W%F@ literal 0 HcmV?d00001