airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1382565 [1/2] - in /incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main: java/org/apache/airavata/persistance/registry/jpa/ java/org/apache/airavata/persistance/registry/jpa/resources/ resources/
Date Sun, 09 Sep 2012 20:14:46 GMT
Author: lahiru
Date: Sun Sep  9 20:14:45 2012
New Revision: 1382565

URL: http://svn.apache.org/viewvc?rev=1382565&view=rev
Log:
applying patch from chathuri for AIRAVATA-562

Added:
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
Modified:
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceType.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
    incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data.sql

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/Resource.java Sun Sep  9 20:14:45 2012
@@ -27,18 +27,8 @@ public interface Resource {
 
     void remove(ResourceType type, Object name);
 
-    void removeMe(Object[] keys);
-
     Resource get(ResourceType type, Object name);
 
-    /**
-     *
-     *
-     * @param keys
-     * @return
-     */
-    List<Resource> getMe(Object[] keys);
-
     List<Resource> get(ResourceType type);
 
     void save();

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceType.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceType.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceType.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceType.java Sun Sep  9 20:14:45 2012
@@ -30,5 +30,6 @@ public enum ResourceType {
     HOST_DESCRIPTOR,
     APPLICATION_DESCRIPTOR,
     EXPERIMENT,
-    CONFIGURATION
+    CONFIGURATION,
+    GATEWAY_WORKER
 }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/ResourceUtils.java Sun Sep  9 20:14:45 2012
@@ -173,4 +173,7 @@ public class ResourceUtils {
     public static void removeConfiguration(String configkey){
 
     }
+
+    public static Resource getResource ()
+
 }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java Sun Sep  9 20:14:45 2012
@@ -30,9 +30,115 @@ import javax.persistence.Persistence;
 public abstract class AbstractResource implements Resource {
     private static final String PERSISTENCE_UNIT_NAME = "airavata_data";
     protected EntityManagerFactory factory;
-
     protected EntityManager em;
 
+    //table names
+    public static final String GATEWAY = "Gateway";
+    public static final String CONFIGURATION = "Configuration";
+    public static final String USERS = "Users";
+    public static final String GATEWAY_WORKER = "Gateway_Worker";
+    public static final String PROJECT = "Project";
+    public static final String PUBLISHED_WORKFLOW = "Published_Workflow";
+    public static final String USER_WORKFLOW = "User_Workflow";
+    public static final String HOST_DESCRIPTOR = "Host_Descriptor";
+    public static final String SERVICE_DESCRIPTOR = "Service_Descriptor";
+    public static final String APPLICATION_DESCRIPTOR = "Application_Descriptor";
+    public static final String EXPERIMENT = "Experiment";
+
+    //Gateway Table
+    protected final class GatewayConstants {
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String GATEWAY_OWNER = "owner";
+    }
+
+    //Configuration Table
+    protected final class ConfigurationConstants{
+        public static final String CONFIG_ID = "config_ID";
+        public static final String CONFIG_KEY = "config_key";
+        public static final String CONFIG_VAL = "config_val";
+        public static final String EXPIRE_DATE = "expire_date";
+    }
+
+
+    //Users table
+    protected final class UserConstants{
+        public static final String USERNAME = "user_name";
+        public static final String PASSWORD = "password";
+
+    }
+
+    //Gateway_Worker table
+    protected final class GatewayWorkerConstants{
+        public static final String USERNAME = "user_name";
+        public static final String GATEWAY_NAME = "gateway_name";
+    }
+
+    //Project table
+    protected final class ProjectConstants {
+        public static final String PROJECT_ID = "project_ID";
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String USERNAME = "user_name";
+        public static final String PROJECT_NAME = "project_name";
+    }
+
+    //Published_Workflow table
+    protected final class PublishedWorkflowConstants {
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String CREATED_USER = "created_user";
+        public static final String PUBLISH_WORKFLOW_NAME = "publish_workflow_name";
+        public static final String VERSION = "version";
+        public static final String PUBLISHED_DATE = "published_date";
+        public static final String PATH = "path";
+        public static final String WORKFLOW_CONTENT = "workflow_content";
+    }
+
+    //User_Workflow table
+    protected final class UserWorkflowConstants {
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String OWNER = "owner";
+        public static final String TEMPLATE_NAME = "template_name";
+        public static final String LAST_UPDATED_DATE = "last_updated_date";
+        public static final String PATH = "path";
+        public static final String WORKFLOW_GRAPH = "workflow_graph";
+    }
+
+    //Host_Descriptor table
+    protected final class  HostDescriptorConstants{
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String UPDATED_USER = "updated_user";
+        public static final String HOST_DESC_ID = "host_descriptor_ID";
+        public static final String HOST_DESC_XML = "host_descriptor_xml";
+    }
+
+    //Service_Descriptor table
+    protected final class  ServiceDescriptorConstants{
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String UPDATED_USER = "updated_user";
+        public static final String SERVICE_DESC_ID = "service_descriptor_ID";
+        public static final String SERVICE_DESC_XML = "service_descriptor_xml";
+    }
+
+    //Application_Descriptor table
+    protected final class ApplicationDescriptorConstants{
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String UPDATED_USER = "updated_user";
+        public static final String APPLICATION_DESC_ID = "application_descriptor_ID";
+        public static final String HOST_DESC_ID = "host_descriptor_ID";
+        public static final String SERVICE_DESC_ID = "service_descriptor_ID";
+        public static final String APPLICATION_DESC_XML = "application_descriptor_xml";
+    }
+
+    //Experiment table
+    protected final class ExperimentConstants{
+        public static final String PROJECT_ID = "project_ID";
+        public static final String USERNAME = "user_name";
+        public static final String GATEWAY_NAME = "gateway_name";
+        public static final String EXPERIMENT_ID = "experiment_ID";
+        public static final String SUBMITTED_DATE = "submitted_date";
+
+    }
+
+
     protected AbstractResource() {
         factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
         em = factory.createEntityManager();
@@ -48,7 +154,6 @@ public abstract class AbstractResource i
 
     }
     
-	@Override
 	public boolean isExists(ResourceType type, Object name) {
 		try {
 			return get(type, name)!=null;

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ApplicationDescriptorResource.java Sun Sep  9 20:14:45 2012
@@ -23,6 +23,7 @@ package org.apache.airavata.persistance.
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.Query;
 import java.util.ArrayList;
@@ -108,12 +109,12 @@ public class ApplicationDescriptorResour
      */
     public void removeMe(Object[] keys) {
         begin();
-        Query q = em.createQuery("Delete p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.gateway_name=:gate_name and p.host_descriptor_ID =:host_id " +
-                "and p.service_descriptor_ID =: service_desc");
-        q.setParameter("gate_name", keys[0]);
-        q.setParameter("app_desc_id", keys[1]);
-        q.setParameter("host_id", keys[2]);
-        q.setParameter("service_desc", keys[3]);
+        QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, keys[0]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, keys[1]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.HOST_DESC_ID, keys[2]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, keys[3]);
+        Query q = queryGenerator.deleteQuery(em);
         q.executeUpdate();
         end();
     }
@@ -127,20 +128,17 @@ public class ApplicationDescriptorResour
      * @param keys
      * @return
      */
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_name and p.gateway_name=:gate_name and p.host_descriptor_ID =:host_id " +
-                "and p.service_descriptor_ID =: service_desc");
-        q.setParameter("gate_name", keys[0]);
-        q.setParameter("app_desc_id", keys[1]);
-        q.setParameter("host_id", keys[2]);
-        q.setParameter("service_desc", keys[3]);
+        QueryGenerator queryGenerator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, keys[0]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, keys[1]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.HOST_DESC_ID, keys[2]);
+        queryGenerator.setParameter(ApplicationDescriptorConstants.SERVICE_DESC_ID, keys[3]);
+        Query q = queryGenerator.selectQuery(em);
         Application_Descriptor applicationDescriptor = (Application_Descriptor)q.getSingleResult();
-        ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource(applicationDescriptor.getApplication_descriptor_ID(),
-                applicationDescriptor.getGateway().getGateway_name(), applicationDescriptor.getHost_descriptor_ID(), applicationDescriptor.getService_descriptor_ID());
-        applicationDescriptorResource.setUpdatedUser(applicationDescriptor.getUser().getUser_name());
-        applicationDescriptorResource.setContent(applicationDescriptor.getApplication_descriptor_xml());
+        ApplicationDescriptorResource applicationDescriptorResource = (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
         end();
         list.add(applicationDescriptorResource);
         return list;
@@ -168,10 +166,6 @@ public class ApplicationDescriptorResour
 
     }
 
-    public void save(boolean isAppendable) {
-
-    }
-
     public boolean isExists(ResourceType type, Object name) {
         throw new UnsupportedOperationException();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ConfigurationResource.java Sun Sep  9 20:14:45 2012
@@ -29,6 +29,7 @@ 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.model.Configuration;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 public class ConfigurationResource extends AbstractResource {
     private int configID = -1;
@@ -68,19 +69,17 @@ public class ConfigurationResource exten
      * @param keys
      * @return
      */
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Configuration p WHERE p.config_key = :confKey");
-        q.setParameter("confKey", keys[0]);
+        QueryGenerator queryGenerator = new QueryGenerator(CONFIGURATION);
+        queryGenerator.setParameter(ConfigurationConstants.CONFIG_KEY, keys[0]);
+        Query q = queryGenerator.selectQuery(em);
         List resultList = q.getResultList();
         if (resultList.size() != 0) {
             for (Object result : resultList) {
                 Configuration configuration = (Configuration) result;
-                ConfigurationResource configurationResource = new ConfigurationResource();
-                configurationResource.setConfigKey(configuration.getConfig_key());
-                configurationResource.setConfigVal(configuration.getConfig_val());
-                configurationResource.setExpireDate(configuration.getExpire_date());
+                ConfigurationResource configurationResource = (ConfigurationResource)Utils.getResource(ResourceType.CONFIGURATION, configuration);
                 list.add(configurationResource);
             }
         }
@@ -119,10 +118,6 @@ public class ConfigurationResource exten
         end();
     }
 
-    public void save(boolean isAppendable) {
-
-    }
-
     public boolean isExists(ResourceType type, Object name) {
         throw new UnsupportedOperationException();
     }

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ExperimentResource.java Sun Sep  9 20:14:45 2012
@@ -32,6 +32,7 @@ import org.apache.airavata.persistance.r
 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;
 
 public class ExperimentResource extends AbstractResource {
     private WorkerResource worker;
@@ -84,21 +85,14 @@ public class ExperimentResource extends 
      * @param keys
      * @return
      */
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Experiment p WHERE p.experiment_ID = :exp_ID");
-        q.setParameter("exp_ID", keys[0]);
+        QueryGenerator queryGenerator = new QueryGenerator(EXPERIMENT);
+        queryGenerator.setParameter(ExperimentConstants.EXPERIMENT_ID, keys[0]);
+        Query q = queryGenerator.selectQuery(em);
         Experiment experiment = (Experiment)q.getSingleResult();
-        ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-        experimentResource.setGateway(getGateway());
-        experimentResource.setWorker(getWorker());
-        ProjectResource projectResource = new ProjectResource(experiment.getProject().getProject_ID());
-        projectResource.setGateway(getGateway());
-        projectResource.setWorker(getWorker());
-        projectResource.setName(experiment.getProject().getProject_name());
-        experimentResource.setProject(projectResource);
-        experimentResource.setSubmittedDate(experiment.getSubmitted_date());
+        ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
         end();
         list.add(experimentResource);
         return list;
@@ -112,16 +106,17 @@ public class ExperimentResource extends 
     public void save() {
         begin();
         Experiment experiment = new Experiment();
-        experiment.setExperiment_ID(getExpID());
         Project project = new Project();
         project.setProject_ID(this.project.getId());
-        experiment.setProject(project);
         Users user = new Users();
         user.setUser_name(getWorker().getUser());
-        experiment.setUser(user);
         Gateway gateway = new Gateway();
         gateway.setGateway_name(getGateway().getGatewayName());
-		experiment.setGateway(gateway);
+
+        experiment.setProject(project);
+        experiment.setExperiment_ID(getExpID());
+        experiment.setUser(user);
+        experiment.setGateway(gateway);
         experiment.setSubmitted_date(submittedDate);
         em.persist(experiment);
         end();

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/GatewayResource.java Sun Sep  9 20:14:45 2012
@@ -27,14 +27,8 @@ 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.model.Application_Descriptor;
-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.Host_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Project;
-import org.apache.airavata.persistance.registry.jpa.model.Published_Workflow;
-import org.apache.airavata.persistance.registry.jpa.model.Service_Descriptor;
-import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 public class GatewayResource extends AbstractResource {
     private String gatewayName;
@@ -64,347 +58,321 @@ public class GatewayResource extends Abs
     }
 
     public Resource create(ResourceType type) {
-        if (type == ResourceType.PROJECT) {
-            ProjectResource projectResource = new ProjectResource();
-            projectResource.setGateway(this);
-            return projectResource;
-        } else if (type == ResourceType.USER) {
-            UserResource userResource = new UserResource();
-            userResource.setGatewayName(this.getGatewayName());
-            return userResource;
-        } else if (type == ResourceType.PUBLISHED_WORKFLOW) {
-            PublishWorkflowResource publishWorkflowResource = new PublishWorkflowResource();
-            publishWorkflowResource.setGateway(this);
-            return publishWorkflowResource;
-        }else if(type == ResourceType.USER_WORKFLOW){
-            UserWorkflowResource userWorkflowResource = new UserWorkflowResource();
-            userWorkflowResource.setGateway(this);
-            return userWorkflowResource;
-        }else if (type == ResourceType.HOST_DESCRIPTOR) {
-            HostDescriptorResource hostDescriptorResource = new HostDescriptorResource();
-            hostDescriptorResource.setGatewayName(gatewayName);
-            return hostDescriptorResource;
-        } else if (type == ResourceType.SERVICE_DESCRIPTOR) {
-            ServiceDescriptorResource serviceDescriptorResource = new ServiceDescriptorResource();
-            serviceDescriptorResource.setGatewayName(gatewayName);
-            return serviceDescriptorResource;
-        } else if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource();
-            applicationDescriptorResource.setGatewayName(gatewayName);
-            return applicationDescriptorResource;
-        } else if(type == ResourceType.EXPERIMENT){
-            ExperimentResource experimentResource =new ExperimentResource();
-            experimentResource.setGateway(this);
-            return experimentResource;
-        }else {
-            return null;
+        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;
+            default:
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
         }
     }
 
     public void remove(ResourceType type, Object name) {
         begin();
-        if (type == ResourceType.USER) {
-            Query q = em.createQuery("Delete p FROM Users p WHERE p.user_name = :usr_name and p.gateway_name = :gate_name");
-            q.setParameter("usr_name", name);
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-        }
-        else if (type == ResourceType.PUBLISHED_WORKFLOW) {
-            Query q = em.createQuery("Delete p FROM Published_Workflow p WHERE p.publish_workflow_name = :pub_workflow_id and p.gateway_name = :gate_name");
-            q.setParameter("pub_workflow_id", name);
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-            end();
-        } else if (type == ResourceType.HOST_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("Delete p FROM Host_Descriptor p WHERE p.host_descriptor_ID = :host_desc_id and p.gateway_name = :gate_name");
-            q.setParameter("host_desc_id", name);
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-        } else if (type == ResourceType.SERVICE_DESCRIPTOR) {
-            Query q = em.createQuery("Delete p FROM Service_Descriptor p WHERE p.service_descriptor_ID = :service_desc_id and p.gateway_name = :gate_name");
-            q.setParameter("service_desc_id", name);
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-        }else if(type == ResourceType.EXPERIMENT){
-            Query q = em.createQuery("Delete p FROM Experiment p WHERE p.experiment_ID = :exp_id and p.gateway_name = :gate_name");
-            q.setParameter("exp_id", name);
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-        }
+        Query q;
+        QueryGenerator generator;
+        switch (type){
+            case USER:
+                generator = new QueryGenerator(USERS);
+                generator.setParameter(UserConstants.USERNAME, name);
+                q = generator.deleteQuery(em);
+                q.executeUpdate();
+                end();
+                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();
+                end();
+                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();
+                end();
+                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();
+                end();
+                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();
+                end();
+                break;
+            default:
+                break;
 
-//        else if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-//            Query q = em.createQuery("Delete p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.gateway_name = :gate_name");
-//            q.setParameter("app_desc_id", name);
-//            q.setParameter("gate_name", gatewayName);
-//            q.executeUpdate();
-//        }
-
-        end();
-
-
-    }
-
-    public void removeMe(Object[] keys) {
+        }
     }
 
     public Resource get(ResourceType type, Object name) {
         begin();
-//        if (type == ResourceType.PROJECT) {
-//            Query q = em.createQuery("SELECT p FROM Project p WHERE p.project_name = :proj_name and p.gateway_name =:gate_name");
-//            q.setParameter("proj_name", name);
-//            q.setParameter("gate_name", gatewayName);
-//            Project eproject = (Project) q.getSingleResult();
-//            ProjectResource projectResource = new ProjectResource(eproject.getProject_ID());
-//            projectResource.setName(eproject.getProject_name());
-//            end();
-//            return projectResource;
-//        } else
-        if (type == ResourceType.USER) {
-            Query q = em.createQuery("SELECT p FROM Gateway_Worker p WHERE p.user_name = :username and p.gateway_name =:gate_name");
-            q.setParameter("username", name);
-            q.setParameter("gate_name", gatewayName);
-            Users eUser = (Users) q.getSingleResult();
-            UserResource userResource = new UserResource();
-            userResource.setUserName(eUser.getUser_name());
-            userResource.setGatewayName(gatewayName);
-            end();
-            return userResource;
-        } else if (type == ResourceType.PUBLISHED_WORKFLOW) {
-            Query q = em.createQuery("SELECT p FROM Published_Workflow p WHERE p.publish_workflow_name = :pub_workflow_name and p.gateway_name =:gate_name");
-            q.setParameter("pub_workflow_name", name);
-            q.setParameter("gate_name", gatewayName);
-            Published_Workflow ePub_workflow = (Published_Workflow) q.getSingleResult();
-            PublishWorkflowResource publishWorkflowResource = new PublishWorkflowResource(this);
-            publishWorkflowResource.setName(ePub_workflow.getPublish_workflow_name());
-            publishWorkflowResource.setContent(ePub_workflow.getWorkflow_content());
-            publishWorkflowResource.setPublishedDate(ePub_workflow.getPublished_date());
-            publishWorkflowResource.setVersion(ePub_workflow.getVersion());
-            end();
-            return publishWorkflowResource;
-        } else if (type == ResourceType.SERVICE_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Service_Descriptor p WHERE p.service_descriptor_ID = :service_desc_id and p.gateway_name =:gate_name");
-            q.setParameter("service_desc_id", name);
-            q.setParameter("gate_name", gatewayName);
-            Service_Descriptor eServiceDesc = (Service_Descriptor) q.getSingleResult();
-            ServiceDescriptorResource serviceDescriptorResource = new ServiceDescriptorResource(eServiceDesc.getService_descriptor_ID());
-            serviceDescriptorResource.setGatewayName(eServiceDesc.getGateway().getGateway_name());
-            serviceDescriptorResource.setContent(eServiceDesc.getService_descriptor_xml());
-            end();
-            return serviceDescriptorResource;
-        } else if (type == ResourceType.HOST_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Host_Descriptor p WHERE p.host_descriptor_ID = :host_desc_id and p.gateway_name =:gate_name");
-            q.setParameter("host_desc_id", name);
-            q.setParameter("gate_name", gatewayName);
-            Host_Descriptor eHostDesc = (Host_Descriptor) q.getSingleResult();
-            HostDescriptorResource hostDescriptorResource = new HostDescriptorResource(eHostDesc.getHost_descriptor_ID());
-            hostDescriptorResource.setGatewayName(eHostDesc.getGateway().getGateway_name());
-            hostDescriptorResource.setContent(eHostDesc.getHost_descriptor_xml());
-            end();
-            return hostDescriptorResource;
-        } else if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.gateway_name =:gate_name");
-            q.setParameter("app_desc_id", name);
-            q.setParameter("gate_name", gatewayName);
-            Application_Descriptor eappDesc = (Application_Descriptor) q.getSingleResult();
-            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource(eappDesc.getApplication_descriptor_ID());
-            applicationDescriptorResource.setGatewayName(eappDesc.getGateway().getGateway_name());
-            applicationDescriptorResource.setContent(eappDesc.getApplication_descriptor_xml());
-            applicationDescriptorResource.setHostDescName(eappDesc.getHost_descriptor_ID());
-            applicationDescriptorResource.setServiceDescName(eappDesc.getService_descriptor_ID());
-            end();
-            return applicationDescriptorResource;
-        } else if(type == ResourceType.EXPERIMENT){
-            Query q = em.createQuery("SELECT p FROM Experiment p WHERE p.experiment_ID = :ex_ID and p.gateway_name =:gate_name");
-            q.setParameter("ex_ID", name);
-            q.setParameter("gate_name", gatewayName);
-            Experiment experiment = (Experiment)q.getSingleResult();
-            ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-            experimentResource.setWorker(new WorkerResource(experiment.getUser().getUser_name(),this));
-            experimentResource.setGateway(this);
-            experimentResource.setSubmittedDate(experiment.getSubmitted_date());
-            return experimentResource;
-        } else {
-                return null;
+        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);
+                Users eUser = (Users) q.getSingleResult();
+                WorkerResource workerResource = (WorkerResource)Utils.getResource(ResourceType.GATEWAY_WORKER, eUser);
+                end();
+                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);
+                end();
+                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);
+                end();
+                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);
+                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);
+                end();
+                return serviceDescriptorResource;
+            default:
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
+
         }
