airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shame...@apache.org
Subject [2/6] git commit: Added parse and toJSON methods to read and write xwf file with JSON
Date Tue, 28 Oct 2014 18:12:54 GMT
Added parse and toJSON methods to read and write xwf file with JSON


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

Branch: refs/heads/master
Commit: 6e42be782c35abe7082ed6e0589f70b04349c25b
Parents: 60937d3
Author: shamrath <shameerainfo@gmail.com>
Authored: Thu Oct 23 13:08:31 2014 -0400
Committer: shamrath <shameerainfo@gmail.com>
Committed: Thu Oct 23 13:08:31 2014 -0400

----------------------------------------------------------------------
 modules/commons/utils/pom.xml                   |   6 +
 .../apache/airavata/common/utils/JSONUtil.java  | 157 +++++++++++++++++++
 .../airavata/common/utils/WSConstants.java      |   3 +-
 .../server/src/main/assembly/bin-assembly.xml   |   1 +
 .../workflow-model/workflow-model-core/pom.xml  |   6 +
 .../model/component/ws/WSComponent.java         |   6 +
 .../component/ws/WSComponentApplication.java    |  84 +++++++++-
 .../model/gpel/script/WorkflowWSDL.java         |  10 +-
 .../workflow/model/graph/ControlEdge.java       |  10 ++
 .../workflow/model/graph/ControlPort.java       |  10 +-
 .../airavata/workflow/model/graph/DataEdge.java |  10 ++
 .../airavata/workflow/model/graph/DataPort.java |   5 +
 .../airavata/workflow/model/graph/Graph.java    |   4 +
 .../workflow/model/graph/GraphFactory.java      |   7 +
 .../model/graph/amazon/InstanceDataPort.java    |   7 +
 .../workflow/model/graph/impl/EdgeImpl.java     |  16 ++
 .../workflow/model/graph/impl/GraphImpl.java    |  66 ++++++++
 .../workflow/model/graph/impl/NodeImpl.java     | 108 ++++++++++++-
 .../workflow/model/graph/impl/PortImpl.java     |  28 ++++
 .../workflow/model/graph/system/InputNode.java  |  38 +++++
 .../workflow/model/graph/system/OutputNode.java |  10 ++
 .../model/graph/system/ParameterNode.java       |  56 +++++++
 .../model/graph/system/SystemDataPort.java      |  12 ++
 .../workflow/model/graph/system/SystemNode.java |   5 +
 .../workflow/model/graph/ws/WSGraph.java        | 133 ++--------------
 .../workflow/model/graph/ws/WSGraphFactory.java | 149 ++++++++++++++----
 .../workflow/model/graph/ws/WSNode.java         |  24 +++
 .../workflow/model/graph/ws/WSPort.java         |  11 ++
 .../workflow/model/graph/ws/WorkflowNode.java   |  10 ++
 .../airavata/workflow/model/wf/Workflow.java    |  89 +++++++----
 .../xbaya/core/generators/WorkflowFiler.java    |  17 +-
 .../workflow/ParameterPropertyWindow.java       |   8 +-
 .../workflow/WorkflowPropertyWindow.java        |  67 ++++----
 .../airavata/xbaya/ui/graph/GraphCanvas.java    |  14 +-
 pom.xml                                         |   7 +
 35 files changed, 960 insertions(+), 234 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/commons/utils/pom.xml
