airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lah...@apache.org
Subject svn commit: r1382565 [2/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
Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.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/UserResource.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/UserResource.java
(original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserResource.java
Sun Sep  9 20:14:45 2012
@@ -53,22 +53,14 @@ public class UserResource extends Abstra
     }
 
     public Resource create(ResourceType type) {
-        return null;
+        throw new UnsupportedOperationException();
     }
 
     public void remove(ResourceType type, Object name) {
-
-    }
-
-    public void removeMe(Object[] keys) {
-
+        throw new UnsupportedOperationException();
     }
 
     public Resource get(ResourceType type, Object name) {
-        return null;
-    }
-
-    public List<Resource> getMe(Object[] keys) {
         throw new UnsupportedOperationException();
     }
 
@@ -82,13 +74,12 @@ public class UserResource extends Abstra
         Users user = new Users();
         user.setUser_name(userName);
         user.setPassword(password);
-
         em.persist(user);
         end();
     }
 
     public boolean isExists(ResourceType type, Object name) {
-        return false;
+        throw new UnsupportedOperationException();
     }
 
     public ProjectResource getProjectResource() {

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.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/UserWorkflowResource.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/UserWorkflowResource.java
(original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/UserWorkflowResource.java
Sun Sep  9 20:14:45 2012
@@ -25,6 +25,7 @@ import org.apache.airavata.persistance.r
 import org.apache.airavata.persistance.registry.jpa.model.Gateway;
 import org.apache.airavata.persistance.registry.jpa.model.User_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;
@@ -37,6 +38,7 @@ public class UserWorkflowResource extend
     private String name;
     private Date lastUpdateDate;
     private String content;
+    private String path;
 
     public UserWorkflowResource() {
     }
@@ -71,6 +73,14 @@ public class UserWorkflowResource extend
         this.name = name;
     }
 
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
     public Resource create(ResourceType type) {
         throw new UnsupportedOperationException();
     }
@@ -79,10 +89,6 @@ public class UserWorkflowResource extend
         throw new UnsupportedOperationException();
     }
 
-    public void removeMe(Object[] keys) {
-
-    }
-
     public Resource get(ResourceType type, Object name) {
         throw new UnsupportedOperationException();
     }
@@ -92,19 +98,16 @@ public class UserWorkflowResource extend
      * @param keys should be in the order of gateway_name,user_name and user_workflow_name
      * @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 User_Workflow p WHERE p.gateway_name = :gate_name
and p.user_name =:usr_name and p.user_workflow_name=:usr_wf_name");
-        q.setParameter("gate_name", keys[0]);
-        q.setParameter("usr_name", keys[1]);
-        q.setParameter("usr_wf_name",keys[2]);
+        QueryGenerator queryGenerator = new QueryGenerator(USER_WORKFLOW);
+        queryGenerator.setParameter(UserWorkflowConstants.GATEWAY_NAME, keys[0]);
+        queryGenerator.setParameter(UserWorkflowConstants.OWNER, keys[1]);
+        queryGenerator.setParameter(UserWorkflowConstants.TEMPLATE_NAME, keys[2]);
+        Query q = queryGenerator.selectQuery(em);
         User_Workflow userWorkflow = (User_Workflow)q.getSingleResult();
-        UserWorkflowResource userWorkflowResource = new UserWorkflowResource();
-//        userWorkflowResource.setUserName(userWorkflow.getUser().getUser_name());
-//        userWorkflowResource.setGatewayname(userWorkflow.getGateway().getGateway_name());
-        userWorkflowResource.setName(userWorkflow.getTemplate_name());
-        userWorkflowResource.setContent(userWorkflow.getWorkflow_graph());
+        UserWorkflowResource userWorkflowResource = (UserWorkflowResource)Utils.getResource(ResourceType.USER_WORKFLOW,
userWorkflow);
         end();
         list.add(userWorkflowResource);
         return list;
@@ -121,19 +124,16 @@ public class UserWorkflowResource extend
         userWorkflow.setLast_updated_date(lastUpdateDate);
         userWorkflow.setWorkflow_graph(content);
         Gateway gateway = new Gateway();
-//        gateway.setGateway_name(gatewayname);
+        gateway.setGateway_name(gateway.getGateway_name());
         userWorkflow.setGateway(gateway);
         Users user = new Users();
-//        user.setUser_name(userName);
+        user.setUser_name(worker.getUser());
         userWorkflow.setUser(user);
