You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2013/12/12 21:53:47 UTC
svn commit: r1550528 - in /airavata/trunk/modules/xbaya-gui: ./
src/main/java/org/apache/airavata/xbaya/menues/tools/
src/main/java/org/apache/airavata/xbaya/ui/dialogs/
src/main/java/org/apache/airavata/xbaya/util/
Author: chathuri
Date: Thu Dec 12 20:53:47 2013
New Revision: 1550528
URL: http://svn.apache.org/r1550528
Log:
adding GO dialog
Added:
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/Data.java
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GOConstants.java
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GlobusOnlineUtils.java
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/TransferFile.java
Modified:
airavata/trunk/modules/xbaya-gui/pom.xml
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/menues/tools/ToolsMenuItem.java
airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/GlobusFileTransferWindow.java
Modified: airavata/trunk/modules/xbaya-gui/pom.xml
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/pom.xml?rev=1550528&r1=1550527&r2=1550528&view=diff
==============================================================================
--- airavata/trunk/modules/xbaya-gui/pom.xml (original)
+++ airavata/trunk/modules/xbaya-gui/pom.xml Thu Dec 12 20:53:47 2013
@@ -315,5 +315,20 @@
<artifactId>derbyclient</artifactId>
<version>${derby.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.globusonline</groupId>
+ <artifactId>transfer-api-client-java</artifactId>
+ <version>0.10.8-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpcore</artifactId>
+ <version>4.3</version>
+ </dependency>
</dependencies>
</project>
Modified: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/menues/tools/ToolsMenuItem.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/menues/tools/ToolsMenuItem.java?rev=1550528&r1=1550527&r2=1550528&view=diff
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/menues/tools/ToolsMenuItem.java (original)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/menues/tools/ToolsMenuItem.java Thu Dec 12 20:53:47 2013
@@ -35,9 +35,7 @@ public class ToolsMenuItem {
private XBayaEngine engine;
private JMenu toolsMenu;
-
- private JMenuItem globusFileTransferItem;
-
+
private static final Logger logger = LoggerFactory.getLogger(ToolsMenuItem.class);
/**
@@ -61,11 +59,10 @@ public class ToolsMenuItem {
* Creates workflow menu.
*/
private void createWorkflowMenu() {
- this.globusFileTransferItem = createGlobusFileTransferItem();
-
+ JMenuItem globusFileTransferItem = createGlobusFileTransferItem();
toolsMenu = new JMenu("Tools");
toolsMenu.setMnemonic(KeyEvent.VK_T);
- toolsMenu.add(this.globusFileTransferItem);
+ toolsMenu.add(globusFileTransferItem);
}
@@ -84,4 +81,20 @@ public class ToolsMenuItem {
});
return item;
}
+
+// private JMenuItem createAmberRunItem() {
+// JMenuItem item = new JMenuItem("Amber Run...");
+// item.setMnemonic(KeyEvent.VK_J);
+// item.addActionListener(new AbstractAction() {
+// private AmberRunWindow window;
+//
+// public void actionPerformed(ActionEvent e) {
+// if (this.window == null) {
+// this.window = new AmberRunWindow(engine);
+// }
+// this.window.show();
+// }
+// });
+// return item;
+// }
}
\ No newline at end of file
Modified: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/GlobusFileTransferWindow.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/GlobusFileTransferWindow.java?rev=1550528&r1=1550527&r2=1550528&view=diff
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/GlobusFileTransferWindow.java (original)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/GlobusFileTransferWindow.java Thu Dec 12 20:53:47 2013
@@ -22,44 +22,49 @@
package org.apache.airavata.xbaya.ui.dialogs;
import org.apache.airavata.xbaya.XBayaEngine;
-//import org.apache.airavata.xbaya.globus.GridFTPFileTransferClient;
import org.apache.airavata.xbaya.ui.widgets.GridPanel;
+import org.apache.airavata.xbaya.ui.widgets.XBayaComboBox;
import org.apache.airavata.xbaya.ui.widgets.XBayaLabel;
import org.apache.airavata.xbaya.ui.widgets.XBayaTextField;
-//import org.globusonline.transfer.APIError;
-//import org.globusonline.transfer.JSONTransferAPIClient;
-//import org.json.JSONException;
+import org.apache.airavata.xbaya.util.GlobusOnlineUtils;
+import org.apache.airavata.xbaya.util.TransferFile;
+import org.globusonline.transfer.APIError;
+import org.json.JSONException;
import javax.swing.*;
import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.io.IOException;
import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
-public class GlobusFileTransferWindow {
- public static final String GLOBUSONLINE_BASE_URL_V0_10 = "https://transfer.api.globusonline.org/v0.10";
+public class GlobusFileTransferWindow {
private XBayaEngine engine;
private XBayaDialog dialog;
private XBayaTextField usernameTextField;
- private XBayaTextField caFileTextField;
-
- private XBayaTextField certFileTextField;
+ private JPasswordField pwdTextField;
- private XBayaTextField keyFileTextField;
-
- private XBayaTextField sourceEndpointTextField;
+ private XBayaComboBox sourceEndpointTextField;
private XBayaTextField sourceFilePathTextField;
- private XBayaTextField destEndpointTextField;
+ private XBayaComboBox destEndpointTextField;
private XBayaTextField destFilePathTextField;
+ private XBayaTextField transferLabelTextField;
+
+ private GlobusOnlineUtils globusOnlineUtils;
+
+
+ private String goUserName;
+ private String goPWD;
+
/**
* @param engine XBaya workflow engine
*/
@@ -80,47 +85,42 @@ public class GlobusFileTransferWindow {
}
private void ok() {
- String username = this.usernameTextField.getText();
- String caFile = this.caFileTextField.getText();
- String certFile = this.certFileTextField.getText();
- String keyFile = this.keyFileTextField.getText();
+
+ goUserName = this.usernameTextField.getText();
+ goPWD = new String(this.pwdTextField.getPassword());
String sourceEndpoint = this.sourceEndpointTextField.getText();
String sourceFilePath = this.sourceFilePathTextField.getText();
String destEndpoint = this.destEndpointTextField.getText();
String destFilePath = this.destFilePathTextField.getText();
+ String transferLabel = this.transferLabelTextField.getText();
-// JSONTransferAPIClient c;
-// try {
-// c = new JSONTransferAPIClient(username, caFile, certFile, keyFile, GLOBUSONLINE_BASE_URL_V0_10);
-// } catch (KeyManagementException e) {
-// this.engine.getGUI().getErrorWindow().error("Key Management Error.", e);
-// return;
-// } catch (NoSuchAlgorithmException e) {
-// this.engine.getGUI().getErrorWindow().error("No Such Algorithm Error.", e);
-// return;
-// }
-// System.out.println("base url: " + c.getBaseUrl());
-// GridFTPFileTransferClient e = new GridFTPFileTransferClient(c);
-// try {
-// e.transfer(sourceEndpoint, sourceFilePath, destEndpoint, destFilePath);
-// } catch (IOException e1) {
-// this.engine.getGUI().getErrorWindow().error("IO Error.", e1);
-// return;
-// } catch (JSONException e1) {
-// this.engine.getGUI().getErrorWindow().error("JSON Error.", e1);
-// return;
-// } catch (GeneralSecurityException e1) {
-// this.engine.getGUI().getErrorWindow().error("Key Management Error.", e1);
-// return;
-// } catch (APIError apiError) {
-// this.engine.getGUI().getErrorWindow().error("Globus Transfer API Calling Error.", apiError);
-// return;
-// }
-
- // TODO: should display a message whether the transfer was successful/unsuccessful
- hide();
+ if(globusOnlineUtils == null){
+ globusOnlineUtils = new GlobusOnlineUtils(goUserName, goPWD);
+ }
+ TransferFile transferFile = globusOnlineUtils.getTransferFile(sourceEndpoint, destEndpoint, sourceFilePath, destFilePath, transferLabel);
+ globusOnlineUtils.transferFiles(transferFile);
+ }
+ private String[] getGOEndpointList(){
+ if (getGoUserName() != null && getGoPWD() != null){
+ globusOnlineUtils = new GlobusOnlineUtils(goUserName, goPWD);
+ }
+ List<String> epList = new ArrayList<String>();
+ try {
+ if (globusOnlineUtils != null){
+ epList = globusOnlineUtils.getEPList();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (APIError apiError) {
+ apiError.printStackTrace();
+ } catch (GeneralSecurityException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return epList.toArray(new String[]{});
}
/**
@@ -128,52 +128,62 @@ public class GlobusFileTransferWindow {
*/
private void initGUI() {
this.usernameTextField = new XBayaTextField();
- this.caFileTextField = new XBayaTextField();
- this.certFileTextField = new XBayaTextField();
- this.keyFileTextField = new XBayaTextField();
- this.sourceEndpointTextField = new XBayaTextField();
- this.sourceFilePathTextField = new XBayaTextField();
- this.destEndpointTextField = new XBayaTextField();
- this.destFilePathTextField = new XBayaTextField();
-
- // Setting some sample values when the Window is loaded
- /*this.usernameTextField.setText("heshan");
- this.caFileTextField
- .setText("/home/heshan/Dev/globusonline/transfer-api-client-java.git/trunk/ca/gd-bundle_ca.cert");
- this.certFileTextField.setText("/tmp/x509up_u780936");
- this.keyFileTextField.setText("/tmp/x509up_u780936");
- this.sourceEndpointTextField.setText("xsede#ranger");
- this.sourceFilePathTextField.setText("~/tmp.log");
- this.destEndpointTextField.setText("xsede#trestles");
- this.destFilePathTextField.setText("~/tmp.log.copy");*/
-
- XBayaLabel nameLabel = new XBayaLabel("Username", this.usernameTextField);
- XBayaLabel caFileLabel = new XBayaLabel("CA File", this.caFileTextField);
- XBayaLabel certFileLabel = new XBayaLabel("Certificate File", this.certFileTextField);
- XBayaLabel keyFileLabel = new XBayaLabel("Key File", this.keyFileTextField);
- XBayaLabel sourceEprLabel = new XBayaLabel("Source Endpoint", this.sourceEndpointTextField);
- XBayaLabel sourceFilePathLabel = new XBayaLabel("Source File Path", this.sourceFilePathTextField);
- XBayaLabel destEprLabel = new XBayaLabel("Destination Endpoint", this.destEndpointTextField);
- XBayaLabel destFilePathLabel = new XBayaLabel("Destination FIle path", this.destFilePathTextField);
+ this.pwdTextField = new JPasswordField();
+ JButton authenticateButton = new JButton("Authenticate");
+
+ XBayaLabel nameLabel = new XBayaLabel("GO Username", this.usernameTextField);
+ XBayaLabel pwdLabel = new XBayaLabel("GO Password", this.pwdTextField);
+ JLabel authLabel = new JLabel("");
GridPanel infoPanel = new GridPanel();
- infoPanel.add(nameLabel);
- infoPanel.add(this.usernameTextField);
- infoPanel.add(caFileLabel);
- infoPanel.add(this.caFileTextField);
- infoPanel.add(certFileLabel);
- infoPanel.add(certFileTextField);
- infoPanel.add(keyFileLabel);
- infoPanel.add(this.keyFileTextField);
- infoPanel.add(sourceEprLabel);
- infoPanel.add(this.sourceEndpointTextField);
- infoPanel.add(sourceFilePathLabel);
- infoPanel.add(this.sourceFilePathTextField);
- infoPanel.add(destEprLabel);
- infoPanel.add(this.destEndpointTextField);
- infoPanel.add(destFilePathLabel);
- infoPanel.add(this.destFilePathTextField);
- infoPanel.layout(8, 2, GridPanel.WEIGHT_NONE, 1);
+ GridPanel authButtonPanel = new GridPanel();
+ GridPanel otherPanel = new GridPanel();
+
+ authButtonPanel.add(nameLabel.getSwingComponent());
+ authButtonPanel.add(this.usernameTextField.getSwingComponent());
+ authButtonPanel.add(pwdLabel.getSwingComponent());
+ authButtonPanel.add(this.pwdTextField);
+ authButtonPanel.add(authLabel);
+ authButtonPanel.add(authenticateButton);
+
+ authButtonPanel.layout(3,2,GridPanel.WEIGHT_NONE, 1);
+
+ String[] goEndpointList = getGOEndpointList();
+ DefaultComboBoxModel cmbModelJobType1 = new DefaultComboBoxModel(goEndpointList);
+ sourceEndpointTextField = new XBayaComboBox(cmbModelJobType1);
+ sourceEndpointTextField.setEditable(true);
+
+ sourceFilePathTextField = new XBayaTextField();
+ DefaultComboBoxModel cmbModelJobType2 = new DefaultComboBoxModel(goEndpointList);
+ destEndpointTextField = new XBayaComboBox(cmbModelJobType2);
+ destEndpointTextField.setEditable(true);
+ destFilePathTextField = new XBayaTextField();
+ transferLabelTextField = new XBayaTextField();
+
+ XBayaLabel sourceEprLabel = new XBayaLabel("Source Endpoint", sourceEndpointTextField);
+ XBayaLabel sourceFilePathLabel = new XBayaLabel("Source File Path", sourceFilePathTextField);
+ XBayaLabel destEprLabel = new XBayaLabel("Destination Endpoint", destEndpointTextField);
+ XBayaLabel destFilePathLabel = new XBayaLabel("Destination FIle path", destFilePathTextField);
+ XBayaLabel labelTransferLabel = new XBayaLabel("Label This Transfer", destFilePathTextField);
+
+
+ otherPanel.add(sourceEprLabel.getSwingComponent());
+ otherPanel.add(sourceEndpointTextField.getSwingComponent());
+ otherPanel.add(sourceFilePathLabel.getSwingComponent());
+ otherPanel.add(sourceFilePathTextField.getSwingComponent());
+ otherPanel.add(destEprLabel.getSwingComponent());
+ otherPanel.add(destEndpointTextField.getSwingComponent());
+ otherPanel.add(destFilePathLabel.getSwingComponent());
+ otherPanel.add(destFilePathTextField.getSwingComponent());
+ otherPanel.add(labelTransferLabel.getSwingComponent());
+ otherPanel.add(transferLabelTextField.getSwingComponent());
+
+ otherPanel.layout(5, 2, GridPanel.WEIGHT_NONE, 1);
+
+ infoPanel.add(otherPanel);
+ JPanel buttonPanel = new JPanel();
+
+ infoPanel.layout(2, 1, GridPanel.WEIGHT_NONE, GridPanel.WEIGHT_NONE);
JButton okButton = new JButton("OK");
okButton.addActionListener(new AbstractAction() {
@@ -189,11 +199,58 @@ public class GlobusFileTransferWindow {
}
});
- JPanel buttonPanel = new JPanel();
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
+ usernameTextField.getSwingComponent().addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ setGoUserName(usernameTextField.getText());
+ }
+ }
+ );
+
+ pwdTextField.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ setGoPWD(new String(pwdTextField.getPassword()));
+ }
+ }
+ );
+
+ authenticateButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ goUserName = usernameTextField.getText();
+ goPWD = new String(pwdTextField.getPassword());
+
+ if (goUserName != null && goPWD != null){
+ globusOnlineUtils = new GlobusOnlineUtils(usernameTextField.getText(), new String(pwdTextField.getPassword()));
+ String[] goEndpointList = getGOEndpointList();
+ DefaultComboBoxModel comboBoxModel1 = new DefaultComboBoxModel(goEndpointList);
+ DefaultComboBoxModel comboBoxModel2 = new DefaultComboBoxModel(goEndpointList);
+ sourceEndpointTextField.setModel(comboBoxModel1);
+ destEndpointTextField.setModel(comboBoxModel2);
+ }
+ }
+ });
+
this.dialog = new XBayaDialog(this.engine.getGUI(), "Globus file transfer", infoPanel, buttonPanel);
this.dialog.setDefaultButton(okButton);
}
+
+ public String getGoUserName() {
+ return goUserName;
+ }
+
+ public void setGoUserName(String goUserName) {
+ this.goUserName = goUserName;
+ }
+
+ public String getGoPWD() {
+ return goPWD;
+ }
+
+ public void setGoPWD(String goPWD) {
+ this.goPWD = goPWD;
+ }
}
Added: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/Data.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/Data.java?rev=1550528&view=auto
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/Data.java (added)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/Data.java Thu Dec 12 20:53:47 2013
@@ -0,0 +1,70 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.util;
+
+public class Data {
+ private String destination_path;
+ private String verify_size;
+ private String source_path;
+ private boolean recursive;
+ private String DATA_TYPE;
+
+ public String getDestination_path() {
+ return destination_path;
+ }
+
+ public void setDestination_path(String destination_path) {
+ this.destination_path = destination_path;
+ }
+
+ public String getVerify_size() {
+ return verify_size;
+ }
+
+ public void setVerify_size(String verify_size) {
+ this.verify_size = verify_size;
+ }
+
+ public String getSource_path() {
+ return source_path;
+ }
+
+ public void setSource_path(String source_path) {
+ this.source_path = source_path;
+ }
+
+ public boolean getRecursive() {
+ return recursive;
+ }
+
+ public void setRecursive(boolean recursive) {
+ this.recursive = recursive;
+ }
+
+ public String getDATA_TYPE() {
+ return DATA_TYPE;
+ }
+
+ public void setDATA_TYPE(String DATA_TYPE) {
+ this.DATA_TYPE = DATA_TYPE;
+ }
+}
Added: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GOConstants.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GOConstants.java?rev=1550528&view=auto
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GOConstants.java (added)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GOConstants.java Thu Dec 12 20:53:47 2013
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.util;
+
+public class GOConstants {
+ public static final String BASEURL = "https://transfer.api.globusonline.org/v0.10";
+ public static final String NEXUS_API_HOST = "nexus.api.globusonline.org";
+ public static final int NEXUS_API_PORT = 443;
+ public static final String NEXUS_API_SCHEMA = "https";
+ public static final String GOAUTH_TOKEN_REQ_URL = "/goauth/token?grant_type=client_credentials";
+}
Added: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GlobusOnlineUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GlobusOnlineUtils.java?rev=1550528&view=auto
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GlobusOnlineUtils.java (added)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/GlobusOnlineUtils.java Thu Dec 12 20:53:47 2013
@@ -0,0 +1,245 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.util;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.globusonline.transfer.APIError;
+import org.globusonline.transfer.Authenticator;
+import org.globusonline.transfer.GoauthAuthenticator;
+import org.globusonline.transfer.JSONTransferAPIClient;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class GlobusOnlineUtils {
+ public static final String ACCESS_TOKEN = "access_token";
+
+ private static String goUserName;
+ private static String goPWD;
+
+ public static void main(String[] args) {
+// String s = appendFileName("/~/Desktop/1.docx", "/~/");
+// System.out.println(s);
+
+ }
+
+ public GlobusOnlineUtils(String goUsername, String goPwd) {
+ goUserName = goUsername;
+ goPWD = goPwd;
+ }
+
+ public String getAuthenticationToken() {
+ String token = null;
+ HttpHost targetHost = new HttpHost(GOConstants.NEXUS_API_HOST, GOConstants.NEXUS_API_PORT, GOConstants.NEXUS_API_SCHEMA);
+ CredentialsProvider credsProvider = new BasicCredentialsProvider();
+ credsProvider.setCredentials(
+ new AuthScope(targetHost.getHostName(), targetHost.getPort()),
+ new UsernamePasswordCredentials(goUserName, goPWD));
+
+ CloseableHttpClient httpclient = HttpClients.custom()
+ .setDefaultCredentialsProvider(credsProvider).build();
+ try {
+
+ // Create AuthCache instance
+ AuthCache authCache = new BasicAuthCache();
+ // Generate BASIC scheme object and add it to the local
+ // auth cache
+ BasicScheme basicScheme = new BasicScheme();
+ authCache.put(targetHost, basicScheme);
+
+ // Add AuthCache to the execution context
+ HttpClientContext localContext = HttpClientContext.create();
+ localContext.setAuthCache(authCache);
+
+ HttpGet httpget = new HttpGet(GOConstants.GOAUTH_TOKEN_REQ_URL);
+ httpget.addHeader("accept", "application/json");
+ System.out.println("executing request: " + httpget.getRequestLine());
+ System.out.println("to target: " + targetHost);
+
+ CloseableHttpResponse response = httpclient.execute(targetHost, httpget, localContext);
+ try {
+ HttpEntity entity = response.getEntity();
+ InputStream entityContent = entity.getContent();
+ InputStreamReader reader = new InputStreamReader(entityContent);
+ JSONTokener tokenizer = new JSONTokener(reader);
+ JSONObject json = new JSONObject(tokenizer);
+ token = (String)json.get(ACCESS_TOKEN);
+ entityContent.close();
+ EntityUtils.consume(entity);
+
+ } catch (JSONException e) {
+ e.printStackTrace();
+ } finally {
+ response.close();
+ }
+ //}
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ httpclient.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return token;
+ }
+
+ public JSONTransferAPIClient getAuthenticated (){
+ JSONTransferAPIClient jsonTransferAPIClient = null;
+ try {
+ String authenticationToken = getAuthenticationToken();
+ Authenticator authenticator = new GoauthAuthenticator(authenticationToken);
+ jsonTransferAPIClient = new JSONTransferAPIClient(goUserName,
+ null, GOConstants.BASEURL);
+ jsonTransferAPIClient.setAuthenticator(authenticator);
+ } catch (KeyManagementException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ return jsonTransferAPIClient;
+ }
+
+ public String transferFiles (TransferFile tf){
+ String taskId = null;
+ try {
+ JSONTransferAPIClient apiClient = getAuthenticated();
+ String submissionId = apiClient.getSubmissionId();
+ tf.setSubmission_id(submissionId);
+ JSONObject jsonObject = new JSONObject(tf);
+ JSONTransferAPIClient.Result result = apiClient.transfer(jsonObject);
+ taskId = (String)result.document.get("task_id");
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (GeneralSecurityException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ } catch (APIError apiError) {
+ apiError.printStackTrace();
+ }
+ return taskId;
+ }
+
+ public TransferFile getTransferFile (String sourceEp,
+ String destEp,
+ String sourcePath,
+ String destPath,
+ String label){
+
+ TransferFile transferFile = new TransferFile();
+
+
+ transferFile.setPreserve_timestamp(false);
+ transferFile.setDATA_TYPE("transfer");
+ transferFile.setEncrypt_data(false);
+ transferFile.setSync_level(null);
+ transferFile.setSource_endpoint(sourceEp);
+ transferFile.setLabel(label);
+ transferFile.setDestination_endpoint(destEp);
+ transferFile.setLength(2);
+ transferFile.setDeadline(getDeadlineForTransfer());
+ transferFile.setNotify_on_succeeded(true);
+ transferFile.setNotify_on_failed(true);
+ transferFile.setVerify_checksum(false);
+ transferFile.setDelete_destination_extra(false);
+ Data[] datas = new Data[1];
+ Data data = new Data();
+ data.setDATA_TYPE("transfer_item");
+ data.setDestination_path(appendFileName(sourcePath, destPath));
+ data.setVerify_size(null);
+ data.setSource_path(sourcePath);
+ data.setRecursive(false);
+ datas[0] = data;
+ transferFile.setDATA(datas);
+ return transferFile;
+ }
+
+ private static String appendFileName(String sourcePath, String destPath){
+ String[] split = sourcePath.split(File.separator);
+ String fileName = split[split.length - 1];
+ if (destPath.endsWith(File.separator)){
+ destPath = destPath.concat(fileName);
+ }else {
+ destPath = destPath.concat("/" + fileName);
+ }
+ System.out.println(destPath);
+ return destPath;
+ }
+
+ private String getDeadlineForTransfer (){
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(calendar.DAY_OF_MONTH, 1);
+ Date tomorrow = calendar.getTime();
+ String date = dateFormat.format(tomorrow);
+ System.out.println(date);
+ return date;
+ }
+
+ public List<String> getEPList() throws IOException, APIError, GeneralSecurityException, JSONException {
+ List<String> epList = new ArrayList<String>();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("limit", "0");
+ JSONTransferAPIClient transferAPIClient = getAuthenticated();
+ JSONTransferAPIClient.Result result = transferAPIClient.getResult("/endpoint_list", params);
+ JSONObject document = result.document;
+ JSONArray dataArray = document.getJSONArray("DATA");
+ for (int i = 0; i < dataArray.length(); i++ ){
+ JSONObject jsonObject = dataArray.getJSONObject(i);
+ String epName = (String)jsonObject.get("canonical_name");
+ epList.add(epName);
+ }
+ return epList;
+ }
+
+}
Added: airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/TransferFile.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/TransferFile.java?rev=1550528&view=auto
==============================================================================
--- airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/TransferFile.java (added)
+++ airavata/trunk/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/TransferFile.java Thu Dec 12 20:53:47 2013
@@ -0,0 +1,170 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.xbaya.util;
+
+
+public class TransferFile {
+ private String submission_id;
+ private boolean preserve_timestamp;
+ private String DATA_TYPE;
+ private boolean encrypt_data;
+ private String sync_level;
+ private String source_endpoint;
+ private String label;
+ private String destination_endpoint;
+ private int length;
+ private String deadline;
+ private boolean notify_on_succeeded;
+ private boolean notify_on_failed;
+ private boolean verify_checksum;
+ private boolean notify_on_inactive;
+ private boolean delete_destination_extra;
+ private Data[] DATA;
+
+ public String getSubmission_id() {
+ return submission_id;
+ }
+
+ public void setSubmission_id(String submission_id) {
+ this.submission_id = submission_id;
+ }
+
+ public boolean getPreserve_timestamp() {
+ return preserve_timestamp;
+ }
+
+ public void setPreserve_timestamp(boolean preserve_timestamp) {
+ this.preserve_timestamp = preserve_timestamp;
+ }
+
+ public String getDATA_TYPE() {
+ return DATA_TYPE;
+ }
+
+ public void setDATA_TYPE(String DATA_TYPE) {
+ this.DATA_TYPE = DATA_TYPE;
+ }
+
+ public boolean getEncrypt_data() {
+ return encrypt_data;
+ }
+
+ public void setEncrypt_data(boolean encrypt_data) {
+ this.encrypt_data = encrypt_data;
+ }
+
+ public String getSync_level() {
+ return sync_level;
+ }
+
+ public void setSync_level(String sync_level) {
+ this.sync_level = sync_level;
+ }
+
+ public String getSource_endpoint() {
+ return source_endpoint;
+ }
+
+ public void setSource_endpoint(String source_endpoint) {
+ this.source_endpoint = source_endpoint;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getDestination_endpoint() {
+ return destination_endpoint;
+ }
+
+ public void setDestination_endpoint(String destination_endpoint) {
+ this.destination_endpoint = destination_endpoint;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public void setLength(int length) {
+ this.length = length;
+ }
+
+ public String getDeadline() {
+ return deadline;
+ }
+
+ public void setDeadline(String deadline) {
+ this.deadline = deadline;
+ }
+
+ public boolean getNotify_on_succeeded() {
+ return notify_on_succeeded;
+ }
+
+ public void setNotify_on_succeeded(boolean notify_on_succeeded) {
+ this.notify_on_succeeded = notify_on_succeeded;
+ }
+
+ public boolean getNotify_on_failed() {
+ return notify_on_failed;
+ }
+
+ public void setNotify_on_failed(boolean notify_on_failed) {
+ this.notify_on_failed = notify_on_failed;
+ }
+
+ public boolean getVerify_checksum() {
+ return verify_checksum;
+ }
+
+ public void setVerify_checksum(boolean verify_checksum) {
+ this.verify_checksum = verify_checksum;
+ }
+
+ public boolean getNotify_on_inactive() {
+ return notify_on_inactive;
+ }
+
+ public void setNotify_on_inactive(boolean notify_on_inactive) {
+ this.notify_on_inactive = notify_on_inactive;
+ }
+
+ public boolean getDelete_destination_extra() {
+ return delete_destination_extra;
+ }
+
+ public void setDelete_destination_extra(boolean delete_destination_extra) {
+ this.delete_destination_extra = delete_destination_extra;
+ }
+
+ public Data[] getDATA() {
+ return DATA;
+ }
+
+ public void setDATA(Data[] DATA) {
+ this.DATA = DATA;
+ }
+}