-    }
 
-    public List<Resource> getMe(Object[] keys) {
-        throw new UnsupportedOperationException();
+
     }
 
     public List<Resource> get(ResourceType type) {
         List<Resource> resourceList = new ArrayList<Resource>();
         begin();
-        if (type == ResourceType.PROJECT) {
-            Query q = em.createQuery("SELECT p FROM Project p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Project project = (Project) result;
-                    ProjectResource projectResource = new ProjectResource(project.getProject_ID());
-                    projectResource.setGateway(this);
-                    projectResource.setName(project.getProject_name());
-                    resourceList.add(projectResource);
+        Query q;
+        QueryGenerator generator;
+        List results;
+        switch (type){
+            case PROJECT:
+                generator = new QueryGenerator(PROJECT);
+                generator.setParameter(ProjectConstants.GATEWAY_NAME, gatewayName);
+                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);
+                    }
                 }
-            }
-        }
-        else if (type == ResourceType.USER) {
-            Query q = em.createQuery("SELECT p FROM Users p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Users user = (Users) result;
-                    UserResource userResource = new UserResource();
-                    userResource.setGatewayName(gatewayName);
-                    userResource.setUserName(user.getUser_name());
-                    resourceList.add(userResource);
+                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);
+                    }
                 }
-            }
-        }
-        else if (type == ResourceType.PUBLISHED_WORKFLOW) {
-            Query q = em.createQuery("SELECT p FROM Published_Workflow p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List<?> results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Published_Workflow publishedWorkflow = (Published_Workflow) result;
-                    PublishWorkflowResource publishWorkflowResource = new PublishWorkflowResource(this);
-                    publishWorkflowResource.setName(publishedWorkflow.getPublish_workflow_name());
-                    publishWorkflowResource.setContent(publishedWorkflow.getWorkflow_content());
-                    publishWorkflowResource.setPublishedDate(publishedWorkflow.getPublished_date());
-                    publishWorkflowResource.setVersion(publishedWorkflow.getVersion());
-                    resourceList.add(publishWorkflowResource);
+                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);
+                    }
                 }
