airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [05/31] airavata git commit: code refactoring
Date Wed, 13 Jul 2016 05:33:12 GMT
code refactoring


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

Branch: refs/heads/grouper-integration
Commit: 4260622609004be83f77245ece7c6c64de240b19
Parents: 2d398cf
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Fri Jul 8 18:53:39 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Fri Jul 8 18:53:39 2016 -0400

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   | 29 ++--------
 .../catalog/impl/ExperimentCatalogImpl.java     | 45 ----------------
 .../catalog/impl/ExperimentRegistry.java        | 56 +-------------------
 .../catalog/impl/ProjectRegistry.java           | 47 ----------------
 .../catalog/resources/WorkerResource.java       | 10 +---
 .../registry/cpi/ExperimentCatalog.java         | 16 ------
 6 files changed, 8 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/42606226/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index 1a7ee72..a0ae34c 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -798,6 +798,7 @@ public class AiravataServerHandler implements Airavata.Iface {
             List<Project> projects = new ArrayList<Project>();
             experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId);
             Map<String, String> regFilters = new HashMap<String, String>();
+            regFilters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
             regFilters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
             for(Map.Entry<ProjectSearchFields, String> entry : filters.entrySet())
             {
@@ -807,18 +808,8 @@ public class AiravataServerHandler implements Airavata.Iface {
                     regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION,
entry.getValue());
                 }
             }
-
-            //FIXME - These accessible IDs should come from grouper
-            Map<String, String> temp = new HashMap();
-            temp.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
-            temp.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
-            List<Object> allUserProjects = experimentCatalog.search(ExperimentCatalogModelType.PROJECT,
temp, -1,
-                    0, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
-            List<String> accessibleProjIds = new ArrayList<>();
-            allUserProjects.stream().forEach(e->accessibleProjIds.add(((Project) e).getProjectID()));
-
-            List<Object> results = experimentCatalog.searchAllAccessible(ExperimentCatalogModelType.PROJECT,
accessibleProjIds,
-                    regFilters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME,
ResultOrderType.DESC);
+            List<Object> results = experimentCatalog.search(ExperimentCatalogModelType.PROJECT,
regFilters, limit, offset,
+                    Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 projects.add((Project)object);
             }
@@ -876,6 +867,7 @@ public class AiravataServerHandler implements Airavata.Iface {
             List<ExperimentSummaryModel> summaries = new ArrayList<ExperimentSummaryModel>();
             experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId);
             Map<String, String> regFilters = new HashMap();
+            regFilters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
             regFilters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId);
             for(Map.Entry<ExperimentSearchFields, String> entry : filters.entrySet())
             {
@@ -895,18 +887,7 @@ public class AiravataServerHandler implements Airavata.Iface {
                     regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID,
entry.getValue());
                 }
             }
-
-            //FIXME - These accessible IDs should come from grouper
-            Map<String, String> temp = new HashMap();
-            temp.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
-            temp.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId);
-            List<Object> allUserExperiments = experimentCatalog.search(ExperimentCatalogModelType.EXPERIMENT,
temp, -1,
-                    0, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
-            List<String> accessibleExpIds = new ArrayList<>();
-            allUserExperiments.stream().forEach(e->accessibleExpIds.add(((ExperimentSummaryModel)
e).getExperimentId()));
-
-            List<Object> results = experimentCatalog.searchAllAccessible(ExperimentCatalogModelType.EXPERIMENT,
-                    accessibleExpIds, regFilters, limit,
+            List<Object> results = experimentCatalog.search(ExperimentCatalogModelType.EXPERIMENT,
regFilters, limit,
                     offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
             for (Object object : results) {
                 summaries.add((ExperimentSummaryModel) object);

http://git-wip-us.apache.org/repos/asf/airavata/blob/42606226/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 3bc0b92..a56e10b 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,51 +546,6 @@ 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/42606226/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 dd555b1..3db46f1 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
@@ -1346,63 +1346,11 @@ public class ExperimentRegistry {
                 }
                 List<ExperimentSummaryResource> experimentSummaryResources;
                 if (fromTime != 0 && toTime != 0) {
-                    experimentSummaryResources = workerResource.searchExperiments(null, new
Timestamp(fromTime), new Timestamp(toTime), fil
+                    experimentSummaryResources = workerResource.searchExperiments(new Timestamp(fromTime),
new Timestamp(toTime), fil
                             ,limit , offset, orderByIdentifier, resultOrderType);
                 } else {
                     experimentSummaryResources = workerResource
-                            .searchExperiments(null, 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 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(accessibleIds,
new Timestamp(fromTime), new Timestamp(toTime), fil
-                            ,limit , offset, orderByIdentifier, resultOrderType);
-                } else {
-                    experimentSummaryResources = workerResource
-                            .searchExperiments(accessibleIds, null, null, fil, limit, offset,
orderByIdentifier, resultOrderType);
+                            .searchExperiments(null, null, fil, limit, offset, orderByIdentifier,
resultOrderType);
                 }
                 if (experimentSummaryResources != null && !experimentSummaryResources.isEmpty())
{
                     for (ExperimentSummaryResource ex : experimentSummaryResources) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/42606226/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 9e16daa..7cc676c 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,53 +262,6 @@ 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, accessibleIds, 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/42606226/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerResource.java
----------------------------------------------------------------------
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerResource.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerResource.java
index dec4e7f..1e8fa4d 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerResource.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/experiment/catalog/resources/WorkerResource.java
@@ -599,7 +599,7 @@ public class WorkerResource extends AbstractExpCatResource {
      * @return
      * @throws org.apache.airavata.registry.cpi.RegistryException
      */
-    public List<ExperimentSummaryResource> searchExperiments(List<String> accessibleIds,
Timestamp fromTime, Timestamp toTime, Map<String, String> filters, int limit,
+    public List<ExperimentSummaryResource> searchExperiments(Timestamp fromTime, Timestamp
toTime, Map<String, String> filters, int limit,
                                                              int offset, Object orderByIdentifier,
ResultOrderType resultOrderType) throws RegistryException {
         List<ExperimentSummaryResource> result = new ArrayList();
         EntityManager em = null;
@@ -607,14 +607,6 @@ public class WorkerResource extends AbstractExpCatResource {
             String query = "SELECT e FROM ExperimentSummary e " +
                     "WHERE ";
 
-            // FIXME There is a performance bottleneck for using IN clause. Try using temporary
tables ?
-            if(accessibleIds != null){
-                query += " e.experimentId IN (";
-                for(String id : accessibleIds)
-                    query += ("'" + id + "'" + ",");
-                query = query.substring(0, query.length()-1) + ") AND ";
-            }
-
             if (filters.get(ExperimentStatusConstants.STATE) != null) {
                 String experimentState = ExperimentState.valueOf(filters.get(ExperimentStatusConstants.STATE)).toString();
                 query += "e.state='" + experimentState + "' AND ";

http://git-wip-us.apache.org/repos/asf/airavata/blob/42606226/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 b9b5dd5..d9df6a9 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,22 +145,6 @@ 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


Mime
View raw message