airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [45/57] airavata git commit: modifying grouper based search in AiravataServerHandler
Date Thu, 28 Jul 2016 17:45:59 GMT
modifying grouper based search in AiravataServerHandler


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

Branch: refs/heads/develop
Commit: d0018464e7eaffa8e6b1ce18dc683a19a7e92517
Parents: d6a8208
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Wed Jul 13 12:00:51 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Wed Jul 13 12:00:51 2016 -0400

----------------------------------------------------------------------
 .../server/handler/AiravataServerHandler.java   |  56 ++----
 .../catalog/resources/WorkerResource.java       | 179 +++++++++----------
 2 files changed, 107 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/d0018464/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 6dc976d..4af8d1a 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
@@ -598,9 +598,15 @@ public class AiravataServerHandler implements Airavata.Iface {
                 throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
             }
             String projectId = (String) experimentCatalog.add(ExpCatParentDataType.PROJECT,
project, gatewayId);
+            GroupManagerCPI groupManager = GroupManagerFactory.getGroupManager();
+            Resource projResource = new Resource(projectId, org.apache.airavata.grouper.resource.ResourceType.PROJECT);
+            projResource.setOwnerId(project.getOwner() + "@" + project.getGatewayId());
+            projResource.setName(project.getName());
+            projResource.setDescription(project.getDescription());
+            groupManager.createResource(projResource);
             logger.debug("Airavata created project with project Id : " + projectId + " for
gateway Id : " + gatewayId);
             return projectId;
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             logger.error("Error while creating the project", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
@@ -864,24 +870,8 @@ public class AiravataServerHandler implements Airavata.Iface {
                     regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION,
entry.getValue());
                 }
             }
-
-            Map<String, String> temp = new HashMap();
-            temp.put(Constants.FieldConstants.ProjectConstants.OWNER, userName);
-            temp.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId);
-            final List<String> accessibleProjIds  = new ArrayList<>();
-            try{
-                accessibleProjIds.addAll(getAllAccessibleResourcesForUser(userName+"@"+gatewayId,
ResourceType.PROJECT, ResourcePermissionType.READ));
-            }catch (Exception ex){
-                logger.error(ex.getMessage(), ex);
-            }
-            List<Object> allUserProjects = experimentCatalog.search(ExperimentCatalogModelType.PROJECT,
temp, -1,
-                    0, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC);
-            allUserProjects.stream().forEach(e->accessibleProjIds.add(((Project) e).getProjectID()));
-            Set<String> hs = new HashSet<>();
-            hs.addAll(accessibleProjIds);
-            accessibleProjIds.clear();
-            accessibleProjIds.addAll(hs);
-
+            List<String> accessibleProjIds  = new ArrayList<>();
+            accessibleProjIds.addAll(getAllAccessibleResourcesForUser(userName+"@"+gatewayId,
ResourceType.PROJECT, ResourcePermissionType.READ));
             List<Object> results = experimentCatalog.searchAllAccessible(ExperimentCatalogModelType.PROJECT,
accessibleProjIds,
                     regFilters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME,
ResultOrderType.DESC);
             for (Object object : results) {
@@ -960,25 +950,8 @@ public class AiravataServerHandler implements Airavata.Iface {
                     regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID,
entry.getValue());
                 }
             }