-            }
-        } else if (type == ResourceType.HOST_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Host_Descriptor p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Host_Descriptor hostDescriptor = (Host_Descriptor) result;
-                    HostDescriptorResource hostDescriptorResource = new HostDescriptorResource(hostDescriptor.getHost_descriptor_ID());
-                    hostDescriptorResource.setGatewayName(gatewayName);
-                    hostDescriptorResource.setContent(hostDescriptor.getHost_descriptor_xml());
-                    resourceList.add(hostDescriptorResource);
+                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);
+                    }
                 }
-            }
-        } else if (type == ResourceType.SERVICE_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Service_Descriptor p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Service_Descriptor serviceDescriptor = (Service_Descriptor) result;
-                    ServiceDescriptorResource serviceDescriptorResource = new ServiceDescriptorResource(serviceDescriptor.getService_descriptor_ID());
-                    serviceDescriptorResource.setGatewayName(gatewayName);
-                    serviceDescriptorResource.setContent(serviceDescriptor.getService_descriptor_xml());
-                    resourceList.add(serviceDescriptorResource);
+                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);
+                    }
                 }
-            }
-        } else if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            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(),
-                            applicationDescriptor.getHost_descriptor_ID(), applicationDescriptor.getService_descriptor_ID());
-                    applicationDescriptorResource.setContent(applicationDescriptor.getApplication_descriptor_xml());
-                    applicationDescriptorResource.setUpdatedUser(applicationDescriptor.getUser().getUser_name());
-                    resourceList.add(applicationDescriptorResource);
+                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);
+                    }
                 }
