You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/14 20:31:22 UTC
[80/90] [abbrv] AIRAVATA-1124
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/component/registry/ComponentRegistryLoader.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/component/registry/ComponentRegistryLoader.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/component/registry/ComponentRegistryLoader.java
new file mode 100644
index 0000000..b0f44e9
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/component/registry/ComponentRegistryLoader.java
@@ -0,0 +1,195 @@
+/*
+ *
+ * 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.component.registry;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Observable;
+import java.util.Observer;
+
+//import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.client.api.AiravataAPI;
+import org.apache.airavata.workflow.model.component.ComponentRegistry;
+import org.apache.airavata.workflow.model.component.ComponentRegistryException;
+import org.apache.airavata.workflow.model.component.registry.JCRComponentRegistry;
+import org.apache.airavata.xbaya.XBayaConfiguration;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.ui.dialogs.WaitDialog;
+import org.apache.airavata.xbaya.ui.utils.Cancelable;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.apache.airavata.xbaya.ui.widgets.component.ComponentTreeNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ComponentRegistryLoader implements Cancelable, Observer {
+
+ private static final Logger logger = LoggerFactory.getLogger(ComponentRegistryLoader.class);
+
+ private XBayaEngine engine;
+
+ private Thread loadThread;
+
+ private boolean canceled;
+
+ private WaitDialog loadingDialog;
+
+ private ComponentTreeNode componentTree;
+
+ private Observable observableRegistry;
+
+ private Map<String,ComponentTreeNode> componentTreeNodesMap;
+
+ private static Map<String, ComponentRegistryLoader> loaders;
+
+ /**
+ * Constructs a WorkflowLoader.
+ *
+ * @param engine
+ */
+ private ComponentRegistryLoader(XBayaEngine engine) {
+ this.setEngine(engine);
+
+ this.loadingDialog = new WaitDialog(this, "Loading a Component List.", "Loading a Component List. "
+ + "Please wait for a moment.", this.getEngine().getGUI());
+ getEngine().getConfiguration().addObserver(this);
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.ui.utils.Cancelable#cancel()
+ */
+ public void cancel() {
+ this.canceled = true;
+ this.loadThread.interrupt();
+ }
+
+ /**
+ * Loads the workflow.
+ *
+ * @param registry
+ *
+ */
+ public void load(final ComponentRegistry registry) {
+ this.canceled = false;
+
+ this.loadThread = new Thread() {
+ @Override
+ public void run() {
+ runInThread(registry);
+ }
+ };
+ this.loadThread.start();
+
+ if (!getComponentTreeNodesMap().containsKey(registry.getName())) {
+ // This has to be the last because it blocks when the dialog is modal.
+ this.loadingDialog.show();
+ }
+ }
+
+ /**
+ * @param registry
+ */
+ /**
+ * TODO : this method triggered twice when connecting to the registy. We need to find
+ * why it is happening
+ */
+ private synchronized void runInThread(ComponentRegistry registry) {
+ try {
+ this.getEngine().getGUI().getComponentSelector().removeComponentRegistry(registry.getName());
+// if (getComponentTreeNodesMap().containsKey(registry.getName())){
+// this.getEngine().getGUI().getComponentSelector().removeComponentTree(getComponentTreeNodesMap().get(registry.getName()));
+// getComponentTreeNodesMap().remove(registry.getName());
+// }
+ componentTree = ComponentController.getComponentTree(registry);
+ if (this.canceled) {
+ return;
+ }
+ this.getEngine().getGUI().getComponentSelector().addComponentTree(componentTree);
+// getComponentTreeNodesMap().put(registry.getName(),componentTree);
+ this.loadingDialog.hide();
+ } catch (ComponentRegistryException e) {
+ if (this.canceled) {
+ logger.error(e.getMessage(), e);
+ } else {
+ this.getEngine().getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_LIST_LOAD_ERROR, e);
+ this.loadingDialog.hide();
+ }
+ } catch (RuntimeException e) {
+ if (this.canceled) {
+ logger.error(e.getMessage(), e);
+ } else {
+ this.getEngine().getGUI().getErrorWindow().error(ErrorMessages.COMPONENT_LIST_LOAD_ERROR, e);
+ this.loadingDialog.hide();
+ }
+ } catch (Error e) {
+ this.getEngine().getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ this.loadingDialog.hide();
+ }
+ }
+
+ @Override
+ public void update(Observable observable, Object o) {
+ if ((observable instanceof XBayaConfiguration) && (o instanceof ComponentRegistry)){
+ ComponentRegistry componentRegistry=(ComponentRegistry)o;
+ if (observableRegistry!=null){
+ observableRegistry.deleteObserver(this);
+ }
+ if (componentRegistry instanceof JCRComponentRegistry){
+ AiravataAPI registry = ((JCRComponentRegistry)componentRegistry).getAiravataAPI();
+ if (registry!=null && registry instanceof Observable){
+ (observableRegistry=(Observable)registry).addObserver(this);
+ }
+ }
+ load(componentRegistry);
+ }else if (observable instanceof AiravataAPI){
+ load(getEngine().getConfiguration().getJcrComponentRegistry());
+ }
+ }
+
+ public XBayaEngine getEngine() {
+ return engine;
+ }
+
+ public void setEngine(XBayaEngine engine) {
+ this.engine = engine;
+ }
+
+ public Map<String,ComponentTreeNode> getComponentTreeNodesMap() {
+ if (componentTreeNodesMap==null){
+ componentTreeNodesMap=new HashMap<String, ComponentTreeNode>();
+ }
+ return componentTreeNodesMap;
+ }
+
+ protected static Map<String, ComponentRegistryLoader> getLoaders() {
+ if (loaders==null){
+ loaders=new HashMap<String, ComponentRegistryLoader>();
+ }
+ return loaders;
+ }
+
+ public static ComponentRegistryLoader getLoader(XBayaEngine engine, String id){
+ if (!getLoaders().containsKey(id)){
+ getLoaders().put(id, new ComponentRegistryLoader(engine));
+ }
+ return getLoaders().get(id);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedExecutable.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedExecutable.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedExecutable.java
new file mode 100644
index 0000000..6a06c19
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedExecutable.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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.concurrent;
+
+/**
+ * Intended for jobs that are runnable; Way of determining
+ * whether a given job is ready to be executed
+ *
+ * @author Chathura Herath
+ */
+public interface PredicatedExecutable extends Runnable{
+
+ public boolean isReady();
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedTaskRunner.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedTaskRunner.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedTaskRunner.java
new file mode 100644
index 0000000..1bed1f4
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/concurrent/PredicatedTaskRunner.java
@@ -0,0 +1,153 @@
+/*
+ *
+ * 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.concurrent;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Used to run jobs that need to be started after a predicate is
+ *
+ * @author Chathura Herath
+ */
+public class PredicatedTaskRunner {
+
+ protected volatile ConcurrentLinkedQueue<PredicatedExecutable> jobQueue = new ConcurrentLinkedQueue<PredicatedExecutable>();
+
+ protected ExecutorService threadPool;
+
+ protected volatile boolean stop = false;
+
+ public PredicatedTaskRunner(int numberOfThreads) {
+ this.threadPool = Executors.newFixedThreadPool(numberOfThreads);
+ addIdleTask();
+ startCheckThread();
+
+ }
+
+ private void addIdleTask() {
+ PredicatedExecutable sleepTask = new PredicatedExecutable() {
+
+ @Override
+ public void run() {
+ synchronized (jobQueue) {
+ if (jobQueue.size() == 1) {
+ try {
+ jobQueue.wait();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ } else if (allTasksAreWaiting(jobQueue)) {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ }
+
+ private boolean allTasksAreWaiting(
+ ConcurrentLinkedQueue<PredicatedExecutable> jobQueue) {
+ for (PredicatedExecutable predicatedExecutable : jobQueue) {
+ if (predicatedExecutable.isReady()) {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ @Override
+ public boolean isReady() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+ };
+
+ this.jobQueue.add(sleepTask);
+ }
+
+ private void startCheckThread() {
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+
+ while (!stop) {
+ try {
+
+
+ synchronized (jobQueue) {
+ while(jobQueue.size() == 0 || allTasksAreWaiting(jobQueue)){
+ jobQueue.wait(50);
+ }
+ }
+
+ PredicatedExecutable job = jobQueue.remove();
+ if (job.isReady()) {
+ // remove from front and execute and you are done
+ threadPool.execute(job);
+ } else {
+ // add to end if not ready to run
+ jobQueue.add(job);
+ }
+
+
+
+ } catch (Throwable e) {
+ // we go on no matter what
+ e.printStackTrace();
+ }
+ }
+
+ }
+ }).start();
+ }
+
+ private boolean allTasksAreWaiting(
+ ConcurrentLinkedQueue<PredicatedExecutable> jobQueue) {
+ for (PredicatedExecutable predicatedExecutable : jobQueue) {
+ if (predicatedExecutable.isReady()) {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+ public void scedule(PredicatedExecutable job) {
+
+ synchronized (jobQueue) {
+ this.jobQueue.add(job);
+ this.jobQueue.notifyAll();
+ }
+
+ }
+
+ public void shutDown() {
+ this.threadPool.shutdown();
+ this.stop = true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/AmazonCredential.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/AmazonCredential.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/AmazonCredential.java
new file mode 100644
index 0000000..fdf2267
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/AmazonCredential.java
@@ -0,0 +1,79 @@
+/*
+ *
+ * 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.core.amazon;
+
+public class AmazonCredential {
+ private static AmazonCredential instance;
+ private String awsAccesskey;
+ private String awsSecretAccessKey;
+
+ private AmazonCredential() {
+ this.awsAccesskey = "";
+ this.awsSecretAccessKey = "";
+ }
+
+ /**
+ *
+ * @return AmazonCredential
+ */
+ public static AmazonCredential getInstance() {
+ if (instance == null) {
+ instance = new AmazonCredential();
+ }
+ return instance;
+ }
+
+ /**
+ *
+ * @param accesskey
+ */
+ public void setAwsAccessKeyId(String accesskey) {
+ this.awsAccesskey = accesskey;
+ }
+
+ /**
+ *
+ * @param secretAccessKey
+ */
+ public void setAwsSecretAccessKey(String secretAccessKey) {
+ this.awsSecretAccessKey = secretAccessKey;
+ }
+
+ /**
+ *
+ * @param accesskey
+ * @return
+ */
+ public String getAwsAccessKeyId() {
+ return this.awsAccesskey;
+ }
+
+ /**
+ *
+ * @param secretAccessKey
+ * @return
+ */
+ public String getAwsSecretAccessKey() {
+ return this.awsSecretAccessKey;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/EC2InstanceResult.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/EC2InstanceResult.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/EC2InstanceResult.java
new file mode 100644
index 0000000..260ef2c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/amazon/EC2InstanceResult.java
@@ -0,0 +1,94 @@
+/*
+ *
+ * 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.core.amazon;
+
+import org.apache.airavata.xbaya.ui.widgets.TableRenderable;
+
+import com.amazonaws.services.ec2.model.Instance;
+
+public class EC2InstanceResult implements TableRenderable {
+
+ private static String[] columnName = { "Instance", "AMI ID", "Root Device", "Type", "Status", "Key Pair Name",
+ "Monitoring", "Virtualization", "Placement Group" };
+
+ private Instance instance;
+
+ /**
+ *
+ * Constructs a EC2InstancesResult.
+ *
+ * @param ins
+ */
+ public EC2InstanceResult(Instance ins) {
+ this.instance = ins;
+ }
+
+ public Instance getInstance() {
+ return this.instance;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.ui.widgets.TableRenderable#getColumnCount()
+ */
+ @Override
+ public int getColumnCount() {
+ return 8;
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.ui.widgets.TableRenderable#getColumnTitle(int)
+ */
+ @Override
+ public String getColumnTitle(int index) {
+ return columnName[index];
+ }
+
+ /**
+ * @see org.apache.airavata.xbaya.ui.widgets.TableRenderable#getValue(int)
+ */
+ @Override
+ public Object getValue(int index) {
+ switch (index) {
+ case 0:
+ return this.instance.getInstanceId();
+ case 1:
+ return this.instance.getImageId();
+ case 2:
+ return this.instance.getRootDeviceType();
+ case 3:
+ return this.instance.getInstanceType();
+ case 4:
+ return this.instance.getState().getName();
+ case 5:
+ return this.instance.getKeyName();
+ case 6:
+ return this.instance.getMonitoring().getState();
+ case 7:
+ return this.instance.getVirtualizationType();
+ case 8:
+ return this.instance.getPlacement().getGroupName();
+ default:
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/BPELFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/BPELFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/BPELFiler.java
new file mode 100644
index 0000000..2e0f4f5
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/BPELFiler.java
@@ -0,0 +1,145 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.gpel.script.BPELScript;
+import org.apache.airavata.workflow.model.gpel.script.BPELScriptType;
+import org.apache.airavata.workflow.model.gpel.script.WorkflowWSDL;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.gpel.model.GpelProcess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BPELFiler {
+
+ private static Logger logger = LoggerFactory.getLogger(BPELFiler.class);
+
+ private XBayaEngine engine;
+
+ private JFileChooser bpelFileChooser;
+
+ private final FileFilter bpelFileFilter = new FileFilter() {
+
+ @Override
+ public String getDescription() {
+ return "BPEL Files";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.BPEL_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Constructs a BPELFiler.
+ *
+ * @param engine
+ */
+ public BPELFiler(XBayaEngine engine) {
+ this.engine = engine;
+
+ this.bpelFileChooser = new JFileChooser(XBayaPathConstants.BPEL_SCRIPT_DIRECTORY);
+ this.bpelFileChooser.addChoosableFileFilter(this.bpelFileFilter);
+
+ }
+
+ /**
+ * Exports a BPEL process to the local file
+ */
+ public void exportBPEL() {
+ Workflow workflow = this.engine.getGUI().getWorkflow();
+ BPELScript bpel = new BPELScript(workflow);
+
+ // Check if there is any errors in the workflow first.
+ ArrayList<String> warnings = new ArrayList<String>();
+ if (!bpel.validate(warnings)) {
+ StringBuilder buf = new StringBuilder();
+ for (String warning : warnings) {
+ buf.append("- ");
+ buf.append(warning);
+ buf.append("\n");
+ }
+ this.engine.getGUI().getErrorWindow().warning(buf.toString());
+ return;
+ }
+
+ int returnVal = this.bpelFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.bpelFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ String path = file.getPath();
+
+ // Remove ".bpel" at the end if any
+ if (path.endsWith(XBayaConstants.BPEL_SUFFIX)) {
+ path = path.substring(0, path.length() - XBayaConstants.BPEL_SUFFIX.length());
+ }
+
+ // Add ".bpel" at the end of the file name
+ File bpelFile = new File(path + XBayaConstants.BPEL_SUFFIX);
+ // Add ".wsdl" at the end of the file name
+ File wsdlFile = new File(path + XBayaConstants.WSDL_SUFFIX);
+
+ try {
+ // Create the script.
+ bpel.create(BPELScriptType.BPEL2);
+
+ GpelProcess gpelProcess = bpel.getGpelProcess();
+ XMLUtil.saveXML(gpelProcess.xml(), bpelFile);
+
+ WorkflowWSDL workflowWSDL = bpel.getWorkflowWSDL();
+ XMLUtil.saveXML(workflowWSDL.getWsdlDefinitions().xml(), wsdlFile);
+
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_NOT_READY_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ImageFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ImageFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ImageFiler.java
new file mode 100644
index 0000000..34902db
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ImageFiler.java
@@ -0,0 +1,106 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ImageFiler {
+
+ private static Logger logger = LoggerFactory.getLogger(ImageFiler.class);
+
+ private XBayaEngine engine;
+
+ private JFileChooser pngFileChooser;
+
+ private final FileFilter pngFileFilter = new FileFilter() {
+ @Override
+ public String getDescription() {
+ return "PNG Files";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.PNG_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Constructs an ImageFiler.
+ *
+ * @param engine
+ */
+ public ImageFiler(XBayaEngine engine) {
+ this.engine = engine;
+
+ this.pngFileChooser = new JFileChooser();
+ this.pngFileChooser.addChoosableFileFilter(this.pngFileFilter);
+ }
+
+ /**
+ * Save the workflow image to the local file
+ */
+ public void saveWorkflowImage() {
+ int returnVal = this.pngFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.pngFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ // Put ".png" at the end of the file name
+ String path = file.getPath();
+ if (!path.endsWith(XBayaConstants.PNG_SUFFIX)) {
+ file = new File(path + XBayaConstants.PNG_SUFFIX);
+ }
+
+ BufferedImage image;
+ try {
+ image = this.engine.getGUI().getWorkflow().getImage();
+ ImageIO.write(image, XBayaConstants.PNG_FORMAT_NAME, file);
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/JythonFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/JythonFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/JythonFiler.java
new file mode 100644
index 0000000..b2dd641
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/JythonFiler.java
@@ -0,0 +1,128 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.airavata.common.utils.IOUtil;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.jython.script.JythonScript;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JythonFiler {
+
+ private static Logger logger = LoggerFactory.getLogger(JythonFiler.class);
+
+ private XBayaEngine engine;
+
+ private JFileChooser jythonFileChooser;
+
+ private final FileFilter jythonFileFilter = new FileFilter() {
+ @Override
+ public String getDescription() {
+ return "Jython Scripts";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.JYTHON_SCRIPT_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Constructs a JythonFile.
+ *
+ * @param engine
+ */
+ public JythonFiler(XBayaEngine engine) {
+ this.engine = engine;
+ this.jythonFileChooser = new JFileChooser(XBayaPathConstants.JYTHON_SCRIPT_DIRECTORY);
+ this.jythonFileChooser.addChoosableFileFilter(this.jythonFileFilter);
+ }
+
+ /**
+ * Exports a Jython script to the local file
+ */
+ public void exportJythonScript() {
+ Workflow workflow = this.engine.getGUI().getWorkflow();
+ JythonScript script = new JythonScript(workflow, this.engine.getConfiguration());
+
+ // Check if there is any errors in the workflow first.
+ ArrayList<String> warnings = new ArrayList<String>();
+ if (!script.validate(warnings)) {
+ StringBuilder buf = new StringBuilder();
+ for (String warning : warnings) {
+ buf.append("- ");
+ buf.append(warning);
+ buf.append("\n");
+ }
+ this.engine.getGUI().getErrorWindow().warning(buf.toString());
+ return;
+ }
+
+ int returnVal = this.jythonFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.jythonFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ // Put ".py" at the end of the file name
+ String path = file.getPath();
+ if (!path.endsWith(XBayaConstants.JYTHON_SCRIPT_SUFFIX)) {
+ file = new File(path + XBayaConstants.JYTHON_SCRIPT_SUFFIX);
+ }
+
+ try {
+ // Create the script.
+ script.create();
+ // Write to a file
+ IOUtil.writeToFile(script.getJythonString(), file);
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ODEScriptFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ODEScriptFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ODEScriptFiler.java
new file mode 100644
index 0000000..a1573d4
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ODEScriptFiler.java
@@ -0,0 +1,165 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSDLUtil;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.gpel.model.GpelProcess;
+import org.xmlpull.infoset.XmlElement;
+
+import xsul5.XmlConstants;
+import xsul5.wsdl.WsdlDefinitions;
+
+public class ODEScriptFiler {
+
+ private XBayaEngine engine;
+
+ private JFileChooser bpelFileChooser;
+
+ private final FileFilter bpelFileFilter = new FileFilter() {
+
+ @Override
+ public String getDescription() {
+ return "BPEL Files";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.BPEL_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Constructs a ODEScriptFiler.
+ *
+ * @param engine
+ */
+ public ODEScriptFiler(XBayaEngine engine) {
+ this.engine = engine;
+
+ this.bpelFileChooser = new JFileChooser(XBayaPathConstants.BPEL_SCRIPT_DIRECTORY);
+ this.bpelFileChooser.addChoosableFileFilter(this.bpelFileFilter);
+ }
+
+ /**
+ *
+ */
+ public void save() {
+ Workflow wf = this.engine.getGUI().getWorkflow();
+ if (0 == wf.getGraph().getNodes().size()) {
+ this.engine.getGUI().getErrorWindow().warning("Workflow is Empty");
+ return;
+ }
+ GpelProcess process;
+ try {
+
+ int returnVal = this.bpelFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.bpelFileChooser.getSelectedFile();
+
+ String path = file.getPath();
+
+ // Remove ".bpel" at the end if any
+ if (path.endsWith(XBayaConstants.BPEL_SUFFIX)) {
+ path = path.substring(0, path.length() - XBayaConstants.BPEL_SUFFIX.length());
+ }
+
+ // Add ".bpel" at the end of the file name
+ File bpelFile = new File(path + XBayaConstants.BPEL_SUFFIX);
+ // Add ".wsdl" at the end of the file name
+ File wsdlFile = new File(path + XBayaConstants.WSDL_SUFFIX);
+ // todo this has to fix, for compilation purpose passing dummy value instead of xregistry url
+ URI temp = null;
+ try {
+ temp = new URI("temp");
+ } catch (URISyntaxException e) {
+ e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates.
+ }
+ process = wf.getOdeProcess(WSDLUtil.appendWSDLQuary(temp), this.engine.getConfiguration().getODEURL());
+ String processString = process.xmlStringPretty();
+ FileWriter writer = new FileWriter(bpelFile);
+ writer.write(processString);
+ writer.close();
+
+ WsdlDefinitions workflowWSDL = wf.getOdeWorkflowWSDL(this.engine.getConfiguration().getDSCURL(),
+ this.engine.getConfiguration().getODEURL());
+ String workflowWsdlStr = XmlConstants.BUILDER.serializeToStringPretty(workflowWSDL.xml());
+ writer = new FileWriter(wsdlFile);
+ writer.write(workflowWsdlStr);
+
+ Map<String, WsdlDefinitions> wsdlMap = wf.getOdeServiceWSDLs(
+ this.engine.getConfiguration().getDSCURL(), this.engine.getConfiguration().getODEURL());
+ Set<String> keySet = wsdlMap.keySet();
+ for (String string : keySet) {
+ writer = new FileWriter(new File(wsdlFile.getParent(), QName.valueOf(string).getLocalPart()));
+ writer.write(XmlConstants.BUILDER.serializeToStringPretty(wsdlMap.get(string).xml()));
+ writer.close();
+ }
+
+ XmlElement deployDescriptor = wf.getODEDeploymentDescriptor(this.engine.getConfiguration().getDSCURL(),
+ this.engine.getConfiguration().getODEURL());
+ writer = new FileWriter(new File(wsdlFile.getParent(), "deploy.xml"));
+ writer.write(XmlConstants.BUILDER.serializeToString(deployDescriptor));
+ writer.close();
+
+ }
+
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (ComponentException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ScuflFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ScuflFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ScuflFiler.java
new file mode 100644
index 0000000..bed2bc4
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/ScuflFiler.java
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.airavata.common.utils.IOUtil;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.apache.airavata.xbaya.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.scufl.script.ScuflScript;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ScuflFiler {
+
+ private static Logger logger = LoggerFactory.getLogger(ScuflFiler.class);
+
+ private XBayaEngine engine;
+
+ private JFileChooser scuflFileChooser;
+
+ private final FileFilter scuflFileFilter = new FileFilter() {
+ @Override
+ public String getDescription() {
+ return "Scufl Scripts";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.SCUFL_SCRIPT_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Constructs a ScuflFiler.
+ *
+ * @param engine
+ */
+ public ScuflFiler(XBayaEngine engine) {
+ this.engine = engine;
+ this.scuflFileChooser = new JFileChooser(XBayaPathConstants.SCUFL_SCRIPT_DIRECTORY);
+ this.scuflFileChooser.addChoosableFileFilter(this.scuflFileFilter);
+ }
+
+ /**
+ * Exports a Scufl script to the local file
+ */
+ public void exportScuflScript() {
+ Workflow workflow = this.engine.getGUI().getWorkflow();
+ ScuflScript script = new ScuflScript(workflow, this.engine.getConfiguration());
+
+ // Check if there is any errors in the workflow first.
+ ArrayList<String> warnings = new ArrayList<String>();
+ if (!script.validate(warnings)) {
+ StringBuilder buf = new StringBuilder();
+ for (String warning : warnings) {
+ buf.append("- ");
+ buf.append(warning);
+ buf.append("\n");
+ }
+ this.engine.getGUI().getErrorWindow().warning(buf.toString());
+ return;
+ }
+ int returnVal = this.scuflFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.scuflFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ // Put ".py" at the end of the file name
+ String path = file.getPath();
+ if (!path.endsWith(XBayaConstants.SCUFL_SCRIPT_SUFFIX)) {
+ file = new File(path + XBayaConstants.SCUFL_SCRIPT_SUFFIX);
+ }
+
+ try {
+ // Create the script.
+ script.create();
+ // Write to a file
+ IOUtil.writeToFile(script.getScript(), file);
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/WorkflowFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/WorkflowFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/WorkflowFiler.java
new file mode 100644
index 0000000..46c567c
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/WorkflowFiler.java
@@ -0,0 +1,267 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import javax.swing.JFileChooser;
+import javax.swing.filechooser.FileFilter;
+
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.component.ComponentException;
+import org.apache.airavata.workflow.model.graph.GraphException;
+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.XBayaConstants;
+import org.apache.airavata.xbaya.XBayaEngine;
+import org.apache.airavata.xbaya.file.XBayaPathConstants;
+import org.apache.airavata.xbaya.ui.graph.GraphCanvas;
+import org.apache.airavata.xbaya.ui.utils.ErrorMessages;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+
+public class WorkflowFiler {
+
+ private static Logger logger = LoggerFactory.getLogger(WorkflowFiler.class);
+
+ private XBayaEngine engine;
+
+ private JFileChooser graphFileChooser;
+
+ private final FileFilter graphFileFilter = new FileFilter() {
+
+ @Override
+ public String getDescription() {
+ return "Workflow Files";
+ }
+
+ @Override
+ public boolean accept(File file) {
+ if (file.isDirectory()) {
+ return true;
+ }
+ String name = file.getName();
+ if (name.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
+ return true;
+ } else if (name.endsWith(XBayaConstants.WORKFLOW_FILE_SUFFIX)) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ /**
+ * Creates a FileMenu.
+ *
+ * @param engine
+ * the XwfClient, which is used to retrieve the current workflow graph.
+ */
+ public WorkflowFiler(XBayaEngine engine) {
+ this.engine = engine;
+
+ this.graphFileChooser = new JFileChooser(XBayaPathConstants.WORKFLOW_DIRECTORY);
+ this.graphFileChooser.addChoosableFileFilter(this.graphFileFilter);
+ this.graphFileChooser.setFileFilter(this.graphFileFilter);
+
+ }
+
+ /**
+ * Opens a current workflow from the local file.
+ */
+ public void openWorkflow() {
+ Workflow workflow = null;
+ int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
+
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.graphFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ try {
+ String path = file.getPath();
+
+ if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
+ WSGraph graph = WSGraphFactory.createGraph(file);
+ workflow = Workflow.graphToWorkflow(graph);
+ } else {
+ XmlElement workflowElement = XMLUtil.loadXML(file);
+ workflow = new Workflow(workflowElement);
+ }
+ GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
+ newGraphCanvas.setWorkflow(workflow);
+ //this.engine.setWorkflow(workflow);
+ engine.getGUI().getGraphCanvas().setWorkflowFile(file);
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (ComponentException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+
+ }
+
+ /**
+ * Saves a current workflow to the local file.
+ */
+ public void saveWorkflow() {
+ saveWorkflow(engine.getGUI().getGraphCanvas());
+ }
+
+ public void saveAsWorkflow() {
+ GraphCanvas graphCanvas = engine.getGUI().getGraphCanvas();
+ File saveAsWorkflowFile = saveAsWorkflow(graphCanvas);
+ if (saveAsWorkflowFile!=null){
+ graphCanvas.setWorkflowFile(saveAsWorkflowFile);
+ }
+ }
+
+ public void saveWorkflow(GraphCanvas graphCanvas) {
+ if (graphCanvas.getWorkflowFile()==null){
+ File saveAsWorkflowFile = saveAsWorkflow(graphCanvas);
+ graphCanvas.setWorkflowFile(saveAsWorkflowFile);
+ }else{
+ saveWorkflow(graphCanvas.getWorkflow(), graphCanvas.getWorkflowFile());
+ }
+ if (graphCanvas.getWorkflowFile()!=null){
+ graphCanvas.workflowSaved();
+ }
+ }
+
+ public void saveAllWorkflows(){
+ List<GraphCanvas> graphCanvases = engine.getGUI().getGraphCanvases();
+ for (GraphCanvas graphCanvas : graphCanvases) {
+ saveWorkflow(graphCanvas);
+ }
+ }
+
+ public File saveAsWorkflow(GraphCanvas graphCanvas) {
+ int returnVal = this.graphFileChooser.showSaveDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.graphFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ // Put ".xwf" at the end of the file name
+ String path = file.getPath();
+ if (!path.endsWith(XBayaConstants.WORKFLOW_FILE_SUFFIX)) {
+ file = new File(path + XBayaConstants.WORKFLOW_FILE_SUFFIX);
+ }
+ saveWorkflow(graphCanvas.getWorkflow(),file);
+ return file;
+ }
+ return null;
+ }
+
+ private void saveWorkflow(Workflow workflow, File file) {
+ try {
+ XMLUtil.saveXML(workflow.toXML(), file);
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.WRITE_FILE_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_SAVE_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+
+ /**
+ * Imports a workflow from the local file to the current workflow.
+ */
+ public void importWorkflow() {
+ int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.graphFileChooser.getSelectedFile();
+ try {
+
+ String path = file.getPath();
+ Workflow importedWorkflow;
+ if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
+ WSGraph importedGraph = WSGraphFactory.createGraph(file);
+ importedWorkflow = Workflow.graphToWorkflow(importedGraph);
+ } else {
+ XmlElement importedWorkflowElement = XMLUtil.loadXML(file);
+ importedWorkflow = new Workflow(importedWorkflowElement);
+ }
+ GraphCanvas newGraphCanvas = engine.getGUI().newGraphCanvas(true);
+ newGraphCanvas.setWorkflow(importedWorkflow);
+ this.engine.getGUI().setWorkflow(importedWorkflow);
+ engine.getGUI().getGraphCanvas().setWorkflowFile(file);
+
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (ComponentException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ }
+ /**
+ * @param workflow
+ * @return
+ */
+ public Workflow getWorkflow() {
+ Workflow workflow = null;
+ int returnVal = this.graphFileChooser.showOpenDialog(this.engine.getGUI().getFrame());
+
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ File file = this.graphFileChooser.getSelectedFile();
+ logger.debug(file.getPath());
+
+ try {
+ String path = file.getPath();
+
+ if (path.endsWith(XBayaConstants.GRAPH_FILE_SUFFIX)) {
+ WSGraph graph = WSGraphFactory.createGraph(file);
+ workflow = Workflow.graphToWorkflow(graph);
+ } else {
+ XmlElement workflowElement = XMLUtil.loadXML(file);
+ workflow = new Workflow(workflowElement);
+ }
+
+ } catch (IOException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.OPEN_FILE_ERROR, e);
+ } catch (GraphException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (ComponentException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.GRAPH_FORMAT_ERROR, e);
+ } catch (RuntimeException e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ } catch (Error e) {
+ this.engine.getGUI().getErrorWindow().error(ErrorMessages.UNEXPECTED_ERROR, e);
+ }
+ }
+ return workflow;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/XmlBeansFiler.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/XmlBeansFiler.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/XmlBeansFiler.java
new file mode 100644
index 0000000..2bb8381
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/generators/XmlBeansFiler.java
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.core.generators;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.LinkedList;
+import java.util.List;
+
+public class XmlBeansFiler /* implements Filer */{
+
+ private String path;
+
+ private List<File> javaFilePaths = new LinkedList<File>();
+
+ /**
+ * Constructs a XmlBeansFiler.
+ *
+ * @param file
+ */
+ public XmlBeansFiler(String path) {
+ this.path = path + "/generated";
+ }
+
+ /**
+ * @see org.apache.xmlbeans.Filer#createBinaryFile(java.lang.String)
+ */
+ public OutputStream createBinaryFile(String name) throws IOException {
+ name = name.replace('.', File.separatorChar);
+ String binPath = this.path + File.separatorChar + name;
+ File srcFile = new File(binPath);
+ srcFile.getParentFile().mkdirs();
+ return new FileOutputStream(new File(binPath));
+ }
+
+ /**
+ * @see org.apache.xmlbeans.Filer#createSourceFile(java.lang.String)
+ */
+ public Writer createSourceFile(String name) throws IOException {
+ name = name.replace('.', File.separatorChar);
+ String srcPath = this.path + File.separatorChar + name + ".java";
+ File srcFile = new File(srcPath);
+ srcFile.getParentFile().mkdirs();
+ javaFilePaths.add(new File(srcFile.getCanonicalPath()));
+ return new FileWriter(srcFile);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/ide/XBayaExecutionModeListener.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/ide/XBayaExecutionModeListener.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/ide/XBayaExecutionModeListener.java
new file mode 100644
index 0000000..9ba3ac5
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/ide/XBayaExecutionModeListener.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.core.ide;
+
+import org.apache.airavata.xbaya.XBayaConfiguration;
+
+public interface XBayaExecutionModeListener {
+ /**
+ * Triggers when the execution mode in xbaya is changed
+ * For possition executions modes see,
+ * XBayaConfiguration.XBayaExecutionMode
+ * @param config - XBaya configuration object
+ */
+ public void executionModeChanged(XBayaConfiguration config);
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/workflow/ParameterListModel.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/workflow/ParameterListModel.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/workflow/ParameterListModel.java
new file mode 100644
index 0000000..7329639
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/core/workflow/ParameterListModel.java
@@ -0,0 +1,88 @@
+/*
+ *
+ * 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.core.workflow;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.swing.AbstractListModel;
+
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.system.ParameterNode;
+
+public class ParameterListModel extends AbstractListModel {
+
+ private List<? extends ParameterNode> parameterNodes;
+
+ /**
+ * Constructs a ParameterListModel.
+ *
+ * @param parameterNodes
+ * @param nodes
+ */
+ public ParameterListModel(List<? extends ParameterNode> parameterNodes) {
+ this.parameterNodes = parameterNodes;
+ }
+
+ /**
+ * @see javax.swing.ListModel#getElementAt(int)
+ */
+ public Object getElementAt(int index) {
+ return this.parameterNodes.get(index).getName();
+ }
+
+ /**
+ * @see javax.swing.ListModel#getSize()
+ */
+ public int getSize() {
+ return this.parameterNodes.size();
+ }
+
+ /**
+ * Moves the node at the index up.
+ *
+ * @param index
+ */
+ public void up(int index) {
+ if (index < 1 || index >= this.parameterNodes.size()) {
+ throw new WorkflowRuntimeException("Illegal index: " + index);
+ }
+ swap(index - 1, index);
+ }
+
+ /**
+ * Moves the node at the index down.
+ *
+ * @param index
+ */
+ public void down(int index) {
+ if (index < 0 || index >= this.parameterNodes.size() - 1) {
+ throw new WorkflowRuntimeException("Illegal index: " + index);
+ }
+ swap(index, index + 1);
+ }
+
+ private void swap(int index0, int index1) {
+ Collections.swap(this.parameterNodes, index0, index1);
+ fireContentsChanged(this, index0, index1);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/datadriven/WorkflowHarvester.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/datadriven/WorkflowHarvester.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/datadriven/WorkflowHarvester.java
new file mode 100644
index 0000000..7202999
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/datadriven/WorkflowHarvester.java
@@ -0,0 +1,191 @@
+/*
+ *
+ * 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.datadriven;
+
+import java.awt.Point;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.Pair;
+import org.apache.airavata.workflow.model.component.system.InputComponent;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.Node;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
+import org.apache.airavata.workflow.model.graph.system.InputNode;
+import org.apache.airavata.workflow.model.graph.ws.WSNode;
+import org.apache.airavata.workflow.model.wf.Workflow;
+
+public class WorkflowHarvester {
+
+ public WorkflowHarvester() {
+
+ }
+
+ public Workflow[] harvest(Workflow workflow, QName dataType) {
+ LinkedList<Workflow> harvest = new LinkedList<Workflow>();
+ LinkedList<Pair<String, String>> candidates = getCandidates(workflow, dataType);
+ for (Pair<String, String> pair : candidates) {
+ Workflow clone = workflow.clone();
+
+ NodeImpl node = clone.getGraph().getNode(pair.getLeft());
+ if (null == node) {
+ throw new WorkflowRuntimeException("Specified node not found:" + pair.getLeft());
+ }
+ Port candidatePort = null;
+ List<DataPort> inPorts = node.getInputPorts();
+ for (DataPort dataPort : inPorts) {
+ if (pair.getRight().equals(dataPort.getID())) {
+ candidatePort = dataPort;
+ break;
+ }
+ }
+ if (null == candidatePort) {
+ throw new WorkflowRuntimeException("Specifies Port was not found:" + pair.getRight());
+ }
+ if (!(candidatePort.getFromNode() instanceof InputNode)) {
+ removeUnnecessaryNodes(node, candidatePort, clone);
+ Node input = clone.addNode(new InputComponent());
+ input.setPosition(new Point(Math.max(0, node.getPosition().x - 150), node.getPosition().y));
+
+ // the returned workflows size should be less than that of the
+ // original
+ if (clone.getGraph().getNodes().size() < workflow.getGraph().getNodes().size()
+ // if the sizes the different its a candidate, but need
+ // to make sure
+ // its not the same as one already harvested
+ && !isWorkflowAlreadyHarvested(harvest, clone)) {
+ try {
+ clone.getGraph().addEdge(input.getOutputPort(0), candidatePort);
+ cleanLeftOverInputNodes(clone);
+ } catch (GraphException e) {
+ throw new RuntimeException(e);
+ }
+
+ harvest.add(clone);
+ }
+
+ }
+ }
+ return harvest.toArray(new Workflow[0]);
+ }
+
+ /**
+ * @param clone
+ */
+ private void cleanLeftOverInputNodes(Workflow clone) {
+
+ List<NodeImpl> nodes = clone.getGraph().getNodes();
+ LinkedList<Node> removeList = new LinkedList<Node>();
+ for (Node nodeImpl : nodes) {
+ if (nodeImpl instanceof InputNode) {
+ if (nodeImpl.getOutputPort(0).getToNodes().size() == 0) {
+ removeList.add(nodeImpl);
+ }
+ }
+ }
+ for (Node node : removeList) {
+ try {
+ clone.removeNode(node);
+ } catch (GraphException e) {
+ throw new WorkflowRuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * @param harvest
+ * @param clone
+ * @return
+ */
+ private boolean isWorkflowAlreadyHarvested(LinkedList<Workflow> harvest, Workflow clone) {
+ for (Workflow workflow : harvest) {
+ if (workflow.equals(clone)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param pair
+ * @param clone
+ */
+ private void removeUnnecessaryNodes(Node node, Port candidatePort, Workflow workflow) {
+ if (candidatePort.getFromPort().getEdges().size() == 1) {
+ Node fromNode = candidatePort.getFromNode();
+ try {
+ List<DataPort> inputPorts = fromNode.getInputPorts();
+ for (DataPort dataPort : inputPorts) {
+ removeUnnecessaryNodes(fromNode, dataPort, workflow);
+ }
+ workflow.removeNode(fromNode);
+ } catch (GraphException e) {
+ throw new WorkflowRuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * @param pair
+ * @return
+ */
+ private List<DataPort> getRemainderPorts(Pair<WSNode, DataPort> pair) {
+ LinkedList<DataPort> ret = new LinkedList<DataPort>();
+ List<DataPort> inputPorts = pair.getLeft().getInputPorts();
+ for (DataPort dataPort : inputPorts) {
+ if (pair.getRight() != dataPort) {
+ ret.add(dataPort);
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * @param workflow
+ * @param dataType
+ * @return pair of nodeid and portid
+ */
+ private LinkedList<Pair<String, String>> getCandidates(Workflow workflow, QName dataType) {
+ LinkedList<Pair<String, String>> candidates = new LinkedList<Pair<String, String>>();
+ List<NodeImpl> nodes = workflow.getGraph().getNodes();
+ for (NodeImpl node : nodes) {
+ if (node instanceof WSNode) {
+ List<DataPort> inputPorts = ((WSNode) node).getInputPorts();
+ for (DataPort dataPort : inputPorts) {
+
+ if (dataType.equals(dataPort.getType())) {
+ candidates.add(new Pair<String, String>(node.getID(), dataPort.getID()));
+ }
+
+ }
+ }
+ }
+
+ return candidates;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/file/XBayaPathConstants.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/file/XBayaPathConstants.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/file/XBayaPathConstants.java
new file mode 100644
index 0000000..659b30b
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/file/XBayaPathConstants.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.file;
+
+import java.io.File;
+
+public interface XBayaPathConstants {
+
+ /**
+ * Root directory of the server.
+ */
+ public static final String XBAYA_DIRECTORY = "modules" + File.separator + "xbaya-gui";
+
+ /**
+ * The path of the directory that stores component definitions.
+ */
+ public static final String WSDL_DIRECTORY = XBAYA_DIRECTORY + File.separator + "src" + File.separator + "main"
+ + File.separator + "resources" + File.separator + "wsdls";
+
+ /**
+ * The path of the directory that stores graphs.
+ */
+ public static final String WORKFLOW_DIRECTORY = XBAYA_DIRECTORY + File.separator + "workflows";
+
+ /**
+ * The path of the directory where the scripts are saved.
+ */
+ public static final String SCRIPT_DIRECTORY = XBAYA_DIRECTORY + File.separator + "scripts";
+
+ /**
+ * The path of the directory where the BPEL scripts are saved.
+ */
+ public static final String JYTHON_SCRIPT_DIRECTORY = SCRIPT_DIRECTORY + File.separator + "jython";
+
+ /**
+ * The path of the directory where the BPEL scripts are saved.
+ */
+ public static final String BPEL_SCRIPT_DIRECTORY = SCRIPT_DIRECTORY + File.separator + "bpel";
+
+ /**
+ * The path of the directory where the scufl scripts are saved.
+ */
+ public static final String SCUFL_SCRIPT_DIRECTORY = SCRIPT_DIRECTORY + File.separator + "scufl";
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/9c47eec8/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/gfac/GFacRegistryClient.java
----------------------------------------------------------------------
diff --git a/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/gfac/GFacRegistryClient.java b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/gfac/GFacRegistryClient.java
new file mode 100644
index 0000000..cdb4c8a
--- /dev/null
+++ b/modules/xbaya-gui/src/main/java/org/apache/airavata/xbaya/gfac/GFacRegistryClient.java
@@ -0,0 +1,169 @@
+/*
+ *
+ * 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.gfac;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.airavata.workflow.model.component.ComponentRegistryException;
+import org.xmlpull.v1.builder.Iterable;
+import org.xmlpull.v1.builder.XmlElement;
+
+import xsul.wsif.WSIFMessage;
+import xsul.wsif.impl.WSIFMessageElement;
+
+public class GFacRegistryClient {
+
+ /**
+ * GFAC_NAMESPACE
+ */
+ public static final String GFAC_NAMESPACE = "http://www.extreme.indiana.edu/namespaces/2004/01/gFac";
+
+ private static final String SEARCH_SERVICE_INSTANCE = "searchServiceInstance";
+
+ private static final String SEARCH_SERVIE = "searchService";
+
+ private static final String QNAME = "qname";
+
+ private static final String DESC_AS_STRING = "descAsStr";
+
+ private static final String LIFE_TIME = "lifetimeAsSeconds";
+
+ private static final String RESULTS = "results";
+
+ private static final String GET_ABSTRACT_WSDL = "getAbstractWsdl";
+
+ private String wsdlURL;
+
+ private SimpleWSClient client;
+
+ /**
+ * Constructs a GFacRegistryClient.
+ *
+ * @param wsdlURL
+ */
+ public GFacRegistryClient(URI wsdlURL) {
+ this(wsdlURL.toString());
+ }
+
+ /**
+ * Constructs a GfacRegistryClient.
+ *
+ * @param wsdlURL
+ */
+ public GFacRegistryClient(String wsdlURL) {
+ this.wsdlURL = wsdlURL;
+ this.client = new SimpleWSClient();
+ }
+
+ /**
+ * @param appDescAsStr
+ * @throws ComponentRegistryException
+ */
+ public void registerAppDesc(String appDescAsStr) throws ComponentRegistryException {
+ this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { DESC_AS_STRING, appDescAsStr } },
+ "registerAppDesc");
+ }
+
+ /**
+ * @param wsdlAsStr
+ * @param lifetimeAsSeconds
+ * @throws ComponentRegistryException
+ */
+ public void registerConcreteWsdl(String wsdlAsStr, int lifetimeAsSeconds) throws ComponentRegistryException {
+ this.client.sendSOAPMessage(this.wsdlURL,
+ new String[][] { { DESC_AS_STRING, wsdlAsStr }, { LIFE_TIME, String.valueOf(lifetimeAsSeconds) } },
+ "registerConcreteWsdl");
+
+ }
+
+ /**
+ * @param wsdlQName
+ * @return The concrete WSDL
+ * @throws ComponentRegistryException
+ */
+ public String getConcreteWsdl(String wsdlQName) throws ComponentRegistryException {
+ WSIFMessage response = this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { QNAME, wsdlQName } },
+ "getConcreateWsdl");
+ return (String) response.getObjectPart(DESC_AS_STRING);
+ }
+
+ /**
+ * @param wsdlQName
+ * @throws ComponentRegistryException
+ */
+ public void removeConcreteWsdl(String wsdlQName) throws ComponentRegistryException {
+ this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { QNAME, wsdlQName } }, "removeConcreteWsdl");
+
+ }
+
+ /**
+ * @param serviceName
+ * @return The list of concreate WSDL QNames.
+ * @throws ComponentRegistryException
+ */
+ public String[] findService(String serviceName) throws ComponentRegistryException {
+ WSIFMessage response = this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { QNAME, serviceName } },
+ SEARCH_SERVICE_INSTANCE);
+ return findArrayValue(RESULTS, (WSIFMessageElement) response).toArray(new String[] {});
+ }
+
+ /**
+ * @param serviceName
+ * @return The list of abstract WSDL QNames.
+ * @throws ComponentRegistryException
+ */
+ public String[] findServiceDesc(String serviceName) throws ComponentRegistryException {
+ WSIFMessage response = this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { QNAME, serviceName } },
+ SEARCH_SERVIE);
+ return findArrayValue(RESULTS, (WSIFMessageElement) response).toArray(new String[] {});
+ }
+
+ /**
+ * @param wsdlQName
+ * @return The AWSDL.
+ * @throws ComponentRegistryException
+ */
+ public String getAbstractWsdl(String wsdlQName) throws ComponentRegistryException {
+ WSIFMessage response = this.client.sendSOAPMessage(this.wsdlURL, new String[][] { { QNAME, wsdlQName } },
+ GET_ABSTRACT_WSDL);
+ return (String) response.getObjectPart(DESC_AS_STRING);
+ }
+
+ private static ArrayList<String> findArrayValue(String name, WSIFMessageElement response) {
+ XmlElement param = response.element(null, name);
+ if (param != null) {
+ Iterable it = param.elements(null, "value");
+ if (it != null) {
+ ArrayList<String> values = new ArrayList<String>();
+
+ Iterator arrayValues = it.iterator();
+ while (arrayValues.hasNext()) {
+ values.add(((XmlElement) arrayValues.next()).requiredTextContent());
+ }
+ return values;
+ }
+ }
+ return null;
+ }
+}