----------------------------------------------------------------------
diff --git a/modules/commons/utils/pom.xml b/modules/commons/utils/pom.xml
index 5b93732..ea659f9 100644
--- a/modules/commons/utils/pom.xml
+++ b/modules/commons/utils/pom.xml
@@ -137,6 +137,12 @@
             <artifactId>libthrift</artifactId>
             <version>${thrift.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${google.gson.version}</version>
+        </dependency>
     </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/JSONUtil.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/JSONUtil.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/JSONUtil.java
new file mode 100644
index 0000000..bb72290
--- /dev/null
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/JSONUtil.java
@@ -0,0 +1,157 @@
+/*
+ *
+ * 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.common.utils;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.stream.JsonReader;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Map;
+import java.util.Set;
+
+public class JSONUtil {
+
+
+    public static void saveJSON(JsonElement jsonElement, File file) throws IOException {
+        Gson gson = new GsonBuilder().setPrettyPrinting().create();
+        IOUtil.writeToFile(gson.toJson(jsonElement), file);
+
+    }
+
+    public static JsonObject stringToJSONObject(String workflowString) {
+        JsonParser parser = new JsonParser();
+        return (JsonObject) parser.parse(workflowString);
+    }
+
+    public static JsonObject loadJSON(File file) throws IOException {
+        return loadJSON(new FileReader(file));
+    }
+
+    public static JsonObject loadJSON(Reader reader) throws IOException {
+       JsonParser parser = new JsonParser();
+       JsonElement jsonElement = parser.parse(reader);
+        if (jsonElement instanceof JsonObject) {
+            return (JsonObject) jsonElement;
+        } else {
+            throw new RuntimeException("Error while loading Json from file");
+        }
+
+    }
+
+    public static boolean isEqual(JsonObject originalJsonObject, JsonObject newJsonObject) {
+        // TODO - Implement this method
+        if (originalJsonObject == null && newJsonObject == null) {
+            return true;
+        }else if (originalJsonObject == null || newJsonObject == null) {
+            return false;
+        } else {
+            // check the number of childs
+            Set<Map.Entry<String , JsonElement>> entrySetOfOriginalJson =  originalJsonObject.entrySet();
+            Set<Map.Entry<String , JsonElement>> entrySetOfNewJson =  newJsonObject.entrySet();
+            if (entrySetOfOriginalJson.size() != entrySetOfNewJson.size()) {
+                return false;
+            }
+
+            for (Map.Entry<String, JsonElement> keyString : entrySetOfOriginalJson) {
+                JsonElement valueOrig = keyString.getValue();
+                JsonElement valueNew = newJsonObject.get(keyString.getKey());
+                if (valueOrig instanceof JsonObject && valueNew instanceof JsonObject &&
+                        !isEqual((JsonObject) valueOrig, (JsonObject) valueNew)) {
+                    return false;
+                }else if (valueOrig instanceof JsonArray && valueNew instanceof JsonArray &&
+                        !isEqual((JsonArray) valueOrig, (JsonArray) valueNew)) {
+                    return false;
+                }else if (valueOrig instanceof JsonPrimitive && valueNew instanceof JsonPrimitive &&
+                        !isEqual((JsonPrimitive) valueOrig, (JsonPrimitive) valueNew)) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    private static boolean isEqual(JsonArray arrayOriginal, JsonArray arrayNew) {
+        if (arrayOriginal == null && arrayNew == null) {
+            return true;
+        }else if (arrayOriginal == null || arrayNew == null) {
+            return false;
+        }else {
+            // check the number of element
+            if (arrayOriginal.size() != arrayNew.size()) {
+                return false;
+            }else if (arrayOriginal.size() == 0) {
+                return true;
+            } else {
+                for (int i = 0; i < arrayOriginal.size(); i++) {
+                    JsonElement valueOrig = arrayOriginal.get(i);
+                    JsonElement valueNew = arrayNew.get(i);
+                    if (valueOrig instanceof JsonObject && valueNew instanceof JsonObject) {
+                        if (!isEqual((JsonObject) valueOrig, (JsonObject) valueNew)) {
+                            return false;
+                        }
+                    }else if (valueOrig instanceof JsonPrimitive && valueNew instanceof JsonPrimitive) {
+                        if (!isEqual((JsonPrimitive) valueOrig, (JsonPrimitive) valueNew)) {
+                            return false;
+                        }
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    private static boolean isEqual(JsonPrimitive primitiveOrig, JsonPrimitive primitiveNew) {
+        if (primitiveOrig == null && primitiveNew == null) {
+            return true;
+        }else if (primitiveOrig == null || primitiveNew == null) {
+            return false;
+        } else {
+            if (primitiveOrig.isString() && primitiveNew.isString()){
+                if(!primitiveOrig.getAsString().equals(primitiveNew.getAsString())) {
+                    return false;
+                }
+            }else if (primitiveOrig.isBoolean() && primitiveNew.isBoolean()) {
+                if ((Boolean.valueOf(primitiveOrig.getAsBoolean()).compareTo(primitiveNew.getAsBoolean()) != 0)) {
+                    return false;
+                }
+            }else if (primitiveOrig.isNumber() && primitiveNew.isNumber() ) {
+                if (new Double(primitiveOrig.getAsDouble()).compareTo(primitiveNew.getAsDouble()) != 0) {
+                    return false;
+                }
+            }else {
+                return primitiveOrig.isJsonNull() && primitiveNew.isJsonNull();
+            }
+        }
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/WSConstants.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/WSConstants.java b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/WSConstants.java
index bb226c4..d780379 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/WSConstants.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/WSConstants.java
@@ -149,7 +149,8 @@ public interface WSConstants {
      * 
      * </appinfo>
      */
-    public static final String EMPTY_APPINFO = "<appinfo xmlns=\"http://www.w3.org/2001/XMLSchema\">\n\n</appinfo>";
+//    public static final String EMPTY_APPINFO = "<appinfo xmlns=\"http://www.w3.org/2001/XMLSchema\">\n\n</appinfo>";
+    public static final String EMPTY_APPINFO = "{'appinfo': '' }";
 
     /**
      * minOccurs

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/distribution/server/src/main/assembly/bin-assembly.xml
----------------------------------------------------------------------
diff --git a/modules/distribution/server/src/main/assembly/bin-assembly.xml b/modules/distribution/server/src/main/assembly/bin-assembly.xml
index 0ed872f..7025d65 100644
--- a/modules/distribution/server/src/main/assembly/bin-assembly.xml
+++ b/modules/distribution/server/src/main/assembly/bin-assembly.xml
@@ -257,6 +257,7 @@
                 <include>com.fasterxml.jackson.core:jackson-core</include>
                 <include>com.fasterxml.jackson.core:jackson-annotations</include>
                 <include>org.apache.zookeeper:zookeeper</include>
+                <include>com.google.code.gson:gson</include>
                 <!-- unicore start
                     <include>eu.unicore:ogsabes-client</include>
                     <include>eu.unicore:ogsabes-types</include>

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/pom.xml b/modules/workflow-model/workflow-model-core/pom.xml
index 5055464..821d5a5 100644
--- a/modules/workflow-model/workflow-model-core/pom.xml
+++ b/modules/workflow-model/workflow-model-core/pom.xml
@@ -86,5 +86,11 @@
             <scope>runtime</scope>
         </dependency>
 
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${google.gson.version}</version>
+        </dependency>
+
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponent.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponent.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponent.java
index 606c88b..bedfaac 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponent.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponent.java
@@ -26,6 +26,8 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.component.Component;
 import org.apache.airavata.workflow.model.component.ComponentControlPort;
 import org.apache.airavata.workflow.model.component.ComponentException;
@@ -234,6 +236,10 @@ public class WSComponent extends Component {
 		return getApplication().toXml();
 	}
 
+    public JsonObject toJSON(){
+        return getApplication().toJSON();
+    }
+
 	public WSComponentApplication getApplication() {
 		return application;
 	}

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponentApplication.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponentApplication.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponentApplication.java
index 0d38d6d..d103538 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponentApplication.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/component/ws/WSComponentApplication.java
@@ -36,11 +36,17 @@ import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.namespace.QName;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.WSConstants;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription;
 import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType;
 import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
 import org.xmlpull.infoset.XmlNamespace;
 
 import xsul.dsig.apache.axis.uti.XMLUtils;
@@ -103,7 +109,50 @@ public class WSComponentApplication {
 		}
 
 	}
-	public org.xmlpull.infoset.XmlElement toXml(){
+
+    public static WSComponentApplication parse(JsonObject applicationObject) {
+        WSComponentApplication wsComponentApplication = new WSComponentApplication();
+        wsComponentApplication.description = applicationObject.getAsJsonPrimitive("description").getAsString();
+        wsComponentApplication.name = applicationObject.getAsJsonPrimitive("name").getAsString();
+        wsComponentApplication.applicationId = applicationObject.getAsJsonPrimitive("application").getAsString();
+
+        if (applicationObject.get("Input") != null) {
+            JsonArray inputArray = applicationObject.getAsJsonArray("Input");
+            WSComponentApplicationParameter inputParameter;
+            JsonObject inputObject;
+            for (JsonElement jsonElement : inputArray) {
+                if (jsonElement instanceof JsonObject) {
+                    inputObject = (JsonObject) jsonElement;
+                    inputParameter = new WSComponentApplicationParameter();
+                    inputParameter.setDefaultValue(inputObject.getAsJsonPrimitive("text").getAsString());
+                    inputParameter.setDescription(inputObject.getAsJsonPrimitive("description").getAsString());
+                    inputParameter.setName(inputObject.getAsJsonPrimitive("name").getAsString());
+                    // do we need to set type ?
+                    wsComponentApplication.addInputParameter(inputParameter);
+                }
+            }
+        }
+
+        if (applicationObject.get("Output") != null) {
+            JsonArray outputArray = applicationObject.getAsJsonArray("Output");
+            WSComponentApplicationParameter outputParameter;
+            JsonObject outputObject;
+            for (JsonElement jsonElement : outputArray) {
+                if (jsonElement instanceof JsonObject) {
+                    outputObject = (JsonObject) jsonElement;
+                    outputParameter = new WSComponentApplicationParameter();
+                    outputParameter.setDescription(outputObject.getAsJsonPrimitive("description").getAsString());
+                    outputParameter.setName(outputObject.getAsJsonPrimitive("name").getAsString());
+                    // do we need to set type ?
+                    wsComponentApplication.addOutputParameter(outputParameter);
+                }
+            }
+        }
+
+        return wsComponentApplication;
+    }
+
+    public org.xmlpull.infoset.XmlElement toXml(){
 		      try {
 				JAXBContext context = JAXBContext.newInstance(WSComponentApplication.class);
 				  Marshaller marshaller = context.createMarshaller();
@@ -118,8 +167,37 @@ public class WSComponentApplication {
 				return null;
 			}
 	}
-	
-	public WSComponentApplication(ApplicationInterfaceDescription application) {
+
+    public JsonObject toJSON() {
+        JsonObject componentObject = new JsonObject();
+        componentObject.addProperty("description", this.description);
+        componentObject.addProperty("name", this.name);
+        componentObject.addProperty("application", this.applicationId);
+        JsonArray inputArray = new JsonArray();
+        JsonObject inputObject;
+        for (WSComponentApplicationParameter inputParameter : this.inputParameters) {
+            inputObject = new JsonObject();
+            inputObject.addProperty("description", inputParameter.getDescription());
+            inputObject.addProperty("name", inputParameter.getName());
+            inputObject.addProperty("text", inputParameter.getDefaultValue());
+            inputArray.add(inputObject);
+        }
+        componentObject.add("Input", inputArray);
+
+        JsonArray outputArray = new JsonArray();
+        JsonObject outputObject;
+        for (WSComponentApplicationParameter outputParameter : this.outputParameters) {
+            outputObject = new JsonObject();
+            outputObject.addProperty("description", outputParameter.getDescription());
+            outputObject.addProperty("name", outputParameter.getName());
+            outputArray.add(outputObject);
+        }
+        componentObject.add("Output", outputArray);
+
+        return componentObject;
+    }
+
+    public WSComponentApplication(ApplicationInterfaceDescription application) {
 		setApplicationId(application.getApplicationInterfaceId());
 		setName(application.getApplicationName());
 		setDescription(application.getApplicationDesription());

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/WorkflowWSDL.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/WorkflowWSDL.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/WorkflowWSDL.java
index 4fd30ad..2a9db54 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/WorkflowWSDL.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/WorkflowWSDL.java
@@ -298,12 +298,12 @@ public class WorkflowWSDL {
         schema.setAttributeValue(WSConstants.XMLNS, WSConstants.XSD_NS_URI);
         schema.setAttributeValue(WSConstants.ELEMENT_FORM_DEFAULT_ATTRIBUTE, WSConstants.UNQUALIFIED_VALUE);
         List<InputNode> inputNodes = GraphUtil.getInputNodes(this.graph);
-        XmlElement inputMetadata = this.graph.getInputMetadata();
-        addParameters(workflowInputMessageElelmentName, inputMetadata, inputNodes, schema);
+//        XmlElement inputMetadata = this.graph.getInputMetadata();
+//        addParameters(workflowInputMessageElelmentName, inputMetadata, inputNodes, schema);
 
-        List<OutputNode> outputNodes = GraphUtil.getOutputNodes(this.graph);
-        XmlElement outputMetadata = this.graph.getOutputMetadata();
-        addParameters(workflowOutputMessageElementName, outputMetadata, outputNodes, schema);
+//        List<OutputNode> outputNodes = GraphUtil.getOutputNodes(this.graph);
+//        XmlElement outputMetadata = this.graph.getOutputMetadata();
+//        addParameters(workflowOutputMessageElementName, outputMetadata, outputNodes, schema);
 
         return types;
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlEdge.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlEdge.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlEdge.java
index 2fe92b7..09fb672 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlEdge.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlEdge.java
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.workflow.model.graph;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.impl.EdgeImpl;
 import org.xmlpull.infoset.XmlElement;
 
@@ -43,6 +44,9 @@ public class ControlEdge extends EdgeImpl {
         super(edgeXml);
     }
 
+    public ControlEdge(JsonObject edgeObject) {
+        super(edgeObject);
+    }
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.EdgeImpl#toXML()
      */
@@ -52,4 +56,10 @@ public class ControlEdge extends EdgeImpl {
         edgeElement.setAttributeValue(GraphSchema.NS, GraphSchema.EDGE_TYPE_ATTRIBUTE, GraphSchema.EDGE_TYPE_CONTROL);
         return edgeElement;
     }
+
+    protected JsonObject toJSON() {
+        JsonObject edgeObject = super.toJSON();
+        edgeObject.addProperty(GraphSchema.EDGE_TYPE_ATTRIBUTE, GraphSchema.EDGE_TYPE_CONTROL);
+        return edgeObject;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlPort.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlPort.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlPort.java
index bdb502c..39e1c55 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlPort.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ControlPort.java
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.workflow.model.graph;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.impl.PortImpl;
 import org.xmlpull.infoset.XmlElement;
 
@@ -45,6 +46,9 @@ public class ControlPort extends PortImpl {
         super(portElement);
     }
 
+    public ControlPort(JsonObject portObject) {
+        super(portObject);
+    }
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#toXML()
      */
@@ -55,7 +59,11 @@ public class ControlPort extends PortImpl {
         return portElement;
     }
 
-    /**
+    protected JsonObject toJSON() {
+        JsonObject portObject = super.toJSON();
+        portObject.addProperty(GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_CONTROL);
+        return portObject;
+    }    /**
      * Set if this port condition is met, flow will execute throw this port
      * 
      * @param condition

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataEdge.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataEdge.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataEdge.java
index 468c292..981dede 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataEdge.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataEdge.java
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.workflow.model.graph;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.impl.EdgeImpl;
 import org.xmlpull.infoset.XmlElement;
 
@@ -43,6 +44,9 @@ public class DataEdge extends EdgeImpl {
         super(edgeElement);
     }
 
+    public DataEdge(JsonObject edgeObject) {
+        super(edgeObject);
+    }
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.EdgeImpl#getFromPort()
      */
@@ -68,4 +72,10 @@ public class DataEdge extends EdgeImpl {
         edgeElement.setAttributeValue(GraphSchema.NS, GraphSchema.EDGE_TYPE_ATTRIBUTE, GraphSchema.EDGE_TYPE_DATA);
         return edgeElement;
     }
+
+    protected JsonObject toJSON() {
+        JsonObject edgeObject = super.toJSON();
+        edgeObject.addProperty(GraphSchema.EDGE_TYPE_ATTRIBUTE, GraphSchema.EDGE_TYPE_DATA);
+        return edgeObject;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataPort.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataPort.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataPort.java
index ba5ba3f..02e5922 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataPort.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/DataPort.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.impl.PortImpl;
 import org.xmlpull.infoset.XmlElement;
 
@@ -47,6 +48,10 @@ public abstract class DataPort extends PortImpl {
         super(portElement);
     }
 
+    public DataPort(JsonObject portObject) {
+        super(portObject);
+    }
+
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#getEdges()
      */

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/Graph.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/Graph.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/Graph.java
index 5f4e756..c8f3054 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/Graph.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/Graph.java
@@ -24,6 +24,7 @@ package org.apache.airavata.workflow.model.graph;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.gson.JsonElement;
 import org.xmlpull.infoset.XmlElement;
 
 public interface Graph extends GraphPiece {
@@ -182,6 +183,9 @@ public interface Graph extends GraphPiece {
      */
     public XmlElement toXML();
 
+
+    public com.google.gson.JsonObject toJSON();
+
     /**
      * @param multipleSelectedNodes
      * @throws GraphException

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/GraphFactory.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/GraphFactory.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/GraphFactory.java
index 0acda11..45fc25b 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/GraphFactory.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/GraphFactory.java
@@ -21,6 +21,8 @@
 
 package org.apache.airavata.workflow.model.graph;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.impl.EdgeImpl;
 import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
 import org.apache.airavata.workflow.model.graph.impl.PortImpl;
@@ -37,6 +39,8 @@ public interface GraphFactory {
      */
     public NodeImpl createNode(XmlElement nodeElement) throws GraphException;
 
+    public NodeImpl createNode(JsonObject nodeObject) throws GraphException;
+
     /**
      * Creates a Port.
      * 
@@ -45,6 +49,7 @@ public interface GraphFactory {
      */
     public PortImpl createPort(XmlElement portElement);
 
+    public PortImpl createPort(JsonObject portObject);
     /**
      * Creates a Edge.
      * 
@@ -62,4 +67,6 @@ public interface GraphFactory {
      */
     public EdgeImpl createEdge(XmlElement edgeXml);
 
+    public EdgeImpl createEdge(JsonObject edgeObject);
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/amazon/InstanceDataPort.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/amazon/InstanceDataPort.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/amazon/InstanceDataPort.java
index 8e1d92c..e3f7426 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/amazon/InstanceDataPort.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/amazon/InstanceDataPort.java
@@ -23,6 +23,7 @@ package org.apache.airavata.workflow.model.graph.amazon;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.WSConstants;
 import org.apache.airavata.workflow.model.graph.DataPort;
 import org.apache.airavata.workflow.model.graph.GraphException;
@@ -74,6 +75,12 @@ public class InstanceDataPort extends DataPort {
         return portElement;
     }
 
+    protected JsonObject toJSON() {
+        JsonObject portObject = super.toJSON();
+        portObject.addProperty(GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_INSTANCE);
+        return portObject;
+    }
+
     /**
      * @see org.apache.airavata.workflow.model.graph.DataPort#copyType(org.apache.airavata.workflow.model.graph.DataPort)
      */

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/EdgeImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/EdgeImpl.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/EdgeImpl.java
index f5145f9..03b867d 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/EdgeImpl.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/EdgeImpl.java
@@ -21,6 +21,8 @@
 
 package org.apache.airavata.workflow.model.graph.impl;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.graph.Edge;
 import org.apache.airavata.workflow.model.graph.GraphException;
@@ -62,6 +64,9 @@ public abstract class EdgeImpl implements Edge {
         parse(edgeXml);
     }
 
+    public EdgeImpl(JsonObject edgeObject) {
+        parse(edgeObject);
+    }
     /**
      * @see org.apache.airavata.workflow.model.graph.Edge#getFromPort()
      */
@@ -127,6 +132,10 @@ public abstract class EdgeImpl implements Edge {
         this.toPortID = toPortElement.requiredText();
     }
 
+    protected void parse(JsonObject edgeObject) {
+        this.fromPortID = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_FROM_PORT_TAG).getAsString();
+        this.toPortID = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_TO_PORT_TAG).getAsString();
+    }
     /**
      * @return the XmlElement
      */
@@ -142,6 +151,13 @@ public abstract class EdgeImpl implements Edge {
         return edgeXml;
     }
 
+    protected JsonObject toJSON() {
+        JsonObject edgeElement = new JsonObject();
+        edgeElement.addProperty(GraphSchema.EDGE_FROM_PORT_TAG, this.fromPort.getID());
+        edgeElement.addProperty(GraphSchema.EDGE_TO_PORT_TAG, this.toPort.getID());
+        return edgeElement;
+    }
+
     /**
      * Returns the label.
      * 

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/GraphImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/GraphImpl.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/GraphImpl.java
index ed3df9d..883b85b 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/GraphImpl.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/GraphImpl.java
@@ -28,6 +28,10 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
 import org.apache.airavata.workflow.model.graph.ControlPort;
@@ -472,6 +476,36 @@ public abstract class GraphImpl implements Graph {
         return graphElement;
     }
 
+    @Override
+    public JsonObject toJSON() {
+        JsonObject graphObject = new JsonObject();
+
+        graphObject.addProperty(GraphSchema.XBAYA_VERSION_ATTRIBUTE, ApplicationVersion.VERSION.getVersion());
+        graphObject.addProperty(GraphSchema.GRAPH_ID_TAG, getID());
+        graphObject.addProperty(GraphSchema.GRAPH_NAME_TAG, getName());
+        graphObject.addProperty(GraphSchema.GRAPH_DESCRIPTION_TAG, getDescription());
+
+        JsonArray nodeArray = new JsonArray();
+        for (NodeImpl node : this.nodes) {
+            nodeArray.add(node.toJSON());
+        }
+        graphObject.add(GraphSchema.NODE_TAG, nodeArray);
+
+        JsonArray portArray = new JsonArray();
+        for (PortImpl port : this.ports) {
+            portArray.add(port.toJSON());
+        }
+        graphObject.add(GraphSchema.PORT_TAG, portArray);
+
+        JsonArray edgeArray = new JsonArray();
+        for (EdgeImpl edge : this.edges) {
+            edgeArray.add(edge.toJSON());
+        }
+        graphObject.add(GraphSchema.EDGE_TAG, edgeArray);
+
+        return graphObject;
+    }
+
     /**
      * @param graphElement
      */
@@ -523,6 +557,38 @@ public abstract class GraphImpl implements Graph {
         indexToPointer();
     }
 
+    protected void parse(JsonObject graphObject) throws GraphException{
+        JsonPrimitive  jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_ID_TAG);
+        if (jsonPrimitive != null) {
+            this.id = jsonPrimitive.getAsString();
+        }
+        jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_NAME_TAG);
+        if (jsonPrimitive != null) {
+            this.name = jsonPrimitive.getAsString();
+        }
+        jsonPrimitive = graphObject.getAsJsonPrimitive(GraphSchema.GRAPH_DESCRIPTION_TAG);
+        if (jsonPrimitive != null) {
+           this.description = jsonPrimitive.getAsString();
+        }
+
+        JsonArray jArray = graphObject.getAsJsonArray(GraphSchema.NODE_TAG);
+        for (JsonElement jsonElement : jArray) {
+            addNode(this.factory.createNode((JsonObject) jsonElement));
+        }
+
+        jArray = graphObject.getAsJsonArray(GraphSchema.PORT_TAG);
+        for (JsonElement jsonElement : jArray) {
+            addPort(this.factory.createPort((JsonObject) jsonElement));
+        }
+
+        jArray = graphObject.getAsJsonArray(GraphSchema.EDGE_TAG);
+        for (JsonElement jsonElement : jArray) {
+            addEdge(this.factory.createEdge((JsonObject)jsonElement));
+        }
+
+        indexToPointer();
+    }
+
     /**
      * Adds a node.
      * 

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/NodeImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/NodeImpl.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/NodeImpl.java
index b9abaa0..6c5fd75 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/NodeImpl.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/NodeImpl.java
@@ -27,6 +27,11 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import org.apache.airavata.common.utils.StringUtil;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.component.Component;
@@ -134,6 +139,11 @@ public abstract class NodeImpl implements Node {
         parse(nodeElement);
     }
 
+    public NodeImpl(JsonObject nodeObject) throws GraphException{
+        this();
+        parse(nodeObject);
+    }
+
     /**
      * @return the ID of the node
      */
@@ -505,6 +515,56 @@ public abstract class NodeImpl implements Node {
         }
     }
 
