airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sma...@apache.org
Subject [1/3] airavata git commit: Adding searchWithPagination support for the RegistryCPI and RegistryImpl
Date Sun, 26 Apr 2015 04:12:24 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 851aa6274 -> 7e3478e58


Adding searchWithPagination support for the RegistryCPI and RegistryImpl


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

Branch: refs/heads/master
Commit: cb600a17e76d2d11e64079b3ef7ae1b3ce30c90a
Parents: cf82465
Author: Supun Nakandala <supun.nakandala@gmail.com>
Authored: Sun Apr 26 07:36:04 2015 +0530
Committer: Supun Nakandala <supun.nakandala@gmail.com>
Committed: Sun Apr 26 07:36:04 2015 +0530

----------------------------------------------------------------------
 .../airavata-jpa-registry/bin/airavata.log      |   8 +
 .../registry/jpa/impl/ExperimentRegistry.java   |  31 +-
 .../registry/jpa/impl/LoggingRegistryImpl.java  |   5 +
 .../registry/jpa/impl/ProjectRegistry.java      |  54 +++-
 .../registry/jpa/impl/RegistryImpl.java         |  34 ++-
 .../jpa/resources/AbstractResource.java         |   7 +-
 .../registry/jpa/resources/WorkerResource.java  |  95 +++++-
 .../registry/jpa/RegistryUseCaseTest.java       | 290 +++++++++++++++++++
 .../apache/airavata/registry/cpi/Registry.java  |  16 +
 .../airavata/registry/cpi/ResultOrderType.java  |  29 ++
 10 files changed, 547 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/modules/registry/airavata-jpa-registry/bin/airavata.log
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/bin/airavata.log b/modules/registry/airavata-jpa-registry/bin/airavata.log
new file mode 100644
index 0000000..ab618a9
--- /dev/null
+++ b/modules/registry/airavata-jpa-registry/bin/airavata.log
@@ -0,0 +1,8 @@
+2014-06-28 01:14:45,167 [main] INFO  org.apache.airavata.common.utils.ApplicationSettings
 - Settings loaded from jar:file:/home/supun/Projects/airavata/modules/configuration/client/target/airavata-client-configuration-0.13-SNAPSHOT.jar!/airavata-client.properties
+2014-06-28 01:15:12,077 [main] INFO  org.apache.airavata.persistance.registry.jpa.util.Initialize
 - New Database created for Registry
+2014-12-19 22:36:21,197 [main] INFO  org.apache.airavata.common.utils.ApplicationSettings
 - Settings loaded from jar:file:/home/supun/Projects/airavata/modules/configuration/client/target/airavata-client-configuration-0.14-SNAPSHOT.jar!/airavata-client.properties
+2014-12-19 22:36:58,450 [main] INFO  org.apache.airavata.persistance.registry.jpa.util.Initialize
 - New Database created for Registry
+2015-01-06 04:25:20,025 [main] INFO  org.apache.airavata.common.utils.ApplicationSettings
 - Settings loaded from jar:file:/home/supun/Projects/airavata/modules/configuration/client/target/airavata-client-configuration-0.14-SNAPSHOT.jar!/airavata-client.properties
+2015-01-06 04:25:47,018 [main] INFO  org.apache.airavata.persistance.registry.jpa.util.Initialize
 - New Database created for Registry
+2015-04-18 01:18:17,329 [main] INFO  org.apache.airavata.common.utils.ApplicationSettings
 - Settings loaded from jar:file:/home/supun/airavata/modules/configuration/client/target/airavata-client-configuration-0.15-SNAPSHOT.jar!/airavata-client.properties
+2015-04-18 01:18:40,413 [main] INFO  org.apache.airavata.persistance.registry.jpa.util.Initialize
 - New Database created for Registry

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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 ec2c081..2ad9d66 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
@@ -35,6 +35,7 @@ import org.apache.airavata.persistance.registry.jpa.utils.ThriftDataModelConvers
 import org.apache.airavata.registry.cpi.CompositeIdentifier;
 import org.apache.airavata.registry.cpi.RegistryException;
 import org.apache.airavata.registry.cpi.RegistryModelType;