+        userWorkflow.setPath(path);
         em.persist(userWorkflow);
         end();
     }
 
-    public void save(boolean isAppendable) {
-
-    }
-
     public boolean isExists(ResourceType type, Object name) {
         throw new UnsupportedOperationException();
     }

Added: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.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/Utils.java?rev=1382565&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
(added)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/Utils.java
Sun Sep  9 20:14:45 2012
@@ -0,0 +1,217 @@
+/*
+ *
+ * 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.model.*;
+
+
+public class Utils {
+    
+    static Resource getResource(ResourceType type, Object o) {
+        switch (type){
+            case GATEWAY:
+                if (o instanceof Gateway) {
+                    return createGateway((Gateway) o);
+                } else {
+                    throw new IllegalArgumentException("Object should be a Gateway.");
+                }
+            case PROJECT:
+                if (o instanceof Project){
+                    return createProject((Project) o);
+                } else {
+                    throw new IllegalArgumentException("Object should be a Project.");
+                }
+            case CONFIGURATION:
+                if(o instanceof Configuration){
+                    return createConfiguration((Configuration) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a Configuration.");
+                }
+            case APPLICATION_DESCRIPTOR:
+                if (o instanceof Application_Descriptor){
+                    return createApplicationDescriptor((Application_Descriptor) o);
+                } else {
+                    throw new IllegalArgumentException("Object should be a Application Descriptor.");
+                }
+            case EXPERIMENT:
+                if (o instanceof Experiment){
+                    return createExperiment((Experiment) o);
+                }  else {
+                    throw new IllegalArgumentException("Object should be a Experiment.");
+                }
+            case USER:
+                if(o instanceof Users) {
+                    return createUser((Users) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a User.");
+                }
+            case HOST_DESCRIPTOR:
+                if (o instanceof Host_Descriptor){
+                    return createHostDescriptor((Host_Descriptor) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a Host Descriptor.");
+                }
+            case SERVICE_DESCRIPTOR:
+                if (o instanceof Service_Descriptor){
+                    return createServiceDescriptor((Service_Descriptor) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a Service Descriptor.");
+                }
+            case PUBLISHED_WORKFLOW:
+                if (o instanceof Published_Workflow){
+                    return createPublishWorkflow((Published_Workflow) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a Publish Workflow.");
+                }
+            case USER_WORKFLOW:
+                if (o instanceof User_Workflow){
+                    return createUserWorkflow((User_Workflow) o);
+                }else {
+                    throw new IllegalArgumentException("Object should be a User Workflow.");
+                }
+            case GATEWAY_WORKER:
+                if (o instanceof Gateway_Worker){
+                    return createGatewayWorker((Gateway_Worker)o);
+                } else {
+                    throw  new IllegalArgumentException("Object should be a Gateway Worker.");
+                }
+            default:
+        }
+        return null;
+
+    }
+
+    private static Resource createGateway(Gateway o) {
+        GatewayResource gatewayResource = new GatewayResource();
+        gatewayResource.setGatewayName(o.getGateway_name());
+        return gatewayResource;
+    }
+
+    private static Resource createProject(Project o) {
+        ProjectResource projectResource = new ProjectResource();
+        projectResource.setName(o.getProject_name());
+        GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway());
+        projectResource.setGateway(gatewayResource);
+        Gateway_Worker gateway_worker = new Gateway_Worker();
+        gateway_worker.setGateway(o.getGateway());
+        gateway_worker.setUser(o.getUsers());
+        WorkerResource workerResource = (WorkerResource) createGatewayWorker(gateway_worker);
+        projectResource.setWorker(workerResource);
+        return projectResource;
+    }
+
+    private static Resource createConfiguration (Configuration o){
+        ConfigurationResource configurationResource = new ConfigurationResource();
+        configurationResource.setConfigKey(o.getConfig_key());
+        configurationResource.setConfigVal(o.getConfig_val());
+        configurationResource.setExpireDate(o.getExpire_date());
+        return configurationResource;
+    }
+
+    private static Resource createApplicationDescriptor(Application_Descriptor o) {
+        ApplicationDescriptorResource applicationDescriptorResource = new ApplicationDescriptorResource();
+        applicationDescriptorResource.setName(o.getApplication_descriptor_ID());
+        applicationDescriptorResource.setHostDescName(o.getHost_descriptor_ID());
+        applicationDescriptorResource.setServiceDescName(o.getService_descriptor_ID());
+        applicationDescriptorResource.setContent(o.getApplication_descriptor_xml());
+        applicationDescriptorResource.setUpdatedUser(o.getUser().getUser_name());
+        applicationDescriptorResource.setGatewayName(o.getGateway().getGateway_name());
+        return applicationDescriptorResource;
+    }
+
+    private static Resource createExperiment(Experiment o) {
+        ExperimentResource experimentResource = new ExperimentResource();
+        GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway());
+        experimentResource.setGateway(gatewayResource);
+        Gateway_Worker gateway_worker = new Gateway_Worker();
+        gateway_worker.setGateway(o.getGateway());
+        gateway_worker.setUser(o.getUser());
+        WorkerResource workerResource = (WorkerResource) createGatewayWorker(gateway_worker);
+        experimentResource.setWorker(workerResource);
+        ProjectResource projectResource = (ProjectResource)createProject(o.getProject());
+        experimentResource.setProject(projectResource);
+        experimentResource.setExpID(o.getExperiment_ID());
+        return experimentResource;
+    }
+
+    private static Resource createGatewayWorker(Gateway_Worker o) {
+        GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway());
+        WorkerResource workerResource = new WorkerResource(o.getUser().getUser_name(),gatewayResource);
+        return workerResource;
+    }
+
+    private static Resource createHostDescriptor(Host_Descriptor o) {
+        HostDescriptorResource hostDescriptorResource = new HostDescriptorResource();
+        hostDescriptorResource.setGatewayName(o.getGateway().getGateway_name());
+        hostDescriptorResource.setUserName(o.getUser().getUser_name());
+        hostDescriptorResource.setHostDescName(o.getHost_descriptor_ID());
+        hostDescriptorResource.setContent(o.getHost_descriptor_xml());
+        return hostDescriptorResource;
+    }
+
+    private static Resource createPublishWorkflow(Published_Workflow o) {
+        PublishWorkflowResource publishWorkflowResource = new PublishWorkflowResource();
+        GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway());
+        publishWorkflowResource.setGateway(gatewayResource);
+        publishWorkflowResource.setCreatedUser(o.getUser().getUser_name());
+        publishWorkflowResource.setName(o.getPublish_workflow_name());
+        publishWorkflowResource.setContent(o.getWorkflow_content());
+        publishWorkflowResource.setPublishedDate(o.getPublished_date());
+        publishWorkflowResource.setVersion(o.getVersion());
+        publishWorkflowResource.setPath(o.getPath());
+        return publishWorkflowResource;
+    }
+
+    private static Resource createServiceDescriptor(Service_Descriptor o) {
+        ServiceDescriptorResource serviceDescriptorResource = new ServiceDescriptorResource();
+        serviceDescriptorResource.setGatewayName(o.getGateway().getGateway_name());
+        serviceDescriptorResource.setUserName(o.getUser().getUser_name());
+        serviceDescriptorResource.setServiceDescName(o.getService_descriptor_ID());
+        serviceDescriptorResource.setContent(o.getService_descriptor_xml());
+        return serviceDescriptorResource;
+    }
+
+    private static Resource createUserWorkflow(User_Workflow o) {
+        UserWorkflowResource userWorkflowResource = new UserWorkflowResource();
+        userWorkflowResource.setName(o.getTemplate_name());
+        GatewayResource gatewayResource = (GatewayResource)createGateway(o.getGateway());
+        userWorkflowResource.setGateway(gatewayResource);
+        Gateway_Worker gateway_worker = new Gateway_Worker();
+        gateway_worker.setGateway(o.getGateway());
+        gateway_worker.setUser(o.getUser());
+        WorkerResource workerResource = (WorkerResource) createGatewayWorker(gateway_worker);
+        userWorkflowResource.setWorker(workerResource);
+        userWorkflowResource.setLastUpdateDate(o.getLast_updated_date());
+        userWorkflowResource.setContent(o.getWorkflow_graph());
+        userWorkflowResource.setPath(o.getPath());
+        return userWorkflowResource;
+    }
+
+    private static Resource createUser(Users o) {
+        UserResource userResource = new UserResource();
+        userResource.setUserName(o.getUser_name());
+        userResource.setPassword(o.getPassword());
+        return userResource;
+    }
+
+}

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.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/WorkerResource.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/WorkerResource.java
(original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
Sun Sep  9 20:14:45 2012
@@ -28,9 +28,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.Experiment;
-import org.apache.airavata.persistance.registry.jpa.model.Project;
-import org.apache.airavata.persistance.registry.jpa.model.User_Workflow;
+import org.apache.airavata.persistance.registry.jpa.model.*;
+import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 
 public class WorkerResource extends AbstractResource {
 	private String user;
@@ -41,7 +40,6 @@ public class WorkerResource extends Abst
 		this.gateway=gateway;
 	}
 	
-	@Override
 	public Resource create(ResourceType type) {
 		Resource result = null;
 		switch (type) {
@@ -62,28 +60,32 @@ public class WorkerResource extends Abst
 		return result;
 	}
 
-	@Override
 	public void remove(ResourceType type, Object name) {
 		begin();
+        Query q;
+        QueryGenerator generator;
 		switch (type) {
 			case PROJECT:
-				Query q = em.createQuery("Delete p FROM Project p WHERE p.user_name = :owner and p.project_name
= :prj_name and p.gateway_name =: gate_name");
-	            q.setParameter("owner", getUser());
-	            q.setParameter("prj_name", name);
-	            q.setParameter("gate_name", gateway.getGatewayName());
+                generator = new QueryGenerator(PROJECT);
+                generator.setParameter(ProjectConstants.USERNAME, getUser());
+                generator.setParameter(ProjectConstants.PROJECT_NAME, name);
+                generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.deleteQuery(em);
 	            q.executeUpdate();
 				break;
 			case USER_WORKFLOW:
-				q = em.createQuery("Delete p FROM User_Workflow p WHERE p.owner = :owner and p.template_name
= :usrwf_name and p.gateway_name =: gate_name");
-	            q.setParameter("owner", getUser());
-	            q.setParameter("usrwf_name", name);
-	            q.setParameter("gate_name", gateway.getGatewayName());
+                generator = new QueryGenerator(USER_WORKFLOW);
+                generator.setParameter(UserWorkflowConstants.OWNER, getUser());
+                generator.setParameter(UserWorkflowConstants.TEMPLATE_NAME, name);
+                generator.setParameter(UserWorkflowConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.deleteQuery(em);
 	            q.executeUpdate();
 	            break;
 			case EXPERIMENT:
-	            q = em.createQuery("Delete p FROM Experiment p WHERE p.user_name = :usr_name
and p.experiment_ID = :ex_name");
-	            q.setParameter("usr_name", getUser());
-	            q.setParameter("ex_name", name);
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.USERNAME, getUser());
+                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+                q = generator.deleteQuery(em);
 	            q.executeUpdate();
 	            break;
 			default:
@@ -92,52 +94,39 @@ public class WorkerResource extends Abst
 		end();
 	}
 
-	@Override
-	public void removeMe(Object[] keys) {
-
-	}
-
-	@Override
 	public Resource get(ResourceType type, Object name) {
 		Resource result = null;
 		begin();
+        QueryGenerator generator;
+        Query q;
 		switch (type) {
 			case PROJECT:
-				Query q = em.createQuery("SELECT p FROM Project p WHERE p.user_name = :owner and p.project_name
= :prj_name and p.gateway_name =: gate_name");
-	            q.setParameter("owner", getUser());
-	            q.setParameter("prj_name", name);
-	            q.setParameter("gate_name", gateway.getGatewayName());
+                generator = new QueryGenerator(PROJECT);
+                generator.setParameter(ProjectConstants.USERNAME, getUser());
+                generator.setParameter(ProjectConstants.PROJECT_NAME, name);
+                generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.selectQuery(em);
 	            Project project = (Project) q.getSingleResult();
-	            ProjectResource projectResource = new ProjectResource(this, gateway, project.getProject_ID());
-	            projectResource.setName(project.getProject_name());
+	            ProjectResource projectResource = (ProjectResource)Utils.getResource(ResourceType.PROJECT,
project);
 	            result=projectResource;
 				break;
 			case USER_WORKFLOW:
-				q = em.createQuery("SELECT p FROM User_Workflow p WHERE p.owner = :usr_name and p.user_workflow_name
= :usrwf_name and p.gateway_name =:gate_name");
-	            q.setParameter("user_name", getUser());
-	            q.setParameter("usrwf_name", name);
-	            q.setParameter("gate_name", gateway.getGatewayName());
+                generator = new QueryGenerator(USER_WORKFLOW);
+                generator.setParameter(UserWorkflowConstants.OWNER, getUser());
+                generator.setParameter(UserWorkflowConstants.TEMPLATE_NAME, name);
+                generator.setParameter(UserWorkflowConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.selectQuery(em);
 	            User_Workflow userWorkflow = (User_Workflow) q.getSingleResult();
-	            UserWorkflowResource userWorkflowResource = new UserWorkflowResource(gateway,
this, userWorkflow.getTemplate_name());
-	            userWorkflowResource.setContent(userWorkflow.getWorkflow_graph());
-	            userWorkflowResource.setLastUpdateDate(userWorkflow.getLast_updated_date());
+	            UserWorkflowResource userWorkflowResource = (UserWorkflowResource)Utils.getResource(ResourceType.USER_WORKFLOW,
userWorkflow);
 	            result=userWorkflowResource;
 	            break;
 			case EXPERIMENT:
-				q = em.createQuery("SELECT p FROM Experiment p WHERE p.gateway_name = :gateway_name and
p.user_name = :usr_name and p.experiment_ID = :ex_name");
-	            q.setParameter("usr_name", getUser());
-	            q.setParameter("ex_name", name);
-	            q.setParameter("gateway_name", gateway.getGatewayName());
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.USERNAME, getUser());
+                generator.setParameter(ExperimentConstants.EXPERIMENT_ID, name);
+                q = generator.selectQuery(em);
 	            Experiment experiment = (Experiment) q.getSingleResult();
-	            ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-	            ProjectResource projectResource1 = new ProjectResource(experiment.getProject().getProject_ID());
-                projectResource1.setGateway(gateway);
-                projectResource1.setWorker(this);
-                projectResource1.setName(experiment.getProject().getProject_name());
-            	experimentResource.setProject(projectResource1);
-	            experimentResource.setWorker(this);
-	            experimentResource.setGateway(gateway);
-	            experimentResource.setSubmittedDate(experiment.getSubmitted_date());
+	            ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT,
experiment);
 	            result=experimentResource;
 				break;
 			default:
@@ -147,53 +136,42 @@ public class WorkerResource extends Abst
 		return result;
 	}
 
-	@Override
-	public List<Resource> getMe(Object[] keys) {
-		return null;
-	}
-
-	@Override
 	public List<Resource> get(ResourceType type) {
 		List<Resource> result = new ArrayList<Resource>();
 		begin();
+        QueryGenerator generator;
+        Query q;
 		switch (type) {
 			case PROJECT:
-				Query q = em.createQuery("SELECT p FROM Project p WHERE p.user_name = :owner and p.gateway_name
=: gate_name");
-	            q.setParameter("owner", getUser());
-	            q.setParameter("gate_name", gateway.getGatewayName());
+                generator = new QueryGenerator(PROJECT);
+                generator.setParameter(ProjectConstants.USERNAME, getUser());
+                generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.selectQuery(em);
 	            for (Object o : q.getResultList()) {
 	            	Project project = (Project) o;
-		            ProjectResource projectResource = new ProjectResource(this, gateway, project.getProject_ID());
-		            projectResource.setName(project.getProject_name());
+		            ProjectResource projectResource = (ProjectResource)Utils.getResource(ResourceType.PROJECT,
project);
 		            result.add(projectResource);
 				}
 				break;
 			case USER_WORKFLOW:
-				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");
+                generator = new QueryGenerator(USER_WORKFLOW);
+                generator.setParameter(UserWorkflowConstants.OWNER, getUser());
+                q = generator.selectQuery(em);
 	            q.setParameter("usr_name", getUser());
 	            for (Object o : q.getResultList()) {
 		            User_Workflow userWorkflow = (User_Workflow) o;
-		            UserWorkflowResource userWorkflowResource = new UserWorkflowResource(gateway,
this, userWorkflow.getTemplate_name());
-		            userWorkflowResource.setContent(userWorkflow.getWorkflow_graph());
-		            userWorkflowResource.setLastUpdateDate(userWorkflow.getLast_updated_date());
+		            UserWorkflowResource userWorkflowResource = (UserWorkflowResource)Utils.getResource(ResourceType.USER_WORKFLOW,
userWorkflow);
 		            result.add(userWorkflowResource);
 	            }
 	            break;
 			case EXPERIMENT:
-				q = em.createQuery("SELECT p FROM Experiment p WHERE p.gateway_name = :gateway_name and
p.user_name = :usr_name and p.experiment_ID = :ex_name");
-	            q.setParameter("usr_name", getUser());
-	            q.setParameter("gateway_name", gateway.getGatewayName());
+                generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.USERNAME, getUser());
+                generator.setParameter(ExperimentConstants.GATEWAY_NAME, gateway.getGatewayName());
+                q = generator.selectQuery(em);
 	            for (Object o : q.getResultList()) {
 	            	Experiment experiment = (Experiment) o;
-	            	ExperimentResource experimentResource = new ExperimentResource(experiment.getExperiment_ID());
-	            	experimentResource.setGateway(gateway);
-	            	experimentResource.setWorker(this);
-	            	ProjectResource projectResource = new ProjectResource(experiment.getProject().getProject_ID());
-	                projectResource.setGateway(gateway);
-	                projectResource.setWorker(this);
-	                projectResource.setName(experiment.getProject().getProject_name());
-	            	experimentResource.setProject(projectResource);
-	            	experimentResource.setSubmittedDate(experiment.getSubmitted_date());
+	            	ExperimentResource experimentResource = (ExperimentResource)Utils.getResource(ResourceType.EXPERIMENT,
experiment);
 		            result.add(experimentResource);
 	            }
 	            break;
@@ -204,9 +182,17 @@ public class WorkerResource extends Abst
 		return result;
 	}
 
-	@Override
 	public void save() {
-		//nothing to do... worker resource is just a concept
+        begin();
+        Gateway_Worker gatewayWorker = new Gateway_Worker();
+        Users users = new Users();
+        users.setUser_name(user);
+        gatewayWorker.setUser(users);
+        Gateway gateway = new Gateway();
+        gateway.setGateway_name(gateway.getGateway_name());
+        gatewayWorker.setGateway(gateway);
+        em.persist(gatewayWorker);
+        end();
 	}
 
 	public String getUser() {
@@ -217,8 +203,15 @@ public class WorkerResource extends Abst
 		this.user = user;
 	}
 
-	
-	public boolean isProjectExists(String name){
+    public GatewayResource getGateway() {
+        return gateway;
+    }
+
+    public void setGateway(GatewayResource gateway) {
+        this.gateway = gateway;
+    }
+
+    public boolean isProjectExists(String name){
 		return isExists(ResourceType.PROJECT, name);
 	}
 	

Modified: incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data.sql
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data.sql?rev=1382565&r1=1382564&r2=1382565&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data.sql
(original)
+++ incubator/airavata/trunk/modules/registry/airavata-jpa-registry/src/main/resources/data.sql
Sun Sep  9 20:14:45 2012
@@ -1,3 +1,23 @@
+/*
+ *
+ * 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.
+ *
+ */
 create table Gateway
 (
         gateway_name varchar(255),
@@ -10,7 +30,7 @@ create table Configuration
         config_ID int(11) NOT NULL AUTO_INCREMENT,
         config_key varchar(255),
         config_val varchar(255),
-        expire_date date,
+        expire_date TIMESTAMP DEFAULT '0000-00-00 00:00:00',
         PRIMARY KEY(config_ID)
 );
 