+    protected void parse(JsonObject nodeObject) {
+        this.id = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_ID_TAG).getAsString();
+        this.name = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_NAME_TAG).getAsString();
+
+        JsonArray jArray;
+        if (nodeObject.get(GraphSchema.NODE_INPUT_PORT_TAG) != null) {
+            jArray  = nodeObject.getAsJsonArray(GraphSchema.NODE_INPUT_PORT_TAG);
+            for (JsonElement jsonElement : jArray) {
+                this.inputPortIDs.add(jsonElement.getAsString());
+            }
+
+        }
+
+        if (nodeObject.get(GraphSchema.NODE_OUTPUT_PORT_TAG) != null) {
+            jArray = nodeObject.getAsJsonArray(GraphSchema.NODE_OUTPUT_PORT_TAG);
+            for (JsonElement jsonElement : jArray) {
+                this.outputPortIDs.add(jsonElement.getAsString());
+            }
+
+        }
+
+        JsonElement jElement = nodeObject.get(GraphSchema.NODE_CONTROL_IN_PORT_TAG);
+        if (jElement != null) {
+           this.controlInPortID = jElement.getAsString();
+        }
+
+        if (nodeObject.get(GraphSchema.NODE_CONTROL_OUT_PORT_TAG) != null) {
+            jArray = nodeObject.getAsJsonArray(GraphSchema.NODE_CONTROL_OUT_PORT_TAG);
+            for (JsonElement jsonElement : jArray) {
+                this.controlOutPortIDs.add(jsonElement.getAsString());
+            }
+        }
+
+        jElement = nodeObject.get(GraphSchema.NODE_EPR_PORT_TAG);
+        if (jElement != null) {
+            this.eprPortID = jElement.getAsString();
+        }
+
+        this.position.x = nodeObject.get(GraphSchema.NODE_X_LOCATION_TAG).getAsInt();
+        this.position.y = nodeObject.get(GraphSchema.NODE_Y_LOCATION_TAG).getAsInt();
+
+        // Parse config element not sure why we used it.
+        // Parse component element.
+        JsonObject configObject = nodeObject.getAsJsonObject(GraphSchema.NODE_CONFIG_TAG);
+        if (configObject != null) {
+            parseConfiguration(configObject);
+        }
+
+    }
+
     /**
      * @param componentElement
      * @throws GraphException
@@ -522,6 +582,10 @@ public abstract class NodeImpl implements Node {
         // Do nothing by default.
     }
 
+    protected void parseConfiguration(JsonObject configObject) {
+        logger.debug("Entering:" + new Gson().toJson(configObject));
+    }
+
     /**
      * @return the node xml
      */
