airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [01/19] airavata git commit: Adding more support to the registry for paginated result retrieval of project and experiment data. Renamed all *searchWithPagination methods to search* with method overloading
Date Fri, 01 May 2015 00:55:57 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 20bf020d5 -> 5cc8b43d0


Adding more support to the registry for paginated result retrieval of project and experiment data. Renamed all *searchWithPagination methods to search* with method overloading


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

Branch: refs/heads/master
Commit: 9f6e30e41d2f4366d4e8cd6f253cc88661a513d2
Parents: cc40cf3
Author: Supun Nakandala <supun.nakandala@gmail.com>
Authored: Mon Apr 27 20:36:08 2015 +0530
Committer: Supun Nakandala <supun.nakandala@gmail.com>
Committed: Mon Apr 27 20:36:08 2015 +0530

----------------------------------------------------------------------
 .../registry/jpa/impl/ExperimentRegistry.java   | 152 ++++++++----
 .../registry/jpa/impl/LoggingRegistryImpl.java  |   7 +-
 .../registry/jpa/impl/ProjectRegistry.java      |  33 ++-
 .../registry/jpa/impl/RegistryImpl.java         |  57 ++++-
 .../registry/jpa/resources/ProjectResource.java | 119 +++++++++-
 .../registry/jpa/resources/WorkerResource.java  | 234 ++++++++++++++++---
 .../registry/jpa/utils/QueryGenerator.java      |  73 ++++--
 .../registry/jpa/RegistryUseCaseTest.java       |  15 +-
 8 files changed, 569 insertions(+), 121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
index 7d47762..a0e9ecf 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ExperimentRegistry.java
@@ -1823,6 +1823,13 @@ public class ExperimentRegistry {
         }
     }
 