@@ -48,7 +68,7 @@ create table Published_Workflow
        created_user varchar(255),
        publish_workflow_name varchar(255),
        version varchar(255),
-       published_date DATE,
+       published_date TIMESTAMP DEFAULT '0000-00-00 00:00:00',
        path varchar (255),
        workflow_content varchar(2000),
        PRIMARY KEY(gateway_name, publish_workflow_name),
@@ -57,11 +77,12 @@ create table Published_Workflow
 );
 
 create table User_Workflow
+
 (
        gateway_name varchar(255),
        owner varchar(255),
        template_name varchar(255),
-       last_updated_date DATE,
+       last_updated_date TIMESTAMP DEFAULT now() on update now(),
        path varchar (255),
        workflow_graph varchar(2000),
        PRIMARY KEY(gateway_name, owner, template_name),
@@ -111,7 +132,7 @@ create table Experiment
 	      gateway_name varchar(255),
           user_name varchar(255),
           experiment_ID varchar(255),
-          submitted_date Date,
+          submitted_date TIMESTAMP DEFAULT '0000-00-00 00:00:00',
           PRIMARY KEY(experiment_ID),
           FOREIGN KEY (gateway_name) REFERENCES Gateway(gateway_name) ON DELETE CASCADE,
           FOREIGN KEY (project_ID) REFERENCES Project(project_ID) ON DELETE CASCADE,



Mime
View raw message