airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject git commit: fixing the workflow save and load issues to the registry and the ui dialogs
Date Sat, 12 Jul 2014 19:12:16 GMT
Repository: airavata
Updated Branches:
  refs/heads/workflow-support c424c37a6 -> 4752d1a3f


fixing the workflow save and load issues to the registry and the ui dialogs


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/4752d1a3
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/4752d1a3
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/4752d1a3

Branch: refs/heads/workflow-support
Commit: 4752d1a3fbf1a7742a71eacc42a0d2eee31aa5c7
Parents: c424c37
Author: Saminda Wijeratne <samindaw@gmail.com>
Authored: Sat Jul 12 15:12:01 2014 -0400
Committer: Saminda Wijeratne <samindaw@gmail.com>
Committed: Sat Jul 12 15:12:01 2014 -0400

----------------------------------------------------------------------
 .../registry/jpa/impl/AiravataJPARegistry.java  |  94 ++++---
 .../workflow/catalog/WorkflowCatalogImpl.java   |  64 ++---
 .../airavata/xbaya/XBayaConfiguration.java      |   8 +-
 .../org/apache/airavata/xbaya/ui/XBayaGUI.java  |  17 +-
 .../ui/dialogs/registry/RegistryWindow.java     |   7 +-
 .../dialogs/workflow/WorkflowImportWindow.java  | 265 +++++++++++++++++++
 .../ui/experiment/RegistrySearchResult.java     |  17 +-
 .../RegistryWorkflowPublisherWindow.java        |  41 ++-
 .../airavata/xbaya/ui/menues/XBayaMenuItem.java |  54 ++--
 .../apache/airavata/xbaya/util/XBayaUtil.java   |   3 +-
 10 files changed, 457 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
