]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5531 - Added project and component to IssueResult
authorStephane Gamard <stephane.gamard@sonarsource.com>
Fri, 5 Sep 2014 18:53:41 +0000 (20:53 +0200)
committerStephane Gamard <stephane.gamard@sonarsource.com>
Fri, 5 Sep 2014 19:00:39 +0000 (21:00 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueResult.java

index 2965917ce45b21f589edbf8551db294cc47b7687..c8741331806769781ca2d2b4dfb3f133a61123ca 100644 (file)
@@ -340,12 +340,26 @@ public class IssueService implements ServerComponent {
     SearchResponse esResults = issueIndex.search(query, options);
 
     // Extend the content of the resultSet to make an actual IssueResponse
-    IssueResult results = new IssueResult(issueIndex, esResults);
-    results.setPaging(Paging.create(
+    IssueResult result = new IssueResult(issueIndex, esResults);
+    result.setPaging(Paging.create(
       options.getLimit(),
       (options.getOffset() * options.getLimit()) + 1,
       new Long(esResults.getHits().getTotalHits()).intValue()));
 
-    return results;
+    // TODO Optimise
+    // Insert the projects and component name;
+    DbSession session = dbClient.openSession(false);
+    try {
+      for (Issue issue : result.getHits()) {
+        result.addProject(issue.key(),
+          dbClient.componentDao().getByKey(session, issue.projectKey()));
+        result.addComponent(issue.key(),
+          dbClient.componentDao().getByKey(session, issue.componentKey()));
+      }
+    } finally {
+      session.close();
+    }
+
+    return result;
   }
 }
index b10f8716ad345e9a516b2a2d53796ce8bb494474..ca80f82259361b9be871f06f1f67dc0ae3c8943e 100644 (file)
@@ -29,6 +29,7 @@ import org.sonar.api.issue.IssueQueryResult;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.user.User;
 import org.sonar.api.utils.Paging;
+import org.sonar.core.component.ComponentDto;
 import org.sonar.server.search.BaseIndex;
 import org.sonar.server.search.Result;
 
@@ -134,4 +135,12 @@ public class IssueResult extends Result<IssueDoc> implements IssueQueryResult {
   public boolean maxResultsReached() {
     return false;
   }
+
+  public void addProject(String key, ComponentDto project) {
+    this.projects.put(key, project);
+  }
+
+  public void addComponent(String key, ComponentDto project) {
+    this.components.put(key, project);
+  }
 }