@@ -581,7 +645,46 @@ public abstract class NodeImpl implements Node {
         return nodeElement;
     }
 
+    protected JsonObject toJSON() {
+        JsonObject nodeObject = new JsonObject();
+        nodeObject.addProperty(GraphSchema.NODE_ID_TAG, getID());
+        nodeObject.addProperty(GraphSchema.NODE_NAME_TAG, getName());
+
+        if (this.inputPorts.size() > 0) {
+            JsonArray inputPortsArray = new JsonArray();
+            for (PortImpl inputPort : this.inputPorts) {
+                inputPortsArray.add(new JsonPrimitive(inputPort.getID()));
+            }
+            nodeObject.add(GraphSchema.NODE_INPUT_PORT_TAG, inputPortsArray);
+        }
+
+        if (this.outputPorts.size() > 0) {
+            JsonArray outputPortsArray = new JsonArray();
+            for (PortImpl outputPort : this.outputPorts) {
+                outputPortsArray.add(new JsonPrimitive(outputPort.getID()));
+            }
+            nodeObject.add(GraphSchema.NODE_OUTPUT_PORT_TAG, outputPortsArray);
+        }
+
+        if (this.controlInPort != null) {
+            nodeObject.addProperty(GraphSchema.NODE_CONTROL_IN_PORT_TAG, this.controlInPort.getID());
+        }
+
+        if (this.controlOutPorts.size() > 0) {
+            JsonArray controlOutPortArray = new JsonArray();
+            for (PortImpl controlOutPort : this.controlOutPorts) {
+                controlOutPortArray.add(new JsonPrimitive(controlOutPort.getID()));
+            }
+            nodeObject.add(GraphSchema.NODE_CONTROL_OUT_PORT_TAG, controlOutPortArray);
+        }
+
+        nodeObject.addProperty(GraphSchema.NODE_X_LOCATION_TAG, Integer.toString(this.position.x));
+        nodeObject.addProperty(GraphSchema.NODE_Y_LOCATION_TAG, Integer.toString(this.position.y));
 
+        addConfigurationElement(nodeObject);
+
+        return nodeObject;
+    }
 
     /**
      * Adds a configuration element to a specified node element.
@@ -596,7 +699,10 @@ public abstract class NodeImpl implements Node {
         return null;
     }
 
-    /**
+    protected JsonObject addConfigurationElement(JsonObject nodeObject) {
+        // Do nothing by default.
+        return null;
+    }    /**
      * Called when an Edge was added. It doesn't do anything by default.
      * 
      * @param edge

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/PortImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/PortImpl.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/PortImpl.java
index 03a1e3d..5231a01 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/PortImpl.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/impl/PortImpl.java
@@ -25,6 +25,9 @@ import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.component.ComponentPort;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
@@ -92,6 +95,11 @@ public abstract class PortImpl implements Port {
         parse(portElement);
     }
 
+    public PortImpl(JsonObject portObject) {
+        this();
+        parse(portObject);
+    }
+
 
     /**
      * @see org.apache.airavata.workflow.model.graph.Port#getID()
@@ -372,6 +380,17 @@ public abstract class PortImpl implements Port {
         this.nodeID = nodeElement.requiredText();
     }
 
+    protected void parse(JsonObject portObject) {
+        this.id = portObject.getAsJsonPrimitive(GraphSchema.PORT_ID_TAG).getAsString();
+
+        JsonPrimitive jPrimitive = portObject.getAsJsonPrimitive(GraphSchema.PORT_NAME_TAG);
+        if (jPrimitive != null) {
+            this.name = jPrimitive.getAsString();
+        }
+
+        this.nodeID = portObject.getAsJsonPrimitive(GraphSchema.PORT_NODE_TAG).getAsString();
+    }
+
     /**
      * @return the XML representation of this Port
      */