-
-            Map<String, String> temp = new HashMap();
-            temp.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName);
-            temp.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId);
-
-            final List<String> accessibleExpIds = new ArrayList<>();
-            try{
-                accessibleExpIds.addAll(getAllAccessibleResourcesForUser(userName + "@" +
gatewayId, ResourceType.EXPERIMENT, ResourcePermissionType.READ));
-            }catch (Exception ex){
-                logger.error(ex.getMessage(), ex);
-            }
-            List<Object> allUserExperiments = experimentCatalog.search(ExperimentCatalogModelType.EXPERIMENT,
temp, -1,
-                    0, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
-            allUserExperiments.stream().forEach(e->accessibleExpIds.add(((ExperimentSummaryModel)
e).getExperimentId()));
-            Set<String> hs = new HashSet<>();
-            hs.addAll(accessibleExpIds);
-            accessibleExpIds.clear();
-            accessibleExpIds.addAll(hs);
-
+            List<String> accessibleExpIds = new ArrayList<>();
+            accessibleExpIds.addAll(getAllAccessibleResourcesForUser(userName + "@" + gatewayId,
ResourceType.EXPERIMENT, ResourcePermissionType.READ));
             List<Object> results = experimentCatalog.searchAllAccessible(ExperimentCatalogModelType.EXPERIMENT,
                     accessibleExpIds, regFilters, limit,
                     offset, Constants.FieldConstants.ExperimentConstants.CREATION_TIME, ResultOrderType.DESC);
@@ -1217,6 +1190,13 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
 
             String experimentId = (String) experimentCatalog.add(ExpCatParentDataType.EXPERIMENT,
experiment, gatewayId);
+            GroupManagerCPI groupManager = GroupManagerFactory.getGroupManager();
+            Resource expResource = new Resource(experimentId, org.apache.airavata.grouper.resource.ResourceType.EXPERIMENT);
+            expResource.setOwnerId(experiment.getUserName()+"@"+experiment.getGatewayId());
+            expResource.setParentResourceId(experiment.getProjectId());
+            expResource.setName(experiment.getExperimentName());
+            expResource.setDescription(experiment.getDescription());
+            groupManager.createResource(expResource);
             ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.CREATED,
                     experimentId,
                     gatewayId);

