adding searchAllAccessible ExperimentCatalogAPI

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

Branch: refs/heads/master
Commit: 10b7b128515eb5e7cf27f4686815e7365d2fca21
Parents: 69e71fb
Author: scnakandala <[email protected]>
Authored: Mon Jun 27 15:41:13 2016 -0400
Committer: scnakandala <[email protected]>
Committed: Mon Jun 27 15:41:13 2016 -0400

----------------------------------------------------------------------
 .../catalog/impl/ExperimentCatalogImpl.java     | 45 +++++++++++++++++
 .../catalog/impl/ExperimentRegistry.java        | 52 ++++++++++++++++++++
 .../catalog/impl/ProjectRegistry.java           | 47 ++++++++++++++++++
 .../registry/cpi/ExperimentCatalog.java         | 16 ++++++
 4 files changed, 160 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/10b7b128/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
index a56e10b..3bc0b92 100644
--- 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
+++ 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentCatalogImpl.java
@@ -546,6 +546,51 @@ public class ExperimentCatalogImpl implements 
ExperimentCatalog {
     }
 
     /**
+     * This method search all the accessible resources given the set of ids of 
all accessible resource IDs.
+     *
+     * @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 accessibleIds     list of string IDs of all accessible resources
+     * @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> searchAllAccessible(ExperimentCatalogModelType 
dataType, List<String> accessibleIds, 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.searchAllAccessibleProjects(accessibleIds, filters, limit, 
offset,
+                            orderByIdentifier, resultOrderType);
+                    for (Project project : projectList ){
+                        result.add(project);
+                    }
+                    return result;
+                case EXPERIMENT:
+                    List<ExperimentSummaryModel> experimentSummaries = 
experimentRegistry
+                            .searchAllAccessibleExperiments(accessibleIds, 
filters, limit, offset, orderByIdentifier,
+                                    resultOrderType);
+                    for (ExperimentSummaryModel ex : experimentSummaries){
+                        result.add(ex);
+                    }
+                    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 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

http://git-wip-us.apache.org/repos/asf/airavata/blob/10b7b128/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
----------------------------------------------------------------------
diff --git 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
index 3db46f1..79e3c66 100644
--- 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
+++ 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ExperimentRegistry.java
@@ -1367,6 +1367,58 @@ public class ExperimentRegistry {
         return null;
     }
 
+    public List<ExperimentSummaryModel> 
searchAllAccessibleExperiments(List<String> accessibleIds, 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<ExperimentSummaryModel> experimentSummaries = new 
ArrayList<>();
+            long fromTime = 0;
+            long toTime = 0;
+            try {
+                for (String field : filters.keySet()) {
+                    if 
(field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.EXPERIMENT_NAME, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.USER_NAME)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.USER_NAME, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.PROJECT_ID)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.PROJECT_ID, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.GATEWAY_ID, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.DESCRIPTION)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.DESCRIPTION, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID)) {
+                        
fil.put(AbstractExpCatResource.ExperimentConstants.EXECUTION_ID, 
filters.get(field));
+                    } else if 
(field.equals(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS)) {
+                        
fil.put(AbstractExpCatResource.ExperimentStatusConstants.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)) {
+                        toTime = Long.parseLong(filters.get(field));
+                    }
+                }
+                List<ExperimentSummaryResource> experimentSummaryResources;
+                if (fromTime != 0 && toTime != 0) {
+                    experimentSummaryResources = 
workerResource.searchExperiments(new Timestamp(fromTime), new 
Timestamp(toTime), fil
+                            ,limit , offset, orderByIdentifier, 
resultOrderType);
+                } else {
+                    experimentSummaryResources = workerResource
+                            .searchExperiments(null, null, fil, limit, offset, 
orderByIdentifier, resultOrderType);
+                }
+                if (experimentSummaryResources != null && 
!experimentSummaryResources.isEmpty()) {
+                    for (ExperimentSummaryResource ex : 
experimentSummaryResources) {
+                        
experimentSummaries.add(ThriftDataModelConversion.getExperimentSummary(ex));
+                    }
+                }
+                return experimentSummaries;
+
+            } catch (Exception e) {
+                logger.error("Error while retrieving experiment summary from 
registry", e);
+                throw new RegistryException(e);
+            }
+        }
+        return null;
+    }
+
     public ExperimentStatistics getExperimentStatistics(Map<String,String> 
filters) throws RegistryException {
         try {
             ExperimentStatistics experimentStatistics = new 
ExperimentStatistics();

http://git-wip-us.apache.org/repos/asf/airavata/blob/10b7b128/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
----------------------------------------------------------------------
diff --git 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
index ef44c64..8861b68 100644
--- 
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
+++ 
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/impl/ProjectRegistry.java
@@ -262,6 +262,53 @@ public class ProjectRegistry {
         return null;
     }
 
+    /**
+     * To search the projects where the user have access(owner or shared with) 
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 accessibleIds
+     * @param filters
+     * @param limit
+     * @param offset
+     * @param orderByIdentifier
+     * @param resultOrderType
+     * @return
+     * @throws RegistryException
+     */
+    public List<Project> searchAllAccessibleProjects(List<String> 
accessibleIds, 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>();
+            try {
+                for (String field : filters.keySet()){
+                    if 
(field.equals(Constants.FieldConstants.ProjectConstants.PROJECT_NAME)){
+                        
fil.put(AbstractExpCatResource.ProjectConstants.PROJECT_NAME, 
filters.get(field));
+                    }else if 
(field.equals(Constants.FieldConstants.ProjectConstants.OWNER)){
+                        
fil.put(AbstractExpCatResource.ProjectConstants.USERNAME, filters.get(field));
+                    }else if 
(field.equals(Constants.FieldConstants.ProjectConstants.DESCRIPTION)){
+                        
fil.put(AbstractExpCatResource.ProjectConstants.DESCRIPTION, 
filters.get(field));
+                    }else if 
(field.equals(Constants.FieldConstants.ProjectConstants.GATEWAY_ID)){
+                        
fil.put(AbstractExpCatResource.ProjectConstants.GATEWAY_ID, filters.get(field));
+                    }
+                }
+                List<ProjectResource> projectResources = workerResource
+                        .searchProjects(fil, limit, offset, orderByIdentifier, 
resultOrderType);
+                if (projectResources != null && !projectResources.isEmpty()){
+                    for (ProjectResource pr : projectResources){
+                        projects.add(ThriftDataModelConversion.getProject(pr));
+                    }
+                }
+                return projects;
+            }catch (Exception e){
+                logger.error("Error while retrieving project from registry", 
e);
+                throw new RegistryException(e);
+            }
+        }
+        return null;
+    }
+
     public List<String> getProjectIDs (String fieldName, Object value) throws 
RegistryException{
         List<String> projectIds = new ArrayList<String>();
         try {

http://git-wip-us.apache.org/repos/asf/airavata/blob/10b7b128/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ExperimentCatalog.java
----------------------------------------------------------------------
diff --git 
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ExperimentCatalog.java
 
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ExperimentCatalog.java
index d9df6a9..b9b5dd5 100644
--- 
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ExperimentCatalog.java
+++ 
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ExperimentCatalog.java
@@ -145,6 +145,22 @@ public interface ExperimentCatalog {
                                              ResultOrderType resultOrderType) 
throws RegistryException;
 
     /**
+     * This method search all the accessible resources given the set of ids of 
all accessible resource IDs.
+     * @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 accessibleIds      list of string IDs of all accessible resources
+     * @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> searchAllAccessible(ExperimentCatalogModelType 
dataType,List<String> accessibleIds, 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

Reply via email to