@@ -393,6 +412,15 @@ public abstract class PortImpl implements Port {
         return portElement;
     }
 
+    protected JsonObject toJSON(){
+        JsonObject portElement = new JsonObject();
+        portElement.addProperty(GraphSchema.PORT_ID_TAG, getID());
+        portElement.addProperty(GraphSchema.PORT_NAME_TAG, getName());
+        portElement.addProperty(GraphSchema.PORT_NODE_TAG, this.node.getID());
+
+        return portElement;
+    }
+
     /**
      * Returns the port index within the node that this port belongs to.
      * 

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java
index cc36c8b..c0bbf55 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java
@@ -25,6 +25,9 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import org.apache.airavata.common.utils.WSConstants;
 import org.apache.airavata.workflow.model.component.Component;
 import org.apache.airavata.workflow.model.component.system.InputComponent;
@@ -75,6 +78,10 @@ public class InputNode extends ParameterNode {
         super(nodeElement);
     }
 
+    public InputNode(JsonObject nodeObject) throws GraphException {
+        super(nodeObject);
+    }
+
     public boolean isVisibility() {
         return visibility;
     }
@@ -296,6 +303,20 @@ public class InputNode extends ParameterNode {
         }
     }
 
+    protected void parseConfiguration(JsonObject configObject) {
+        super.parseConfiguration(configObject);
+        JsonElement jsonElement = configObject.get(VALUE_TAG_NAME);
+        if (jsonElement != null) {
+            this.defaultValue = jsonElement.getAsString();
+        }
+
+        jsonElement = configObject.get(VISIBILITY_TAG_NAME);
+        if (jsonElement != null) {
+            this.visibility = jsonElement.getAsBoolean();
+        } else {
+            this.visibility = true;
+        }
+    }
     @Override
     public XmlElement toXML() {
         XmlElement nodeElement = super.toXML();
@@ -304,6 +325,13 @@ public class InputNode extends ParameterNode {
     }
 
     @Override
+    protected JsonObject toJSON() {
+        JsonObject nodeObject = super.toJSON();
+        nodeObject.addProperty(GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_INPUT);
+        return nodeObject;
+    }
+
+    @Override
     protected XmlElement addConfigurationElement(XmlElement nodeElement) {
         XmlElement configElement = super.addConfigurationElement(nodeElement);
         if (this.defaultValue != null) {
@@ -316,6 +344,16 @@ public class InputNode extends ParameterNode {
         return configElement;
     }
 
+    @Override
+    protected JsonObject addConfigurationElement(JsonObject nodeObject) {
+        JsonObject configObject= super.addConfigurationElement(nodeObject);
+        if (this.defaultValue != null) {
+            configObject.addProperty(VALUE_TAG_NAME, this.defaultValue.toString());
+
+        }
+        configObject.addProperty(VISIBILITY_TAG_NAME, this.visibility);
+        return configObject;
+    }
     /**
      * @param toWSPort
      */

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java
index 04d21b1..6e58200 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.component.Component;
 import org.apache.airavata.workflow.model.component.system.OutputComponent;
 import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
@@ -60,6 +61,9 @@ public class OutputNode extends ParameterNode {
         super(nodeElement);
     }
 
+    public OutputNode(JsonObject nodeObject) throws GraphException {
+        super(nodeObject);
+    }
     /**
      * Returns the type of the parameter
      * 
@@ -199,4 +203,10 @@ public class OutputNode extends ParameterNode {
         return nodeElement;
     }
 
+    @Override
+    protected JsonObject toJSON() {
+        JsonObject nodeObject = super.toJSON();
+        nodeObject.addProperty(GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_OUTPUT);
+        return nodeObject;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java
index 7ef8914..62ad244 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java
@@ -26,6 +26,8 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.exception.UtilsException;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.graph.DataEdge;
@@ -59,6 +61,7 @@ abstract public class ParameterNode extends SystemNode {
     private String description;
 
     private XmlElement metadata;
+    private JsonObject metadataJson;
 
     /**
      * Constructs a ParameterNode.
@@ -70,6 +73,9 @@ abstract public class ParameterNode extends SystemNode {
         super(nodeElement);
     }
 
+    public ParameterNode(JsonObject nodeObject) throws GraphException {
+        super(nodeObject);
+    }
     /**
      * Constructs a ParameterNode.
      * 
@@ -188,6 +194,10 @@ abstract public class ParameterNode extends SystemNode {
         }
     }
 
+    public void setMetadataJson(JsonObject metadata1) {
+        this.metadataJson = metadata1;
+    }
+
     /**
      * @return The metadata
      */
@@ -268,6 +278,30 @@ abstract public class ParameterNode extends SystemNode {
         }
     }
 
