airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1553518 [6/15] - in /airavata/sandbox: orchestrator-service/ orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/ orchestrator/orchestrator-core/src/main/java/org/apache/airavata/orchestrator/core/context/ or...
Date Thu, 26 Dec 2013 17:31:40 GMT
Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,744 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GatewayResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(GatewayResource.class);
+    private String gatewayName;
+    private String owner;
+
+    /**
+     *
+     * @param gatewayName gateway name
+     */
+    public GatewayResource(String gatewayName) {
+    	setGatewayName(gatewayName);
+	}
+
+    /**
+     *
+     */
+    public GatewayResource() {
+	}
+
+    /**
+     *
+     * @return gateway name
+     */
+    public String getGatewayName() {
+        return gatewayName;
+    }
+
+    /**
+     *
+     * @param gatewayName
+     */
+    public void setGatewayName(String gatewayName) {
+        this.gatewayName = gatewayName;
+    }
+
+    /**
+     *
+     * @return owner of the gateway
+     */
+    public String getOwner() {
+        return owner;
+    }
+
+    /**
+     *
+     * @param owner owner of the gateway
+     */
+    public void setOwner(String owner) {
+        this.owner = owner;
+    }
+
+    /**
+     * Gateway is at the root level.  So it can populate his child resources.
+     * Project, User, Published Workflows, User workflows, Host descriptors,
+     * Service Descriptors, Application descriptors and Experiments are all
+     * its children
+     * @param type resource type of the children
+     * @return specific child resource type
+     */
+    public Resource create(ResourceType type) {
+        switch (type) {
+            case PROJECT:
+                ProjectResource projectResource = new ProjectResource();
+                projectResource.setGateway(this);
+                return projectResource;
+            case USER:
+                UserResource userResource = new UserResource();
+                userResource.setGatewayName(this.getGatewayName());
+                return userResource;
+            case PUBLISHED_WORKFLOW:
+                PublishWorkflowResource publishWorkflowResource = new PublishWorkflowResource();
+                publishWorkflowResource.setGateway(this);
+                return publishWorkflowResource;
+            case USER_WORKFLOW:
+                UserWorkflowResource userWorkflowResource = new UserWorkflowResource();
+                userWorkflowResource.setGateway(this);
+                return userWorkflowResource;
+            case HOST_DESCRIPTOR:
+                HostDescriptorResource hostDescriptorResource = new HostDescriptorResource();
+                hostDescriptorResource.setGatewayName(gatewayName);
+                return hostDescriptorResource;
+            case SERVICE_DESCRIPTOR:
+                ServiceDescriptorResource serviceDescriptorResource = new ServiceDescriptorResource();
+                serviceDescriptorResource.setGatewayName(gatewayName);
+                return serviceDescriptorResource;
+            case APPLICATION_DESCRIPTOR:
+                ApplicationDescriptorResource applicationDescriptorResource =
+                        new ApplicationDescriptorResource();
+                applicationDescriptorResource.setGatewayName(gatewayName);
+                return applicationDescriptorResource;
+            case EXPERIMENT:
+                ExperimentResource experimentResource =new ExperimentResource();
+                experimentResource.setGateway(this);
+                return experimentResource;
+            case GATEWAY_WORKER:
+                WorkerResource workerResource = new WorkerResource();
+                workerResource.setGateway(this);
+                return workerResource;
+            default:
+                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
+        }
+    }
+
+    /**
+     * Child resources can be removed from a gateway
+     * @param type child resource type
+     * @param name child resource name
+     */
+    public void remove(ResourceType type, Object name) {
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Query q;
+        QueryGenerator generator;
+        switch (type){
+            case USER:
+                generator = new QueryGenerator(USERS);
+                generator.setParameter(UserConstants.USERNAME, name);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            case PUBLISHED_WORKFLOW:
+                generator = new QueryGenerator(PUBLISHED_WORKFLOW);
+                generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME, name);
+                generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            case HOST_DESCRIPTOR:
+                generator = new QueryGenerator(HOST_DESCRIPTOR);
+                generator.setParameter(HostDescriptorConstants.HOST_DESC_ID, name);
+                generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            case SERVICE_DESCRIPTOR:
+                generator = new QueryGenerator(SERVICE_DESCRIPTOR);
+                generator.setParameter(ServiceDescriptorConstants.SERVICE_DESC_ID, name);
+                generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            case EXPERIMENT:
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            case APPLICATION_DESCRIPTOR:
+                generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+                generator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, name);
+                generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            default:
+                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
+                break;
+        }
+
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    /**
+     * Gateway can get information of his children
+     * @param type child resource type
+     * @param name child resource name
+     * @return specific child resource type
+     */
+    public Resource get(ResourceType type, Object name) {
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator generator;
+        Query q;
+        switch (type) {
+            case USER:
+                generator = new QueryGenerator(GATEWAY_WORKER);
+                generator.setParameter(GatewayWorkerConstants.USERNAME, name);
+                generator.setParameter(GatewayWorkerConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Gateway_Worker worker = (Gateway_Worker) q.getSingleResult();
+                WorkerResource workerResource =
+                        (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, worker);
+                em.getTransaction().commit();
+                em.close();
+                return workerResource;
+            case PUBLISHED_WORKFLOW:
+                generator = new QueryGenerator(PUBLISHED_WORKFLOW);
+                generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME, name);
+                generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Published_Workflow ePub_workflow = (Published_Workflow) q.getSingleResult();
+                PublishWorkflowResource publishWorkflowResource =
+                        (PublishWorkflowResource)Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, ePub_workflow);
+                em.getTransaction().commit();
+                em.close();
+                return publishWorkflowResource;
+            case HOST_DESCRIPTOR:
+                generator = new QueryGenerator(HOST_DESCRIPTOR);
+                generator.setParameter(HostDescriptorConstants.HOST_DESC_ID, name);
+                generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Host_Descriptor eHostDesc = (Host_Descriptor) q.getSingleResult();
+                HostDescriptorResource hostDescriptorResource =
+                        (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, eHostDesc);
+                em.getTransaction().commit();
+                em.close();
+                return hostDescriptorResource;
+            case EXPERIMENT:
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Experiment experiment = (Experiment)q.getSingleResult();
+                ExperimentResource experimentResource =
+                        (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
+                em.getTransaction().commit();
+                em.close();
+                return experimentResource;
+            case SERVICE_DESCRIPTOR:
+                generator = new QueryGenerator(SERVICE_DESCRIPTOR);
+                generator.setParameter(ServiceDescriptorConstants.SERVICE_DESC_ID, name);
+                generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Service_Descriptor eServiceDesc = (Service_Descriptor) q.getSingleResult();
+                ServiceDescriptorResource serviceDescriptorResource =
+                        (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, eServiceDesc);
+                em.getTransaction().commit();
+                em.close();
+                return serviceDescriptorResource;
+            case APPLICATION_DESCRIPTOR:
+                generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+                generator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, name);
+                generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                Application_Descriptor eAppDesc = (Application_Descriptor) q.getSingleResult();
+                ApplicationDescriptorResource applicationDescriptorResource =
+                        (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, eAppDesc);
+                em.getTransaction().commit();
+                em.close();
+                return applicationDescriptorResource;
+            default:
+                em.getTransaction().commit();
+                em.close();
+                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
+
+        }
+
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @return list of child resources
+     */
+    public List<Resource> get(ResourceType type) {
+        List<Resource> resourceList = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Query q;
+        QueryGenerator generator;
+        List results;
+        switch (type){
+            case PROJECT:
+                generator = new QueryGenerator(PROJECT);
+                Gateway gatewayModel = em.find(Gateway.class, gatewayName);
+                generator.setParameter("gateway", gatewayModel);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Project project = (Project) result;
+                        ProjectResource projectResource =
+                                (ProjectResource)Utils.getResource(ResourceType.PROJECT, project);
+                        resourceList.add(projectResource);
+                    }
+                }
+                break;
+            case GATEWAY_WORKER:
+                generator = new QueryGenerator(GATEWAY_WORKER);
+                generator.setParameter(GatewayWorkerConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Gateway_Worker gatewayWorker = (Gateway_Worker) result;
+                        WorkerResource workerResource =
+                                (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, gatewayWorker);
+                        resourceList.add(workerResource);
+                    }
+                }
+                break;
+            case  PUBLISHED_WORKFLOW :
+                generator = new QueryGenerator(PUBLISHED_WORKFLOW);
+                generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Published_Workflow publishedWorkflow = (Published_Workflow) result;
+                        PublishWorkflowResource publishWorkflowResource =
+                                (PublishWorkflowResource)Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, publishedWorkflow);
+                        resourceList.add(publishWorkflowResource);
+                    }
+                }
+                break;
+            case HOST_DESCRIPTOR:
+                generator = new QueryGenerator(HOST_DESCRIPTOR);
+                generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Host_Descriptor hostDescriptor = (Host_Descriptor) result;
+                        HostDescriptorResource hostDescriptorResource =
+                                (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, hostDescriptor);
+                        resourceList.add(hostDescriptorResource);
+                    }
+                }
+                break;
+            case SERVICE_DESCRIPTOR:
+                generator = new QueryGenerator(SERVICE_DESCRIPTOR);
+                generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Service_Descriptor serviceDescriptor = (Service_Descriptor) result;
+                        ServiceDescriptorResource serviceDescriptorResource =
+                                (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, serviceDescriptor);
+                        resourceList.add(serviceDescriptorResource);
+                    }
+                }
+                break;
+            case APPLICATION_DESCRIPTOR:
+                generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+                generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Application_Descriptor applicationDescriptor = (Application_Descriptor) result;
+                        ApplicationDescriptorResource applicationDescriptorResource =
+                                (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
+                        resourceList.add(applicationDescriptorResource);
+                    }
+                }
+                break;
+            case EXPERIMENT:
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Experiment experiment = (Experiment) result;
+                        ExperimentResource experimentResource =
+                                (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
+                        resourceList.add(experimentResource);
+                    }
+                }
+                break;
+            case USER:
+		        generator = new QueryGenerator(USERS);
+		        q = generator.selectQuery(em);
+		        for (Object o : q.getResultList()) {
+		        	Users user = (Users) o;
+		        	UserResource userResource =
+	                        (UserResource)Utils.getResource(ResourceType.USER, user);
+		        	resourceList.add(userResource);
+		        }
+		        break;
+            default:
+                em.getTransaction().commit();
+                em.close();
+                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
+        }
+        em.getTransaction().commit();
+        em.close();
+        return resourceList;
+    }
+
+    /**
+     * save the gateway to the database
+     */
+    public void save() {
+        EntityManager em = ResourceUtils.getEntityManager();
+        Gateway existingGateway = em.find(Gateway.class, gatewayName);
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Gateway gateway = new Gateway();
+        gateway.setGateway_name(gatewayName);
+        gateway.setOwner(owner);
+        if (existingGateway != null) {
+            existingGateway.setOwner(owner);
+            gateway = em.merge(existingGateway);
+        } else {
+            em.persist(gateway);
+        }
+        em.getTransaction().commit();
+        em.close();
+
+    }
+
+    /**
+     * check whether child resource already exist in the database
+     * @param type child resource type
+     * @param name name of the child resource
+     * @return true or false
+     */
+    public boolean isExists(ResourceType type, Object name) {
+        EntityManager em;
+        Query q;
+        Number count;
+        switch (type){
+            case USER:
+                em = ResourceUtils.getEntityManager();
+                Gateway_Worker existingWorker = em.find(Gateway_Worker.class, new Gateway_Worker_PK(gatewayName, name.toString()));
+                em.close();
+                return existingWorker!= null;
+            case PUBLISHED_WORKFLOW:
+                em = ResourceUtils.getEntityManager();
+                Published_Workflow existingWf = em.find(Published_Workflow.class, new Published_Workflow_PK(gatewayName, name.toString()));
+                em.close();
+                boolean a = existingWf != null;
+                return existingWf != null;
+            case HOST_DESCRIPTOR:
+                em = ResourceUtils.getEntityManager();
+                Host_Descriptor existingHostDesc = em.find(Host_Descriptor.class, new Host_Descriptor_PK(gatewayName, name.toString()));
+                em.close();
+                return existingHostDesc != null;
+            case SERVICE_DESCRIPTOR:
+                em = ResourceUtils.getEntityManager();
+                Service_Descriptor existingServiceDesc = em.find(Service_Descriptor.class, new Service_Descriptor_PK(gatewayName, name.toString()));
+                em.close();
+                return existingServiceDesc != null;
+            case APPLICATION_DESCRIPTOR:
+                em = ResourceUtils.getEntityManager();
+                Application_Descriptor existingAppDesc = em.find(Application_Descriptor.class, new Application_Descriptor_PK(gatewayName, name.toString()));
+                em.close();
+                return existingAppDesc != null;
+            case EXPERIMENT:
+                em = ResourceUtils.getEntityManager();
+                Experiment existingExp = em.find(Experiment.class, name.toString());
+                em.close();
+                return existingExp != null;
+            default:
+                logger.error("Unsupported resource type for gateway resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
+        }
+    }
+
+    /**
+     *
+     * @param descriptorName host descriptor name
+     * @return whether host descriptor already available
+     */
+    public boolean isHostDescriptorExists(String descriptorName){
+    	return isExists(ResourceType.HOST_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @param hostDescriptorName host descriptor name
+     * @return HostDescriptorResource
+     */
+    public HostDescriptorResource createHostDescriptorResource(String hostDescriptorName){
+    	HostDescriptorResource hdr = (HostDescriptorResource)create(ResourceType.HOST_DESCRIPTOR);
+    	hdr.setHostDescName(hostDescriptorName);
+    	return hdr;
+    }
+
+    /**
+     *
+     * @param hostDescriptorName host descriptor name
+     * @return HostDescriptorResource
+     */
+    public HostDescriptorResource getHostDescriptorResource(String hostDescriptorName){
+    	return (HostDescriptorResource)get(ResourceType.HOST_DESCRIPTOR,hostDescriptorName);
+    }
+
+    /**
+     *
+     * @param descriptorName host descriptor name
+     */
+    public void removeHostDescriptor(String descriptorName){
+    	remove(ResourceType.HOST_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @return list of host descriptors available for the gateway
+     */
+    public List<HostDescriptorResource> getHostDescriptorResources(){
+    	List<HostDescriptorResource> results=new ArrayList<HostDescriptorResource>();
+    	List<Resource> list = get(ResourceType.HOST_DESCRIPTOR);
+    	for (Resource resource : list) {
+    		results.add((HostDescriptorResource) resource);
+		}
+    	return results;
+    }
+
+    /**
+     *
+     * @param descriptorName service descriptor name
+     * @return whether service descriptor already available
+     */
+    public boolean isServiceDescriptorExists(String descriptorName){
+    	return isExists(ResourceType.SERVICE_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @param descriptorName  service descriptor name
+     * @return  ServiceDescriptorResource
+     */
+    public ServiceDescriptorResource createServiceDescriptorResource(String descriptorName){
+    	ServiceDescriptorResource hdr = (ServiceDescriptorResource)create(ResourceType.SERVICE_DESCRIPTOR);
+    	hdr.setServiceDescName(descriptorName);
+    	return hdr;
+    }
+
+    /**
+     *
+     * @param descriptorName   service descriptor name
+     * @return ServiceDescriptorResource
+     */
+    public ServiceDescriptorResource getServiceDescriptorResource(String descriptorName){
+    	return (ServiceDescriptorResource)get(ResourceType.SERVICE_DESCRIPTOR,descriptorName);
+    }
+
+    /**
+     *
+     * @param descriptorName Service descriptor name
+     */
+    public void removeServiceDescriptor(String descriptorName){
+    	remove(ResourceType.SERVICE_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @return list of service descriptors for the gateway
+     */
+    public List<ServiceDescriptorResource> getServiceDescriptorResources(){
+    	List<ServiceDescriptorResource> results=new ArrayList<ServiceDescriptorResource>();
+    	List<Resource> list = get(ResourceType.SERVICE_DESCRIPTOR);
+    	for (Resource resource : list) {
+    		results.add((ServiceDescriptorResource) resource);
+		}
+    	return results;
+    }
+
+    /**
+     *
+     * @param descriptorName application descriptor name
+     * @return  whether application descriptor already available
+     */
+    public boolean isApplicationDescriptorExists(String descriptorName){
+    	return isExists(ResourceType.APPLICATION_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @param descriptorName  application descriptor name
+     * @return ApplicationDescriptorResource
+     */
+    public ApplicationDescriptorResource createApplicationDescriptorResource(String descriptorName){
+    	ApplicationDescriptorResource hdr = (ApplicationDescriptorResource)create(ResourceType.APPLICATION_DESCRIPTOR);
+    	hdr.setName(descriptorName);
+    	return hdr;
+    }
+
+    /**
+     *
+     * @param descriptorName application descriptor name
+     * @return ApplicationDescriptorResource
+     */
+    public ApplicationDescriptorResource getApplicationDescriptorResource(String descriptorName){
+    	return (ApplicationDescriptorResource)get(ResourceType.APPLICATION_DESCRIPTOR,descriptorName);
+    }
+
+    /**
+     *
+     * @param descriptorName  application descriptor name
+     */
+    public void removeApplicationDescriptor(String descriptorName){
+    	remove(ResourceType.APPLICATION_DESCRIPTOR, descriptorName);
+    }
+
+    /**
+     *
+     * @return list of application descriptors for the gateway
+     */
+    public List<ApplicationDescriptorResource> getApplicationDescriptorResources(){
+    	List<ApplicationDescriptorResource> results=new ArrayList<ApplicationDescriptorResource>();
+    	List<Resource> list = get(ResourceType.APPLICATION_DESCRIPTOR);
+    	for (Resource resource : list) {
+    		results.add((ApplicationDescriptorResource) resource);
+		}
+    	return results;
+    }
+
+    /**
+     *
+     * @param serviceName service descriptor name
+     * @param hostName host descriptor name
+     * @return  list of application descriptors for the gateway
+     */
+    public List<ApplicationDescriptorResource> getApplicationDescriptorResources(String serviceName,String hostName){
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        String qString = "SELECT p FROM Application_Descriptor p WHERE " +
+                "p.gateway_name =:gate_name";
+        if (hostName!=null){
+        	qString+=" and p.host_descriptor_ID =:host_name";
+        }
+        if (serviceName!=null){
+        	qString+=" and p.service_descriptor_ID =:service_name";
+        }
+		Query q = em.createQuery(qString);
+        q.setParameter("gate_name", gatewayName);
+        if (serviceName!=null){
+        	q.setParameter("service_name", serviceName);
+        }
+        if (hostName!=null){
+        	q.setParameter("host_name",hostName);
+        }
+        List<?> results = q.getResultList();
+    	List<ApplicationDescriptorResource> resourceList = new ArrayList<ApplicationDescriptorResource>();
+        if (results.size() != 0) {
+            for (Object result : results) {
+                Application_Descriptor applicationDescriptor = (Application_Descriptor) result;
+                ApplicationDescriptorResource applicationDescriptorResource =
+                        new ApplicationDescriptorResource(
+                                applicationDescriptor.getApplication_descriptor_ID(),
+                                applicationDescriptor.getGateway().getGateway_name());
+                applicationDescriptorResource.setContent(new String(applicationDescriptor.getApplication_descriptor_xml()));
+                applicationDescriptorResource.setUpdatedUser(applicationDescriptor.getUser().getUser_name());
+                applicationDescriptorResource.setHostDescName(applicationDescriptor.getHost_descriptor_ID());
+                applicationDescriptorResource.setServiceDescName(applicationDescriptor.getService_descriptor_ID());
+                resourceList.add(applicationDescriptorResource);
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+        return resourceList;
+    }
+
+    /**
+     *
+     * @param workflowTemplateName published workflow template name
+     * @return boolean - whether workflow with the same name exists
+     */
+    public boolean isPublishedWorkflowExists(String workflowTemplateName){
+    	return isExists(ResourceType.PUBLISHED_WORKFLOW, workflowTemplateName);
+    }
+
+    /**
+     *
+     * @param workflowTemplateName published workflow template name
+     * @return publish workflow resource
+     */
+    public PublishWorkflowResource createPublishedWorkflow(String workflowTemplateName){
+    	PublishWorkflowResource publishedWorkflowResource =
+                (PublishWorkflowResource)create(ResourceType.PUBLISHED_WORKFLOW);
+    	publishedWorkflowResource.setName(workflowTemplateName);
+    	publishedWorkflowResource.setPath("/");
+    	publishedWorkflowResource.setVersion("1.0");
+    	return publishedWorkflowResource;
+    }
+
+    /**
+     *
+     * @param workflowTemplateName published workflow template name
+     * @return publish workflow resource
+     */
+    public PublishWorkflowResource getPublishedWorkflow(String workflowTemplateName){
+    	return (PublishWorkflowResource)get(ResourceType.PUBLISHED_WORKFLOW,workflowTemplateName);
+    }
+
+    /**
+     *
+     * @return list of publish workflows for the gateway
+     */
+    public List<PublishWorkflowResource> getPublishedWorkflows(){
+    	List<PublishWorkflowResource> result=new ArrayList<PublishWorkflowResource>();
+    	List<Resource> list = get(ResourceType.PUBLISHED_WORKFLOW);
+    	for (Resource resource : list) {
+			result.add((PublishWorkflowResource) resource);
+		}
+    	return result;
+    }
+
+    /**
+     *
+     * @param workflowTemplateName published workflow template name
+     */
+    public void removePublishedWorkflow(String workflowTemplateName){
+    	remove(ResourceType.PUBLISHED_WORKFLOW, workflowTemplateName);
+    }
+}
+

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GramDataResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GramDataResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GramDataResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GramDataResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,133 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.Gram_Data;
+import org.apache.airavata.persistance.registry.jpa.model.Gram_DataPK;
+import org.apache.airavata.persistance.registry.jpa.model.Node_Data;
+import org.apache.airavata.persistance.registry.jpa.model.Workflow_Data;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+
+public class GramDataResource extends AbstractResource{
+    private final static Logger logger = LoggerFactory.getLogger(GramDataResource.class);
+    private WorkflowDataResource workflowDataResource;
+    private String nodeID;
+    private String rsl;
+    private String invokedHost;
+    private String localJobID;
+
+    public String getNodeID() {
+        return nodeID;
+    }
+
+    public String getRsl() {
+        return rsl;
+    }
+
+    public String getInvokedHost() {
+        return invokedHost;
+    }
+
+    public String getLocalJobID() {
+        return localJobID;
+    }
+
+    public WorkflowDataResource getWorkflowDataResource() {
+        return workflowDataResource;
+    }
+
+    public void setWorkflowDataResource(WorkflowDataResource workflowDataResource) {
+        this.workflowDataResource = workflowDataResource;
+    }
+
+    public void setNodeID(String nodeID) {
+        this.nodeID = nodeID;
+    }
+
+    public void setRsl(String rsl) {
+        this.rsl = rsl;
+    }
+
+    public void setInvokedHost(String invokedHost) {
+        this.invokedHost = invokedHost;
+    }
+
+    public void setLocalJobID(String localJobID) {
+        this.localJobID = localJobID;
+    }
+
+    public Resource create(ResourceType type) {
+        logger.error("Unsupported resource type for Gram data resource" ,new UnsupportedOperationException() );
+        throw new UnsupportedOperationException();
+    }
+
+    public void remove(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for Gram data resource" ,new UnsupportedOperationException() );
+        throw new UnsupportedOperationException();
+    }
+
+    public Resource get(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for Gram data resource" ,new UnsupportedOperationException() );
+        throw new UnsupportedOperationException();
+    }
+
+    public List<Resource> get(ResourceType type) {
+        logger.error("Unsupported resource type for Gram data resource" ,new UnsupportedOperationException() );
+        throw new UnsupportedOperationException();
+    }
+
+    public void save() {
+        EntityManager em = ResourceUtils.getEntityManager();
+        Gram_Data existingGramData = em.find(Gram_Data.class, new Gram_DataPK(workflowDataResource.getWorkflowInstanceID(), nodeID));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Gram_Data gramData = new Gram_Data();
+        gramData.setNode_id(nodeID);
+        Workflow_Data workflow_data = em.find(Workflow_Data.class, workflowDataResource.getWorkflowInstanceID());
+        gramData.setWorkflow_Data(workflow_data);
+        gramData.setNode_id(nodeID);
+        gramData.setInvoked_host(invokedHost);
+        gramData.setLocal_Job_ID(localJobID);
+        byte[] bytes = rsl.getBytes();
+        gramData.setRsl(bytes);
+        if(existingGramData != null){
+            existingGramData.setInvoked_host(invokedHost);
+            existingGramData.setLocal_Job_ID(localJobID);
+            existingGramData.setRsl(bytes);
+            gramData = em.merge(existingGramData);
+        }  else {
+            em.persist(gramData);
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+}

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,256 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.sql.rowset.serial.SerialBlob;
+import java.sql.Blob;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class HostDescriptorResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(HostDescriptorResource.class);
+    private String hostDescName;
+    private String gatewayName;
+    private String userName;
+    private String content;
+
+    /**
+     *
+     */
+    public HostDescriptorResource() {
+    }
+
+    /**
+     *
+     * @return user name
+     */
+    public String getUserName() {
+        return userName;
+    }
+
+    /**
+     *
+     * @param userName user name
+     */
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    /**
+     *
+     * @return  host descriptor name
+     */
+    public String getHostDescName() {
+        return hostDescName;
+    }
+
+    /**
+     *
+     * @return gateway name
+     */
+    public String getGatewayName() {
+        return gatewayName;
+    }
+
+    /**
+     *
+     * @return  content of the host descriptor
+     */
+    public String getContent() {
+        return content;
+    }
+
+    /**
+     *
+     * @param gatewayName gateway name
+     */
+    public void setGatewayName(String gatewayName) {
+        this.gatewayName = gatewayName;
+    }
+
+    /**
+     *
+     * @param content content of the host descriptor
+     */
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    /**
+     * Host descriptor can create an application descriptor
+     * @param type child resource type
+     * @return child resource
+     */
+    public Resource create(ResourceType type) {
+        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
+            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource();
+            applicationDescriptorResource.setGatewayName(gatewayName);
+            applicationDescriptorResource.setHostDescName(getHostDescName());
+            return applicationDescriptorResource;
+        }else{
+            logger.error("Unsupported resource type for host descriptor resource.", new IllegalArgumentException());
+            throw new IllegalArgumentException("Unsupported resource type for host descriptor resource.");
+        }
+
+    }
+
+    /**
+     * Host descriptor by alone cannot remove any other resource types
+     * @param type child resource type
+     * @param name child resource name
+     */
+    public void remove(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for host descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Host descriptor by alone cannot get any other resource types
+     * @param type child resource type
+     * @param name child resource name
+     * @return UnsupportedOperationException
+     */
+    public Resource get(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for host descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * key should be host_descriptor_name
+     * @param keys host descriptor names
+     * @return list of host descriptors
+     */
+    public List<Resource> populate(Object[] keys) {
+        List<Resource> list = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator generator = new QueryGenerator(HOST_DESCRIPTOR);
+        generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, keys [0]);
+        generator.setParameter(HostDescriptorConstants.HOST_DESC_ID, keys[1]);
+        Query q = generator.selectQuery(em);
+        Host_Descriptor hostDescriptor = (Host_Descriptor)q.getSingleResult();
+        HostDescriptorResource hostDescriptorResource =
+                (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, hostDescriptor);
+        em.getTransaction().commit();
+        em.close();
+        list.add(hostDescriptorResource);
+        return list;
+    }
+
+    /**
+     * Host descriptors can get a list of application descriptors
+     * @param type child resource type
+     * @return list of child resources
+     */
+    public List<Resource> get(ResourceType type) {
+        List<Resource> resourceList = new ArrayList<Resource>();
+        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+            generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+            generator.setParameter(ApplicationDescriptorConstants.HOST_DESC_ID, getHostDescName());
+            Query q = generator.selectQuery(em);
+            List results = q.getResultList();
+            if (results.size() != 0) {
+                for (Object result : results) {
+                    Application_Descriptor applicationDescriptor = (Application_Descriptor) result;
+                    ApplicationDescriptorResource applicationDescriptorResource =
+                            (ApplicationDescriptorResource)Utils.getResource(
+                                    ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
+                    resourceList.add(applicationDescriptorResource);
+                }
+            }
+            em.getTransaction().commit();
+            em.close();
+        }
+        return resourceList;
+    }
+
+    /**
+     * save host descriptor to the database
+     */
+    public void save() {
+        try {
+            EntityManager em = ResourceUtils.getEntityManager();
+            Host_Descriptor existingHost_desc = em.find(Host_Descriptor.class, new Host_Descriptor_PK(gatewayName, hostDescName));
+            em.close();
+
+            em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            Host_Descriptor hostDescriptor = new Host_Descriptor();
+            Gateway existingGateway = em.find(Gateway.class, gatewayName);
+            Users existingUser = em.find(Users.class, userName);
+//            Gateway gateway = new Gateway();
+//            gateway.setGateway_name(gatewayName);
+//            Users user = new Users();
+//            user.setUser_name(userName);
+            hostDescriptor.setHost_descriptor_ID(getHostDescName());
+            hostDescriptor.setGateway(existingGateway);
+            byte[] contentBytes = content.getBytes();
+            hostDescriptor.setHost_descriptor_xml(contentBytes);
+            hostDescriptor.setUser(existingUser);
+            if (existingHost_desc != null) {
+                existingHost_desc.setUser(existingUser);
+                existingHost_desc.setHost_descriptor_xml(contentBytes);
+                hostDescriptor = em.merge(existingHost_desc);
+            } else {
+                em.merge(hostDescriptor);
+            }
+
+            em.getTransaction().commit();
+            em.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @param name child resource name
+     * @return boolean whether the child resource already exists
+     */
+    public boolean isExists(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for host descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     *
+     * @param hostDescName host descriptor name
+     */
+    public void setHostDescName(String hostDescName) {
+		this.hostDescName = hostDescName;
+	}
+}

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeDataResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeDataResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeDataResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/NodeDataResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,274 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+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 NodeDataResource extends AbstractResource{
+    private final static Logger logger = LoggerFactory.getLogger(NodeDataResource.class);
+    private WorkflowDataResource workflowDataResource;
+    private String nodeID;
+    private String nodeType;
+    private String inputs;
+    private String outputs;
+    private String status;
+    private Timestamp startTime;
+    private Timestamp lastUpdateTime;
+    private int executionIndex;
+
+    public WorkflowDataResource getWorkflowDataResource() {
+        return workflowDataResource;
+    }
+
+    public String getNodeID() {
+        return nodeID;
+    }
+
+    public String getNodeType() {
+        return nodeType;
+    }
+
+    public String getInputs() {
+        return inputs;
+    }
+
+    public String getOutputs() {
+        return outputs;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public Timestamp getStartTime() {
+        return startTime;
+    }
+
+    public Timestamp getLastUpdateTime() {
+        return lastUpdateTime;
+    }
+
+    public void setWorkflowDataResource(WorkflowDataResource workflowDataResource) {
+        this.workflowDataResource = workflowDataResource;
+    }
+
+    public void setNodeID(String nodeID) {
+        this.nodeID = nodeID;
+    }
+
+    public void setNodeType(String nodeType) {
+        this.nodeType = nodeType;
+    }
+
+    public void setInputs(String inputs) {
+        this.inputs = inputs;
+    }
+
+    public void setOutputs(String outputs) {
+        this.outputs = outputs;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public void setStartTime(Timestamp startTime) {
+        this.startTime = startTime;
+    }
+
+    public void setLastUpdateTime(Timestamp lastUpdateTime) {
+        this.lastUpdateTime = lastUpdateTime;
+    }
+
+    public Resource create(ResourceType type) {
+        switch (type){
+            case GFAC_JOB_DATA:
+                GFacJobDataResource gFacJobDataResource = new GFacJobDataResource();
+                gFacJobDataResource.setWorkflowDataResource(workflowDataResource);
+                gFacJobDataResource.setNodeID(nodeID);
+                return gFacJobDataResource;
+            default:
+                logger.error("Unsupported resource type for node data resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for node data resource.");
+        }
+    }
+
+    public void remove(ResourceType type, Object name) {
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Query q;
+        QueryGenerator generator;
+        switch (type){
+            case GFAC_JOB_DATA:
+                generator = new QueryGenerator(GFAC_JOB_DATA);
+                generator.setParameter(GFacJobDataConstants.LOCAL_JOB_ID, name);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                break;
+            default:
+                logger.error("Unsupported resource type for node data resource.", new IllegalArgumentException());
+                break;
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public Resource get(ResourceType type, Object name) {
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator generator;
+        Query q;
+        switch (type) {
+            case GFAC_JOB_DATA:
+                generator = new QueryGenerator(GFAC_JOB_DATA);
+                generator.setParameter(GFacJobDataConstants.LOCAL_JOB_ID, name);
+                q = generator.selectQuery(em);
+                GFac_Job_Data gFac_job_data = (GFac_Job_Data)q.getSingleResult();
+                GFacJobDataResource gFacJobDataResource = (GFacJobDataResource)Utils.getResource(ResourceType.GFAC_JOB_DATA, gFac_job_data);
+                em.getTransaction().commit();
+                em.close();
+                return gFacJobDataResource;
+            default:
+                em.getTransaction().commit();
+                em.close();
+                logger.error("Unsupported resource type for node data resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for node data resource.");
+        }
+    }
+
+    public List<Resource> getGFacJobs(){
+    	return get(ResourceType.GFAC_JOB_DATA);
+    }
+    public List<Resource> get(ResourceType type) {
+        List<Resource> resourceList = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Query q;
+        QueryGenerator generator;
+        List<?> results;
+        switch (type){
+            case EXECUTION_ERROR:
+                generator = new QueryGenerator(EXECUTION_ERROR);
+                generator.setParameter(ExecutionErrorConstants.NODE_ID, nodeID);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Execution_Error execution_error = (Execution_Error)result;
+                        ExecutionErrorResource executionErrorResource = (ExecutionErrorResource)Utils.getResource(ResourceType.EXECUTION_ERROR, execution_error);
+                        resourceList.add(executionErrorResource);
+                    }
+                }
+                break;
+            case GFAC_JOB_DATA:
+                generator = new QueryGenerator(GFAC_JOB_DATA);
+                generator.setParameter(GFacJobDataConstants.EXPERIMENT_ID, workflowDataResource.getExperimentID());
+                generator.setParameter(GFacJobDataConstants.WORKFLOW_INSTANCE_ID, workflowDataResource.getWorkflowInstanceID());
+                generator.setParameter(GFacJobDataConstants.NODE_ID, nodeID);
+                q = generator.selectQuery(em);
+                results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        GFac_Job_Data gFac_job_data = (GFac_Job_Data)result;
+                        GFacJobDataResource gFacJobDataResource = (GFacJobDataResource)Utils.getResource(ResourceType.GFAC_JOB_DATA, gFac_job_data);
+                        resourceList.add(gFacJobDataResource);
+                    }
+                }
+                break;
+            default:
+                em.getTransaction().commit();
+                em.close();
+                logger.error("Unsupported resource type for node data resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for node data resource.");
+        }
+        em.getTransaction().commit();
+        em.close();
+        return resourceList;
+    }
+
+    public void save() {
+        if(lastUpdateTime == null){
+            java.util.Date date= new java.util.Date();
+            lastUpdateTime = new Timestamp(date.getTime());
+        }
+        EntityManager em = ResourceUtils.getEntityManager();
+        Node_Data existingNodeData = em.find(Node_Data.class, new Node_DataPK(workflowDataResource.getWorkflowInstanceID(), nodeID, executionIndex));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Node_Data nodeData = new Node_Data();
+        nodeData.setNode_id(nodeID);
+        Workflow_Data workflow_data = em.find(Workflow_Data.class, workflowDataResource.getWorkflowInstanceID());
+        nodeData.setWorkflow_Data(workflow_data);
+        byte[] inputsByte = null;
+        if (inputs!=null) {
+			inputsByte = inputs.getBytes();
+			nodeData.setInputs(inputsByte);
+		}
+		byte[] outputsByte = null;
+        if (outputs!=null) {
+			outputsByte = outputs.getBytes();
+			nodeData.setOutputs(outputsByte);
+		}
+		nodeData.setNode_type(nodeType);
+        nodeData.setLast_update_time(lastUpdateTime);
+        nodeData.setStart_time(startTime);
+        nodeData.setStatus(status);
+        nodeData.setExecution_index(executionIndex);
+        if(existingNodeData != null){
+            existingNodeData.setInputs(inputsByte);
+            existingNodeData.setOutputs(outputsByte);
+            existingNodeData.setLast_update_time(lastUpdateTime);
+            existingNodeData.setNode_type(nodeType);
+            existingNodeData.setStart_time(startTime);
+            existingNodeData.setStatus(status);
+            existingNodeData.setExecution_index(executionIndex);
+            nodeData = em.merge(existingNodeData);
+        }  else {
+            em.persist(nodeData);
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public int getExecutionIndex() {
+        return executionIndex;
+    }
+
+    public void setExecutionIndex(int executionIndex) {
+        this.executionIndex = executionIndex;
+    }
+}

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,315 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.Experiment;
+import org.apache.airavata.persistance.registry.jpa.model.Gateway;
+import org.apache.airavata.persistance.registry.jpa.model.Project;
+import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProjectResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(ProjectResource.class);
+    private String name;
+    private GatewayResource gateway;
+    private WorkerResource worker;
+
+    /**
+     *
+     */
+    public ProjectResource() {
+    }
+
+    /**
+     *
+     * @param worker gateway worker
+     * @param gateway gateway
+     * @param projectName project name
+     */
+    public ProjectResource(WorkerResource worker, GatewayResource gateway, String projectName) {
+        this.setWorker(worker);
+        this.setGateway(gateway);
+        this.name = projectName;
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @return child resource
+     */
+    public Resource create(ResourceType type) {
+        if (type == ResourceType.EXPERIMENT) {
+            ExperimentResource experimentResource = new ExperimentResource();
+            experimentResource.setGateway(getGateway());
+            experimentResource.setProject(this);
+            experimentResource.setWorker(getWorker());
+            return experimentResource;
+        } else {
+            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
+            throw new IllegalArgumentException("Unsupported resource type for project resource.");
+        }
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @param name child resource name
+     */
+    public void remove(ResourceType type, Object name) {
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        if (type == ResourceType.EXPERIMENT) {
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+        	Query q = generator.deleteQuery(em);
+        	q.executeUpdate();
+        }else {
+            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
+            throw new IllegalArgumentException("Unsupported resource type for project resource.");
+        }
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @param name child resource name
+     * @return child resource
+     */
+    public Resource get(ResourceType type, Object name) {
+        if (type == ResourceType.EXPERIMENT) {
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+        	Query q = generator.selectQuery(em);
+            Experiment experiment = (Experiment) q.getSingleResult();
+            ExperimentResource experimentResource = (ExperimentResource)
+                    Utils.getResource(ResourceType.EXPERIMENT, experiment);
+            em.getTransaction().commit();
+            em.close();
+            return experimentResource;
+        }else{
+            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
+            throw new IllegalArgumentException("Unsupported resource type for project resource.");
+        }
+
+    }
+
+    /**
+     *
+     * @param keys project name
+     * @return project resource
+     */
+    public List<Resource> populate(Object[] keys) {
+        List<Resource> list = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator queryGenerator = new QueryGenerator(PROJECT);
+        queryGenerator.setParameter(ProjectConstants.PROJECT_NAME, keys[0]);
+        Query q = queryGenerator.selectQuery(em);
+        List<?> resultList = q.getResultList();
+        if (resultList.size() != 0) {
+            for (Object result : resultList) {
+                Project project = (Project) result;
+                ProjectResource projectResource = (ProjectResource)
+                        Utils.getResource(ResourceType.PROJECT, project);
+                list.add(projectResource);
+            }
+        }
+        em.getTransaction().commit();
+        em.close();
+        return list;
+    }
+
+    /**
+     *
+     * @param type child resource type
+     * @return list of child resources
+     */
+    public List<Resource> get(ResourceType type) {
+        List<Resource> resourceList = new ArrayList<Resource>();
+
+        if (type == ResourceType.EXPERIMENT) {
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.PROJECT_NAME, name);
+        	Query q = generator.selectQuery(em);
+            List<?> results = q.getResultList();
+            if (results.size() != 0) {
+                for (Object result : results) {
+                    Experiment experiment = (Experiment) result;
+                    ExperimentResource experimentResource = (ExperimentResource)
+                            Utils.getResource(ResourceType.EXPERIMENT, experiment);
+                    resourceList.add(experimentResource);
+                }
+            }
+            em.getTransaction().commit();
+            em.close();
+        } else {
+            logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
+            throw new IllegalArgumentException("Unsupported resource type for project resource.");
+        }
+        return resourceList;
+    }
+
+    /**
+     * save project to the database
+     */
+    public void save() {
+        EntityManager em = ResourceUtils.getEntityManager();
+        Project existingprojectResource = em.find(Project.class, name);
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Project project = new Project();
+        project.setProject_name(name);
+        Gateway modelGateway = em.find(Gateway.class, gateway.getGatewayName());
+        project.setGateway(modelGateway);
+        Users user = em.find(Users.class, worker.getUser());
+        project.setUsers(user);
+
+        if(existingprojectResource != null){
+           existingprojectResource.setGateway(modelGateway);
+            existingprojectResource.setUsers(user);
+            project = em.merge(existingprojectResource);
+        }else {
+            em.persist(project);
+        }
+
+        em.getTransaction().commit();
+        em.close();
+
+    }
+
+    /**
+     *
+     * @return project name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     *
+     * @param name  project name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     *
+     * @return gateway worker
+     */
+    public WorkerResource getWorker() {
+		return worker;
+	}
+
+    /**
+     *
+     * @param worker gateway worker
+     */
+    public void setWorker(WorkerResource worker) {
+		this.worker = worker;
+	}
+
+    /**
+     *
+     * @return gateway resource
+     */
+    public GatewayResource getGateway() {
+		return gateway;
+	}
+
+    /**
+     *
+     * @param gateway gateway resource
+     */
+    public void setGateway(GatewayResource gateway) {
+		this.gateway = gateway;
+	}
+
+    /**
+     *
+     * @param experimentId experiment ID
+     * @return whether the experiment exist
+     */
+    public boolean isExperimentExists(String experimentId){
+		return isExists(ResourceType.EXPERIMENT, experimentId);
+	}
+
+    /**
+     *
+     * @param experimentId experiment ID
+     * @return  experiment resource
+     */
+    public ExperimentResource createExperiment(String experimentId){
+		ExperimentResource experimentResource = (ExperimentResource)create(ResourceType.EXPERIMENT);
+		experimentResource.setExpID(experimentId);
+		return experimentResource;
+	}
+
+    /**
+     *
+     * @param experimentId experiment ID
+     * @return experiment resource
+     */
+	public ExperimentResource getExperiment(String experimentId){
+		return (ExperimentResource)get(ResourceType.EXPERIMENT,experimentId);
+	}
+
+    /**
+     *
+     * @return  list of experiments
+     */
+    public List<ExperimentResource> getExperiments(){
+		List<Resource> list = get(ResourceType.EXPERIMENT);
+		List<ExperimentResource> result=new ArrayList<ExperimentResource>();
+		for (Resource resource : list) {
+			result.add((ExperimentResource) resource);
+		}
+		return result;
+	}
+
+    /**
+     *
+     * @param experimentId experiment ID
+     */
+    public void removeExperiment(String experimentId){
+		remove(ResourceType.EXPERIMENT, experimentId);
+	}
+
+}

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,292 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.Gateway;
+import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow;
+import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow_PK;
+import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+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 PublishWorkflowResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(PublishWorkflowResource.class);
+    private String name;
+    private String version;
+    private Timestamp publishedDate;
+    private String content;
+    private GatewayResource gateway;
+    private String createdUser;
+    private String path;
+
+    /**
+     *
+     */
+    public PublishWorkflowResource() {
+    }
+
+    /**
+     *
+     * @param gateway gateway resource
+     */
+    public PublishWorkflowResource(GatewayResource gateway) {
+        this.gateway = gateway;
+    }
+
+    /**
+     *
+     * @return created user
+     */
+    public String getCreatedUser() {
+        return createdUser;
+    }
+
+    /**
+     *
+     * @return path of the workflow
+     */
+    public String getPath() {
+        return path;
+    }
+
+    /**
+     *
+     * @param createdUser  created user
+     */
+    public void setCreatedUser(String createdUser) {
+        this.createdUser = createdUser;
+    }
+
+    /**
+     *
+     * @param path path of the workflow
+     */
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    /**
+     *
+     * @return name of the publish workflow
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     *
+     * @return version
+     */
+    public String getVersion() {
+        return version;
+    }
+
+    /**
+     *
+     * @return published date
+     */
+    public Timestamp getPublishedDate() {
+        return publishedDate;
+    }
+
+    /**
+     *
+     * @return content of the workflow
+     */
+    public String getContent() {
+        return content;
+    }
+
+    /**
+     *
+     * @param version version of the workflow
+     */
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    /**
+     *
+     * @param publishedDate published date of the workflow
+     */
+    public void setPublishedDate(Timestamp publishedDate) {
+        this.publishedDate = publishedDate;
+    }
+
+    /**
+     *
+     * @param content content of the workflow
+     */
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    /**
+     * Since published workflows are at the leaf level of the
+     * data structure, this method is not valid
+     * @param type type of the child resource
+     * @return UnsupportedOperationException
+     */
+    public Resource create(ResourceType type) {
+        logger.error("Unsupported resource type for published workflow resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Since published workflows are at the leaf level of the
+     * data structure, this method is not valid
+     * @param type type of the child resource
+     * @param name name of the child resource
+     */
+    public void remove(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for published workflow resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Since published workflows are at the leaf level of the
+     * data structure, this method is not valid
+     * @param type type of the child resource
+     * @param name name of the child resource
+     * @return UnsupportedOperationException
+     */
+    public Resource get(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for published workflow resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     *
+     * @param keys object list including gateway name and published workflow name
+     * @return published workflow resource
+     */
+    public List<Resource> populate(Object[] keys) {
+        List<Resource> list = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator generator = new QueryGenerator(PUBLISHED_WORKFLOW);
+        generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, keys[0]);
+        generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME, keys[1]);
+        Query q = generator.selectQuery(em);
+        Published_Workflow publishedWorkflow = (Published_Workflow)q.getSingleResult();
+        PublishWorkflowResource publishWorkflowResource = (PublishWorkflowResource)
+                Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, publishedWorkflow);
+        em.getTransaction().commit();
+        em.close();
+        list.add(publishWorkflowResource);
+        return list;
+    }
+
+    /**
+     * since published workflows are at the leaf level of the
+     * data structure, this method is not valid
+     * @param type type of the child resource
+     * @return UnsupportedOperationException
+     */
+    public List<Resource> get(ResourceType type) {
+        logger.error("Unsupported resource type for published workflow resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * save published workflow to the database
+     */
+    public void save() {
+        EntityManager em = ResourceUtils.getEntityManager();
+        Published_Workflow existingWF = em.find(Published_Workflow.class, new Published_Workflow_PK(gateway.getGatewayName(), name));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        Published_Workflow publishedWorkflow = new Published_Workflow();
+        publishedWorkflow.setPublish_workflow_name(getName());
+        publishedWorkflow.setPublished_date(publishedDate);
+        publishedWorkflow.setVersion(version);
+        byte[] bytes = content.getBytes();
+        publishedWorkflow.setWorkflow_content(bytes);
+        Gateway gateway = new Gateway();
+        gateway.setGateway_name(this.gateway.getGatewayName());
+        publishedWorkflow.setGateway(gateway);
+        Users user = new Users();
+        user.setUser_name(createdUser);
+        publishedWorkflow.setUser(user);
+        if(existingWF != null){
+            existingWF.setUser(user);
+            existingWF.setPublished_date(publishedDate);
+            existingWF.setWorkflow_content(bytes);
+            existingWF.setVersion(version);
+            existingWF.setPath(path);
+            publishedWorkflow = em.merge(existingWF);
+        }else {
+            em.merge(publishedWorkflow);
+        }
+
+        em.getTransaction().commit();
+        em.close();
+    }
+
+
+    /**
+     * Since published workflows are at the leaf level of the
+     * data structure, this method is not valid
+     * @param type type of the child resource
+     * @param name name of the child resource
+     * @return UnsupportedOperationException
+     */
+    public boolean isExists(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for published workflow resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     *
+     * @return gateway resource
+     */
+    public GatewayResource getGateway() {
+		return gateway;
+	}
+
+    /**
+     *
+     * @param gateway gateway resource
+     */
+    public void setGateway(GatewayResource gateway) {
+		this.gateway = gateway;
+	}
+
+    /**
+     *
+     * @param name published workflow name
+     */
+    public void setName(String name) {
+		this.name = name;
+	}
+}

Added: airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java?rev=1553518&view=auto
==============================================================================
--- airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java (added)
+++ airavata/sandbox/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java Thu Dec 26 17:31:35 2013
@@ -0,0 +1,171 @@
+/*
+ *
+ * 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.persistance.registry.jpa.resources;
+
+import org.apache.airavata.persistance.registry.jpa.Resource;
+import org.apache.airavata.persistance.registry.jpa.ResourceType;
+import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ServiceDescriptorResource extends AbstractResource {
+    private final static Logger logger = LoggerFactory.getLogger(ServiceDescriptorResource.class);
+    private String serviceDescName;
+    private String gatewayName;
+    private String userName;
+    private String content;
+
+    public ServiceDescriptorResource() {
+
+    }
+
+    public String getGatewayName() {
+        return gatewayName;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setGatewayName(String gatewayName) {
+        this.gatewayName = gatewayName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getServiceDescName() {
+        return serviceDescName;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
+    public Resource create(ResourceType type) {
+        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
+            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource();
+            applicationDescriptorResource.setGatewayName(gatewayName);
+            applicationDescriptorResource.setHostDescName(getServiceDescName());
+            return applicationDescriptorResource;
+        }
+        logger.error("Unsupported resource type for service descriptor resource.", new IllegalArgumentException());
+        throw new IllegalArgumentException("Unsupported resource type for service descriptor resource.");
+    }
+
+    public void remove(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for service descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    public Resource get(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for service descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+    public List<Resource> populate(Object[] keys) {
+        List<Resource> list = new ArrayList<Resource>();
+        EntityManager em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+        QueryGenerator generator = new QueryGenerator(SERVICE_DESCRIPTOR);
+        generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, keys[0]);
+        generator.setParameter(ServiceDescriptorConstants.SERVICE_DESC_ID, keys[1]);
+        Query q = generator.selectQuery(em);
+        Service_Descriptor serviceDescriptor = (Service_Descriptor)q.getSingleResult();
+        ServiceDescriptorResource serviceDescriptorResource = (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, serviceDescriptor);
+        em.getTransaction().commit();
+        em.close();
+        list.add(serviceDescriptorResource);
+        return list;
+    }
+
+    public List<Resource> get(ResourceType type) {
+        List<Resource> resourceList = new ArrayList<Resource>();
+        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
+            EntityManager em = ResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+            queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+            queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, serviceDescName);
+            Query q = queryGenerator.selectQuery(em);
+            List results = q.getResultList();
+            if (results.size() != 0) {
+                for (Object result : results) {
+                    Application_Descriptor applicationDescriptor = (Application_Descriptor) result;
+                    ApplicationDescriptorResource applicationDescriptorResource = (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
+                    resourceList.add(applicationDescriptorResource);
+                }
+            }
+            em.getTransaction().commit();
+            em.close();
+        }
+        return resourceList;
+    }
+
+    public void save() {
+        EntityManager em = ResourceUtils.getEntityManager();
+        Service_Descriptor existingServiceDesc = em.find(Service_Descriptor.class, new Service_Descriptor_PK(gatewayName, serviceDescName));
+        em.close();
+
+        em = ResourceUtils.getEntityManager();
+        em.getTransaction().begin();
+
+        Service_Descriptor serviceDescriptor = new Service_Descriptor();
+        serviceDescriptor.setService_descriptor_ID(getServiceDescName());
+        Gateway gateway = em.find(Gateway.class, gatewayName);
+        serviceDescriptor.setGateway(gateway);
+        byte[] bytes = content.getBytes();
+        serviceDescriptor.setService_descriptor_xml(bytes);
+        Users user = em.find(Users.class, userName);
+        serviceDescriptor.setUser(user);
+        if(existingServiceDesc != null) {
+            existingServiceDesc.setUser(user);
+            existingServiceDesc.setService_descriptor_xml(bytes);
+            serviceDescriptor = em.merge(existingServiceDesc);
+        }else {
+            em.merge(serviceDescriptor);
+        }
+        em.getTransaction().commit();
+        em.close();
+
+    }
+
+    public boolean isExists(ResourceType type, Object name) {
+        logger.error("Unsupported resource type for service descriptor resource.", new UnsupportedOperationException());
+        throw new UnsupportedOperationException();
+    }
+
+	public void setServiceDescName(String serviceDescName) {
+		this.serviceDescName = serviceDescName;
+	}
+}



Mime
View raw message