airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: fixing emptyIds bug
Date Fri, 08 Jul 2016 22:55:50 GMT
Repository: airavata
Updated Branches:
  refs/heads/grouper-integration 639813231 -> 35466d476


fixing emptyIds bug


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

Branch: refs/heads/grouper-integration
Commit: 35466d476e2db5b50286e934c556bcf3bcbb6929
Parents: 6398132
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Fri Jul 8 18:55:39 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Fri Jul 8 18:55:39 2016 -0400

----------------------------------------------------------------------
 .../catalog/resources/WorkerResource.java       | 186 ++++++++++---------
 1 file changed, 94 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/35466d47/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..f19eec6 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
@@ -518,57 +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){
+            if(accessibleIds != null && accessibleIds.size()>0) {
                 query += " p.projectId IN (";
-                for(String id : accessibleIds)
+                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 = 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 ";
                         }
-                        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);
+                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();
             }
-            em.getTransaction().commit();
-            em.close();
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             throw new RegistryException(e);
@@ -608,70 +609,71 @@ public class WorkerResource extends AbstractExpCatResource {
                     "WHERE ";
 
             // FIXME There is a performance bottleneck for using IN clause. Try using temporary
tables ?
-            if(accessibleIds != null){
+            if(accessibleIds != null && accessibleIds.size()>0) {
                 query += " e.experimentId IN (";
-                for(String id : accessibleIds)
+                for (String id : accessibleIds)
                     query += ("'" + id + "'" + ",");
-                query = query.substring(0, query.length()-1) + ") AND ";
-            }
+                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 (toTime != null && fromTime != null && toTime.after(fromTime))
{
-                query += "e.creationTime > '" + fromTime + "' " + "AND e.creationTime
<'" + toTime + "' AND ";
-            }
+                if (filters.get(ExperimentStatusConstants.STATE) != null) {
+                    String experimentState = ExperimentState.valueOf(filters.get(ExperimentStatusConstants.STATE)).toString();
+                    query += "e.state='" + experimentState + "' 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("\\*", "");
+                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 ";
                         }
-                        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);
+                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();
             }
-            em.getTransaction().commit();
-            em.close();
         } catch (Exception e) {
             logger.error(e.getMessage(), e);
             throw new RegistryException(e);


Mime
View raw message