+    protected void parseConfiguration(JsonObject configObject) {
+        JsonElement nameElement = configObject.get(NAME_TAG);
+        if (nameElement != null) {
+            this.configured = true;
+            this.configuredName = nameElement.getAsString();
+        }
+        JsonElement descriptionElement = configObject.get(DESCRIPTION_TAG);
+        if (descriptionElement != null) {
+            this.description = descriptionElement.getAsString();
+        }
+        JsonElement typeElement = configObject.get(DATA_TYPE_QNAME_TAG);
+        if (typeElement != null) {
+            this.parameterType = QName.valueOf(typeElement.getAsString());
+        }
+        JsonElement metadataElement = configObject.get(METADATA_TAG);
+        if (metadataElement != null) {
+            JsonObject metaObject = (JsonObject) metadataElement;
+            JsonElement appInfoElement = metaObject.get("appinfo");
+            if (appInfoElement != null) {
+                setMetadataJson((JsonObject) appInfoElement);
+            }
+        }
+    }
+
     @Override
     protected XmlElement addConfigurationElement(XmlElement nodeElement) {
 
@@ -300,6 +334,28 @@ abstract public class ParameterNode extends SystemNode {
         return configElement;
     }
 
+    @Override
+    protected JsonObject addConfigurationElement(JsonObject nodeObject) {
+        JsonObject configObject = new JsonObject();
+
+        if (this.configured) {
+            // Don't save the name here if this node has not been configured.
+            configObject.addProperty(NAME_TAG, this.configuredName);
+        }
+        if (this.description != null) {
+            configObject.addProperty(DESCRIPTION_TAG, this.description);
+        }
+        if (this.parameterType != null) {
+            configObject.addProperty(DATA_TYPE_QNAME_TAG, this.parameterType.toString());
+        }
+        if (this.metadata != null) {
+            configObject.add(METADATA_TAG, this.metadataJson);
+        }
+        nodeObject.add(GraphSchema.NODE_CONFIG_TAG, configObject);
+
+        return configObject;
+    }
+
     protected List<DataEdge> getEdges() {
         DataPort port = getPort();
         List<DataEdge> edges = port.getEdges();

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java
index dec0fa7..6f0dcba 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java
@@ -23,6 +23,7 @@ package org.apache.airavata.workflow.model.graph.system;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.WSConstants;
 import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
@@ -59,6 +60,11 @@ public class SystemDataPort extends DataPort {
         resetType();
     }
 
+    public SystemDataPort(JsonObject portObject) {
+        super(portObject);
+        resetType();
+    }
+
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#getNode()
      */
@@ -171,6 +177,12 @@ public class SystemDataPort extends DataPort {
         return portElement;
     }
 
+    protected JsonObject toJSON() {
+        JsonObject portObject = super.toJSON();
+        portObject.addProperty(GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_SYSTEM_DATA);
+        return portObject;
+    }
+
     public int getIndex(){
             if(this.getNode() instanceof InputNode){
                 return this.getGraph().getCurrentInputNodeCount() + 1;

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java
index fb0929c..ff07936 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemNode.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
 import org.apache.airavata.workflow.model.graph.DataEdge;
 import org.apache.airavata.workflow.model.graph.DataPort;
@@ -59,6 +60,10 @@ public abstract class SystemNode extends NodeImpl {
         super(nodeElement);
     }
 
+    public SystemNode(JsonObject nodeObject) throws GraphException {
+        super(nodeObject);
+    }
+
     /**
      * @throws GraphException
      * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.Edge)

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java
index ff691e1..a922284 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraph.java
@@ -21,13 +21,7 @@
 
 package org.apache.airavata.workflow.model.graph.ws;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.airavata.common.exception.UtilsException;
-import org.apache.airavata.common.utils.XMLUtil;
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.graph.DataEdge;
 import org.apache.airavata.workflow.model.graph.DataPort;
 import org.apache.airavata.workflow.model.graph.GraphException;
@@ -40,13 +34,14 @@ import org.apache.airavata.workflow.model.graph.impl.NodeImpl;
 import org.apache.airavata.workflow.model.graph.util.GraphUtil;
 import org.xmlpull.infoset.XmlElement;
 
-public class WSGraph extends GraphImpl {
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
 
-    private XmlElement metadata;
+public class WSGraph extends GraphImpl {
 
-    private XmlElement inputMetadata;
 
-    private XmlElement outputMetadata;
 
     private boolean editable=true;
     /**
@@ -59,97 +54,16 @@ public class WSGraph extends GraphImpl {
     }
 
     /**
-     * Returns the metadata.
-     * 
-     * @return The metadata
-     */
-    public XmlElement getMetadata() {
-        return this.metadata;
-    }
-
-    /**
-     * Sets metadata.
-     * 
-     * @param metadata
-     *            The metadata to set.
-     */
-    public void setMetadata(XmlElement metadata) {
-        this.metadata = metadata;
-    }
-
-    /**
-     * Returns the inputMetadata.
-     * 
-     * @return The inputMetadata
-     */
-    public XmlElement getInputMetadata() {
-        return this.inputMetadata;
-    }
-
-    /**
-     * Sets inputMetadata.
-     * 
-     * @param inputMetadata
-     *            The inputMetadata to set.
-     */
-    public void setInputMetadata(XmlElement inputMetadata) {
-        this.inputMetadata = inputMetadata;
-    }
-
-    /**
-     * Returns the outputMetadata.
-     * 
-     * @return The outputMetadata
-     */
-    public XmlElement getOutputMetadata() {
-        return this.outputMetadata;
-    }
-
-    /**
-     * Sets outputMetadata.
-     * 
-     * @param outputMetadata
-     *            The outputMetadata to set.
-     */
-    public void setOutputMetadata(XmlElement outputMetadata) {
-        this.outputMetadata = outputMetadata;
-    }
-
-    /**
      * @see org.apache.airavata.workflow.model.graph.impl.GraphImpl#toXML(org.xmlpull.infoset.XmlElement)
      */
     @Override
     protected void toXML(XmlElement graphElement) {
         super.toXML(graphElement);
+    }
 
-        try {
-            graphElement.setAttributeValue(GraphSchema.NS, GraphSchema.GRAPH_TYPE_ATTRIBUTE, GraphSchema.GRAPH_TYPE_WS);
-
-            if (this.metadata != null) {
-                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS, GraphSchema.GRAPH_METADATA_TAG);
-                // Clone the metadata to avoid parent problem because this can be
-                // called multiple times.
-                metadataElement.addChild(XMLUtil.deepClone(this.metadata));
-            }
-
-            if (this.inputMetadata != null) {
-                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS,
-                        GraphSchema.GRAPH_INPUT_METADATA_TAG);
-                // Clone the metadata to avoid parent problem because this can be
-                // called multiple times.
-                metadataElement.addChild(XMLUtil.deepClone(this.inputMetadata));
-            }
 
-            if (this.outputMetadata != null) {
-                XmlElement metadataElement = graphElement.addElement(GraphSchema.NS,
-                        GraphSchema.GRAPH_OUTPUT_METADATA_TAG);
-                // Clone the metadata to avoid parent problem because this can be
-                // called multiple times.
-                metadataElement.addChild(XMLUtil.deepClone(this.outputMetadata));
-            }
-        } catch (UtilsException e) {
-            e.printStackTrace();
-        }
+    protected void parse(JsonObject graphObject) throws GraphException {
+        super.parse(graphObject);
     }
 
     /**
@@ -158,33 +72,6 @@ public class WSGraph extends GraphImpl {
     @Override
     protected void parse(XmlElement graphElement) throws GraphException {
         super.parse(graphElement);
-
-        XmlElement metadataElement = graphElement.element(GraphSchema.GRAPH_METADATA_TAG);
-        if (metadataElement != null) {
-            for (XmlElement appinfo : metadataElement.requiredElementContent()) {
-                this.metadata = appinfo;
-                // It should have only one element.
-                break;
-            }
-        }
-
-        XmlElement inputMetadataElement = graphElement.element(GraphSchema.GRAPH_INPUT_METADATA_TAG);
-        if (inputMetadataElement != null) {
-            for (XmlElement appinfo : inputMetadataElement.requiredElementContent()) {
-                this.inputMetadata = appinfo;
-                // It should have only one element.
-                break;
-            }
-        }
-
-        XmlElement outputMetadataElement = graphElement.element(GraphSchema.GRAPH_OUTPUT_METADATA_TAG);
-        if (outputMetadataElement != null) {
-            for (XmlElement appinfo : outputMetadataElement.requiredElementContent()) {
-                this.outputMetadata = appinfo;
-                // It should have only one element.
-                break;
-            }
-        }
     }
 
     public boolean equals(WSGraph graph) {
@@ -240,7 +127,7 @@ public class WSGraph extends GraphImpl {
     }
 
     /**
-     * @param name
+     * @param id
      * @param nodes
      * @return
      */

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java
index 6a0613f..9fc9567 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSGraphFactory.java
@@ -24,7 +24,10 @@ package org.apache.airavata.workflow.model.graph.ws;
 import java.io.File;
 import java.io.IOException;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.IOUtil;
+import org.apache.airavata.common.utils.JSONUtil;
 import org.apache.airavata.common.utils.XMLUtil;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
 import org.apache.airavata.workflow.model.graph.ControlEdge;
@@ -96,12 +99,14 @@ public class WSGraphFactory implements GraphFactory {
 	 */
 	public static WSGraph createGraph(String graphString) throws GraphException {
 		XmlElement graphElement;
+        JsonObject graphElementJSON;
 		try {
-			graphElement = XMLUtil.stringToXmlElement(graphString);
-		} catch (RuntimeException e) {
+//			graphElement = XMLUtil.stringToXmlElement(graphString);
+            graphElementJSON = JSONUtil.stringToJSONObject(graphString);
+        } catch (RuntimeException e) {
 			throw new GraphException(MessageConstants.XML_ERROR, e);
 		}
-		return createGraph(graphElement);
+		return createGraph(graphElementJSON);
 	}
 
 	/**
@@ -120,6 +125,12 @@ public class WSGraphFactory implements GraphFactory {
 		}
 	}
 
+    public static WSGraph createGraph(JsonObject graphObject) throws GraphException {
+        WSGraph graph = createWSGraph();
+        graph.parse(graphObject);
+        return graph;
+    }
+
 	/**
 	 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createNode(org.xmlpull.infoset.XmlElement)
 	 */
@@ -175,34 +186,102 @@ public class WSGraphFactory implements GraphFactory {
 		return node;
 	}
 
+    public NodeImpl createNode(JsonObject nodeObject) throws GraphException {
+
+        String type = nodeObject.getAsJsonPrimitive(GraphSchema.NODE_TYPE_ATTRIBUTE).getAsString();
+
+        NodeImpl node;
+        if (GraphSchema.NODE_TYPE_WS.equals(type)) {
+            node = new WSNode(nodeObject);
+        } else if (GraphSchema.NODE_TYPE_WORKFLOW.equals(type)) {
+            node = new WorkflowNode(nodeObject);
+        } else if (GraphSchema.NODE_TYPE_INPUT.equals(type)) {
+            node = new InputNode(nodeObject);
+        } else if (GraphSchema.NODE_TYPE_OUTPUT.equals(type)) {
+            node = new OutputNode(nodeObject);
+/*        } else if (GraphSchema.NODE_TYPE_STREAM_SOURCE.equals(type)) {
+            node = new StreamSourceNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_CONSTANT.equals(type)) {
+            node = new ConstantNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_SPLIT.equals(type)) {
+            node = new ForEachNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_MERGE.equals(type)) {
+            node = new EndForEachNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_IF.equals(type)) {
+            node = new IfNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_ENDIF.equals(type)) {
+            node = new EndifNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_DOWHILE.equals(type)) {
+            node = new DoWhileNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_ENDDOWHILE.equals(type)) {
+            node = new EndDoWhileNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_MEMO.equals(type)) {
+            node = new MemoNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_RECEIVE.equals(type)) {
+            node = new ReceiveNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_BLOCK.equals(type)) {
+            node = new BlockNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_ENDBLOCK.equals(type)) {
+            node = new EndBlockNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_INSTANCE.equals(type)) {
+            node = new InstanceNode(nodeElement);
+        } else if (GraphSchema.NODE_TYPE_TERMINATE.equals(type)) {
+            node = new TerminateInstanceNode(nodeElement);*/
+        } else {
+            // Default is WsNode for backward compatibility.
+            node = new WSNode(nodeObject);
+        }
+
+        return node;
+    }
 	/**
 	 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createPort(org.xmlpull.infoset.XmlElement)
 	 */
-	public PortImpl createPort(XmlElement portElement) {
-		String type = portElement.attributeValue(GraphSchema.NS,
-				GraphSchema.PORT_TYPE_ATTRIBUTE);
-		if (type == null) {
-			// Old graphs don't have the namespace for the attribute.
-			type = portElement.attributeValue(GraphSchema.PORT_TYPE_ATTRIBUTE);
-		}
-		PortImpl port;
-		if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
-			port = new WSPort(portElement);
-		} else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
-			port = new SystemDataPort(portElement);
-		} else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
-			port = new ControlPort(portElement);
-		} else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
-			port = new EPRPort(portElement);
-		} else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
-			port = new InstanceDataPort(portElement);
-		} else {
-			// Default is WsPort because of backword compatibility
-			port = new WSPort(portElement);
-		}
-		return port;
-	}
+	public PortImpl createPort(JsonObject portObject) {
+
+        String type = portObject.getAsJsonPrimitive(GraphSchema.PORT_TYPE_ATTRIBUTE).getAsString();
+        PortImpl port;
+        if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
+            port = new WSPort(portObject);
+        } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
+            port = new SystemDataPort(portObject);
+        } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
+            port = new ControlPort(portObject);
+/*        } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
+            port = new EPRPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
+            port = new InstanceDataPort(portElement);*/
+        } else {
+            // Default is WsPort because of backword compatibility
+            port = new WSPort(portObject);
+        }
+        return port;
+    }
 