index 1a56a49..45aefad 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/AiravataJPARegistry.java
@@ -1310,56 +1310,70 @@ public class AiravataJPARegistry extends AiravataRegistry2{
     }
 
     public void updateWorkflow(String workflowName, String workflowGraphXml) throws RegException
{
-//        if (userWorkflowRegistry != null){
-//            userWorkflowRegistry.updateWorkflow(workflowName, workflowGraphXml);
-//        }else {
-//            WorkerResource worker = jpa.getWorker();
-//            if (!isWorkflowExists(workflowName)){
-//                throw new UserWorkflowDoesNotExistsException(workflowName);
-//            }
-//            UserWorkflowResource workflowResource = worker.getWorkflowTemplate(workflowName);
-//            workflowResource.setContent(workflowGraphXml);
-//            workflowResource.save();
-//        }
+        if (userWorkflowRegistry != null){
+            userWorkflowRegistry.updateWorkflow(workflowName, workflowGraphXml);
+        }else {
+            WorkerResource worker = jpa.getWorker();
+            if (!isWorkflowExists(workflowName)){
+                throw new UserWorkflowDoesNotExistsException(workflowName);
+            }
+            try {
+				UserWorkflowResource workflowResource = worker.getWorkflowTemplate(workflowName);
+				workflowResource.setContent(workflowGraphXml);
+				workflowResource.save();
+			} catch (RegistryException e) {
+				throw new RegException(e);
+			}
+        }
     }
 
     public String getWorkflowGraphXML(String workflowName) throws RegException {
-//        if (userWorkflowRegistry != null){
-//            return userWorkflowRegistry.getWorkflowGraphXML(workflowName);
-//        }
-//        WorkerResource worker = jpa.getWorker();
-//		if (!isWorkflowExists(workflowName)){
-//        	throw new UserWorkflowDoesNotExistsException(workflowName);
-//        }
-//		return worker.getWorkflowTemplate(workflowName).getContent();
-        return null;
+        if (userWorkflowRegistry != null){
+            return userWorkflowRegistry.getWorkflowGraphXML(workflowName);
+        }
+        WorkerResource worker = jpa.getWorker();
+		if (!isWorkflowExists(workflowName)){
+        	throw new UserWorkflowDoesNotExistsException(workflowName);
+        }
+		try {
+			return worker.getWorkflowTemplate(workflowName).getContent();
+		} catch (RegistryException e) {
+			throw new RegException(e);
+		}
     }
 
 	@Override
 	public Map<String, String> getWorkflows() throws RegException {
-//        if (userWorkflowRegistry != null){
-//            return userWorkflowRegistry.getWorkflows();
-//        }
-//        WorkerResource worker = jpa.getWorker();
-//    	Map<String, String> workflows=new HashMap<String, String>();
-//    	List<UserWorkflowResource> workflowTemplates = worker.getWorkflowTemplates();
-//    	for (UserWorkflowResource resource : workflowTemplates) {
-//    		workflows.put(resource.getName(), resource.getContent());
-//		}
-//    	return workflows;
-        return null;
+        try {
+			if (userWorkflowRegistry != null){
+			    return userWorkflowRegistry.getWorkflows();
+			}
+			WorkerResource worker = jpa.getWorker();
+			Map<String, String> workflows=new HashMap<String, String>();
+			List<UserWorkflowResource> workflowTemplates = worker.getWorkflowTemplates();
+			for (UserWorkflowResource resource : workflowTemplates) {
+				workflows.put(resource.getName(), resource.getContent());
+			}
+			return workflows;
+		} catch (RegistryException e) {
+			throw new RegException(e);
+		}
 	}
 
     public void removeWorkflow(String workflowName) throws RegException {
-//        if (userWorkflowRegistry != null){
-//            userWorkflowRegistry.removeWorkflow(workflowName);
-//        }else {
-//            WorkerResource worker = jpa.getWorker();
-//            if (!isWorkflowExists(workflowName)){
-//                throw new UserWorkflowDoesNotExistsException(workflowName);
-//            }
-//            worker.removeWorkflowTemplate(workflowName);
-//        }
+        if (userWorkflowRegistry != null){
+            userWorkflowRegistry.removeWorkflow(workflowName);
+        }else {
+            WorkerResource worker = jpa.getWorker();
+            if (!isWorkflowExists(workflowName)){
+                throw new UserWorkflowDoesNotExistsException(workflowName);
+            }
+            try {
+				worker.removeWorkflowTemplate(workflowName);
+			} catch (RegistryException e) {
+				throw new RegException(e);
+			}
+        }
     }
 
     public ResourceMetadata getWorkflowMetadata(String workflowName) throws RegException
{

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogImpl.java
b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogImpl.java
index 4a3dcf1..16009eb 100644
--- a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogImpl.java
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogImpl.java
@@ -21,28 +21,29 @@
 
 package org.apache.airavata.workflow.catalog;
 
+import java.util.Arrays;
 import java.util.List;
 
-import org.apache.airavata.client.AiravataAPIFactory;
-import org.apache.airavata.client.api.AiravataAPI;
-import org.apache.airavata.client.api.exception.AiravataAPIInvocationException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.model.Workflow;
+import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.registry.api.AiravataRegistryFactory;
+import org.apache.airavata.registry.api.AiravataUser;
+import org.apache.airavata.registry.api.Gateway;
+import org.apache.airavata.registry.api.exception.RegException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class WorkflowCatalogImpl implements WorkflowCatalog {
     private static final Logger log = LoggerFactory.getLogger(WorkflowCatalogImpl.class);
 
-	private AiravataAPI airavataAPI;
+	private AiravataRegistry2 registry;
 	
 	public List<String> getAllWorkflows() throws WorkflowCatalogException{
 		try {
-			return getAiravataAPI().getWorkflowManager()
-					.getWorkflowTemplateIds();
-		} catch (AiravataAPIInvocationException e) {
+			return Arrays.asList(getRegistry().getWorkflows().keySet().toArray(new String[]{}));
+		} catch (RegException e) {
 			String msg = "Error in retrieving all workflow template Ids.";
 			log.error(msg, e);
 			WorkflowCatalogException exception = new WorkflowCatalogException(msg + " More info :
" + e.getMessage());
@@ -54,14 +55,12 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public Workflow getWorkflow(String workflowTemplateId)
 			throws WorkflowCatalogException{
 		try {
-			org.apache.airavata.workflow.model.wf.Workflow w = getAiravataAPI()
-					.getWorkflowManager().getWorkflow(workflowTemplateId);
 			Workflow workflow = new Workflow();
 			workflow.setTemplateId(workflowTemplateId);
-			workflow.setGraph(XMLUtil.xmlElementToString(w.toXML()));
-			workflow.setName(w.getName());
+			workflow.setGraph(getRegistry().getWorkflowGraphXML(workflowTemplateId));
+			workflow.setName(workflowTemplateId);
 			return workflow;
-		} catch (AiravataAPIInvocationException e) {
+		} catch (RegException e) {
 			String msg = "Error in retrieving the workflow "
 					+ workflowTemplateId + ".";
 			log.error(msg, e);
@@ -74,9 +73,8 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public void deleteWorkflow(String workflowTemplateId)
 			throws WorkflowCatalogException{
 		try {
-			getAiravataAPI().getWorkflowManager().deleteWorkflow(
-					workflowTemplateId);
-		} catch (AiravataAPIInvocationException e) {
+			getRegistry().removeWorkflow(workflowTemplateId);
+		} catch (RegException e) {
 			String msg = "Error in deleting the workflow " + workflowTemplateId
 					+ ".";
 			log.error(msg, e);
@@ -89,10 +87,9 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public String registerWorkflow(Workflow workflow)
 			throws WorkflowCatalogException {
 		try {
-			getAiravataAPI().getWorkflowManager().addWorkflow(
-					workflow.getGraph());
+			getRegistry().addWorkflow(workflow.getName(),workflow.getGraph());
 			return workflow.getName();
-		} catch (AiravataAPIInvocationException e) {
+		} catch (RegException e) {
 			String msg = "Error in registering the workflow "
 					+ workflow.getName() + ".";
 			log.error(msg, e);
@@ -105,9 +102,8 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public void updateWorkflow(String workflowTemplateId, Workflow workflow)
 			throws WorkflowCatalogException {
 		try {
-			getAiravataAPI().getWorkflowManager().updateWorkflow(
-					workflowTemplateId, workflow.getGraph());
-		} catch (AiravataAPIInvocationException e) {
+			getRegistry().updateWorkflow(workflowTemplateId, workflow.getGraph());
+		} catch (RegException e) {
 			String msg = "Error in updating the workflow " + workflow.getName()
 					+ ".";
 			log.error(msg, e);
@@ -120,14 +116,13 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public String getWorkflowTemplateId(String workflowName)
 			throws WorkflowCatalogException {
 		try {
-			if (getAiravataAPI().getWorkflowManager().isWorkflowExists(
-					workflowName)) {
+			if (getRegistry().isWorkflowExists(workflowName)) {
 				return workflowName;
 			}
 			WorkflowCatalogException airavataClientException = new WorkflowCatalogException("No worklfow
exists with the name "
 							+ workflowName);
 			throw airavataClientException;
-		} catch (AiravataAPIInvocationException e) {
+		} catch (RegException e) {
 			String msg = "Error in retrieving the workflow template id for "
 					+ workflowName + ".";
 			log.error(msg, e);
@@ -140,9 +135,8 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	public boolean isWorkflowExistWithName(String workflowName)
 			throws WorkflowCatalogException {
 		try {
-			return getAiravataAPI().getWorkflowManager().isWorkflowExists(
-					workflowName);
-		} catch (AiravataAPIInvocationException e) {
+			return getRegistry().isWorkflowExists(workflowName);
+		} catch (RegException e) {
 			String msg = "Error in veriying the workflow for workflow name "
 					+ workflowName + ".";
 			log.error(msg, e);
@@ -152,22 +146,22 @@ public class WorkflowCatalogImpl implements WorkflowCatalog {
 	}
 
 	private String getAiravataUserName() throws ApplicationSettingsException {
-		return ServerSettings.getDefaultUserGateway();
+		return ServerSettings.getDefaultUser();
 	}
 
 	private String getGatewayName() throws ApplicationSettingsException {
-		return ServerSettings.getDefaultUser();
+		return ServerSettings.getDefaultUserGateway();
 	}
 
-	private AiravataAPI getAiravataAPI() {
-		if (airavataAPI == null) {
+	private AiravataRegistry2 getRegistry() {
+		if (registry == null) {
 			try {
-				airavataAPI = AiravataAPIFactory.getAPI(getGatewayName(),
-						getAiravataUserName());
+				registry = AiravataRegistryFactory.getRegistry(new Gateway(getGatewayName()),
+						new AiravataUser(getAiravataUserName()));
 			} catch (Exception e) {
 				log.error("Unable to create Airavata API", e);
 			}
 		}
-		return airavataAPI;
+		return registry;
 	}
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/XBayaConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/XBayaConfiguration.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/XBayaConfiguration.java
index 6b94cc2..5e6d364 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/XBayaConfiguration.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/XBayaConfiguration.java
@@ -897,6 +897,12 @@ public class XBayaConfiguration extends Observable implements Observer
{
 	}
 	
 	public ThriftClientData getThriftClientData(ThriftServiceType serviceType){
-		return (getThriftClientDataList().containsKey(serviceType)?getThriftClientDataList().get(serviceType):null);
+		return (isThriftServiceDataExist(serviceType)?getThriftClientDataList().get(serviceType):null);
 	}
+
+	public boolean isThriftServiceDataExist(ThriftServiceType serviceType) {
+		return getThriftClientDataList().containsKey(serviceType);
+	}
+	
+	
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
index 32743a5..d5de6bb 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/XBayaGUI.java
@@ -63,11 +63,13 @@ import org.apache.airavata.ws.monitor.event.Event.Type;
 import org.apache.airavata.ws.monitor.event.EventListener;
 import org.apache.airavata.xbaya.XBayaConfiguration;
 import org.apache.airavata.xbaya.XBayaConfiguration.XBayaExecutionMode;
+import org.apache.airavata.xbaya.ThriftServiceType;
 import org.apache.airavata.xbaya.XBayaConstants;
 import org.apache.airavata.xbaya.XBayaEngine;
 import org.apache.airavata.xbaya.core.generators.WorkflowFiler;
 import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
 import org.apache.airavata.xbaya.ui.dialogs.ErrorWindow;
+import org.apache.airavata.xbaya.ui.dialogs.registry.RegistryWindow;
 import org.apache.airavata.xbaya.ui.dialogs.workflow.WorkflowPropertyWindow;
 import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
 import org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent;
@@ -713,7 +715,7 @@ public class XBayaGUI implements EventListener, XBayaExecutionModeListener
{
         this.frame.addWindowListener(new WindowAdapter() {
             @Override
             public void windowClosing(WindowEvent event) {
-            	int result = JOptionPane.showConfirmDialog(frame, "'Are you sure you want to
exit?", "Exit XBaya", JOptionPane.YES_NO_OPTION);
+            	int result = JOptionPane.showConfirmDialog(frame, "Are you sure you want to
exit?", "Exit XBaya", JOptionPane.YES_NO_OPTION);
 				if (result==JOptionPane.NO_OPTION || (!closeAllGraphCanvas())){
 					return;
 				}
@@ -835,10 +837,21 @@ public class XBayaGUI implements EventListener, XBayaExecutionModeListener
{
 //                getErrorWindow().error(ErrorMessages.COMPONENT_FORMAT_ERROR, e);
 //            }
         }
-
     }
 
 	public XBayaConfiguration getConfiguration() {
 		return engine.getConfiguration();
 	}
+	
+	public boolean setupThriftClientData(ThriftServiceType type){
+		return setupThriftClientData(type, false); 
+	}
+	
+	public boolean setupThriftClientData(ThriftServiceType type, boolean force){
+		if (force || !engine.getConfiguration().isThriftServiceDataExist(type)){
+			RegistryWindow window = new RegistryWindow(engine, type);
+	        window.show();
+		}
+		return engine.getConfiguration().isThriftServiceDataExist(type);
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/registry/RegistryWindow.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/registry/RegistryWindow.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/registry/RegistryWindow.java
index 1ae1131..61040ac 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/registry/RegistryWindow.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/registry/RegistryWindow.java
@@ -72,15 +72,16 @@ public class RegistryWindow {
 
     private static String previousServerName;
 
-    private ThriftServiceType serviceType;
+    private ThriftServiceType serviceType = ThriftServiceType.API_SERVICE;
     
     private DefaultComboBoxModel serviceTypeModel;
     
     /**
      * @param engine
      */
-    public RegistryWindow(XBayaEngine engine) {
+    public RegistryWindow(XBayaEngine engine, ThriftServiceType serviceType) {
         this.engine = engine;
+        this.serviceType = serviceType;
         ComponentRegistryLoader.getLoader(this.engine, RegistryConstants.REGISTRY_TYPE_JCR);
         initGUI();
     }
@@ -142,7 +143,7 @@ public class RegistryWindow {
         XBayaLabel gatewayNameLabel = new XBayaLabel("Gateway Name", this.gatewayNameTextField);
         XBayaLabel gatewayUserLabel = new XBayaLabel("Gateway TUser", this.usernameTextField);
         serviceTypeModel = new DefaultComboBoxModel(ThriftServiceType.values());
-        serviceTypeModel.setSelectedItem(ThriftServiceType.API_SERVICE);
+        serviceTypeModel.setSelectedItem(getServiceType());
 		this.serviceTypeCombo = new XBayaComboBox(serviceTypeModel);
         JLabel serviceTypeLabel = new JLabel("Airavata Service");
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/workflow/WorkflowImportWindow.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/workflow/WorkflowImportWindow.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/workflow/WorkflowImportWindow.java
new file mode 100644
index 0000000..e35eebd
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/dialogs/workflow/WorkflowImportWindow.java
@@ -0,0 +1,265 @@
+/*
+ *
+ * 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.ui.dialogs.workflow;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+import javax.swing.border.EtchedBorder;
+import javax.swing.border.TitledBorder;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.api.client.AiravataClientFactory;
+import org.apache.airavata.api.workflow.Workflow.Client;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.model.error.AiravataClientException;
+import org.apache.airavata.model.error.AiravataSystemException;
+import org.apache.airavata.model.error.InvalidRequestException;
+import org.apache.airavata.workflow.model.graph.ws.WSGraph;
+import org.apache.airavata.workflow.model.graph.ws.WSGraphFactory;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.ThriftClientData;
+import org.apache.airavata.xbaya.ThriftServiceType;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.ui.dialogs.XBayaDialog;
+import org.apache.airavata.xbaya.ui.experiment.RegistrySearchResult;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.apache.airavata.xbaya.ui.widgets.GridPanel;
+import org.apache.airavata.xbaya.ui.widgets.XbayaEnhancedList;
+import org.apache.thrift.TException;
+import org.xmlpull.infoset.XmlElement;
+
+public class WorkflowImportWindow {
+
+    private XBayaEngine engine;
+
+    private XBayaDialog dialog;
+
+    private JButton okButton;
+
+    private JButton deleteButton;
+
+    private XbayaEnhancedList<RegistrySearchResult> list;
+
+    private Client client;
+    /**
+     * Constructs a RegistryLoaderWindow.
+     *
+     * @param engine
+     * @throws Exception 
+     */
+    public WorkflowImportWindow(XBayaEngine engine) throws Exception {
+        this.engine = engine;
+        if (engine.getGUI().setupThriftClientData(ThriftServiceType.WORKFLOW_SERVICE)) {
+        	ThriftClientData thriftClientData = engine.getConfiguration().getThriftClientData(ThriftServiceType.WORKFLOW_SERVICE);
+        	setClient(AiravataClientFactory.createWorkflowClient(thriftClientData.getServerAddress(),
thriftClientData.getServerPort()));
+            initGUI();
+        } else {
+        	throw new Exception("Thrift data not setup for workflow service!!!");
+        }
+    }
+
+    /**
+     * Shows the window.
+     */
+    public void show() {
+
+        /*
+         * this.list.getList().setListData( new String[]{ "Loading the workflow list from
the Registry.",
+         * "Please wait for a moment."});
+         */
+        this.list.setEnabled(false);
+        this.okButton.setEnabled(false);
+        this.deleteButton.setEnabled(false);
+
+        new Thread() {
+            @Override
+            public void run() {
+                try {
+                    SwingUtilities.invokeLater(new Runnable() {
+                        public void run() {
+                            try {
+								List<String> resultList = getClient().getAllWorkflows();
+								if (resultList == null || resultList.size() == 0) {
+								    /*
+								     * OGCEXRegistryLoaderWindow.this.list.getList(). setListData( new
+								     * String[]{"No workflow"});
+								     */
+								} else {
+								    Vector<RegistrySearchResult> results = new Vector<RegistrySearchResult>();
+								    String val = null;
+								    for (String key : resultList) {
+								       results.add(new RegistrySearchResult(new QName(key),key,key));
+								    }
+								    WorkflowImportWindow.this.list.setListData(results);
+								    WorkflowImportWindow.this.list.setEnabled(true);
+								}
+							} catch (InvalidRequestException e) {
+								e.printStackTrace();
+							} catch (AiravataClientException e) {
+								e.printStackTrace();
+							} catch (AiravataSystemException e) {
+								e.printStackTrace();
+							} catch (TException e) {
+								e.printStackTrace();
+							}
+                        }
+                    });
+                } catch (RuntimeException e) {
+                	WorkflowImportWindow.this.engine.getGUI().getErrorWindow().error(
+                            ErrorMessages.REGISTRY_WORKFLOW_LIST_LOAD_ERROR, e);
+                    hide();
+                } catch (Error e) {
+                	WorkflowImportWindow.this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR,
e);
+                    hide();
+                }
+            }
+        }.start();
+
+        // This has to be the last because it blocks when the dialog is modal.
+        this.dialog.show();
+    }
+
+    /**
+     * Hides the window.
+     */
+    public void hide() {
+        this.dialog.hide();
+    }
+
+    private void ok() {
+    	List<RegistrySearchResult> selectedValues = this.list.getSelectedValues();
+		try {
+	    	for (RegistrySearchResult result : selectedValues) {
+            	org.apache.airavata.model.Workflow workflow = getClient().getWorkflow(result.getResourceName());
+                XmlElement workflowElement = XMLUtil.stringToXmlElement(workflow.getGraph());
+                Workflow w = new Workflow(workflowElement);
+                GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
+                newGraphCanvas.setWorkflow(w);
+                engine.getGUI().getGraphCanvas().setWorkflowFile(null);
+			}
+	    	hide();
+        } catch (Exception e) {
+        	e.printStackTrace();
+        	engine.getGUI().getErrorWindow().error(e);
+        }
+    }
+
+    private void delete() {
+        for (RegistrySearchResult i : this.list.getSelectedValues()) {
+            try {
+                getClient().deleteWorkflow(i.getResourceName());
+            } catch (Exception e) {
+				e.printStackTrace();
+	        	engine.getGUI().getErrorWindow().error(e);
+			}
+        }
+        this.list.removeSelectedRows();
+        hide();
+    }
+
+    /**
+     * Initializes the GUI
+     */
+    private void initGUI() {
+
+        this.list = new XbayaEnhancedList<RegistrySearchResult>();
+
+        this.list.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseClicked(MouseEvent e) {
+                if (e.getClickCount() >= 2) {
+                    // double click is same as cliking the OK button.
+                	WorkflowImportWindow.this.okButton.doClick();
+                }
+                if (WorkflowImportWindow.this.list.getSelectedIndex() == -1) {
+                	WorkflowImportWindow.this.okButton.setEnabled(false);
+                	WorkflowImportWindow.this.deleteButton.setEnabled(false);
+                } else {
+                	WorkflowImportWindow.this.okButton.setEnabled(true);
+                    WorkflowImportWindow.this.deleteButton.setEnabled(true);
+                }
+
+//                if (WorkflowImportWindow.this.list.getSelectedIndex() == 2) {
+//                	WorkflowImportWindow.this.okButton.setEnabled(false);
+//                	WorkflowImportWindow.this.deleteButton.setEnabled(true);
+//                } else if (WorkflowImportWindow.this.list.getSelectedIndex() != 1) {
+//                	WorkflowImportWindow.this.okButton.setEnabled(true);
+//                	WorkflowImportWindow.this.deleteButton.setEnabled(true);
+//                } else {
+//                	WorkflowImportWindow.this.okButton.setEnabled(false);
+//                    WorkflowImportWindow.this.deleteButton.setEnabled(false);
+//                }
+            }
+        });
+
+        GridPanel mainPanel = new GridPanel();
+        TitledBorder border = new TitledBorder(new EtchedBorder(), "Select a workflow to
load");
+        mainPanel.getSwingComponent().setBorder(border);
+        mainPanel.add(this.list);
+        mainPanel.layout(1, 1, 0, 0);
+
+        JPanel buttonPanel = new JPanel();
+        this.okButton = new JButton("Load");
+        this.okButton.addActionListener(new AbstractAction() {
+            public void actionPerformed(ActionEvent e) {
+                ok();
+            }
+        });
+        buttonPanel.add(this.okButton);
+
+        this.deleteButton = new JButton("Delete");
+        this.deleteButton.addActionListener(new AbstractAction() {
+            public void actionPerformed(ActionEvent e) {
+                delete();
+            }
+        });
+        buttonPanel.add(this.deleteButton);
+
+        JButton cancelButton = new JButton("Cancel");
+        cancelButton.addActionListener(new AbstractAction() {
+            public void actionPerformed(ActionEvent e) {
+                hide();
+            }
+        });
+        buttonPanel.add(cancelButton);
+
+        this.dialog = new XBayaDialog(this.engine.getGUI(), "Load a Workflow from the Registry",
mainPanel, buttonPanel);
+        this.dialog.setDefaultButton(this.okButton);
+    }
+
+	public Client getClient() {
+		return client;
+	}
+
+	public void setClient(Client client) {
+		this.client = client;
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistrySearchResult.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistrySearchResult.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistrySearchResult.java
index c17eb4e..a9a2307 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistrySearchResult.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistrySearchResult.java
@@ -45,20 +45,15 @@ public class RegistrySearchResult implements TableRenderable {
      */
 
     public RegistrySearchResult(Workflow workflow) {
-        //Never user so far during the project lifetime, thus assumption will never need
-//            String property = node.getProperty("Type").getString();
-//            if (property.equals(XBayaConstants.REGISTRY_TYPE_HOST_DESC)) {
-//                // todo
-//            } else if (property.equals(XBayaConstants.REGISTRY_TYPE_APPLICATION_DESC))
{
-//                // todo
-//            } else if (property.equals(XBayaConstants.REGISTRY_TYPE_SERVICE_DESC)) {
-//                // todo
-//            } else if (property.equals(XBayaConstants.REGISTRY_TYPE_WORKFLOW)) {
-		    // this.qname = new ;
 		    this.resourceID = workflow.getQname();
 		    this.description = workflow.getDescription();
 		    this.resourceName = workflow.getName();
-//            }
+    }
+    
+    public RegistrySearchResult(QName resourceID, String resourceName, String description)
{
+	    this.resourceID = resourceID;
+	    this.description = description;
+	    this.resourceName = resourceName;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistryWorkflowPublisherWindow.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistryWorkflowPublisherWindow.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistryWorkflowPublisherWindow.java
index 8835be0..59aef22 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistryWorkflowPublisherWindow.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/experiment/RegistryWorkflowPublisherWindow.java
@@ -21,16 +21,30 @@
 
 package org.apache.airavata.xbaya.ui.experiment;
 
+import java.awt.HeadlessException;
 import java.awt.event.ActionEvent;
 
 import javax.swing.AbstractAction;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.border.EtchedBorder;
 import javax.swing.border.TitledBorder;
 
+import org.apache.airavata.api.client.AiravataClientFactory;
+import org.apache.airavata.api.workflow.Workflow.Client;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.model.error.AiravataClientConnectException;
+import org.apache.airavata.model.error.AiravataClientException;
+import org.apache.airavata.model.error.AiravataSystemException;
+import org.apache.airavata.model.error.InvalidRequestException;
+import org.apache.airavata.workflow.catalog.WorkflowCatalog;
+import org.apache.airavata.workflow.catalog.WorkflowCatalogException;
+import org.apache.airavata.workflow.catalog.WorkflowCatalogFactory;
 import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.ThriftClientData;
+import org.apache.airavata.xbaya.ThriftServiceType;
 import org.apache.airavata.xbaya.XBayaEngine;
 import org.apache.airavata.xbaya.ui.dialogs.XBayaDialog;
 import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
@@ -38,6 +52,7 @@ import org.apache.airavata.xbaya.ui.widgets.GridPanel;
 import org.apache.airavata.xbaya.ui.widgets.XBayaLabel;
 import org.apache.airavata.xbaya.ui.widgets.XBayaTextArea;
 import org.apache.airavata.xbaya.ui.widgets.XBayaTextField;
+import org.apache.thrift.TException;
 
 public class RegistryWorkflowPublisherWindow {
 
@@ -73,7 +88,31 @@ public class RegistryWorkflowPublisherWindow {
 
         GraphCanvas graphCanvas = this.engine.getGUI().getGraphCanvas();
         graphCanvas.setNameAndDescription(name, description);
-        hide();
+        workflow.setName(name);
+        String workflowTemplateName = workflow.getName();
+        try {
+        	if (engine.getGUI().setupThriftClientData(ThriftServiceType.WORKFLOW_SERVICE)){
+        		ThriftClientData thriftClientData = engine.getConfiguration().getThriftClientData(ThriftServiceType.WORKFLOW_SERVICE);
+				Client client = AiravataClientFactory.createWorkflowClient(thriftClientData.getServerAddress(),
thriftClientData.getServerPort());
+    			if (client.isWorkflowExistWithName(workflowTemplateName)){
+    				int result = JOptionPane.showConfirmDialog(this.dialog.getDialog(), "A workflow with
the name "+workflowTemplateName+" already exists. Do you want to update it?", "Register Workflow",
JOptionPane.YES_NO_CANCEL_OPTION);
+    				if (result==JOptionPane.NO_OPTION){
+    					return;
+    				} else if (result==JOptionPane.CANCEL_OPTION){
+    					hide();
+    				}
+    			}
+    			String workflowAsString = XMLUtil.xmlElementToString(engine.getGUI().getGraphCanvas().getWorkflow().toXML());
+    			org.apache.airavata.model.Workflow workflowData = new org.apache.airavata.model.Workflow();
+    			workflowData.setName(workflowTemplateName);
+    			workflowData.setGraph(workflowAsString);
+    			client.registerWorkflow(workflowData);
+    			hide();
+        	}
+		} catch (Exception e) {
+			e.printStackTrace();
+            this.engine.getGUI().getErrorWindow().error(e.getMessage());
+		}
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
index e58f0da..e8b7bb8 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/ui/menues/XBayaMenuItem.java
@@ -46,7 +46,10 @@ import org.apache.airavata.xbaya.core.generators.ODEScriptFiler;
 import org.apache.airavata.xbaya.core.generators.WorkflowFiler;
 import org.apache.airavata.xbaya.core.ide.XBayaExecutionModeListener;
 import org.apache.airavata.xbaya.ui.dialogs.component.URLRegistryWindow;
+import org.apache.airavata.xbaya.ui.dialogs.workflow.WorkflowImportWindow;
+import org.apache.airavata.xbaya.ui.experiment.RegistryWorkflowPublisherWindow;
 import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
 import org.apache.airavata.xbaya.ui.widgets.ToolbarButton;
 import org.apache.airavata.xbaya.ui.widgets.XBayaToolBar;
 import org.slf4j.Logger;
@@ -192,6 +195,12 @@ public class XBayaMenuItem implements XBayaExecutionModeListener {
 //        xbayaMenuItem.add(registerHostDesc);
 //        xbayaMenuItem.add(this.registerServiceDesc);
 //        xbayaMenuItem.add(registerApplicationDesc);
+        
+        xbayaMenuItem.add(importWorkflowItemFromRegistry);
+        xbayaMenuItem.add(saveWorkflowtoRegistryItem);
+
+        xbayaMenuItem.addSeparator();
+        
         xbayaMenuItem.add(this.openWorkflowItem);
 
         xbayaMenuItem.addSeparator();
@@ -210,24 +219,23 @@ public class XBayaMenuItem implements XBayaExecutionModeListener {
         xbayaMenuItem.add(this.saveAsWorkflowItem);
         xbayaMenuItem.add(this.saveAllWorkflowItem);
         
-        xbayaMenuItem.addSeparator();
-        JMenu importMenu = new JMenu("Import");
-        	importMenu.add(importWorkflowItemFromFileSystem);
-        	importMenu.add(importWorkflowItemFromRegistry);
-        	importMenu.addSeparator();
-        	importMenu.add(urlItem);	
+//        JMenu importMenu = new JMenu("Import");
+//        	importMenu.add(importWorkflowItemFromFileSystem);
+//        	importMenu.add(importWorkflowItemFromRegistry);
+//        	importMenu.addSeparator();
+//        	importMenu.add(urlItem);	
         	
-        JMenu exportMenu = new JMenu("Export");
-        	exportMenu.add(saveWorkflowtoRegistryItem);
-        	exportMenu.addSeparator();
-	        exportMenu.add(exportJythonItem);
-	        exportMenu.add(exportBpelItem);
-	        exportMenu.add(exportODEScriptsItem);
-	        exportMenu.addSeparator();
-	        exportMenu.add(saveImageItem);
-        
-        xbayaMenuItem.add(importMenu);
-        xbayaMenuItem.add(exportMenu);
+//        JMenu exportMenu = new JMenu("Export");
+//        	exportMenu.add(saveWorkflowtoRegistryItem);
+//        	exportMenu.addSeparator();
+//	        exportMenu.add(exportJythonItem);
+//	        exportMenu.add(exportBpelItem);
+//	        exportMenu.add(exportODEScriptsItem);
+//	        exportMenu.addSeparator();
+//	        exportMenu.add(saveImageItem);
+//        
+//        xbayaMenuItem.add(importMenu);
+//        xbayaMenuItem.add(exportMenu);
         
         xbayaMenuItem.addSeparator();
         
@@ -263,12 +271,14 @@ public class XBayaMenuItem implements XBayaExecutionModeListener {
     }
 
     private void createSaveWorkflowtoRegistryItem() {
-        this.saveWorkflowtoRegistryItem = new JMenuItem("Workflow To Registry...");
+        this.saveWorkflowtoRegistryItem = new JMenuItem("Register workflow...");
         this.saveWorkflowtoRegistryItem.setMnemonic(KeyEvent.VK_C);
         this.saveWorkflowtoRegistryItem.addActionListener(new AbstractAction() {
 			private static final long serialVersionUID = 1L;
             public void actionPerformed(ActionEvent e) {
             	//FIXME
+            	RegistryWorkflowPublisherWindow window = new RegistryWorkflowPublisherWindow(engine);
+            	window.show();
 //                if (registryAccesser.saveWorkflow()){
 //                	if (engine.getGUI().getGraphCanvas().getWorkflowFile()==null){
 //                		engine.getGUI().getGraphCanvas().workflowSaved();
@@ -507,10 +517,16 @@ public class XBayaMenuItem implements XBayaExecutionModeListener {
     }
     
     private void createImportWorkflowItemFromRegistry() {
-        importWorkflowItemFromRegistry = new JMenuItem("Workflow From Registry...");
+        importWorkflowItemFromRegistry = new JMenuItem("Import workflow...");
         importWorkflowItemFromRegistry.addActionListener(new AbstractAction() {
 			private static final long serialVersionUID = 1L;
             public void actionPerformed(ActionEvent e) {
+            	try {
+					WorkflowImportWindow window = new WorkflowImportWindow(engine);
+					window.show();
+				} catch (Exception e1) {
+                	engine.getGUI().getErrorWindow().error(e1);
+				}
             }
         });
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/4752d1a3/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/XBayaUtil.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/XBayaUtil.java
b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/XBayaUtil.java
index 0be61b0..9ba735a 100644
--- a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/XBayaUtil.java
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/util/XBayaUtil.java
@@ -48,6 +48,7 @@ import org.apache.airavata.workflow.model.graph.system.InputNode;
 import org.apache.airavata.workflow.model.wf.Workflow;
 import org.apache.airavata.ws.monitor.MonitorConfiguration;
 import org.apache.airavata.xbaya.ThriftClientData;
+import org.apache.airavata.xbaya.ThriftServiceType;
 import org.apache.airavata.xbaya.XBayaConfiguration;
 import org.apache.airavata.xbaya.XBayaEngine;
 import org.apache.airavata.xbaya.invoker.Invoker;
@@ -147,7 +148,7 @@ public class XBayaUtil {
 //    }
     
     public static void updateJCRRegistryInfo(XBayaEngine xbayaEngine) {
-    	RegistryWindow window = new RegistryWindow(xbayaEngine);
+    	RegistryWindow window = new RegistryWindow(xbayaEngine, ThriftServiceType.API_SERVICE);
         window.show();
 	}
    


Mime
View raw message