+    /**
+     * Method to get matching experiment list
+     * @param fieldName
+     * @param value
+     * @return
+     * @throws RegistryException
+     */
     public List<Experiment> getExperimentList(String fieldName, Object value) throws RegistryException {
         List<Experiment> experiments = new ArrayList<Experiment>();
         try {
@@ -1830,7 +1837,6 @@ public class ExperimentRegistry {
                 WorkerResource resource = (WorkerResource) gatewayResource.create(ResourceType.GATEWAY_WORKER);
                 resource.setUser((String) value);
                 List<ExperimentResource> resources = resource.getExperiments();
-//                List<ExperimentResource> resources = resource.getExperimentsByCaching((String)value);
                 for (ExperimentResource experimentResource : resources) {
                     Experiment experiment = ThriftDataModelConversion.getExperiment(experimentResource);
                     experiments.add(experiment);
@@ -1876,6 +1882,50 @@ public class ExperimentRegistry {
         return experiments;
     }
 
+    /**
+     * Method to get matching experiment list with pagination and ordering
+     * @param fieldName
+     * @param value
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<Experiment> getExperimentList(String fieldName, Object value, int limit, int offset,
+                                              Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+        List<Experiment> experiments = new ArrayList<Experiment>();
+        try {
+            if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
+                WorkerResource resource = (WorkerResource) gatewayResource.create(ResourceType.GATEWAY_WORKER);
+                resource.setUser((String) value);
+                List<ExperimentResource> resources = resource.getExperiments(limit, offset,
+                        orderByIdentifier, resultOrderType);
+                for (ExperimentResource experimentResource : resources) {
+                    Experiment experiment = ThriftDataModelConversion.getExperiment(experimentResource);
+                    experiments.add(experiment);
+                }
+                return experiments;
+            } else if (fieldName.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
+                ProjectResource project = workerResource.getProject((String) value);
+                List<ExperimentResource> resources = project.getExperiments(limit, offset,
+                        Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
+                for (ExperimentResource resource : resources) {
+                    Experiment experiment = ThriftDataModelConversion.getExperiment(resource);
+                    experiments.add(experiment);
+                }
+                return experiments;
+            }
+            logger.error("Unsupported field name to retrieve experiment list...");
+        } catch (Exception e) {
+            logger.error("Error while getting experiment list...", e);
+            throw new RegistryException(e);
+        }
+        return experiments;
+    }
+
+
     public List<WorkflowNodeDetails> getWFNodeDetails(String fieldName, Object value) throws RegistryException {
         try {
             if (fieldName.equals(Constants.FieldConstants.WorkflowNodeConstants.EXPERIMENT_ID)) {
@@ -2810,7 +2860,7 @@ public class ExperimentRegistry {
      * @throws RegistryException
      */
     public List<ExperimentSummary> searchExperiments(Map<String, String> filters) throws RegistryException {
-        return searchExperimentsWithPagination(filters, -1, -1, null, null);
+        return searchExperiments(filters, -1, -1, null, null);
     }
 
 
@@ -2827,8 +2877,8 @@ public class ExperimentRegistry {
      * @return
      * @throws RegistryException
      */
-    public List<ExperimentSummary> searchExperimentsWithPagination(Map<String, String> filters, int limit,
-        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+    public List<ExperimentSummary> searchExperiments(Map<String, String> filters, int limit,
+              int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         Map<String, String> fil = new HashMap<String, String>();
         if (filters != null && filters.size() != 0) {
             List<ExperimentSummary> experimentSummaries = new ArrayList<ExperimentSummary>();
@@ -2847,7 +2897,7 @@ public class ExperimentRegistry {
                     } else if (field.equals(Constants.FieldConstants.ExperimentConstants.APPLICATION_ID)) {
                         fil.put(AbstractResource.ExperimentConstants.APPLICATION_ID, filters.get(field));
                     } else if (field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS)) {
-                        return searchExperimentsByStatus(ExperimentState.valueOf(filters.get(field)));
+                        fil.put(AbstractResource.StatusConstants.STATE, filters.get(field));
                     } else if (field.equals(Constants.FieldConstants.ExperimentConstants.FROM_DATE)) {
                         fromTime = Long.parseLong(filters.get(field));
                     } else if (field.equals(Constants.FieldConstants.ExperimentConstants.TO_DATE)) {
@@ -2855,13 +2905,13 @@ public class ExperimentRegistry {
                     }
                 }
                 if (fromTime != 0 && toTime != 0) {
-                    return searchExperimentsByCreationTime(new Timestamp(fromTime), new Timestamp(toTime));
-                }
-                if (fil.containsKey(AbstractResource.ExperimentConstants.APPLICATION_ID)) {
-                    return searchExperimentsByApplication(fil);
+                    return searchExperimentsByCreationTime(new Timestamp(fromTime), new Timestamp(toTime)
+                            , limit, offset, orderByIdentifier, resultOrderType);
+                } else if(fil.get(AbstractResource.StatusConstants.STATE) != null ) {
+                    return searchExperimentsByStatus(fil, limit, offset, orderByIdentifier, resultOrderType);
                 } else {
                     List<ExperimentResource> experimentResources = workerResource
-                            .searchExperimentsWithPagination(fil, limit, offset, orderByIdentifier, resultOrderType);
+                            .searchExperiments(fil, limit, offset, orderByIdentifier, resultOrderType);
                     if (experimentResources != null && !experimentResources.isEmpty()) {
                         for (ExperimentResource ex : experimentResources) {
                             experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
@@ -2878,10 +2928,33 @@ public class ExperimentRegistry {
         return null;
     }
 
-    public List<ExperimentSummary> searchExperimentsByStatus(ExperimentState experimentState) throws RegistryException {
+    /**
+     * To get list of experiments of specified state
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentSummary> searchExperimentsByStatus(Map<String, String> filters) throws RegistryException {
+        return searchExperimentsByStatus(filters, -1, -1, null, null);
+    }
+
+    /**
+     * To get list of experiments of specified state with pagination and ordering
+     *
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentSummary> searchExperimentsByStatus(Map<String, String> filters, int limit,
+        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         try {
             List<ExperimentSummary> experimentSummaries = new ArrayList<ExperimentSummary>();
-            List<ExperimentResource> experimentResources = workerResource.searchExperimentsByState(experimentState.toString());
+            List<ExperimentResource> experimentResources = workerResource.searchExperimentsByState(filters, limit, offset,
+                    orderByIdentifier, resultOrderType);
             if (experimentResources != null && !experimentResources.isEmpty()) {
                 for (ExperimentResource ex : experimentResources) {
                     experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
@@ -2895,40 +2968,37 @@ public class ExperimentRegistry {
         }
     }
 
-    public List<ExperimentSummary> searchExperimentsByApplication(Map<String, String> fil) throws RegistryException {
-        try {
-            List<ExperimentSummary> experimentSummaries = new ArrayList<ExperimentSummary>();
-            List<ExperimentResource> experimentResources = workerResource.searchExperiments(fil);
-            if (experimentResources != null && !experimentResources.isEmpty()) {
-                for (ExperimentResource ex : experimentResources) {
-                    String applicationId = ex.getApplicationId();
-                    String[] splits = applicationId.split("_");
-                    if (splits.length != 0) {
-                        for (int i = 0; i < splits.length - 1; i++) {
-                            String appId = fil.get(AbstractResource.ExperimentConstants.APPLICATION_ID);
-                            if (!appId.equals("*")) {
-                                if (splits[i].contains(appId)) {
-                                    experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
-                                }
-                            } else {
-                                experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
-                            }
-                        }
-                    }
-                }
-            }
-            return experimentSummaries;
 
-        } catch (Exception e) {
-            logger.error("Error while retrieving experiment summary from registry", e);
-            throw new RegistryException(e);
-        }
+    /**
+     * Search experiements based on creation time within specified time interval.
+     * @param fromTime
+     * @param toTime
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentSummary> searchExperimentsByCreationTime(Timestamp fromTime, Timestamp toTime) throws RegistryException {
+        return searchExperimentsByCreationTime(fromTime, toTime, -1, -1, null, null);
     }
 
-    public List<ExperimentSummary> searchExperimentsByCreationTime(Timestamp fromTime, Timestamp toTime) throws RegistryException {
+    /**
+     * Search experiements based on creation time within specified time interval with pagination.
+     * @param fromTime
+     * @param toTime
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentSummary> searchExperimentsByCreationTime(
+            Timestamp fromTime, Timestamp toTime, int limit,
+            int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         try {
             List<ExperimentSummary> experimentSummaries = new ArrayList<ExperimentSummary>();
-            List<ExperimentResource> experimentResources = workerResource.searchExperimentsByCreationTime(fromTime, toTime);
+            List<ExperimentResource> experimentResources
+                    = workerResource.searchExperimentsByCreationTime(fromTime, toTime, limit, offset,
+                    orderByIdentifier, resultOrderType);
             if (experimentResources != null && !experimentResources.isEmpty()) {
                 for (ExperimentResource ex : experimentResources) {
                     experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/LoggingRegistryImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/LoggingRegistryImpl.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/LoggingRegistryImpl.java
index d7e9c0a..0274518 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/LoggingRegistryImpl.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/LoggingRegistryImpl.java
@@ -61,12 +61,17 @@ public class LoggingRegistryImpl implements Registry {
     }
 
     @Override
+    public List<Object> get(RegistryModelType dataType, String fieldName, Object value, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+        return null;
+    }
+
+    @Override
     public List<Object> search(RegistryModelType dataType, Map<String, String> filters) throws RegistryException {
         return null;
     }
 
     @Override
-    public List<Object> searchWithPagination(RegistryModelType dataType, Map<String, String> filters, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+    public List<Object> search(RegistryModelType dataType, Map<String, String> filters, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
index 5bfcc3d..e0e2a46 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/ProjectRegistry.java
@@ -164,7 +164,30 @@ public class ProjectRegistry {
         return null;
     }
 
+    /**
+     * Get list of projects of the user
+     * @param fieldName
+     * @param value
+     * @return
+     * @throws RegistryException
+     */
     public List<Project> getProjectList (String fieldName, Object value) throws RegistryException{
+        return getProjectList(fieldName, value, -1, -1, null, null);
+    }
+
+    /**
+     * Get projects list with pagination and result ordering
+     * @param fieldName
+     * @param value
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<Project> getProjectList (String fieldName, Object value, int limit, int offset,
+                                         Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException{
         List<Project> projects = new ArrayList<Project>();
         try {
             if (fieldName.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
@@ -179,7 +202,7 @@ public class ProjectRegistry {
             }
         }catch (Exception e){
             logger.error("Error while retrieving project from registry", e);
-           throw new RegistryException(e);
+            throw new RegistryException(e);
         }
         return projects;
     }
@@ -192,7 +215,7 @@ public class ProjectRegistry {
      * @throws RegistryException
      */
     public List<Project> searchProjects (Map<String, String> filters) throws RegistryException{
-        return searchProjectsWithPagination(filters, -1, -1, null, null);
+        return searchProjects(filters, -1, -1, null, null);
     }
 
     /**
@@ -208,8 +231,8 @@ public class ProjectRegistry {
      * @return
      * @throws RegistryException
      */
-    public List<Project> searchProjectsWithPagination(Map<String, String> filters, int limit,
-        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+    public List<Project> searchProjects(Map<String, String> filters, int limit,
+            int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         Map<String, String> fil = new HashMap<String, String>();
         if (filters != null && filters.size() != 0){
             List<Project> projects = new ArrayList<Project>();
@@ -226,7 +249,7 @@ public class ProjectRegistry {
                     }
                 }
                 List<ProjectResource> projectResources = workerResource
-                        .searchProjectsWithPagination(fil, limit, offset, orderByIdentifier, resultOrderType);
+                        .searchProjects(fil, limit, offset, orderByIdentifier, resultOrderType);
                 if (projectResources != null && !projectResources.isEmpty()){
                     for (ProjectResource pr : projectResources){
                         projects.add(ThriftDataModelConversion.getProject(pr));

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
index a2f1e11..953b11e 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/impl/RegistryImpl.java
@@ -454,6 +454,51 @@ public class RegistryImpl implements Registry {
     }
 
     /**
+     * This method is to retrieve list of objects according to a given criteria with pagination and ordering
+     *
+     * @param dataType  Data type is a predefined type which the programmer should choose according to the object he
+     *                  is going to save in to registry
+     * @param fieldName FieldName is the field that filtering should be done. For example, if we want to retrieve all
+     *                  the experiments for a given user, filterBy will be "userName"
+     * @param value     value for the filtering field. In the experiment case, value for "userName" can be "admin"
+     * @param limit     Size of the results to be returned
+     * @param offset    Start position of the results to be retrieved
+     * @param orderByIdentifier     Named of the column in which the ordering is based
+     * @param resultOrderType       Type of ordering i.e ASC or DESC
+     * @return
+     * @throws RegistryException
+     */
+    @Override
+    public List<Object> get(RegistryModelType dataType, String fieldName, Object value, int limit,
+                            int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+        try {
+            List<Object> result = new ArrayList<Object>();
+            switch (dataType) {
+                case PROJECT:
+                    List<Project> projectList = projectRegistry
+                            .getProjectList(fieldName, value, limit, offset, orderByIdentifier, resultOrderType);
+                    for (Project project : projectList ){
+                        result.add(project);
+                    }
+                    return result;
+                case EXPERIMENT:
+                    List<Experiment> experimentList = experimentRegistry.getExperimentList(fieldName, value,
+                            limit, offset, orderByIdentifier, resultOrderType);
+                    for (Experiment experiment : experimentList) {
+                        result.add(experiment);
+                    }
+                    return result;
+                default:
+                    logger.error("Unsupported data type...", new UnsupportedOperationException());
+                    throw new UnsupportedOperationException();
+            }
+        } catch (Exception e) {
+            logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e));
+            throw new RegistryException("Error while retrieving the resource " + dataType.toString(), e);
+        }
+    }
+
+    /**
      * This method is to retrieve list of objects according to a given criteria
      * @param dataType Data type is a predefined type which the programmer should choose according to the object he
      *                 is going to save in to registry
@@ -462,7 +507,7 @@ public class RegistryImpl implements Registry {
      */
     @Override
     public List<Object> search(RegistryModelType dataType, Map<String, String> filters) throws RegistryException {
-        return searchWithPagination(dataType, filters, -1, -1, null, null);
+        return search(dataType, filters, -1, -1, null, null);
     }
 
     /**
@@ -478,23 +523,23 @@ public class RegistryImpl implements Registry {
      * @return List of objects according to the given criteria
      */
     @Override
-    public List<Object> searchWithPagination(RegistryModelType dataType, Map<String, String> filters, int limit,
+    public List<Object> search(RegistryModelType dataType, Map<String, String> filters, int limit,
         int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         try {
             List<Object> result = new ArrayList<Object>();
             switch (dataType) {
                 case PROJECT:
                     List<Project> projectList
-                            = projectRegistry.searchProjectsWithPagination(filters, limit, offset,
-                            orderByIdentifier, resultOrderType );
+                            = projectRegistry.searchProjects(filters, limit, offset,
+                            orderByIdentifier, resultOrderType);
                     for (Project project : projectList ){
                         result.add(project);
                     }
                     return result;
                 case EXPERIMENT:
                     List<ExperimentSummary> experimentSummaries = experimentRegistry
-                            .searchExperimentsWithPagination(filters, limit, offset, orderByIdentifier,
-                                    resultOrderType );
+                            .searchExperiments(filters, limit, offset, orderByIdentifier,
+                                    resultOrderType);
                     for (ExperimentSummary ex : experimentSummaries){
                         result.add(ex);
                     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
index c53b489..4dc4160 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/ProjectResource.java
@@ -20,22 +20,23 @@
 */
 package org.apache.airavata.persistance.registry.jpa.resources;
 
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 import org.apache.airavata.registry.cpi.RegistryException;
+import org.apache.airavata.registry.cpi.ResultOrderType;
+import org.apache.airavata.registry.cpi.utils.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
 public class ProjectResource extends AbstractResource {
     private final static Logger logger = LoggerFactory.getLogger(ProjectResource.class);
     private String name;
@@ -182,6 +183,7 @@ public class ProjectResource extends AbstractResource {
      * @param type child resource type
      * @return list of child resources
      */
+    @Override
     public List<Resource> get(ResourceType type) throws RegistryException{
         List<Resource> resourceList = new ArrayList<Resource>();
         EntityManager em = null;
@@ -239,6 +241,99 @@ public class ProjectResource extends AbstractResource {
     }
 
     /**
+     * Get results with pagination and ordering
+     *
+     * @param type
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @return
+     * @throws RegistryException
+     */
+    public List<Resource> get(ResourceType type, int limit, int offset, Object orderByIdentifier,
+                              ResultOrderType resultOrderType) throws RegistryException{
+        List<Resource> resourceList = new ArrayList<Resource>();
+        EntityManager em = null;
+        try {
+            if (type == ResourceType.EXPERIMENT) {
+                em = ResourceUtils.getEntityManager();
+                em.getTransaction().begin();
+                QueryGenerator generator = new QueryGenerator(EXPERIMENT);
+                generator.setParameter(ExperimentConstants.PROJECT_ID, id);
+                Query q;
+                //ordering - supported only by CREATION_TIME
+                if(orderByIdentifier != null && resultOrderType != null
+                        && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)) {
+                    q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType);
+                }else{
+                    q = generator.selectQuery(em);
+                }
+
+                //pagination
+                if(limit>0 && offset>=0){
+                    q.setFirstResult(offset);
+                    q.setMaxResults(limit);
+                }
+                List<?> results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        Experiment experiment = (Experiment) result;
+                        ExperimentResource experimentResource = (ExperimentResource)
+                                Utils.getResource(ResourceType.EXPERIMENT, experiment);
+                        resourceList.add(experimentResource);
+                    }
+                }
+                em.getTransaction().commit();
+                em.close();
+            } else if (type == ResourceType.PROJECT_USER) {
+                em = ResourceUtils.getEntityManager();
+                em.getTransaction().begin();
+                QueryGenerator generator = new QueryGenerator(PROJECT_USER);
+                generator.setParameter(ProjectUserConstants.PROJECT_ID, id);
+                Query q;
+                //ordering - only supported only by CREATION_TIME
+                if(orderByIdentifier != null && resultOrderType != null
+                        && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
+                    q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType);
+                }else{
+                    q = generator.selectQuery(em);
+                }
+
+                //pagination
+                if(limit>0 && offset>=0){
+                    q.setFirstResult(offset);
+                    q.setMaxResults(limit);
+                }
+                List<?> results = q.getResultList();
+                if (results.size() != 0) {
+                    for (Object result : results) {
+                        ProjectUser projectUser = (ProjectUser) result;
+                        ProjectUserResource pr = (ProjectUserResource)
+                                Utils.getResource(ResourceType.PROJECT_USER, projectUser);
+                        resourceList.add(pr);
+                    }
+                }
+                em.getTransaction().commit();
+                em.close();
+            } else {
+                logger.error("Unsupported resource type for project resource.", new IllegalArgumentException());
+                throw new IllegalArgumentException("Unsupported resource type for project resource.");
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw new RegistryException(e);
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return resourceList;
+    }
+
+    /**
      * save project to the database
      */
     public void save() throws RegistryException{
@@ -404,6 +499,16 @@ public class ProjectResource extends AbstractResource {
 		return result;
 	}
 
+    public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier,
+                                                   ResultOrderType resultOrderType) throws RegistryException{
+        List<Resource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType);
+        List<ExperimentResource> result=new ArrayList<ExperimentResource>();
+        for (Resource resource : list) {
+            result.add((ExperimentResource) resource);
+        }
+        return result;
+    }
+
     /**
      *
      * @param experimentId experiment ID

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
index dfa887f..d3609b8 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/WorkerResource.java
@@ -21,12 +21,14 @@
 
 package org.apache.airavata.persistance.registry.jpa.resources;
 
+import org.apache.airavata.model.workspace.experiment.ExperimentState;
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.persistance.registry.jpa.ResourceUtils;
 import org.apache.airavata.persistance.registry.jpa.model.*;
 import org.apache.airavata.persistance.registry.jpa.utils.QueryGenerator;
 import org.apache.airavata.registry.cpi.ResultOrderType;
+import org.apache.airavata.registry.cpi.utils.Constants;
 import org.apache.airavata.registry.cpi.utils.StatusType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -220,11 +222,28 @@ public class WorkerResource extends AbstractResource {
 //	}
 
     /**
+     * Method get all results of the given child resource type
      *
      * @param type child resource type
      * @return list of child resources
      */
     public List<Resource> get(ResourceType type) throws RegistryException{
+        return get(type, -1, -1, null, null);
+    }
+
+    /**
+     * Method get all results of the given child resource type with paginaltion and ordering
+     *
+     * @param type child resource type
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return list of child resources
+     * @throws RegistryException
+     */
+    public List<Resource> get(ResourceType type, int limit, int offset, Object orderByIdentifier,
+                              ResultOrderType resultOrderType) throws RegistryException{
         List<Resource> result = new ArrayList<Resource>();
         EntityManager em = null;
         try {
@@ -239,9 +258,21 @@ public class WorkerResource extends AbstractResource {
                     Gateway gatewayModel = em.find(Gateway.class, gateway.getGatewayId());
                     generator.setParameter("users", users);
                     generator.setParameter("gateway", gatewayModel);
-//                generator.setParameter(ProjectConstants.USERNAME, getUser());
-//                generator.setParameter(ProjectConstants.GATEWAY_NAME, gateway.getGatewayName());
-                    q = generator.selectQuery(em);
+
+                    //ordering - only supported only by CREATION_TIME
+                    if(orderByIdentifier != null && resultOrderType != null
+                            && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
+                        q = generator.selectQuery(em, ProjectConstants.CREATION_TIME, resultOrderType);
+                    }else{
+                        q = generator.selectQuery(em);
+                    }
+
+                    //pagination
+                    if(limit>0 && offset>=0){
+                        q.setFirstResult(offset);
+                        q.setMaxResults(limit);
+                    }
+
                     for (Object o : q.getResultList()) {
                         Project project = (Project) o;
                         ProjectResource projectResource = (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
@@ -251,12 +282,26 @@ public class WorkerResource extends AbstractResource {
                 case EXPERIMENT:
                     generator = new QueryGenerator(EXPERIMENT);
                     generator.setParameter(ExperimentConstants.EXECUTION_USER, getUser());
-                    q = generator.selectQuery(em);
+
+                    //ordering - only supported only by CREATION_TIME
+                    if(orderByIdentifier != null && resultOrderType != null
+                            && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)) {
+                        q = generator.selectQuery(em, ExperimentConstants.CREATION_TIME, resultOrderType);
+                    }else{
+                        q = generator.selectQuery(em);
+                    }
+
+                    //pagination
+                    if(limit>0 && offset>=0){
+                        q.setFirstResult(offset);
+                        q.setMaxResults(limit);
+                    }
                     for (Object o : q.getResultList()) {
                         Experiment experiment = (Experiment) o;
                         ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                         result.add(experimentResource);
                     }
+
                     break;
                 default:
                     logger.error("Unsupported resource type for worker resource.", new IllegalArgumentException());
@@ -396,18 +441,29 @@ public class WorkerResource extends AbstractResource {
 	}
 
     /**
-     *
+     * Get projects list of user
      * @return  list of projects for the user
      */
     public List<ProjectResource> getProjects() throws RegistryException{
-		List<ProjectResource> result=new ArrayList<ProjectResource>();
-		List<Resource> list = get(ResourceType.PROJECT);
-		for (Resource resource : list) {
-			result.add((ProjectResource) resource);
-		}
-		return result;
+		return getProjects(-1, -1, null, null);
 	}
 
+
+    /**
+     * Get projects list of user with pagination and ordering
+     *
+     * @return  list of projects for the user
+     */
+    public List<ProjectResource> getProjects(int limit, int offset, Object orderByIdentifier,
+                                             ResultOrderType resultOrderType) throws RegistryException{
+        List<ProjectResource> result=new ArrayList<ProjectResource>();
+        List<Resource> list = get(ResourceType.PROJECT, limit, offset, orderByIdentifier, resultOrderType);
+        for (Resource resource : list) {
+            result.add((ProjectResource) resource);
+        }
+        return result;
+    }
+
     /**
      *
      * @param name experiment name
@@ -432,19 +488,33 @@ public class WorkerResource extends AbstractResource {
 //    }
 
     /**
-     *
+     * Method to get list of expeirments of user
      * @return list of experiments for the user
      */
 	public List<ExperimentResource> getExperiments() throws RegistryException{
-		List<ExperimentResource> result=new ArrayList<ExperimentResource>();
-		List<Resource> list = get(ResourceType.EXPERIMENT);
-		for (Resource resource : list) {
-			result.add((ExperimentResource) resource);
-		}
-		return result;
+		return getExperiments(-1, -1, null, null);
 	}
 
     /**
+     * Method to get list of experiments of user with pagination and ordering
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentResource> getExperiments(int limit, int offset, Object orderByIdentifier,
+                                                   ResultOrderType resultOrderType) throws RegistryException{
+        List<ExperimentResource> result=new ArrayList<ExperimentResource>();
+        List<Resource> list = get(ResourceType.EXPERIMENT, limit, offset, orderByIdentifier, resultOrderType);
+        for (Resource resource : list) {
+            result.add((ExperimentResource) resource);
+        }
+        return result;
+    }
+
+    /**
      *
      * @param experimentId  experiment name
      */
@@ -460,7 +530,7 @@ public class WorkerResource extends AbstractResource {
      * @throws RegistryException
      */
     public List<ProjectResource> searchProjects (Map<String, String> filters) throws RegistryException{
-        return searchProjectsWithPagination(filters, -1, -1, null, null);
+        return searchProjects(filters, -1, -1, null, null);
     }
 
     /**
@@ -477,8 +547,8 @@ public class WorkerResource extends AbstractResource {
      * @return
      * @throws RegistryException
      */
-    public List<ProjectResource> searchProjectsWithPagination(Map<String, String> filters, int limit,
-        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+    public List<ProjectResource> searchProjects(Map<String, String> filters, int limit,
+             int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
         List<ProjectResource> result = new ArrayList<ProjectResource>();
         EntityManager em = null;
         try {
@@ -502,7 +572,7 @@ public class WorkerResource extends AbstractResource {
 
             //ordering
             if( orderByIdentifier != null && resultOrderType != null
-                    && orderByIdentifier.equals(ProjectConstants.CREATION_TIME)){
+                    && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME)){
                 String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
                 query += " ORDER BY p." + ProjectConstants.CREATION_TIME + " " + order;
             }
@@ -549,7 +619,7 @@ public class WorkerResource extends AbstractResource {
      * @throws RegistryException
      */
     public List<ExperimentResource> searchExperiments (Map<String, String> filters) throws RegistryException{
-        return searchExperimentsWithPagination(filters, -1, -1, null, null);
+        return searchExperiments(filters, -1, -1, null, null);
     }
 
     /**
@@ -565,8 +635,8 @@ public class WorkerResource extends AbstractResource {
      * @return
      * @throws RegistryException
      */
-    public List<ExperimentResource> searchExperimentsWithPagination(Map<String, String> filters, int limit,
-        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
+    public List<ExperimentResource> searchExperiments(Map<String, String> filters, int limit,
+                                                      int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException {
 
         List<ExperimentResource> result = new ArrayList<ExperimentResource>();
         EntityManager em = null;
@@ -579,6 +649,8 @@ public class WorkerResource extends AbstractResource {
                         query += "e." + field + "= '" + filterVal + "' AND ";
                     }else if (field.equals(ExperimentConstants.GATEWAY_ID)) {
                         query += "e." + field + "= '" + filterVal + "' AND ";
+                    } else if (field.equals(ExperimentConstants.PROJECT_ID)) {
+                        query += "e." + field + "= '" + filterVal + "' AND ";
                     } else {
                         if (filterVal.contains("*")){
                             filterVal = filterVal.replaceAll("\\*", "");
@@ -591,7 +663,7 @@ public class WorkerResource extends AbstractResource {
 
             //ordering
             if( orderByIdentifier != null && resultOrderType != null
-                    && orderByIdentifier.equals(ExperimentConstants.CREATION_TIME)){
+                    && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)){
                 String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
                 query += " ORDER BY e." + ExperimentConstants.CREATION_TIME + " " + order;
             }
@@ -630,17 +702,75 @@ public class WorkerResource extends AbstractResource {
         return result;
     }
 
-    public List<ExperimentResource> searchExperimentsByState (String experimentState) throws RegistryException{
+    /**
+     * Method to get experiments by state
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentResource> searchExperimentsByState (Map<String, String> filters) throws RegistryException{
+        return searchExperimentsByState(filters, -1, -1, null, null);
+    }
+
+    /**
+     * Method to get experiments of the given state with pagination and ordering
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentResource> searchExperimentsByState (Map<String, String> filters, int limit, int offset,
+            Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException{
         List<ExperimentResource> result = new ArrayList<ExperimentResource>();
         EntityManager em = null;
         try {
+            String experimentState = ExperimentState.valueOf(filters.get(StatusConstants.STATE)).toString();
             String query = "SELECT e FROM Status s " +
                     "JOIN s.experiment e " +
                     "WHERE s.state='" + experimentState +  "' " +
-                    "AND s.statusType='" + StatusType.EXPERIMENT + "'";
+                    "AND s.statusType='" + StatusType.EXPERIMENT + "' AND ";
+
+            filters.remove(StatusConstants.STATE);
+            if (filters.size() != 0) {
+                for (String field : filters.keySet()) {
+                    String filterVal = filters.get(field);
+                    if (field.equals(ExperimentConstants.EXECUTION_USER)) {
+                        query += "e." + field + "= '" + filterVal + "' AND ";
+                    }else if (field.equals(ExperimentConstants.GATEWAY_ID)) {
+                        query += "e." + field + "= '" + filterVal + "' AND ";
+                    } else if (field.equals(ExperimentConstants.PROJECT_ID)) {
+                        query += "e." + field + "= '" + filterVal + "' AND ";
+                    } else {
+                        if (filterVal.contains("*")){
+                            filterVal = filterVal.replaceAll("\\*", "");
+                        }
+                        query += "e." + field + " LIKE '%" + filterVal + "%' AND ";
+                    }
+                }
+            }
+            query = query.substring(0, query.length() - 5);
+
+            //ordering
+            if( orderByIdentifier != null && resultOrderType != null
+                    && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)){
+                String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
+                query += " ORDER BY e." + ExperimentConstants.CREATION_TIME + " " + order;
+            }
+
             em = ResourceUtils.getEntityManager();
             em.getTransaction().begin();
-            Query q = em.createQuery(query);
+            Query q;
+
+            //pagination
+            if(offset>=0 && limit >=0){
+                q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
+            }else{
+                q = em.createQuery(query);
+            }
+
             List resultList = q.getResultList();
             for (Object o : resultList) {
                 Experiment experiment = (Experiment) o;
@@ -663,16 +793,60 @@ public class WorkerResource extends AbstractResource {
         return result;
     }
 
+    /**
+     * Search experiments from creation time between interval. Returns all results
+     * @param fromTime
+     * @param toTime
+     * @return
+     * @throws RegistryException
+     */
     public List<ExperimentResource> searchExperimentsByCreationTime (Timestamp fromTime, Timestamp toTime) throws RegistryException{
+        return  searchExperimentsByCreationTime(fromTime, toTime, -1, -1, null, null);
+    }
+
+
+    /**
+     * Search experiments from creation time between interval. Results are ordered creation time DESC.
+     * Supports pagination
+     *
+     * @param fromTime
+     * @param toTime
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentResource> searchExperimentsByCreationTime(
+            Timestamp fromTime, Timestamp toTime, int limit, int offset, Object orderByIdentifier,
+            ResultOrderType resultOrderType) throws RegistryException{
+
         List<ExperimentResource> result = new ArrayList<ExperimentResource>();
         EntityManager em = null;
         try {
             String query = "SELECT e FROM Experiment e " +
                     "WHERE e.creationTime > '" + fromTime +  "' " +
                     "AND e.creationTime <'" + toTime + "'";
+
+            //ordering
+            if( orderByIdentifier != null && resultOrderType != null
+                    && orderByIdentifier.equals(Constants.FieldConstants.ExperimentConstants.CREATION_TIME)){
+                String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
+                query += " ORDER BY e." + ExperimentConstants.CREATION_TIME + " " + order;
+            }
+
             em = ResourceUtils.getEntityManager();
             em.getTransaction().begin();
-            Query q = em.createQuery(query);
+            Query q;
+
+            //pagination
+            if(offset>=0 && limit >=0){
+                q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
+            }else{
+                q = em.createQuery(query);
+            }
+
             List resultList = q.getResultList();
             for (Object o : resultList) {
                 Experiment experiment = (Experiment) o;

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/utils/QueryGenerator.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/utils/QueryGenerator.java b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/utils/QueryGenerator.java
index 56594e0..b0ebe45 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/utils/QueryGenerator.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/utils/QueryGenerator.java
@@ -21,11 +21,12 @@
 
 package org.apache.airavata.persistance.registry.jpa.utils;
 
-import java.util.HashMap;
-import java.util.Map;
+import org.apache.airavata.registry.cpi.ResultOrderType;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
+import java.util.HashMap;
+import java.util.Map;
 
 public class QueryGenerator {
 	private String tableName;
@@ -58,12 +59,32 @@ public class QueryGenerator {
 	public void setParameter(String colName, Object matchValue){
 		addMatch(colName, matchValue);
 	}
-	
+
+    /**
+     * Select query
+     * @param entityManager
+     * @return
+     */
 	public Query selectQuery(EntityManager entityManager){
         String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ;
         return generateQueryWithParameters(entityManager, queryString);
     }
 
+    /**
+     * Select query with pagination
+     * @param entityManager
+     * @param orderByColumn
+     * @param resultOrderType
+     * @return
+     */
+    public Query selectQuery(EntityManager entityManager, String orderByColumn,
+                             ResultOrderType resultOrderType){
+        String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
+        String orderByClause = " ORDER BY " + SELECT_OBJ + "." + orderByColumn + " " + order;
+        String queryString="SELECT "+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ;
+        return generateQueryWithParameters(entityManager, queryString, orderByClause);
+    }
+
 //    public Query countQuery(EntityManager entityManager){
 //        SELECT COUNT(p.host_descriptor_ID) FROM Host_Descriptor p WHERE p.gateway_name =:gate_ID and p.host_descriptor_ID =:host_desc_name")
 //        String queryString="SELECT COUNT("+ SELECT_OBJ + " FROM " +getTableName()+" "+TABLE_OBJ;
@@ -77,25 +98,31 @@ public class QueryGenerator {
 
 	private Query generateQueryWithParameters(EntityManager entityManager,
 			String queryString) {
-		Map<String,Object> queryParameters=new HashMap<String, Object>();
-		if (matches.size()>0){
-			String matchString = "";
-			int paramCount=0;
-			for (String colName : matches.keySet()) {
-				String paramName="param"+paramCount;
-				queryParameters.put(paramName, matches.get(colName));
-				if (!matchString.equals("")){
-					matchString+=" AND ";
-				}
-				matchString+=TABLE_OBJ+"."+colName+" =:"+paramName;
-				paramCount++;
-			}
-			queryString+=" WHERE "+matchString;
-		}
-		Query query = entityManager.createQuery(queryString);
-		for (String paramName : queryParameters.keySet()) {
-			query.setParameter(paramName, queryParameters.get(paramName));
-		}
-		return query;
+		return generateQueryWithParameters(entityManager, queryString, "");
 	}
+
+    private Query generateQueryWithParameters(EntityManager entityManager,
+                                              String queryString, String orderByClause) {
+        Map<String,Object> queryParameters=new HashMap<String, Object>();
+        if (matches.size()>0){
+            String matchString = "";
+            int paramCount=0;
+            for (String colName : matches.keySet()) {
+                String paramName="param"+paramCount;
+                queryParameters.put(paramName, matches.get(colName));
+                if (!matchString.equals("")){
+                    matchString+=" AND ";
+                }
+                matchString+=TABLE_OBJ+"."+colName+" =:"+paramName;
+                paramCount++;
+            }
+            queryString+=" WHERE "+matchString;
+        }
+        queryString += orderByClause;
+        Query query = entityManager.createQuery(queryString);
+        for (String paramName : queryParameters.keySet()) {
+            query.setParameter(paramName, queryParameters.get(paramName));
+        }
+        return query;
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/9f6e30e4/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java
index 17f4e71..1a78b1e 100644
--- a/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java
@@ -29,7 +29,6 @@ import org.apache.airavata.model.workspace.experiment.Experiment;
 import org.apache.airavata.model.workspace.experiment.ExperimentSummary;
 import org.apache.airavata.model.workspace.experiment.UserConfigurationData;
 import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
-import org.apache.airavata.persistance.registry.jpa.resources.AbstractResource;
 import org.apache.airavata.persistance.registry.jpa.util.Initialize;
 import org.apache.airavata.registry.cpi.*;
 import org.apache.airavata.registry.cpi.utils.Constants;
@@ -89,7 +88,7 @@ public class RegistryUseCaseTest {
             Assert.assertEquals(updatedProject.getName(), retrievedProject.getName());
             Assert.assertEquals(updatedProject.getDescription(), retrievedProject.getDescription());
             Assert.assertNotNull(retrievedProject.getCreationTime());
-            //created users should be in the shared users list
+            //created user should be in the shared users list
             Assert.assertTrue(retrievedProject.getSharedUsers().size()==1);
 
             //creating more projects for the same user
@@ -149,8 +148,8 @@ public class RegistryUseCaseTest {
             //search projects with pagination
             filters = new HashMap<String, String>();
             filters.put(Constants.FieldConstants.ProjectConstants.OWNER, "TestUser"+TAG);
-            list = registry.searchWithPagination(RegistryModelType.PROJECT, filters, 2, 2,
-                    AbstractResource.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
+            list = registry.search(RegistryModelType.PROJECT, filters, 2, 2,
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
             Assert.assertTrue(list.size()==2);
             Project project1 = (Project)list.get(0);
             Project project2 = (Project)list.get(1);
@@ -236,7 +235,7 @@ public class RegistryUseCaseTest {
             experiment.addToExperimentInputs(inputDataObjectType);
 
             String experimentId2 = (String)registry.add(ParentDataType.EXPERIMENT, experiment, gatewayId);
-            Assert.assertNotNull(experimentId1);
+            Assert.assertNotNull(experimentId2);
 
             experiment = new Experiment();
             experiment.setProjectID(projectId1);
@@ -248,7 +247,7 @@ public class RegistryUseCaseTest {
             experiment.addToExperimentInputs(inputDataObjectType);
 
             String experimentId3 = (String)registry.add(ParentDataType.EXPERIMENT, experiment, gatewayId);
-            Assert.assertNotNull(experimentId1);
+            Assert.assertNotNull(experimentId3);
 
             //searching experiments by name
             Map<String, String> filters = new HashMap<String, String>();
@@ -274,8 +273,8 @@ public class RegistryUseCaseTest {
             filters = new HashMap<String, String>();
             filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, "TestUser" + TAG);
             filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
-            list = registry.searchWithPagination(RegistryModelType.EXPERIMENT, filters, 2, 1,
-                    AbstractResource.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
+            list = registry.search(RegistryModelType.EXPERIMENT, filters, 2, 1,
+                    Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             Assert.assertTrue(list.size()==2);
             ExperimentSummary exp1 = (ExperimentSummary)list.get(0);
             ExperimentSummary exp2 = (ExperimentSummary)list.get(1);


Mime
View raw message