-            }
-        } else if (type == ResourceType.EXPERIMENT) {
-            Query q = em.createQuery("SELECT p FROM Experiment p WHERE p.gateway_name =:gate_name");
-            q.setParameter("gate_name", gatewayName);
-            List results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    Experiment experiment = (Experiment) result;
-                    ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-                    experimentResource.setGateway(this);
-                    experimentResource.setWorker(new WorkerResource(experiment.getUser().getUser_name(),this));
-                    experimentResource.setSubmittedDate(experiment.getSubmitted_date());
-                    ProjectResource project = new ProjectResource(experimentResource.getWorker(),this,experiment.getProject().getProject_ID());
-                    project.setName(experiment.getProject().getProject_name());
-					experimentResource.setProject(project);
-                    resourceList.add(experimentResource);
+                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;
+            default:
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
         }
         end();
         return resourceList;
-
     }
 
     public void save() {
-        // save me..
         begin();
         Gateway gateway = new Gateway();
         gateway.setGateway_name(gatewayName);
         em.persist(gateway);
-        System.out.println(gateway);
         end();
     }
 
-    public void save(boolean isAppendable) {
-         throw new UnsupportedOperationException();
-    }
-
     public boolean isExists(ResourceType type, Object name) {
         begin();
-//        if (type == ResourceType.PROJECT) {
-//            Query q = em.createQuery("SELECT p FROM Project p WHERE p.gateway_name =:gate_name and p.project_name =:proj_name");
-//            q.setParameter("gate_name", gatewayName);
-//            q.setParameter("proj_name", name);
-//            Project project = (Project) q.getSingleResult();
-//            return project != null;
-//        } else
-
-        if (type == ResourceType.USER) {
-            Query q = em.createQuery("SELECT p FROM Gateway_Worker p WHERE p.gateway_name =:gate_name and p.user_name =:usr_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("usr_name", name);
-            Users users = (Users) q.getSingleResult();
-            return users != null;
-        } else if (type == ResourceType.PUBLISHED_WORKFLOW) {
-            Query q = em.createQuery("SELECT p FROM Published_Workflow p WHERE p.gateway_name =:gate_name and p.Published_Workflow =:pub_wf_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("pub_wf_name", name);
-            Published_Workflow publishedWrkflow = (Published_Workflow) q.getSingleResult();
-            return publishedWrkflow != null;
-        } else if (type == ResourceType.HOST_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Host_Descriptor p WHERE p.gateway_name =:gate_name and p.host_descriptor_ID =:host_desc_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("host_desc_name", name);
-            Host_Descriptor hostDescriptor = (Host_Descriptor) q.getSingleResult();
-            return hostDescriptor != null;
-        } else if (type == ResourceType.SERVICE_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Service_Descriptor p WHERE p.gateway_name =:gate_name and p.service_descriptor_ID =:service_desc_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("service_desc_name", name);
-            Service_Descriptor serviceDescriptor = (Service_Descriptor) q.getSingleResult();
-            return serviceDescriptor != null;
-        } else if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.gateway_name =:gate_name and p.application_descriptor_ID =:app_desc_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("app_desc_name", name);
-            Application_Descriptor applicationDescriptor = (Application_Descriptor) q.getSingleResult();
-            return applicationDescriptor != null;
-        } else if (type == ResourceType.EXPERIMENT) {
-            Query q = em.createQuery("SELECT p FROM Experiment p WHERE p.gateway_name =:gate_name and p.experiment_ID =:ex_ID");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("ex_ID", name);
-            Experiment experiment = (Experiment) q.getSingleResult();
-            return experiment != null;
+        Query q;
+        QueryGenerator generator;
+        switch (type){
+            case USER:
+                generator = new QueryGenerator(GATEWAY_WORKER);
+                generator.setParameter(GatewayWorkerConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(GatewayWorkerConstants.USERNAME, name);
+                q = generator.selectQuery(em);
+                Gateway_Worker gatewayWorker = (Gateway_Worker) q.getSingleResult();
+                end();
+                return gatewayWorker != null;
+            case PUBLISHED_WORKFLOW:
+                generator = new QueryGenerator(PUBLISHED_WORKFLOW);
+                generator.setParameter(PublishedWorkflowConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(PublishedWorkflowConstants.PUBLISH_WORKFLOW_NAME, name);
+                q = generator.selectQuery(em);
+                Published_Workflow publishedWrkflow = (Published_Workflow) q.getSingleResult();
+                end();
+                return publishedWrkflow != null;
+            case HOST_DESCRIPTOR:
+                generator = new QueryGenerator(HOST_DESCRIPTOR);
+                generator.setParameter(HostDescriptorConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(HostDescriptorConstants.HOST_DESC_ID, name);
+                q = generator.selectQuery(em);
+                Host_Descriptor hostDescriptor = (Host_Descriptor) q.getSingleResult();
+                end();
+                return hostDescriptor != null;
+            case SERVICE_DESCRIPTOR:
+                generator = new QueryGenerator(SERVICE_DESCRIPTOR);
+                generator.setParameter(ServiceDescriptorConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(ServiceDescriptorConstants.SERVICE_DESC_ID, name);
+                q = generator.selectQuery(em);
+                Service_Descriptor serviceDescriptor = (Service_Descriptor) q.getSingleResult();
+                end();
+                return serviceDescriptor != null;
+            case APPLICATION_DESCRIPTOR:
+                generator = new QueryGenerator(APPLICATION_DESCRIPTOR);
+                generator.setParameter(ApplicationDescriptorConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(ApplicationDescriptorConstants.APPLICATION_DESC_ID, name);
+                q = generator.selectQuery(em);
+                Application_Descriptor applicationDescriptor = (Application_Descriptor) q.getSingleResult();
+                end();
+                return applicationDescriptor != null;
+            case EXPERIMENT:
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gatewayName);
+                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+                q = generator.selectQuery(em);
+                Experiment experiment = (Experiment) q.getSingleResult();
+                end();
+                return experiment != null;
+            default:
+                end();
+                throw new IllegalArgumentException("Unsupported resource type for gateway resource.");
         }
-        end();
-        return false;
     }
 
     public boolean isHostDescriptorExists(String descriptorName){

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/HostDescriptorResource.java Sun Sep  9 20:14:45 2012
@@ -25,6 +25,8 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Host_Descriptor;
+import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.Query;
 import java.util.ArrayList;
@@ -82,39 +84,11 @@ public class HostDescriptorResource exte
     }
 
     public void remove(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("Delete p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.host_descriptor_ID = :host_desc_name and p.gateway_name =:gate_name");
-            q.setParameter("app_desc_id", name);
-            q.setParameter("host_desc_name", getHostDescName());
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-            end();
-        }
-    }
-
-    public void removeMe(Object[] keys) {
-
+       throw new UnsupportedOperationException();
     }
 
     public Resource get(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.host_descriptor_ID =:host_desc_name and p.gateway_name =:gate_name");
-            q.setParameter("app_desc_id", name);
-            q.setParameter("host_desc_name", getHostDescName());
-            q.setParameter("gate_name", gatewayName);
-            Application_Descriptor eappDesc = (Application_Descriptor) q.getSingleResult();
-            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource(eappDesc.getApplication_descriptor_ID(),
-                    eappDesc.getGateway().getGateway_name(),
-                    eappDesc.getHost_descriptor_ID(),
-                    eappDesc.getService_descriptor_ID());
-            applicationDescriptorResource.setContent(eappDesc.getApplication_descriptor_xml());
-            applicationDescriptorResource.setUpdatedUser(eappDesc.getUser().getUser_name());
-            end();
-            return applicationDescriptorResource;
-        }
-        return null;
+        throw new UnsupportedOperationException();
     }
 
     /**
@@ -122,16 +96,15 @@ public class HostDescriptorResource exte
      * @param keys
      * @return
      */
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Host_Descriptor p WHERE p.host_descriptor_ID = :host_desc_name");
-        q.setParameter("host_desc_name", keys[0]);
+        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 = new HostDescriptorResource(hostDescriptor.getHost_descriptor_ID());
-        hostDescriptorResource.setGatewayName(hostDescriptor.getGateway().getGateway_name());
-        hostDescriptorResource.setUserName(hostDescriptor.getUser().getUser_name());
-        hostDescriptorResource.setContent(hostDescriptor.getHost_descriptor_xml());
+        HostDescriptorResource hostDescriptorResource = (HostDescriptorResource)Utils.getResource(ResourceType.HOST_DESCRIPTOR, hostDescriptor);
         end();
         list.add(hostDescriptorResource);
         return list;
@@ -141,19 +114,15 @@ public class HostDescriptorResource exte
         List<Resource> resourceList = new ArrayList<Resource>();
         if (type == ResourceType.APPLICATION_DESCRIPTOR) {
             begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.gateway_name =:gate_name and p.host_descriptor_ID =:host_desc_id");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("host_desc_id", getHostDescName());
+            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 = new ApplicationDescriptorResource(applicationDescriptor.getApplication_descriptor_ID(),
-                            applicationDescriptor.getGateway().getGateway_name(),
-                            applicationDescriptor.getHost_descriptor_ID(),
-                            applicationDescriptor.getService_descriptor_ID());
-                    applicationDescriptorResource.setContent(applicationDescriptor.getApplication_descriptor_xml());
-                    applicationDescriptor.setUser(applicationDescriptor.getUser());
+                    ApplicationDescriptorResource applicationDescriptorResource = (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
                     resourceList.add(applicationDescriptorResource);
                 }
             }
@@ -165,34 +134,21 @@ public class HostDescriptorResource exte
     public void save() {
         begin();
         Host_Descriptor hostDescriptor = new Host_Descriptor();
-        hostDescriptor.setHost_descriptor_ID(getHostDescName());
         Gateway gateway = new Gateway();
         gateway.setGateway_name(gatewayName);
+        Users user = new Users();
+        user.setUser_name(userName);
+        hostDescriptor.setHost_descriptor_ID(getHostDescName());
         hostDescriptor.setGateway(gateway);
         hostDescriptor.setHost_descriptor_xml(content);
+        hostDescriptor.setUser(user);
         em.persist(hostDescriptor);
         end();
 
     }
 
-    public void save(boolean isAppendable) {
-
-    }
-
     public boolean isExists(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.host_descriptor_ID =:host_desc_id and p.application_descriptor_ID =:app_dist_id");
-            q.setParameter("host_desc_id", getHostDescName());
-            q.setParameter("app_dist_id", name);
-            Application_Descriptor applicationDescriptor = (Application_Descriptor) q.getSingleResult();
-            if (applicationDescriptor != null) {
-                return true;
-            } else {
-                return false;
-            }
-        }
-        return false;
+        throw new UnsupportedOperationException();
     }
 
 	public void setHostDescName(String hostDescName) {

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java Sun Sep  9 20:14:45 2012
@@ -30,6 +30,7 @@ import org.apache.airavata.persistance.r
 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;
 
 public class ProjectResource extends AbstractResource {
@@ -67,61 +68,43 @@ public class ProjectResource extends Abs
     public void remove(ResourceType type, Object name) {
         begin();
         if (type == ResourceType.EXPERIMENT) {
-        	QueryGenerator generator = new QueryGenerator("Experiment");
-        	generator.setParameter("project_ID", id);
-        	generator.setParameter("user_name", getWorker().getUser());
-        	generator.setParameter("experiment_ID", name);
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
+        	generator.setParameter(ExperimentConstants.USERNAME, getWorker().getUser());
+        	generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
         	Query q = generator.deleteQuery(em);
         	q.executeUpdate();
-//            Query q = em.createQuery("Delete p FROM Experiment p WHERE p.project_ID = :proj_id and p.user_name = :usr_name and p.experiment_ID = :ex_name");
-//            q.setParameter("proj_id", id);
-//            q.setParameter("usr_name", getWorker().getUser());
-//            q.setParameter("ex_name", name);
-//            q.executeUpdate();
         }
         end();
     }
 
-    public void removeMe(Object[] keys) {
-
-    }
-
     public Resource get(ResourceType type, Object name) {
         begin();
         if (type == ResourceType.EXPERIMENT) {
-        	QueryGenerator generator = new QueryGenerator("Experiment");
-        	generator.setParameter("project_ID", id);
-        	generator.setParameter("user_name", getWorker().getUser());
-        	generator.setParameter("experiment_ID", name);
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
+        	generator.setParameter(ExperimentConstants.USERNAME, getWorker().getUser());
+        	generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
         	Query q = generator.selectQuery(em);
-//            Query q = em.createQuery("SELECT p FROM Experiment p WHERE p.project_ID = :proj_id and p.user_name = :usr_name and p.experiment_ID = :ex_name");
-//            q.setParameter("proj_id", id);
-//            q.setParameter("usr_name", getWorker().getUser());
-//            q.setParameter("ex_name", name);
             Experiment experiment = (Experiment) q.getSingleResult();
-            ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-            experimentResource.setProject(this);
-            experimentResource.setWorker(getWorker());
-            experimentResource.setGateway(getGateway());
-            experimentResource.setSubmittedDate(experiment.getSubmitted_date());
+            ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT, experiment);
             end();
             return experimentResource;
         }
         return null;
     }
 
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Project p WHERE p.project_name = :proj_name");
-        q.setParameter("proj_name", keys[0]);
+        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 = new ProjectResource();
-//                projectResource.setGateway(gateway);
-//                projectResource.setName(name)UserName(workerResource.getUser());
+                ProjectResource projectResource = (ProjectResource)Utils.getResource(ResourceType.PROJECT, project);
                 list.add(projectResource);
             }
         }
@@ -133,18 +116,14 @@ public class ProjectResource extends Abs
         List<Resource> resourceList = new ArrayList<Resource>();
         begin();
         if (type == ResourceType.EXPERIMENT) {
-        	QueryGenerator generator = new QueryGenerator("Experiment");
-        	generator.setParameter("project_ID", id);
+        	QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+        	generator.setParameter(ExperimentConstants.PROJECT_ID, id);
         	Query q = generator.selectQuery(em);
             List<?> results = q.getResultList();
             if (results.size() != 0) {
                 for (Object result : results) {
                     Experiment experiment = (Experiment) result;
-                    ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-                    experimentResource.setProject(this);
-                    experimentResource.setGateway(new GatewayResource(experiment.getGateway().getGateway_name()));
-                    experimentResource.setWorker(new WorkerResource(experiment.getUser().getUser_name(), experimentResource.getGateway()));
-                    experimentResource.setSubmittedDate(experiment.getSubmitted_date());
+                    ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.USER, experiment);
                     resourceList.add(experimentResource);
                 }
             }
@@ -163,6 +142,9 @@ public class ProjectResource extends Abs
         if (id != -1) {
             project.setProject_ID(id);
         }
+        Users user = new Users();
+        user.setUser_name(worker.getUser());
+        project.setUsers(user);
         em.persist(project);
         end();
 

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/PublishWorkflowResource.java Sun Sep  9 20:14:45 2012
@@ -24,6 +24,8 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 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.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.Query;
 import java.sql.Date;
@@ -98,26 +100,19 @@ public class PublishWorkflowResource ext
         throw new UnsupportedOperationException();
     }
 
-    public void removeMe(Object[] keys) {
-
-    }
-
     public Resource get(ResourceType type, Object name) {
         throw new UnsupportedOperationException();
     }
 
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Published_Workflow p WHERE p.gateway_name = :gate_name and p.publish_workflow_name =:pub_wf_name");
-        q.setParameter("gate_name", keys[0]);
-        q.setParameter("pub_wf_name", keys[1]);
+        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 = new PublishWorkflowResource();
-        publishWorkflowResource.setGateway(new GatewayResource(publishedWorkflow.getGateway().getGateway_name()));
-        publishWorkflowResource.setContent(publishedWorkflow.getWorkflow_content());
-        publishWorkflowResource.setPublishedDate(publishedWorkflow.getPublished_date());
-        publishWorkflowResource.setVersion(publishedWorkflow.getVersion());
+        PublishWorkflowResource publishWorkflowResource = (PublishWorkflowResource)Utils.getResource(ResourceType.PUBLISHED_WORKFLOW, publishedWorkflow);
         end();
         list.add(publishWorkflowResource);
         return list;
@@ -137,13 +132,13 @@ public class PublishWorkflowResource ext
         Gateway gateway = new Gateway();
         gateway.setGateway_name(this.gateway.getGatewayName());
         publishedWorkflow.setGateway(gateway);
+        Users user = new Users();
+        user.setUser_name(createdUser);
+        publishedWorkflow.setUser(user);
         em.persist(gateway);
         end();
     }
 
