airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject [2/5] airavata git commit: adding workflow related resource layer
Date Wed, 03 Feb 2016 17:09:04 GMT
http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowInputResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowInputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowInputResource.java
new file mode 100644
index 0000000..5cda60b
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowInputResource.java
@@ -0,0 +1,496 @@
+/**
+ * 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.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowInput_PK;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WorkflowInputResource extends WorkflowCatAbstractResource {
+
+    private final static Logger logger = LoggerFactory.getLogger(WorkflowInputResource.class);
+
+    private String wfTemplateId;
+    private String inputKey;
+    private String dataType;
+    private String inputVal;
+    private String metadata;
+    private String appArgument;
+    private String userFriendlyDesc;
+    private boolean standardInput;
+    private int inputOrder;
+    private boolean isRequired;
+    private boolean requiredToCMD;
+    private boolean dataStaged;
+
+    private WorkflowResource workflowResource;
+
+    public void remove(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
+            generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, ids.get(WorkflowInputConstants.WF_TEMPLATE_ID));
+            generator.setParameter(WorkflowInputConstants.INPUT_KEY, ids.get(WorkflowInputConstants.INPUT_KEY));
+            Query q = generator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap<String, String>) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
+            generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, ids.get(WorkflowInputConstants.WF_TEMPLATE_ID));
+            generator.setParameter(WorkflowInputConstants.INPUT_KEY, ids.get(WorkflowInputConstants.INPUT_KEY));
+            Query q = generator.selectQuery(em);
+            WorkflowInput workflowInput = (WorkflowInput) q.getSingleResult();
+            WorkflowInputResource workflowInputResource =
+                    (WorkflowInputResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW_INPUT
+                            , workflowInput);
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflowInputResource;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+        List<WorkflowCatalogResource> wfInputResources = new ArrayList<WorkflowCatalogResource>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
+            List results;
+            if (fieldName.equals(WorkflowInputConstants.WF_TEMPLATE_ID)) {
+                generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        WorkflowInputResource workflowInputResource =
+                                (WorkflowInputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_INPUT, workflowInput);
+                        wfInputResources.add(workflowInputResource);
+                    }
+                }
+            } else if (fieldName.equals(WorkflowInputConstants.INPUT_KEY)) {
+                generator.setParameter(WorkflowInputConstants.INPUT_KEY, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        WorkflowInputResource workflowInputResource =
+                                (WorkflowInputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_INPUT, workflowInput);
+                        wfInputResources.add(workflowInputResource);
+                    }
+                }
+            } else if (fieldName.equals(WorkflowInputConstants.DATA_TYPE)) {
+                generator.setParameter(WorkflowInputConstants.DATA_TYPE, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        WorkflowInputResource workflowInputResource =
+                                (WorkflowInputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_INPUT, workflowInput);
+                        wfInputResources.add(workflowInputResource);
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for WFInput Resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for WFInput Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return wfInputResources;
+    }
+
+    public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getAllIds() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+        List<String> wfInputResourceIDs = new ArrayList<String>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_INPUT);
+            List results;
+            if (fieldName.equals(WorkflowInputConstants.WF_TEMPLATE_ID)) {
+                generator.setParameter(WorkflowInputConstants.WF_TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        wfInputResourceIDs.add(workflowInput.getTemplateID());
+                    }
+                }
+            } else if (fieldName.equals(WorkflowInputConstants.INPUT_KEY)) {
+                generator.setParameter(WorkflowInputConstants.INPUT_KEY, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        wfInputResourceIDs.add(workflowInput.getTemplateID());
+                    }
+                }
+            } else if (fieldName.equals(WorkflowInputConstants.DATA_TYPE)) {
+                generator.setParameter(WorkflowInputConstants.DATA_TYPE, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowInput workflowInput = (WorkflowInput) result;
+                        wfInputResourceIDs.add(workflowInput.getTemplateID());
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for WFInput resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for WFInput Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return wfInputResourceIDs;
+    }
+
+    public void save() throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowInput existingWFInput = em.find(WorkflowInput.class, new WorkflowInput_PK(wfTemplateId, inputKey));
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            WorkflowInput workflowInput;
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            if (existingWFInput == null) {
+                workflowInput = new WorkflowInput();
+            } else {
+            	workflowInput=existingWFInput;
+            }
+            workflowInput.setTemplateID(wfTemplateId);
+            Workflow workflow = em.find(Workflow.class, wfTemplateId);
+            workflowInput.setWorkflow(workflow);
+            workflowInput.setDataType(dataType);
+            workflowInput.setInputKey(inputKey);
+            if (inputVal != null){
+                workflowInput.setInputVal(inputVal.toCharArray());
+            }
+            workflowInput.setMetadata(metadata);
+            workflowInput.setAppArgument(appArgument);
+            workflowInput.setUserFriendlyDesc(userFriendlyDesc);
+            workflowInput.setStandardInput(standardInput);
+            workflowInput.setRequiredToCMD(requiredToCMD);
+            workflowInput.setRequired(isRequired);
+            workflowInput.setDataStaged(dataStaged);
+            if (existingWFInput == null) {
+                em.persist(workflowInput);
+            } else {
+                em.merge(workflowInput);
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public boolean isExists(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap<String, String>) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowInput workflowInput = em.find(WorkflowInput.class, new WorkflowInput_PK(
+                    ids.get(WorkflowInputConstants.WF_TEMPLATE_ID),
+                    ids.get(WorkflowInputConstants.INPUT_KEY)));
+
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflowInput != null;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public String getWfTemplateId() {
+        return wfTemplateId;
+    }
+
+    public void setWfTemplateId(String wfTemplateId) {
+        this.wfTemplateId = wfTemplateId;
+    }
+
+    public String getInputKey() {
+        return inputKey;
+    }
+
+    public void setInputKey(String inputKey) {
+        this.inputKey = inputKey;
+    }
+
+    public String getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(String dataType) {
+        this.dataType = dataType;
+    }
+
+    public String getInputVal() {
+        return inputVal;
+    }
+
+    public void setInputVal(String inputVal) {
+        this.inputVal = inputVal;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+
+    public void setMetadata(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getAppArgument() {
+        return appArgument;
+    }
+
+    public void setAppArgument(String appArgument) {
+        this.appArgument = appArgument;
+    }
+
+    public String getUserFriendlyDesc() {
+        return userFriendlyDesc;
+    }
+
+    public void setUserFriendlyDesc(String userFriendlyDesc) {
+        this.userFriendlyDesc = userFriendlyDesc;
+    }
+
+    public WorkflowResource getWorkflowResource() {
+        return workflowResource;
+    }
+
+    public void setWorkflowResource(WorkflowResource workflowResource) {
+        this.workflowResource = workflowResource;
+    }
+
+    public boolean isStandardInput() {
+        return standardInput;
+    }
+
+    public void setStandardInput(boolean standardInput) {
+        this.standardInput = standardInput;
+    }
+
+    public int getInputOrder() {
+        return inputOrder;
+    }
+
+    public void setInputOrder(int inputOrder) {
+        this.inputOrder = inputOrder;
+    }
+
+    public boolean getRequired() {
+        return isRequired;
+    }
+
+    public void setRequired(boolean required) {
+        this.isRequired = required;
+    }
+
+    public boolean getRequiredToCMD() {
+        return requiredToCMD;
+    }
+
+    public void setRequiredToCMD(boolean requiredToCMD) {
+        this.requiredToCMD = requiredToCMD;
+    }
+
+    public boolean isDataStaged() {
+        return dataStaged;
+    }
+
+    public void setDataStaged(boolean dataStaged) {
+        this.dataStaged = dataStaged;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowOutputResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowOutputResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowOutputResource.java
new file mode 100644
index 0000000..910136f
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowOutputResource.java
@@ -0,0 +1,489 @@
+/**
+ * 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.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowOutput_PK;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WorkflowOutputResource extends WorkflowCatAbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(WorkflowOutputResource.class);
+
+    private String wfTemplateId;
+    private String outputKey;
+    private String outputVal;
+    private String dataType;
+    private boolean isRequired;
+    private boolean dataMovement;
+    private String dataNameLocation;
+    private boolean requiredToCMD;
+    private String searchQuery;
+    private String appArgument;
+    private boolean outputStreaming;
+
+    private WorkflowResource workflowResource;
+
+    public void remove(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_OUTPUT);
+            generator.setParameter(WorkflowOutputConstants.WF_TEMPLATE_ID, ids.get(WorkflowOutputConstants.WF_TEMPLATE_ID));
+            generator.setParameter(WorkflowOutputConstants.OUTPUT_KEY, ids.get(WorkflowOutputConstants.OUTPUT_KEY));
+            Query q = generator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_OUTPUT);
+            generator.setParameter(WorkflowOutputConstants.WF_TEMPLATE_ID, ids.get(WorkflowOutputConstants.WF_TEMPLATE_ID));
+            generator.setParameter(WorkflowOutputConstants.OUTPUT_KEY, ids.get(WorkflowOutputConstants.OUTPUT_KEY));
+            Query q = generator.selectQuery(em);
+            WorkflowOutput wfOutput = (WorkflowOutput) q.getSingleResult();
+            WorkflowOutputResource workflowOutputResource =
+                    (WorkflowOutputResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW_OUTPUT
+                            , wfOutput);
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflowOutputResource;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+        List<WorkflowCatalogResource> wfOutputResources = new ArrayList<WorkflowCatalogResource>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_OUTPUT);
+            List results;
+            if (fieldName.equals(WorkflowOutputConstants.WF_TEMPLATE_ID)) {
+                generator.setParameter(WorkflowOutputConstants.WF_TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput wfOutput = (WorkflowOutput) result;
+                        WorkflowOutputResource workflowOutputResource =
+                                (WorkflowOutputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_OUTPUT, wfOutput);
+                        wfOutputResources.add(workflowOutputResource);
+                    }
+                }
+            } else if (fieldName.equals(WorkflowOutputConstants.OUTPUT_KEY)) {
+                generator.setParameter(WorkflowOutputConstants.OUTPUT_KEY, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput workflowOutput = (WorkflowOutput) result;
+                        WorkflowOutputResource workflowOutputResource =
+                                (WorkflowOutputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput);
+                        wfOutputResources.add(workflowOutputResource);
+                    }
+                }
+            } else if (fieldName.equals(WorkflowOutputConstants.DATA_TYPE)) {
+                generator.setParameter(WorkflowOutputConstants.DATA_TYPE, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput workflowOutput = (WorkflowOutput) result;
+                        WorkflowOutputResource workflowOutputResource =
+                                (WorkflowOutputResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_OUTPUT, workflowOutput);
+                        wfOutputResources.add(workflowOutputResource);
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for WF Output Resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for WF Output Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return wfOutputResources;
+    }
+
+    public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getAllIds() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+        List<String> wfOutputResourceIDs = new ArrayList<String>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_OUTPUT);
+            List results;
+            if (fieldName.equals(WorkflowOutputConstants.WF_TEMPLATE_ID)) {
+                generator.setParameter(WorkflowOutputConstants.WF_TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput workflowOutput = (WorkflowOutput) result;
+                        wfOutputResourceIDs.add(workflowOutput.getTemplateId());
+                    }
+                }
+            }
+            if (fieldName.equals(WorkflowOutputConstants.OUTPUT_KEY)) {
+                generator.setParameter(WorkflowOutputConstants.OUTPUT_KEY, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput workflowOutput = (WorkflowOutput) result;
+                        wfOutputResourceIDs.add(workflowOutput.getTemplateId());
+                    }
+                }
+            } else if (fieldName.equals(WorkflowOutputConstants.DATA_TYPE)) {
+                generator.setParameter(WorkflowOutputConstants.DATA_TYPE, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowOutput workflowOutput = (WorkflowOutput) result;
+                        wfOutputResourceIDs.add(workflowOutput.getTemplateId());
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for WF Output resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for WF Output Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return wfOutputResourceIDs;
+    }
+
+    public void save() throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowOutput existingWorkflowOutput = em.find(WorkflowOutput.class,
+                    new WorkflowOutput_PK(wfTemplateId, outputKey));
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            if (existingWorkflowOutput != null) {
+                existingWorkflowOutput.setTemplateId(wfTemplateId);
+                Workflow workflow = em.find(Workflow.class, wfTemplateId);
+                existingWorkflowOutput.setWorkflow(workflow);
+                existingWorkflowOutput.setDataType(dataType);
+                existingWorkflowOutput.setOutputKey(outputKey);
+                if (outputVal != null){
+                    existingWorkflowOutput.setOutputVal(outputVal.toCharArray());
+                }
+                existingWorkflowOutput.setDataMovement(dataMovement);
+                existingWorkflowOutput.setDataNameLocation(dataNameLocation);
+                em.merge(existingWorkflowOutput);
+            } else {
+                WorkflowOutput workflowOutput = new WorkflowOutput();
+                workflowOutput.setTemplateId(wfTemplateId);
+                Workflow workflow = em.find(Workflow.class, wfTemplateId);
+                workflowOutput.setWorkflow(workflow);
+                workflowOutput.setDataType(dataType);
+                workflowOutput.setOutputKey(outputKey);
+                if (outputVal != null){
+                    workflowOutput.setOutputVal(outputVal.toCharArray());
+                }
+                workflowOutput.setDataMovement(dataMovement);
+                workflowOutput.setDataNameLocation(dataNameLocation);
+                em.persist(workflowOutput);
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public boolean isExists(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowOutput workflowOutput = em.find(WorkflowOutput.class, new WorkflowOutput_PK(
+                    ids.get(WorkflowOutputConstants.WF_TEMPLATE_ID),
+                    ids.get(WorkflowOutputConstants.OUTPUT_KEY)));
+
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflowOutput != null;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public String getWfTemplateId() {
+        return wfTemplateId;
+    }
+
+    public void setWfTemplateId(String wfTemplateId) {
+        this.wfTemplateId = wfTemplateId;
+    }
+
+    public String getOutputKey() {
+        return outputKey;
+    }
+
+    public void setOutputKey(String outputKey) {
+        this.outputKey = outputKey;
+    }
+
+    public String getOutputVal() {
+        return outputVal;
+    }
+
+    public void setOutputVal(String outputVal) {
+        this.outputVal = outputVal;
+    }
+
+    public String getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(String dataType) {
+        this.dataType = dataType;
+    }
+
+    public WorkflowResource getWorkflowResource() {
+        return workflowResource;
+    }
+
+    public void setWorkflowResource(WorkflowResource workflowResource) {
+        this.workflowResource = workflowResource;
+    }
+
+    public boolean isDataMovement() {
+        return dataMovement;
+    }
+
+    public void setDataMovement(boolean dataMovement) {
+        this.dataMovement = dataMovement;
+    }
+
+    public String getDataNameLocation() {
+        return dataNameLocation;
+    }
+
+    public void setDataNameLocation(String dataNameLocation) {
+        this.dataNameLocation = dataNameLocation;
+    }
+
+    public boolean isRequired() {
+        return isRequired;
+    }
+
+    public void setRequired(boolean isRequired) {
+        this.isRequired = isRequired;
+    }
+
+    public boolean isRequiredToCMD() {
+        return requiredToCMD;
+    }
+
+    public void setRequiredToCMD(boolean requiredToCMD) {
+        this.requiredToCMD = requiredToCMD;
+    }
+
+    public String getSearchQuery() {
+        return searchQuery;
+    }
+
+    public void setSearchQuery(String searchQuery) {
+        this.searchQuery = searchQuery;
+    }
+
+    public String getAppArgument() {
+        return appArgument;
+    }
+
+    public void setAppArgument(String appArgument) {
+        this.appArgument = appArgument;
+    }
+
+    public boolean isOutputStreaming() {
+        return outputStreaming;
+    }
+
+    public void setOutputStreaming(boolean outputStreaming) {
+        this.outputStreaming = outputStreaming;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowResource.java
new file mode 100644
index 0000000..d487742
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowResource.java
@@ -0,0 +1,437 @@
+/*
+ *
+ * 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.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+public class WorkflowResource extends WorkflowCatAbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(WorkflowResource.class);
+    private String wfName;
+    private String createdUser;
+    private String graph;
+    private String wfTemplateId;
+    private Timestamp createdTime;
+    private Timestamp updatedTime;
+    private String image;
+    private String gatewayId;
+
+    public Timestamp getCreatedTime() {
+        return createdTime;
+    }
+
+    public void setCreatedTime(Timestamp createdTime) {
+        this.createdTime = createdTime;
+    }
+
+    public Timestamp getUpdatedTime() {
+        return updatedTime;
+    }
+
+    public void setUpdatedTime(Timestamp updatedTime) {
+        this.updatedTime = updatedTime;
+    }
+
+    public String getImage() {
+        return image;
+    }
+
+    public void setImage(String image) {
+        this.image = image;
+    }
+
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    @Override
+    public void remove(Object identifier) throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            generator.setParameter(WorkflowConstants.TEMPLATE_ID, identifier);
+            Query q = generator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
+    public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            generator.setParameter(WorkflowConstants.TEMPLATE_ID, identifier);
+            Query q = generator.selectQuery(em);
+            Workflow workflow = (Workflow) q.getSingleResult();
+            WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflowResource;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
+    public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+        List<WorkflowCatalogResource> workflowResources = new ArrayList<WorkflowCatalogResource>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            Query q;
+            if ((fieldName.equals(WorkflowConstants.TEMPLATE_ID)) || (fieldName.equals(WorkflowConstants.GATEWAY_ID))) {
+                generator.setParameter(fieldName, value);
+                q = generator.selectQuery(em);
+                List<?> results = q.getResultList();
+                for (Object result : results) {
+                    Workflow workflow = (Workflow) result;
+                    WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
+                    workflowResources.add(workflowResource);
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return workflowResources;
+    }
+
+    @Override
+    public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+        List<WorkflowCatalogResource> workflows = new ArrayList<WorkflowCatalogResource>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId);
+            Query q = generator.selectQuery(em);
+            List results = q.getResultList();
+            if (results.size() != 0) {
+                for (Object result : results) {
+                    Workflow workflow = (Workflow) result;
+                    WorkflowResource wfResource =
+                            (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
+                    workflows.add(wfResource);
+                }
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return workflows;
+    }
+
+    @Override
+    public List<String> getAllIds() throws WorkflowCatalogException {
+        List<String> workflowIds = new ArrayList<String>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            generator.setParameter(WorkflowConstants.GATEWAY_ID, gatewayId);
+            Query q = generator.selectQuery(em);
+            List results = q.getResultList();
+            if (results.size() != 0) {
+                for (Object result : results) {
+                    Workflow workflow = (Workflow) result;
+                    workflowIds.add(workflow.getTemplateId());
+                }
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return workflowIds;
+    }
+
+    @Override
+    public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+        List<String> workflowResourceIDs = new ArrayList<String>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW);
+            Query q;
+            if ((fieldName.equals(WorkflowConstants.TEMPLATE_ID)) || (fieldName.equals(WorkflowConstants.GATEWAY_ID))) {
+                generator.setParameter(fieldName, value);
+                q = generator.selectQuery(em);
+                List<?> results = q.getResultList();
+                for (Object result : results) {
+                    Workflow workflow = (Workflow) result;
+                    WorkflowResource workflowResource = (WorkflowResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW, workflow);
+                    workflowResourceIDs.add(workflowResource.getWfTemplateId());
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for Workflow Resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for Workflow Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return workflowResourceIDs;
+    }
+
+    @Override
+    public void save() throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            Workflow existingWorkflow = em.find(Workflow.class, wfTemplateId);
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            Workflow workflow;
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            if (existingWorkflow == null) {
+                workflow = new Workflow();
+                workflow.setCreationTime(AiravataUtils.getCurrentTimestamp());
+            } else {
+                workflow = existingWorkflow;
+                workflow.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+            }
+            workflow.setWorkflowName(getWfName());
+            workflow.setCreatedUser(getCreatedUser());
+            workflow.setGatewayId(gatewayId);
+            if (getGraph() != null){
+                workflow.setGraph(getGraph().toCharArray());
+            }
+            if (image != null){
+                workflow.setImage(image.getBytes());
+            }
+            workflow.setTemplateId(getWfTemplateId());
+            if (existingWorkflow == null) {
+                em.persist(workflow);
+            } else {
+                em.merge(workflow);
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    @Override
+    public boolean isExists(Object identifier) throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            Workflow workflow = em.find(Workflow.class, identifier);
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return workflow != null;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public String getWfName() {
+        return wfName;
+    }
+
+    public String getCreatedUser() {
+        return createdUser;
+    }
+
+    public String getGraph() {
+        return graph;
+    }
+
+    public String getWfTemplateId() {
+        return wfTemplateId;
+    }
+
+    public void setWfName(String wfName) {
+        this.wfName=wfName;
+    }
+
+    public void setCreatedUser(String createdUser) {
+        this.createdUser=createdUser;
+    }
+
+    public void setGraph(String graph) {
+        this.graph=graph;
+    }
+
+    public void setWfTemplateId(String wfTemplateId) {
+        this.wfTemplateId=wfTemplateId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowStatusResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowStatusResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowStatusResource.java
new file mode 100644
index 0000000..3e0c034
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/resources/WorkflowStatusResource.java
@@ -0,0 +1,369 @@
+/**
+ * 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.registry.core.workflow.catalog.resources;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.registry.core.workflow.catalog.model.Workflow;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowStatus;
+import org.apache.airavata.registry.core.workflow.catalog.model.WorkflowStatus_PK;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogJPAUtils;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogQueryGenerator;
+import org.apache.airavata.registry.core.workflow.catalog.utils.WorkflowCatalogResourceType;
+import org.apache.airavata.registry.cpi.WorkflowCatalogException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WorkflowStatusResource extends WorkflowCatAbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(WorkflowStatusResource.class);
+
+    private String statusId;
+    private String state;
+    private String reason;
+    private String templateId;
+    private Timestamp updatedTime;
+
+    public void remove(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_STATUS);
+            generator.setParameter(WorkflowStatusConstants.STATUS_ID, ids.get(WorkflowStatusConstants.STATUS_ID));
+            generator.setParameter(WorkflowStatusConstants.TEMPLATE_ID, ids.get(WorkflowStatusConstants.TEMPLATE_ID));
+            Query q = generator.deleteQuery(em);
+            q.executeUpdate();
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public WorkflowCatalogResource get(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap<String, String>) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_STATUS);
+            generator.setParameter(WorkflowStatusConstants.STATUS_ID, ids.get(WorkflowStatusConstants.STATUS_ID));
+            generator.setParameter(WorkflowStatusConstants.TEMPLATE_ID, ids.get(WorkflowStatusConstants.TEMPLATE_ID));
+            Query q = generator.selectQuery(em);
+            WorkflowStatus status = (WorkflowStatus) q.getSingleResult();
+            WorkflowStatusResource statusResource =
+                    (WorkflowStatusResource) WorkflowCatalogJPAUtils.getResource(WorkflowCatalogResourceType.WORKFLOW_STATUS
+                            , status);
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return statusResource;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public List<WorkflowCatalogResource> get(String fieldName, Object value) throws WorkflowCatalogException {
+        List<WorkflowCatalogResource> statusResources = new ArrayList<WorkflowCatalogResource>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_STATUS);
+            List results;
+            if (fieldName.equals(WorkflowStatusConstants.TEMPLATE_ID)) {
+                generator.setParameter(WorkflowStatusConstants.TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowStatus WorkflowStatus = (WorkflowStatus) result;
+                        WorkflowStatusResource statusResource =
+                                (WorkflowStatusResource) WorkflowCatalogJPAUtils.getResource(
+                                        WorkflowCatalogResourceType.WORKFLOW_STATUS, WorkflowStatus);
+                        statusResources.add(statusResource);
+                    }
+                }
+            }else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for Workflow status Resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for Workflow status Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return statusResources;
+    }
+
+    public List<WorkflowCatalogResource> getAll() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getAllIds() throws WorkflowCatalogException {
+        return null;
+    }
+
+    public List<String> getIds(String fieldName, Object value) throws WorkflowCatalogException {
+        List<String> statusResourceIds = new ArrayList<String>();
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
+            WorkflowCatalogQueryGenerator generator = new WorkflowCatalogQueryGenerator(WORKFLOW_STATUS);
+            List results;
+            if (fieldName.equals(WorkflowStatusConstants.TEMPLATE_ID)) {
+                generator.setParameter(WorkflowStatusConstants.TEMPLATE_ID, value);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        WorkflowStatus WorkflowStatus = (WorkflowStatus) result;
+                        statusResourceIds.add(WorkflowStatus.getTemplateId());
+                    }
+                }
+            } else {
+                em.getTransaction().commit();
+                if (em.isOpen()) {
+                    if (em.getTransaction().isActive()){
+                        em.getTransaction().rollback();
+                    }
+                    em.close();
+                }
+                logger.error("Unsupported field name for Workflow Status resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported field name for Workflow Status Resource.");
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return statusResourceIds;
+    }
+
+    public void save() throws WorkflowCatalogException {
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowStatus existingStatus = em.find(WorkflowStatus.class,new WorkflowStatus_PK(templateId, statusId));
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            if (existingStatus != null) {
+                existingStatus.setTemplateId(templateId);
+                Workflow workflow = em.find(Workflow.class, templateId);
+                existingStatus.setWorkflow(workflow);
+                existingStatus.setReason(reason);
+                existingStatus.setState(state);
+                existingStatus.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+                em.merge(existingStatus);
+            } else {
+                WorkflowStatus status = new WorkflowStatus();
+                status.setTemplateId(templateId);
+                Workflow workflow = em.find(Workflow.class, templateId);
+                status.setWorkflow(workflow);
+                status.setReason(reason);
+                status.setState(state);
+                status.setUpdateTime(AiravataUtils.getCurrentTimestamp());
+                em.persist(status);
+            }
+            em.getTransaction().commit();
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public boolean isExists(Object identifier) throws WorkflowCatalogException {
+        HashMap<String, String> ids;
+        if (identifier instanceof Map) {
+            ids = (HashMap) identifier;
+        } else {
+            logger.error("Identifier should be a map with the field name and it's value");
+            throw new WorkflowCatalogException("Identifier should be a map with the field name and it's value");
+        }
+
+        EntityManager em = null;
+        try {
+            em = WorkflowCatalogJPAUtils.getEntityManager();
+            WorkflowStatus status = em.find(WorkflowStatus.class, new WorkflowStatus_PK(ids.get(WorkflowStatusConstants.TEMPLATE_ID),ids.get(WorkflowStatusConstants.STATUS_ID)));
+
+            if (em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+            return status != null;
+        } catch (ApplicationSettingsException e) {
+            logger.error(e.getMessage(), e);
+            throw new WorkflowCatalogException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()) {
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public String getStatusId() {
+        return statusId;
+    }
+
+    public void setStatusId(String statusId) {
+        this.statusId = statusId;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getReason() {
+        return reason;
+    }
+
+    public void setReason(String reason) {
+        this.reason = reason;
+    }
+
+    public String getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(String templateId) {
+        this.templateId = templateId;
+    }
+
+    public Timestamp getUpdatedTime() {
+        return updatedTime;
+    }
+
+    public void setUpdatedTime(Timestamp updatedTime) {
+        this.updatedTime = updatedTime;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/2a2782a6/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/utils/WorkflowCatalogJPAUtils.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/utils/WorkflowCatalogJPAUtils.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/utils/WorkflowCatalogJPAUtils.java
new file mode 100644
index 0000000..c78ef9b
--- /dev/null
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/workflow/catalog/utils/WorkflowCatalogJPAUtils.java
@@ -0,0 +1,270 @@
+/*
+ *
+ * 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.registry.core.workflow.catalog.utils;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.registry.core.workflow.catalog.model.*;
+import org.apache.airavata.registry.core.workflow.catalog.resources.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.*;
+import java.util.HashMap;
+import java.util.Map;
+
+public class WorkflowCatalogJPAUtils {
+    private final static Logger logger = LoggerFactory.getLogger(WorkflowCatalogJPAUtils.class);
+    private static final String PERSISTENCE_UNIT_NAME = "workflowcatalog_data";
+    private static final String WFCATALOG_JDBC_DRIVER = "wfcatalog.jdbc.driver";
+    private static final String WFCATALOG_JDBC_URL = "wfcatalog.jdbc.url";
+    private static final String WFCATALOG_JDBC_USER = "wfcatalog.jdbc.user";
+    private static final String WFCATALOG_JDBC_PASSWORD = "wfcatalog.jdbc.password";
+    private static final String WFCATALOG_VALIDATION_QUERY = "wfcatalog.validationQuery";
+    private static final String JPA_CACHE_SIZE = "jpa.cache.size";
+    private static final String JPA_CACHE_ENABLED = "cache.enable";
+    @PersistenceUnit(unitName="workflowcatalog_data")
+    protected static EntityManagerFactory factory;
+    @PersistenceContext(unitName="worlkflowcatalog_data")
+    private static EntityManager wfCatEntityManager;
+
+    public static EntityManager getEntityManager() throws ApplicationSettingsException {
+        if (factory == null) {
+            String connectionProperties = "DriverClassName=" + readServerProperties(WFCATALOG_JDBC_DRIVER) + "," +
+                    "Url=" + readServerProperties(WFCATALOG_JDBC_URL) + "?autoReconnect=true," +
+                    "Username=" + readServerProperties(WFCATALOG_JDBC_USER) + "," +
+                    "Password=" + readServerProperties(WFCATALOG_JDBC_PASSWORD) +
+                    ",validationQuery=" + readServerProperties(WFCATALOG_VALIDATION_QUERY);
+            System.out.println(connectionProperties);
+            Map<String, String> properties = new HashMap<String, String>();
+            properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
+            properties.put("openjpa.ConnectionProperties", connectionProperties);
+            properties.put("openjpa.DynamicEnhancementAgent", "true");
+            properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
+            // For app catalog, we don't need caching
+//            properties.put("openjpa.DataCache","" + readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
+//            properties.put("openjpa.QueryCache","" + readServerProperties(JPA_CACHE_ENABLED) + "(CacheSize=" + Integer.valueOf(readServerProperties(JPA_CACHE_SIZE)) + ", SoftReferenceSize=0)");
+            properties.put("openjpa.RemoteCommitProvider","sjvm");
+            properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
+            properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+            properties.put("openjpa.jdbc.QuerySQLCache", "false");
+            properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000,  autoReconnect=true");
+            factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+        }
+        wfCatEntityManager = factory.createEntityManager();
+        return wfCatEntityManager;
+    }
+
+    private static String readServerProperties (String propertyName) throws ApplicationSettingsException {
+        try {
+            return ServerSettings.getSetting(propertyName);
+        } catch (ApplicationSettingsException e) {
+            logger.error("Unable to read airavata-server.properties...", e);
+            throw new ApplicationSettingsException("Unable to read airavata-server.properties...");
+        }
+    }
+
+    /**
+     *
+     * @param type model type
+     * @param o model type instance
+     * @return corresponding resource object
+     */
+    public static WorkflowCatalogResource getResource(WorkflowCatalogResourceType type, Object o) {
+        switch (type){
+            case WORKFLOW:
+                if (o instanceof Workflow) {
+                    return createWorkflow((Workflow) o);
+                } else {
+                    logger.error("Object should be a Workflow.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Workflow.");
+                }
+            case WORKFLOW_INPUT:
+                if (o instanceof WorkflowInput){
+                    return createWorflowInput((WorkflowInput) o);
+                }else {
+                    logger.error("Object should be a Workflow Input.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Workflow Input.");
+                }
+            case WORKFLOW_OUTPUT:
+                if (o instanceof WorkflowOutput){
+                    return createWorkflowOutput((WorkflowOutput) o);
+                }else {
+                    logger.error("Object should be a Workflow Output.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Workflow Output.");
+                }
+            case COMPONENT_STATUS:
+                if (o instanceof ComponentStatus){
+                    return createComponentStatus((ComponentStatus) o);
+                }else {
+                    logger.error("Object should be a Workflow Output.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Workflow Output.");
+                }
+            case NODE:
+                if (o instanceof Node){
+                    return createNode((Node) o);
+                }else {
+                    logger.error("Object should be a Node.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Node.");
+                }
+            case PORT:
+                if (o instanceof Port){
+                    return createPort((Port) o);
+                }else {
+                    logger.error("Object should be a Port.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Port.");
+                }
+            case EDGE:
+                if (o instanceof Edge){
+                    return createEdge((Edge) o);
+                }else {
+                    logger.error("Object should be a Edge.", new IllegalArgumentException());
+                    throw new IllegalArgumentException("Object should be a Edge.");
+                }
+            default:
+                logger.error("Illegal data type..", new IllegalArgumentException());
+                throw new IllegalArgumentException("Illegal data type..");
+        }
+    }
+	
+    private static WorkflowCatalogResource createWorflowInput(WorkflowInput o) {
+        WorkflowInputResource resource = new WorkflowInputResource();
+        if (o != null){
+            resource.setWfTemplateId(o.getTemplateID());
+            resource.setInputKey(o.getInputKey());
+            if (o.getInputVal() != null){
+                resource.setInputVal(new String(o.getInputVal()));
+            }
+            resource.setDataType(o.getDataType());
+            resource.setMetadata(o.getMetadata());
+            resource.setAppArgument(o.getAppArgument());
+            resource.setInputOrder(o.getInputOrder());
+            resource.setUserFriendlyDesc(o.getUserFriendlyDesc());
+            resource.setStandardInput(o.isStandardInput());
+            resource.setRequired(o.isRequired());
+            resource.setRequiredToCMD(o.isRequiredToCMD());
+            resource.setDataStaged(o.isDataStaged());
+            resource.setWorkflowResource((WorkflowResource)createWorkflow(o.getWorkflow()));
+        }
+        return resource;
+    }
+
+    private static WorkflowCatalogResource createWorkflowOutput(WorkflowOutput o) {
+        WorkflowOutputResource resource = new WorkflowOutputResource();
+        if (o != null){
+            resource.setWfTemplateId(o.getTemplateId());
+            resource.setOutputKey(o.getOutputKey());
+            if (o.getOutputVal() != null){
+                resource.setOutputVal(new String(o.getOutputVal()));
+            }
+            resource.setDataType(o.getDataType());
+            resource.setDataMovement(o.isDataMovement());
+            resource.setDataNameLocation(o.getDataNameLocation());
+            resource.setWorkflowResource((WorkflowResource)createWorkflow(o.getWorkflow()));
+        }
+        return resource;
+    }
+
+    private static ComponentStatusResource createComponentStatus(ComponentStatus o) {
+        ComponentStatusResource resource = new ComponentStatusResource();
+        if (o != null){
+            resource.setStatusId(o.getStatusId());
+            resource.setTemplateId(o.getTemplateId());
+            resource.setUpdatedTime(o.getUpdateTime());
+            resource.setReason(o.getReason());
+            resource.setState(o.getState());
+        }
+        return resource;
+    }
+
+    private static WorkflowStatusResource createWorkflowStatus(WorkflowStatus o) {
+        WorkflowStatusResource resource = new WorkflowStatusResource();
+        if (o != null){
+            resource.setStatusId(o.getStatusId());
+            resource.setTemplateId(o.getTemplateId());
+            resource.setReason(o.getReason());
+            resource.setState(o.getState());
+            resource.setUpdatedTime(o.getUpdateTime());
+        }
+        return resource;
+    }
+
+    private static EdgeResource createEdge(Edge o) {
+        EdgeResource resource = new EdgeResource();
+        if (o != null){
+            resource.setStatusId(o.getComponentStatusId());
+            resource.setTemplateId(o.getTemplateId());
+            resource.setEdgeId(o.getEdgeId());
+            resource.setDescription(o.getDescription());
+            resource.setName(o.getName());
+            resource.setCreatedTime(o.getCreatedTime());
+        }
+        return resource;
+    }
+
+    private static PortResource createPort(Port o) {
+        PortResource resource = new PortResource();
+        if (o != null){
+            resource.setStatusId(o.getComponentStatusId());
+            resource.setTemplateId(o.getTemplateId());
+            resource.setPortId(o.getPortId());
+            resource.setDescription(o.getDescription());
+            resource.setName(o.getName());
+            resource.setCreatedTime(o.getCreatedTime());
+        }
+        return resource;
+    }
+
+    private static NodeResource createNode(Node o) {
+        NodeResource resource = new NodeResource();
+        if (o != null){
+            resource.setStatusId(o.getComponentStatusId());
+            resource.setTemplateId(o.getTemplateId());
+            resource.setNodeId(o.getNodeId());
+            resource.setDescription(o.getDescription());
+            resource.setName(o.getName());
+            resource.setCreatedTime(o.getCreatedTime());
+            resource.setApplicationId(o.getApplicationId());
+            resource.setApplicationName(o.getApplicationName());
+        }
+        return resource;
+    }
+
+    private static WorkflowCatalogResource createWorkflow(Workflow o) {
+        WorkflowResource workflowResource = new WorkflowResource();
+        workflowResource.setWfName(o.getWorkflowName());
+        workflowResource.setCreatedUser(o.getCreatedUser());
+        if (o.getGraph() != null){
+            workflowResource.setGraph(new String(o.getGraph()));
+        }
+        if (o.getImage() != null){
+            workflowResource.setImage(new String(o.getImage()));
+        }
+        workflowResource.setCreatedTime(o.getCreationTime());
+        if (o.getUpdateTime() != null){
+            workflowResource.setUpdatedTime(o.getUpdateTime());
+        }
+        workflowResource.setWfTemplateId(o.getTemplateId());
+        workflowResource.setGatewayId(o.getGatewayId());
+        return workflowResource;
+    }
+}


Mime
View raw message