http://git-wip-us.apache.org/repos/asf/airavata/blob/d0018464/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 f19eec6..16f28e1 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
@@ -428,7 +428,7 @@ public class WorkerResource extends AbstractExpCatResource {
      * @return list of projects for the user
      */
     public List<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource>
getProjects(int limit, int offset, Object orderByIdentifier,
-                                             ResultOrderType resultOrderType) throws RegistryException
{
+                                                                                        
                   ResultOrderType resultOrderType) throws RegistryException {
         List<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource>
result = new ArrayList<org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource>();
         List<ExperimentCatResource> list = get(ResourceType.PROJECT, limit, offset,
orderByIdentifier, resultOrderType);
         for (ExperimentCatResource resource : list) {
@@ -518,58 +518,58 @@ public class WorkerResource extends AbstractExpCatResource {
             String query = "SELECT DISTINCT p from Project p WHERE ";
 
             // FIXME There is a performance bottleneck for using IN clause. Try using temporary
tables ?
-            if(accessibleIds != null && accessibleIds.size()>0) {
+            if (accessibleIds != null && accessibleIds.size() > 0) {
                 query += " p.projectId IN (";
                 for (String id : accessibleIds)
                     query += ("'" + id + "'" + ",");
                 query = query.substring(0, query.length() - 1) + ") AND ";
+            }
 
-
-                if (filters != null && filters.size() != 0) {
-                    for (String field : filters.keySet()) {
-                        String filterVal = filters.get(field);
-                        if (field.equals(ProjectConstants.USERNAME)) {
-                            query += "p." + field + "= '" + filterVal + "' AND ";
-                        } else if (field.equals(ProjectConstants.GATEWAY_ID)) {
-                            query += "p." + field + "= '" + filterVal + "' AND ";
-                        } else {
-                            if (filterVal.contains("*")) {
-                                filterVal = filterVal.replaceAll("\\*", "");
-                            }
-                            query += "p." + field + " LIKE '%" + filterVal + "%' AND ";
+            if (filters != null && filters.size() != 0) {
+                for (String field : filters.keySet()) {
+                    String filterVal = filters.get(field);
+                    if (field.equals(ProjectConstants.USERNAME)) {
+                        query += "p." + field + "= '" + filterVal + "' AND ";
+                    } else if (field.equals(ProjectConstants.GATEWAY_ID)) {
+                        query += "p." + field + "= '" + filterVal + "' AND ";
+                    } else {
+                        if (filterVal.contains("*")) {
+                            filterVal = filterVal.replaceAll("\\*", "");
                         }
+                        query += "p." + field + " LIKE '%" + filterVal + "%' AND ";
                     }
                 }
-                query = query.substring(0, query.length() - 5);
+            }
+            query = query.substring(0, query.length() - 5);
 
-                //ordering
-                if (orderByIdentifier != null && resultOrderType != null
-                        && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME))
{
-                    String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
-                    query += " ORDER BY p." + ProjectConstants.CREATION_TIME + " " + order;
-                }
+            //ordering
+            if (orderByIdentifier != null && resultOrderType != null
+                    && orderByIdentifier.equals(Constants.FieldConstants.ProjectConstants.CREATION_TIME))
{
+                String order = (resultOrderType == ResultOrderType.ASC) ? "ASC" : "DESC";
+                query += " ORDER BY p." + ProjectConstants.CREATION_TIME + " " + order;
+            }
 
-                em = ExpCatResourceUtils.getEntityManager();
-                em.getTransaction().begin();
-                Query q;
+            em = ExpCatResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
 
-                //pagination
-                if (offset >= 0 && limit >= 0) {
-                    q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
-                } else {
-                    q = em.createQuery(query);
-                }
+            //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;
-                    org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource
projectResource =
-                            (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
-                    result.add(projectResource);
-                }
-                em.getTransaction().commit();
-                em.close();
+            List resultList = q.getResultList();
+            for (Object o : resultList) {
+                Project project = (Project) o;
+                org.apache.airavata.registry.core.experiment.catalog.resources.ProjectResource
projectResource =
+                        (ProjectResource) Utils.getResource(ResourceType.PROJECT, project);
+                result.add(projectResource);
             }
+            em.getTransaction().commit();
+            em.close();
+
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             throw new RegistryException(e);
@@ -609,71 +609,70 @@ public class WorkerResource extends AbstractExpCatResource {
                     "WHERE ";
 
             // FIXME There is a performance bottleneck for using IN clause. Try using temporary
tables ?
-            if(accessibleIds != null && accessibleIds.size()>0) {
+            if (accessibleIds != null && accessibleIds.size() > 0) {
                 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 ";
+            }
 
-                if (filters.get(ExperimentStatusConstants.STATE) != null) {
-                    String experimentState = ExperimentState.valueOf(filters.get(ExperimentStatusConstants.STATE)).toString();
-                    query += "e.state='" + experimentState + "' AND ";
-                }
-
-                if (toTime != null && fromTime != null && toTime.after(fromTime))
{
-                    query += "e.creationTime > '" + fromTime + "' " + "AND e.creationTime
<'" + toTime + "' AND ";
-                }
+            if (toTime != null && fromTime != null && toTime.after(fromTime))
{
+                query += "e.creationTime > '" + fromTime + "' " + "AND e.creationTime
<'" + toTime + "' AND ";
+            }
 
-                filters.remove(ExperimentStatusConstants.STATE);
-                if (filters != null && filters.size() != 0) {
-                    for (String field : filters.keySet()) {
-                        String filterVal = filters.get(field);
-                        if (field.equals(ExperimentConstants.USER_NAME)) {
-                            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 ";
+            filters.remove(ExperimentStatusConstants.STATE);
+            if (filters != null && filters.size() != 0) {
+                for (String field : filters.keySet()) {
+                    String filterVal = filters.get(field);
+                    if (field.equals(ExperimentConstants.USER_NAME)) {
+                        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);
+            }
+            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;
-                }
+            //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 = ExpCatResourceUtils.getEntityManager();
-                em.getTransaction().begin();
-                Query q;
+            em = ExpCatResourceUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query q;
 
-                //pagination
-                if (offset >= 0 && limit >= 0) {
-                    q = em.createQuery(query).setFirstResult(offset).setMaxResults(limit);
-                } else {
-                    q = em.createQuery(query);
-                }
+            //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) {
-                    ExperimentSummary experimentSummary = (ExperimentSummary) o;
-                    ExperimentSummaryResource experimentSummaryResource =
-                            (ExperimentSummaryResource) Utils.getResource(ResourceType.EXPERIMENT_SUMMARY,
-                                    experimentSummary);
-                    result.add(experimentSummaryResource);
-                }
-                em.getTransaction().commit();
-                em.close();
+            List resultList = q.getResultList();
+            for (Object o : resultList) {
+                ExperimentSummary experimentSummary = (ExperimentSummary) o;
+                ExperimentSummaryResource experimentSummaryResource =
+                        (ExperimentSummaryResource) Utils.getResource(ResourceType.EXPERIMENT_SUMMARY,
+                                experimentSummary);
+                result.add(experimentSummaryResource);
             }
+            em.getTransaction().commit();
+            em.close();
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             throw new RegistryException(e);


Mime
View raw message