-    public void save(boolean isAppendable) {
-
-    }
 
     public boolean isExists(ResourceType type, Object name) {
         throw new UnsupportedOperationException();

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java (original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ServiceDescriptorResource.java Sun Sep  9 20:14:45 2012
@@ -25,6 +25,8 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.model.Application_Descriptor;
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.Service_Descriptor;
+import org.apache.airavata.persistance.registry.jpa.model.Users;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 import javax.persistence.Query;
 import java.util.ArrayList;
@@ -84,50 +86,22 @@ public class ServiceDescriptorResource e
     }
 
     public void remove(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("Delete p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.service_descriptor_ID = :service_desc_name and p.gateway_name =:gate_name");
-            q.setParameter("app_desc_id", name);
-            q.setParameter("service_desc_name", getServiceDescName());
-            q.setParameter("gate_name", gatewayName);
-            q.executeUpdate();
-            end();
-        }
-
-    }
-
-    public void removeMe(Object[] keys) {
-
+        throw new UnsupportedOperationException();
     }
 
     public Resource get(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.application_descriptor_ID = :app_desc_id and p.service_descriptor_ID = :service_desc_name and p.gateway_name =:gate_name");
-            q.setParameter("app_desc_id", name);
-            q.setParameter("service_desc_name", getServiceDescName());
-            q.setParameter("gate_name", gatewayName);
-            Application_Descriptor eappDesc = (Application_Descriptor) q.getSingleResult();
-            ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource(eappDesc.getApplication_descriptor_ID(),
-                    eappDesc.getGateway().getGateway_name(), eappDesc.getHost_descriptor_ID(), eappDesc.getService_descriptor_ID());
-            applicationDescriptorResource.setContent(eappDesc.getApplication_descriptor_xml());
-            applicationDescriptorResource.setUpdatedUser(eappDesc.getUser().getUser_name());
-            end();
-            return applicationDescriptorResource;
-        }
-        return null;
+        throw new UnsupportedOperationException();
     }
 