+    public PortImpl createPort(XmlElement portElement) {
+        String type = portElement.attributeValue(GraphSchema.NS,
+                GraphSchema.PORT_TYPE_ATTRIBUTE);
+        if (type == null) {
+            // Old graphs don't have the namespace for the attribute.
+            type = portElement.attributeValue(GraphSchema.PORT_TYPE_ATTRIBUTE);
+        }
+        PortImpl port;
+        if (GraphSchema.PORT_TYPE_WS_DATA.equals(type)) {
+            port = new WSPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_SYSTEM_DATA.equals(type)) {
+            port = new SystemDataPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
+            port = new ControlPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_EPR.equals(type)) {
+            port = new EPRPort(portElement);
+        } else if (GraphSchema.PORT_TYPE_INSTANCE.equals(type)) {
+            port = new InstanceDataPort(portElement);
+        } else {
+            // Default is WsPort because of backword compatibility
+            port = new WSPort(portElement);
+        }
+        return port;
+    }
 	/**
 	 * @see org.apache.airavata.workflow.model.graph.GraphFactory#createEdge(org.apache.airavata.workflow.model.graph.Port,
 	 *      org.apache.airavata.workflow.model.graph.Port)
@@ -244,7 +323,21 @@ public class WSGraphFactory implements GraphFactory {
 		return edge;
 	}
 
-	/**
+    public EdgeImpl createEdge(JsonObject edgeObject) {
+        String type = edgeObject.getAsJsonPrimitive(GraphSchema.EDGE_TYPE_ATTRIBUTE).getAsString();
+        EdgeImpl edge;
+        if (GraphSchema.EDGE_TYPE_DATA.equals(type)) {
+            edge = new DataEdge(edgeObject);
+        } else if (GraphSchema.PORT_TYPE_CONTROL.equals(type)) {
+            edge = new ControlEdge(edgeObject);
+        } else {
+            // Default is WsPort because of backword compatibility
+            edge = new DataEdge(edgeObject);
+        }
+        return edge;
+    }
+
+    /**
 	 * @return The graph created.
 	 */
 	private static WSGraph createWSGraph() {

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java
index 7a6d1ba..3894a0e 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSNode.java
@@ -23,6 +23,7 @@ package org.apache.airavata.workflow.model.graph.ws;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.component.ComponentException;
 import org.apache.airavata.workflow.model.component.ws.WSComponent;
 import org.apache.airavata.workflow.model.component.ws.WSComponentApplication;
@@ -53,6 +54,10 @@ public class WSNode extends NodeImpl implements ForEachExecutableNode{
         super(nodeElement);
     }
 
+    public WSNode(JsonObject nodeObject) throws GraphException{
+        super(nodeObject);
+    }
+
     /**
      * Constructs a WSNode.
      * 
@@ -135,6 +140,14 @@ public class WSNode extends NodeImpl implements ForEachExecutableNode{
         return nodeElement;
     }
 
+    @Override
+    protected JsonObject toJSON() {
+        JsonObject nodeObject = (JsonObject) super.toJSON();
+        nodeObject.addProperty(GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_WS);
+        nodeObject.add("Application", getComponent().toJSON());
+        return nodeObject;
+    }
+
     /**
      * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#parse(org.xmlpull.infoset.XmlElement)
      */
@@ -166,5 +179,16 @@ public class WSNode extends NodeImpl implements ForEachExecutableNode{
 //            this.operationName = operationElement.requiredText();
 //        }
     }
+
+    protected void parse(JsonObject nodeObject) {
+        super.parse(nodeObject);
+        JsonObject applicationObject = nodeObject.getAsJsonObject("Application");
+        WSComponentApplication application = WSComponentApplication.parse(applicationObject);
+        try {
+            setComponent(new WSComponent(application));
+        } catch (ComponentException e) {
+            e.printStackTrace();
+        }
+    }
    
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java
index a21b694..606982f 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WSPort.java
@@ -23,6 +23,7 @@ package org.apache.airavata.workflow.model.graph.ws;
 
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.common.utils.WSConstants;
 import org.apache.airavata.workflow.model.component.ComponentPort;
 import org.apache.airavata.workflow.model.component.system.SystemComponentDataPort;
@@ -55,6 +56,9 @@ public class WSPort extends DataPort {
         super(portElement);
     }
 
+    public WSPort(JsonObject portObject) {
+        super(portObject);
+    }
     /**
      * Returns the typeQName.
      * 
@@ -125,4 +129,11 @@ public class WSPort extends DataPort {
         portElement.setAttributeValue(GraphSchema.NS, GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_WS_DATA);
         return portElement;
     }
+
+    protected JsonObject toJSON() {
+        JsonObject portObject = super.toJSON();
+        portObject.addProperty(GraphSchema.PORT_TYPE_ATTRIBUTE, GraphSchema.PORT_TYPE_WS_DATA);
+        portObject.addProperty(GraphSchema.PORT_DATA_TYPE_TAG, this.getType().toString());
+        return portObject;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java
index 695bc8e..d485550 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/graph/ws/WorkflowNode.java
@@ -21,6 +21,7 @@
 
 package org.apache.airavata.workflow.model.graph.ws;
 
+import com.google.gson.JsonObject;
 import org.apache.airavata.workflow.model.component.ws.WorkflowComponent;
 import org.apache.airavata.workflow.model.graph.Graph;
 import org.apache.airavata.workflow.model.graph.GraphException;
@@ -39,6 +40,9 @@ public class WorkflowNode extends WSNode {
         super(nodeElement);
     }
 
+    public WorkflowNode(JsonObject nodeObject) throws GraphException{
+        super(nodeObject);
+    }
     /**
      * Constructs a WorkflowNode.
      * 
@@ -63,4 +67,10 @@ public class WorkflowNode extends WSNode {
         return nodeElement;
     }
 
+    @Override
+    protected JsonObject toJSON() {
+        JsonObject nodeObject = (JsonObject) super.toJSON();
+        nodeObject.addProperty(GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_WORKFLOW);
+        return nodeObject;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/6e42be78/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java
index 04446aa..a886e75 100644
--- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java
+++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/wf/Workflow.java
@@ -37,6 +37,9 @@ import java.util.Map;
 import javax.imageio.ImageIO;
 import javax.xml.namespace.QName;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
 import org.apache.airavata.common.exception.UtilsException;
 import org.apache.airavata.common.utils.WSDLUtil;
 import org.apache.airavata.common.utils.XMLUtil;
@@ -49,6 +52,7 @@ import org.apache.airavata.workflow.model.exceptions.WorkflowException;
 import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
 import org.apache.airavata.workflow.model.gpel.script.BPELScript;
 import org.apache.airavata.workflow.model.gpel.script.BPELScriptType;
+import org.apache.airavata.workflow.model.graph.Graph;
 import org.apache.airavata.workflow.model.graph.GraphException;
 import org.apache.airavata.workflow.model.graph.GraphSchema;
 import org.apache.airavata.workflow.model.graph.Node;
@@ -207,6 +211,10 @@ public class Workflow implements Cloneable {
         parse(workflowElement);
     }
 
+    public Workflow(JsonObject workflowObject) throws GraphException, ComponentException {
+        this();
+        parse(workflowObject);
+    }
 
     /**
      * This is used for ODE
@@ -288,34 +296,6 @@ public class Workflow implements Cloneable {
     }
 
     /**
-     * @return The metadata, appinfo.
-     */
-    public XmlElement getMetadata() {
-        return this.graph.getMetadata();
-    }
-
-    /**
-     * @param metadata
-     */
-    public void setMetadata(XmlElement metadata) {
-        this.graph.setMetadata(metadata);
-    }
-
-    /**
-     * @return The output metadata, appinfo.
-     */
-    public XmlElement getInputMetadata() {
-        return this.graph.getInputMetadata();
-    }
-
-    /**
-     * @return The input metadata, appinfo.
-     */
-    public XmlElement getOutputMetadata() {
-        return this.graph.getOutputMetadata();
-    }
-
-    /**
      * Returns the graph.
      * 
      * @return The graph
@@ -526,7 +506,7 @@ public class Workflow implements Cloneable {
      */
     public XmlElement toXML() {
         // This must be before graph.toXML() to set WSDL ID to each node.
-    	//FIXME 
+    	//FIXME
 //        Map<String, WsdlDefinitions> wsdls = getWSDLs();
 
         XmlElement workflowElement = XMLUtil.BUILDER.newFragment(NS_XWF, WORKFLOW_TAG);
@@ -583,6 +563,32 @@ public class Workflow implements Cloneable {
         return workflowElement;
     }
 
+    public JsonObject toJSON() {
+        JsonObject workflowRoot = new JsonObject();
+        JsonObject workflow = new JsonObject();
+        workflowRoot.add(WORKFLOW_TAG, workflow);
+
+        workflow.addProperty(VERSION_ATTRIBUTE, ApplicationVersion.VERSION.getVersion());
+        workflow.add(GraphSchema.GRAPH_TAG, this.graph.toJSON());
+
+        if (this.image != null) {
+            try {
+                workflow.addProperty(IMAGE_TAG, getBase64String());
+            } catch (IOException e) {
+                logger.error("Failed to attached image to workflow description", e);
+            }
+        }
+        return workflowRoot;
+    }
+
+    private String getBase64String() throws IOException {
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+        ImageIO.write(this.image, WorkflowConstants.PNG_FORMAT_NAME, outputStream);
+        byte[] bytes = outputStream.toByteArray();
+        byte[] base64 = Base64.encodeBase64Chunked(bytes);
+        return new String(base64);
+    }
+
     /**
      * Binds WSNodes to components
      * 
@@ -749,6 +755,31 @@ public class Workflow implements Cloneable {
         }
     }
 
+    private void parse(JsonObject workflowObject) throws GraphException, ComponentException {
+        // Graph
+        if (workflowObject.getAsJsonObject(WORKFLOW_TAG) == null) {
+            throw new GraphException("Failed to parse the json object, workflow object doesn't exist");
+        }
+        JsonObject workflowObj = workflowObject.getAsJsonObject(WORKFLOW_TAG);
+        JsonObject graphObject = workflowObj.getAsJsonObject(GraphSchema.GRAPH_TAG);
+        this.graph = WSGraphFactory.createGraph(graphObject);
+
+        bindComponents();
+
+        // Image
+        JsonPrimitive imagePrimitive = workflowObj.getAsJsonPrimitive(IMAGE_TAG);
+        if (imagePrimitive != null) {
+            String base64 = imagePrimitive.getAsString();
+            byte[] bytes = Base64.decodeBase64(base64.getBytes());
+
+            try {
+                this.image = ImageIO.read(new ByteArrayInputStream(bytes));
+            } catch (IOException e) {
+                logger.error(e.getMessage(), e);
+            }
+        }
+    }
+
     public XmlElement getODEDeploymentDescriptor(URI dscUrl, String odeEprEndingWithPort) throws GraphException,
             ComponentException {
         if (this.odeDeploymentDiscriptor == null) {


Mime
View raw message