+import org.apache.airavata.registry.cpi.ResultOrderType;
 import org.apache.airavata.registry.cpi.utils.Constants;
 import org.apache.airavata.registry.cpi.utils.StatusType;
 
@@ -2795,7 +2796,33 @@ public class ExperimentRegistry {
         }
     }
 
+    /**
+     * To search experiments of user with the given filter criteria. All the matching results
will be sent.
+     * Results are not ordered in any order
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
     public List<ExperimentSummary> searchExperiments(Map<String, String> filters)
throws RegistryException {
+        return searchExperimentsWithPagination(filters, -1, -1, null, null);
+    }
+
+
+    /**
+     * To search the experiments of user with the given filter criteria and retrieve the
results with
+     * pagination support. Results can be ordered based on an identifier (i.e column) either
ASC or
+     * DESC.
+     *
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentSummary> searchExperimentsWithPagination(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>();
@@ -2827,7 +2854,8 @@ public class ExperimentRegistry {
                 if (fil.containsKey(AbstractResource.ExperimentConstants.APPLICATION_ID))
{
                     return searchExperimentsByApplication(fil);
                 } else {
-                    List<ExperimentResource> experimentResources = workerResource.searchExperiments(fil);
+                    List<ExperimentResource> experimentResources = workerResource
+                            .searchExperimentsWithPagination(fil, limit, offset, orderByIdentifier,
resultOrderType);
                     if (experimentResources != null && !experimentResources.isEmpty())
{
                         for (ExperimentResource ex : experimentResources) {
                             experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
@@ -2907,5 +2935,4 @@ public class ExperimentRegistry {
             throw new RegistryException(e);
         }
     }
-
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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 a288884..d7e9c0a 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
@@ -66,6 +66,11 @@ public class LoggingRegistryImpl implements Registry {
     }
 
     @Override
+    public List<Object> searchWithPagination(RegistryModelType dataType, Map<String,
String> filters, int limit, int offset, Object orderByIdentifier, ResultOrderType resultOrderType)
throws RegistryException {
+        return null;
+    }
+
+    @Override
     public Object getValue(RegistryModelType dataType, Object identifier, String field) throws
RegistryException {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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 ad2a32d..5bfcc3d 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
@@ -21,20 +21,20 @@
 
 package org.apache.airavata.persistance.registry.jpa.impl;
 
-import java.util.*;
-
 import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.workspace.Project;
-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.resources.*;
 import org.apache.airavata.persistance.registry.jpa.utils.ThriftDataModelConversion;
 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 java.util.*;
+
 public class ProjectRegistry {
     private GatewayResource gatewayResource;
     private WorkerResource workerResource;
@@ -49,7 +49,8 @@ public class ProjectRegistry {
         if (!gatewayResource.isExists(ResourceType.GATEWAY_WORKER, user.getUserName())){
             workerResource = ResourceUtils.addGatewayWorker(gatewayResource, user);
         }else {
-            workerResource = (WorkerResource)ResourceUtils.getWorker(gatewayResource.getGatewayId(),
user.getUserName());
+            workerResource = (WorkerResource)ResourceUtils.getWorker(gatewayResource.getGatewayId(),
+                    user.getUserName());
         }
     }
 
@@ -71,7 +72,8 @@ public class ProjectRegistry {
             WorkerResource worker = new WorkerResource(project.getOwner(), workerResource.getGateway());
             projectResource.setWorker(worker);
             projectResource.save();
-            ProjectUserResource resource = (ProjectUserResource)projectResource.create(ResourceType.PROJECT_USER);
+            ProjectUserResource resource = (ProjectUserResource)projectResource.create(
+                    ResourceType.PROJECT_USER);
             resource.setProjectId(project.getProjectID());
             resource.setUserName(project.getOwner());
             resource.save();
@@ -86,7 +88,8 @@ public class ProjectRegistry {
             List<String> sharedUsers = project.getSharedUsers();
             if (sharedUsers != null && !sharedUsers.isEmpty()){
                 for (String username : sharedUsers){
-                    ProjectUserResource pr = (ProjectUserResource)projectResource.create(ResourceType.PROJECT_USER);
+                    ProjectUserResource pr = (ProjectUserResource)projectResource.
+                            create(ResourceType.PROJECT_USER);
                     pr.setUserName(username);
                     pr.save();
                 }
@@ -114,12 +117,14 @@ public class ProjectRegistry {
             if (!gatewayResource.isExists(ResourceType.GATEWAY_WORKER, user.getUserName())){
                 workerResource = ResourceUtils.addGatewayWorker(gatewayResource, user);
             }else {
-                workerResource = (WorkerResource)ResourceUtils.getWorker(gatewayResource.getGatewayName(),
user.getUserName());
+                workerResource = (WorkerResource)ResourceUtils.getWorker(
+                        gatewayResource.getGatewayName(), user.getUserName());
             }
             WorkerResource worker = new WorkerResource(project.getOwner(), gatewayResource);
             existingProject.setWorker(worker);
             existingProject.save();
-            ProjectUserResource resource = (ProjectUserResource)existingProject.create(ResourceType.PROJECT_USER);
+            ProjectUserResource resource = (ProjectUserResource)existingProject.create(
+                    ResourceType.PROJECT_USER);
             resource.setProjectId(projectId);
             resource.setUserName(project.getOwner());
             resource.save();
@@ -134,7 +139,8 @@ public class ProjectRegistry {
             List<String> sharedUsers = project.getSharedUsers();
             if (sharedUsers != null && !sharedUsers.isEmpty()){
                 for (String username : sharedUsers){
-                    ProjectUserResource pr = (ProjectUserResource)existingProject.create(ResourceType.PROJECT_USER);
+                    ProjectUserResource pr = (ProjectUserResource)existingProject.create(
+                            ResourceType.PROJECT_USER);
                     pr.setUserName(username);
                     pr.save();
                 }
@@ -178,7 +184,32 @@ public class ProjectRegistry {
         return projects;
     }
 
+    /**
+     * To search projects of user with the given filter criteria. All the matching results
will be sent.
+     * Results are not ordered in any order
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
     public List<Project> searchProjects (Map<String, String> filters) throws
RegistryException{
+        return searchProjectsWithPagination(filters, -1, -1, null, null);
+    }
+
+    /**
+     * To search the projects of user with the given filter criteria and retrieve the results
with
+     * pagination support. Results can be ordered based on an identifier (i.e column) either
ASC or
+     * DESC.
+     *
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<Project> searchProjectsWithPagination(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>();
@@ -194,7 +225,8 @@ public class ProjectRegistry {
                         fil.put(AbstractResource.ProjectConstants.GATEWAY_ID, filters.get(field));
                     }
                 }
-                List<ProjectResource> projectResources = workerResource.searchProjects(fil);
+                List<ProjectResource> projectResources = workerResource
+                        .searchProjectsWithPagination(fil, limit, offset, orderByIdentifier,
resultOrderType);
                 if (projectResources != null && !projectResources.isEmpty()){
                     for (ProjectResource pr : projectResources){
                         projects.add(ThriftDataModelConversion.getProject(pr));
@@ -203,7 +235,7 @@ public class ProjectRegistry {
                 return projects;
             }catch (Exception e){
                 logger.error("Error while retrieving project from registry", e);
-               throw new RegistryException(e);
+                throw new RegistryException(e);
             }
         }
         return null;

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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 9dcf96f..a2f1e11 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
@@ -453,18 +453,48 @@ public class RegistryImpl implements Registry {
 
     }
 
+    /**
+     * 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
+     * @param filters filters is a map of field name and value that you need to use for search
filtration
+     * @return List of objects according to the given criteria
+     */
+    @Override
     public List<Object> search(RegistryModelType dataType, Map<String, String>
filters) throws RegistryException {
+        return searchWithPagination(dataType, filters, -1, -1, null, null);
+    }
+
+    /**
+     * This method is to retrieve list of objects with pagination according to a given criteria
sorted
+     * according by the specified  identified and specified ordering (i.e either ASC or DESC)
+     * @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 filters            filters is a map of field name and value that you need to
use for search filtration
+     * @param limit              amount of the results to be returned
+     * @param offset             offset of the results from the sorted list to be fetched
from
+     * @param orderByIdentifier  identifier (i.e the column) which will be used as the basis
to sort the results
+     * @param resultOrderType    The type of ordering (i.e ASC or DESC) that has to be used
when retrieving the results
+     * @return List of objects according to the given criteria
+     */
+    @Override
+    public List<Object> searchWithPagination(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.searchProjects(filters);
+                    List<Project> projectList
+                            = projectRegistry.searchProjectsWithPagination(filters, limit,
offset,
+                            orderByIdentifier, resultOrderType );
                     for (Project project : projectList ){
                         result.add(project);
                     }
                     return result;
                 case EXPERIMENT:
-                    List<ExperimentSummary> experimentSummaries = experimentRegistry.searchExperiments(filters);
+                    List<ExperimentSummary> experimentSummaries = experimentRegistry
+                            .searchExperimentsWithPagination(filters, limit, offset, orderByIdentifier,
+                                    resultOrderType );
                     for (ExperimentSummary ex : experimentSummaries){
                         result.add(ex);
                     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
index cb45087..e05d59d 100644
--- a/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
+++ b/modules/registry/airavata-jpa-registry/src/main/java/org/apache/airavata/persistance/registry/jpa/resources/AbstractResource.java
@@ -20,13 +20,13 @@
  */
 package org.apache.airavata.persistance.registry.jpa.resources;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.airavata.persistance.registry.jpa.Resource;
 import org.apache.airavata.persistance.registry.jpa.ResourceType;
 import org.apache.airavata.registry.cpi.RegistryException;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public abstract class AbstractResource implements Resource {
 	// table names
 	public static final String GATEWAY = "Gateway";
@@ -94,6 +94,7 @@ public abstract class AbstractResource implements Resource {
 		public static final String PROJECT_NAME = "project_name";
 		public static final String PROJECT_ID = "project_id";
 		public static final String DESCRIPTION = "description";
+        public static final String CREATION_TIME = "creationTime";
 	}
 
     // Project table

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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 2654596..dfa887f 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
@@ -26,6 +26,7 @@ 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.StatusType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -451,7 +452,33 @@ public class WorkerResource extends AbstractResource {
 		remove(ResourceType.EXPERIMENT, experimentId);
 	}
 
+    /**
+     * To search projects of user with the given filter criteria. All the matching results
will be sent.
+     * Results are not ordered in any order
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
     public List<ProjectResource> searchProjects (Map<String, String> filters)
throws RegistryException{
+        return searchProjectsWithPagination(filters, -1, -1, null, null);
+    }
+
+    /**
+     * To search the projects of user with the given filter criteria and retrieve the results
with
+     * pagination support. Results can be ordered based on an identifier (i.e column) either
ASC or
+     * DESC. But in the current implementation ordering is only supported based on the project
+     * creation time
+     *
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ProjectResource> searchProjectsWithPagination(Map<String, String>
filters, int limit,
+        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException
{
         List<ProjectResource> result = new ArrayList<ProjectResource>();
         EntityManager em = null;
         try {
@@ -472,13 +499,30 @@ public class WorkerResource extends AbstractResource {
                 }
             }
             query = query.substring(0, query.length() - 5);
+
+            //ordering
+            if( orderByIdentifier != null && resultOrderType != null
+                    && orderByIdentifier.equals(ProjectConstants.CREATION_TIME)){
+                String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
+                query += " ORDER BY p." + ProjectConstants.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) {
                 Project project = (Project) o;
-                ProjectResource projectResource = (ProjectResource) Utils.getResource(ResourceType.PROJECT,
project);
+                ProjectResource projectResource =
+                        (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
                 result.add(projectResource);
             }
             em.getTransaction().commit();
@@ -497,7 +541,33 @@ public class WorkerResource extends AbstractResource {
         return result;
     }
 
+    /**
+     * To search experiments of user with the given filter criteria. All the matching results
will be sent.
+     * Results are not ordered in any order
+     * @param filters
+     * @return
+     * @throws RegistryException
+     */
     public List<ExperimentResource> searchExperiments (Map<String, String> filters)
throws RegistryException{
+        return searchExperimentsWithPagination(filters, -1, -1, null, null);
+    }
+
+    /**
+     * To search the experiments of user with the given filter criteria and retrieve the
results with
+     * pagination support. Results can be ordered based on an identifier (i.e column) either
ASC or
+     * DESC. But in the current implementation ordering is only supported based on creationTime
+     *
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<ExperimentResource> searchExperimentsWithPagination(Map<String,
String> filters, int limit,
+        int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException
{
+
         List<ExperimentResource> result = new ArrayList<ExperimentResource>();
         EntityManager em = null;
         try {
@@ -518,13 +588,30 @@ public class WorkerResource extends AbstractResource {
                 }
             }
             query = query.substring(0, query.length() - 5);
+
+            //ordering
+            if( orderByIdentifier != null && resultOrderType != null
+                    && orderByIdentifier.equals(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;
-                ExperimentResource experimentResource = (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT,
experiment);
+                ExperimentResource experimentResource =
+                        (ExperimentResource) Utils.getResource(ResourceType.EXPERIMENT, experiment);
                 result.add(experimentResource);
             }
             em.getTransaction().commit();

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/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
new file mode 100644
index 0000000..17f4e71
--- /dev/null
+++ b/modules/registry/airavata-jpa-registry/src/test/java/org/apache/airavata/persistance/registry/jpa/RegistryUseCaseTest.java
@@ -0,0 +1,290 @@
+/*
+ *
+ * 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;
+
+import junit.framework.Assert;
+import org.apache.airavata.model.appcatalog.appinterface.InputDataObjectType;
+import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType;
+import org.apache.airavata.model.workspace.Project;
+import org.apache.airavata.model.workspace.experiment.ComputationalResourceScheduling;
+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;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * This class contains test cases for the RegistryImpl class which is the default registry
+ * implementation. These test cases are written from the perspective of the Airavata API
+ * such as creating/updating/deleting/searching projects and experiments etc.
+ */
+public class RegistryUseCaseTest {
+
+    private static Registry registry;
+    private static Initialize initialize;
+
+    @BeforeClass
+    public static void setupBeforeClass() throws RegistryException, SQLException {
+        initialize = new Initialize("registry-derby.sql");
+        initialize.initializeDB();
+        registry = RegistryFactory.getDefaultRegistry();
+    }
+
+    @Test
+    public void testProject(){
+        try {
+            String TAG = System.currentTimeMillis() + "";
+
+            String gatewayId = "default";
+
+            //testing the creation of a project
+            Project project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("TestProject"+TAG);
+            project.setDescription("This is a test project"+TAG);
+            String projectId1 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId1);
+
+            //testing the update of a project
+            Project updatedProject = new Project();
+            updatedProject.setProjectID(projectId1);
+            updatedProject.setOwner("TestUser"+TAG);
+            updatedProject.setName("UpdatedTestProject"+TAG);
+            updatedProject.setDescription("This is an updated test project"+TAG);
+            registry.update(RegistryModelType.PROJECT, updatedProject, projectId1);
+
+            //testing project retrieval
+            Project retrievedProject = (Project)registry.get(RegistryModelType.PROJECT, projectId1);
+            Assert.assertEquals(updatedProject.getProjectID(), retrievedProject.getProjectID());
+            Assert.assertEquals(updatedProject.getOwner(), retrievedProject.getOwner());
+            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
+            Assert.assertTrue(retrievedProject.getSharedUsers().size()==1);
+
+            //creating more projects for the same user
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Terrible"+TAG);
+            project.setDescription("This is a test project_2"+TAG);
+            String projectId2 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId2);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Funny"+TAG);
+            project.setDescription("This is a test project_3"+TAG);
+            String projectId3 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId3);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Stupid"+TAG);
+            project.setDescription("This is a test project_4"+TAG);
+            String projectId4 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId4);
+
+            project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("Project Boring"+TAG);
+            project.setDescription("This is a test project_5"+TAG);
+            String projectId5 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId5);
+
+            //test get all projects created by the user
+            List<Object> list = registry.get(RegistryModelType.PROJECT,
+                    Constants.FieldConstants.ProjectConstants.OWNER, "TestUser"+TAG);
+            Assert.assertTrue(list.size()==5);
+
+            //search project by project name
+            Map<String, String> filters = new HashMap<String, String>();
+            filters.put(Constants.FieldConstants.ProjectConstants.OWNER, "TestUser"+TAG);
+            filters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, "Terrible"+TAG);
+            list = registry.search(RegistryModelType.PROJECT, filters);
+            Assert.assertTrue(list.size()==1);
+
+            //search project by project description
+            filters = new HashMap<String, String>();
+            filters.put(Constants.FieldConstants.ProjectConstants.OWNER, "TestUser"+TAG);
+            filters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, "test project_2"+TAG);
+            list = registry.search(RegistryModelType.PROJECT, filters);
+            Assert.assertTrue(list.size()==1);
+
+            //search project with only ownername
+            filters = new HashMap<String, String>();
+            filters.put(Constants.FieldConstants.ProjectConstants.OWNER, "TestUser"+TAG);
+            list = registry.search(RegistryModelType.PROJECT, filters);
+            Assert.assertTrue(list.size()==5);
+
+            //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);
+            Assert.assertTrue(list.size()==2);
+            Project project1 = (Project)list.get(0);
+            Project project2 = (Project)list.get(1);
+            Assert.assertTrue(project1.getCreationTime()-project2.getCreationTime() >
0);
+        } catch (RegistryException e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testExperiment(){
+        try {
+            String TAG = System.currentTimeMillis() + "";
+
+            String gatewayId = "default";
+
+            //creating project
+            Project project = new Project();
+            project.setOwner("TestUser"+TAG);
+            project.setName("TestProject"+TAG);
+            project.setDescription("This is a test project"+TAG);
+            String projectId1 = (String)registry.add(ParentDataType.PROJECT, project, gatewayId);
+            Assert.assertNotNull(projectId1);
+
+            //creating sample echo experiment. assumes echo application is already defined
+            InputDataObjectType inputDataObjectType = new InputDataObjectType();
+            inputDataObjectType.setName("Input_to_Echo");
+            inputDataObjectType.setValue("Hello World");
+
+            ComputationalResourceScheduling scheduling = new ComputationalResourceScheduling();
+            scheduling.setResourceHostId(UUID.randomUUID().toString());
+            scheduling.setComputationalProjectAccount("TG-STA110014S");
+            scheduling.setTotalCPUCount(1);
+            scheduling.setNodeCount(1);
+            scheduling.setWallTimeLimit(15);
+            scheduling.setQueueName("normal");
+
+            UserConfigurationData userConfigurationData = new UserConfigurationData();
+            userConfigurationData.setAiravataAutoSchedule(false);
+            userConfigurationData.setOverrideManualScheduledParams(false);
+            userConfigurationData.setComputationalResourceScheduling(scheduling);
+
+            Experiment experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment"+TAG);
+            experiment.setDescription("Test 1 experiment");
+            experiment.setApplicationId(UUID.randomUUID().toString());
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId1 = (String)registry.add(ParentDataType.EXPERIMENT, experiment,
gatewayId);
+            Assert.assertNotNull(experimentId1);
+
+            //retrieving the stored experiment
+            Experiment retrievedExperiment = (Experiment)registry.get(RegistryModelType.EXPERIMENT,
+                    experimentId1);
+            Assert.assertNotNull(retrievedExperiment);
+            Assert.assertEquals(retrievedExperiment.getProjectID(), experiment.getProjectID());
+            Assert.assertEquals(retrievedExperiment.getDescription(), experiment.getDescription());
+            Assert.assertEquals(retrievedExperiment.getName(), experiment.getName());
+            Assert.assertEquals(retrievedExperiment.getApplicationId(), experiment.getApplicationId());
+            Assert.assertNotNull(retrievedExperiment.getUserConfigurationData());
+            Assert.assertNotNull(retrievedExperiment.getExperimentInputs());
+
+            //updating an existing experiment
+            experiment.setName("NewExperimentName"+TAG);
+            OutputDataObjectType outputDataObjectType = new OutputDataObjectType();
+            outputDataObjectType.setName("Output_to_Echo");
+            outputDataObjectType.setValue("Hello World");
+            experiment.addToExperimentOutputs(outputDataObjectType);
+            registry.update(RegistryModelType.EXPERIMENT, experiment, experimentId1);
+
+            //creating more experiments
+            experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment2" + TAG);
+            experiment.setDescription("Test 2 experiment");
+            experiment.setApplicationId(UUID.randomUUID().toString());
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId2 = (String)registry.add(ParentDataType.EXPERIMENT, experiment,
gatewayId);
+            Assert.assertNotNull(experimentId1);
+
+            experiment = new Experiment();
+            experiment.setProjectID(projectId1);
+            experiment.setUserName("TestUser" + TAG);
+            experiment.setName("TestExperiment3"+TAG);
+            experiment.setDescription("Test 3 experiment");
+            experiment.setApplicationId(UUID.randomUUID().toString());
+            experiment.setUserConfigurationData(userConfigurationData);
+            experiment.addToExperimentInputs(inputDataObjectType);
+
+            String experimentId3 = (String)registry.add(ParentDataType.EXPERIMENT, experiment,
gatewayId);
+            Assert.assertNotNull(experimentId1);
+
+            //searching experiments by name
+            Map<String, String> filters = new HashMap<String, String>();
+            filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, "TestUser"
+ TAG);
+            filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
+            filters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, "Experiment2");
+            List<Object> results = registry.search(RegistryModelType.EXPERIMENT, filters);
+            Assert.assertTrue(results.size()==1);
+
+            //retrieving all experiments in project
+            List<Object> list = registry.get(RegistryModelType.EXPERIMENT,
+                    Constants.FieldConstants.ExperimentConstants.PROJECT_ID, projectId1);
+            Assert.assertTrue(list.size()==3);
+
+            //searching all user experiments
+            filters = new HashMap<String, String>();
+            filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, "TestUser"
+ TAG);
+            filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY, gatewayId);
+            list = registry.search(RegistryModelType.EXPERIMENT, filters);
+            Assert.assertTrue(list.size()==3);
+
+            //searching user experiemets with pagination
+            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);
+            Assert.assertTrue(list.size()==2);
+            ExperimentSummary exp1 = (ExperimentSummary)list.get(0);
+            ExperimentSummary exp2 = (ExperimentSummary)list.get(1);
+            Assert.assertTrue(exp1.getCreationTime()-exp2.getCreationTime() > 0);
+
+        } catch (RegistryException e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java
index 6d0ad4f..c0bb059 100644
--- a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/Registry.java
@@ -112,6 +112,22 @@ public interface Registry {
     public List<Object> search(RegistryModelType dataType, Map<String, String>
filters) throws RegistryException;
 
     /**
+     * This method is to retrieve list of objects with pagination according to a given criteria
sorted
+     * according by the specified  identified and specified ordering (i.e either ASC or DESC)
+     * @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 filters            filters is a map of field name and value that you need to
use for search filtration
+     * @param limit              amount of the results to be returned
+     * @param offset             offset of the results from the sorted list to be fetched
from
+     * @param orderByIdentifier  identifier (i.e the column) which will be used as the basis
to sort the results
+     * @param resultOrderType    The type of ordering (i.e ASC or DESC) that has to be used
when retrieving the results
+     * @return List of objects according to the given criteria
+     */
+    public List<Object> searchWithPagination(RegistryModelType dataType, Map<String,
String> filters,
+                                             int limit, int offset, Object orderByIdentifier,
+                                             ResultOrderType resultOrderType) throws RegistryException;
+
+    /**
      * This method is to retrieve a specific value for a given field.
      * @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

http://git-wip-us.apache.org/repos/asf/airavata/blob/cb600a17/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ResultOrderType.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ResultOrderType.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ResultOrderType.java
new file mode 100644
index 0000000..3988094
--- /dev/null
+++ b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ResultOrderType.java
@@ -0,0 +1,29 @@
+package org.apache.airavata.registry.cpi;/*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Enum to specify the order type for a specific column when
+ * retrieving results
+ */
+public enum ResultOrderType {
+    ASC,
+    DESC
+}


Mime
View raw message