-    public List<Resource> getMe(Object[] keys) {
+    public List<Resource> populate(Object[] keys) {
         List<Resource> list = new ArrayList<Resource>();
         begin();
-        Query q = em.createQuery("SELECT p FROM Service_Descriptor p WHERE p.service_descriptor_ID = :service_desc_name");
-        q.setParameter("service_desc_name", keys[0]);
+        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 = new ServiceDescriptorResource(serviceDescriptor.getService_descriptor_ID());
-        serviceDescriptorResource.setGatewayName(serviceDescriptor.getGateway().getGateway_name());
-        serviceDescriptorResource.setUserName(serviceDescriptor.getUser().getUser_name());
-        serviceDescriptorResource.setContent(serviceDescriptor.getService_descriptor_xml());
+        ServiceDescriptorResource serviceDescriptorResource = (ServiceDescriptorResource)Utils.getResource(ResourceType.SERVICE_DESCRIPTOR, serviceDescriptor);
         end();
         list.add(serviceDescriptorResource);
         return list;
@@ -137,19 +111,15 @@ public class ServiceDescriptorResource e
         List<Resource> resourceList = new ArrayList<Resource>();
         if (type == ResourceType.APPLICATION_DESCRIPTOR) {
             begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.gateway_name =:gate_name and p.service_descriptor_ID = :service_desc_name");
-            q.setParameter("gate_name", gatewayName);
-            q.setParameter("service_desc_name", getServiceDescName());
+            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 = new ApplicationDescriptorResource(applicationDescriptor.getApplication_descriptor_ID(),
-                            applicationDescriptor.getGateway().getGateway_name(),
-                            applicationDescriptor.getHost_descriptor_ID(),
-                            applicationDescriptor.getService_descriptor_ID());
-                    applicationDescriptorResource.setContent(applicationDescriptor.getApplication_descriptor_xml());
-                    applicationDescriptorResource.setUpdatedUser(applicationDescriptor.getUser().getUser_name());
+                    ApplicationDescriptorResource applicationDescriptorResource = (ApplicationDescriptorResource)Utils.getResource(ResourceType.APPLICATION_DESCRIPTOR, applicationDescriptor);
                     resourceList.add(applicationDescriptorResource);
                 }
             }
@@ -166,29 +136,16 @@ public class ServiceDescriptorResource e
         gateway.setGateway_name(gatewayName);
         serviceDescriptor.setGateway(gateway);
         serviceDescriptor.setService_descriptor_xml(content);
+        Users user = new Users();
+        user.setUser_name(userName);
+        serviceDescriptor.setUser(user);
         em.persist(serviceDescriptor);
         end();
 
     }
 
-    public void save(boolean isAppendable) {
-
-    }
-
     public boolean isExists(ResourceType type, Object name) {
-        if (type == ResourceType.APPLICATION_DESCRIPTOR) {
-            begin();
-            Query q = em.createQuery("SELECT p FROM Application_Descriptor p WHERE p.service_descriptor_ID =:service_desc_id and p.application_descriptor_ID =:app_dist_id");
-            q.setParameter("service_desc_id", getServiceDescName());
-            q.setParameter("app_dist_id", name);
-            Application_Descriptor applicationDescriptor = (Application_Descriptor) q.getSingleResult();
-            if (applicationDescriptor != null) {
-                return true;
-            } else {
-                return false;
-            }
-        }
-        return false;
+        throw new UnsupportedOperationException();
     }
 
 	public void setServiceDescName(String serviceDescName) {



Mime
View raw message