]> source.dussan.org Git - sonarqube.git/commitdiff
Replace usage of IssueService#search by IssueIndex#search
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 8 Mar 2016 10:00:31 +0000 (11:00 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Mar 2016 09:44:15 +0000 (10:44 +0100)
server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java

index f7360f347e0524ee4c6e531d12ff7a1689e36f2d..352defecc4be1c8e398d86cd854fe50e4fbfb867 100644 (file)
@@ -49,6 +49,7 @@ import org.sonar.db.issue.IssueDto;
 import org.sonar.server.es.SearchOptions;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.issue.index.IssueDoc;
+import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.notification.IssueChangeNotification;
 import org.sonar.server.notification.NotificationManager;
 import org.sonar.server.rule.DefaultRuleFinder;
@@ -63,17 +64,17 @@ public class IssueBulkChangeService {
   private static final Logger LOG = Loggers.get(IssueBulkChangeService.class);
 
   private final DbClient dbClient;
-  private final IssueService issueService;
+  private final IssueIndex issueIndex;
   private final IssueStorage issueStorage;
   private final DefaultRuleFinder ruleFinder;
   private final NotificationManager notificationService;
   private final List<Action> actions;
   private final UserSession userSession;
 
-  public IssueBulkChangeService(DbClient dbClient, IssueService issueService, IssueStorage issueStorage, DefaultRuleFinder ruleFinder,
+  public IssueBulkChangeService(DbClient dbClient, IssueIndex issueIndex, IssueStorage issueStorage, DefaultRuleFinder ruleFinder,
                                 NotificationManager notificationService, List<Action> actions, UserSession userSession) {
     this.dbClient = dbClient;
-    this.issueService = issueService;
+    this.issueIndex = issueIndex;
     this.issueStorage = issueStorage;
     this.ruleFinder = ruleFinder;
     this.notificationService = notificationService;
@@ -128,7 +129,7 @@ public class IssueBulkChangeService {
     // Load from index to check permission
     SearchOptions options = new SearchOptions().setLimit(SearchOptions.MAX_LIMIT);
     // TODO restrict fields to issue key, in order to not load all other fields;
-    List<IssueDoc> authorizedIssues = issueService.search(IssueQuery.builder(userSession).issueKeys(issueKeys).build(), options).getDocs();
+    List<IssueDoc> authorizedIssues = issueIndex.search(IssueQuery.builder(userSession).issueKeys(issueKeys).build(), options).getDocs();
     Collection<String> authorizedKeys = Collections2.transform(authorizedIssues, new Function<IssueDoc, String>() {
       @Override
       public String apply(IssueDoc input) {
index a0d70d6e838b81cb9bd3ad53df129f04c8113612..39c9a1969e9c5d75372ab7ee2e2eddeb4938d198 100644 (file)
@@ -50,11 +50,8 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.rule.RuleDto;
-import org.sonar.server.es.SearchOptions;
-import org.sonar.server.es.SearchResult;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.issue.actionplan.ActionPlanService;
-import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.issue.notification.IssueChangeNotification;
 import org.sonar.server.issue.workflow.IssueWorkflow;
@@ -327,10 +324,6 @@ public class IssueService {
     }
   }
 
-  public SearchResult<IssueDoc> search(IssueQuery query, SearchOptions options) {
-    return issueIndex.search(query, options);
-  }
-
   /**
    * Search for all tags, whatever issue resolution or user access rights
    */
index 92966ca7b0ec625208baff1ab4aee705a23bc31c..6f1e87e29a9688c5ee539656431b3729d187199c 100644 (file)
@@ -42,7 +42,6 @@ import org.sonar.server.es.SearchOptions;
 import org.sonar.server.es.SearchResult;
 import org.sonar.server.issue.IssueQuery;
 import org.sonar.server.issue.IssueQueryService;
-import org.sonar.server.issue.IssueService;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
 import org.sonar.server.rule.RuleKeyFunctions;
@@ -100,15 +99,15 @@ public class SearchAction implements IssuesWsAction {
   public static final String SEARCH_ACTION = "search";
 
   private final UserSession userSession;
-  private final IssueService service;
+  private final IssueIndex issueIndex;
   private final IssueQueryService issueQueryService;
   private final SearchResponseLoader searchResponseLoader;
   private final SearchResponseFormat searchResponseFormat;
 
-  public SearchAction(UserSession userSession, IssueService service, IssueQueryService issueQueryService,
+  public SearchAction(UserSession userSession, IssueIndex issueIndex, IssueQueryService issueQueryService,
     SearchResponseLoader searchResponseLoader, SearchResponseFormat searchResponseFormat) {
     this.userSession = userSession;
-    this.service = service;
+    this.issueIndex = issueIndex;
     this.issueQueryService = issueQueryService;
     this.searchResponseLoader = searchResponseLoader;
     this.searchResponseFormat = searchResponseFormat;
@@ -283,7 +282,7 @@ public class SearchAction implements IssuesWsAction {
     IssueQuery query = issueQueryService.createFromRequest(request);
 
     // execute request
-    SearchResult<IssueDoc> result = service.search(query, options);
+    SearchResult<IssueDoc> result = issueIndex.search(query, options);
     List<String> issueKeys = from(result.getDocs()).transform(IssueDocToKey.INSTANCE).toList();
 
     // load the additional information to be returned in response
index e5ae889e4e07376b5ec444853bde143db039e47a..862284fbfad67da460110650d43397695bce2695 100644 (file)
@@ -56,13 +56,10 @@ import org.sonar.db.source.FileSourceDto;
 import org.sonar.db.user.GroupDao;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
-import org.sonar.server.es.SearchOptions;
-import org.sonar.server.es.SearchResult;
 import org.sonar.server.exceptions.BadRequestException;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.index.IssueDoc;
 import org.sonar.server.issue.index.IssueIndex;
-import org.sonar.server.issue.index.IssueIndexDefinition;
 import org.sonar.server.issue.index.IssueIndexer;
 import org.sonar.server.issue.workflow.Transition;
 import org.sonar.server.permission.PermissionChange;
@@ -121,25 +118,6 @@ public class IssueServiceMediumTest {
     assertThat(service.getByKey(issue.getKey())).isNotNull();
   }
 
-  @Test
-  public void can_facet() {
-    RuleDto rule = newRule();
-    ComponentDto project = newProject();
-    ComponentDto file = newFile(project);
-
-    saveIssue(IssueTesting.newDto(rule, file, project).setActionPlanKey("P1"));
-    saveIssue(IssueTesting.newDto(rule, file, project).setActionPlanKey("P2").setResolution("NONE"));
-
-    SearchResult<IssueDoc> result = service.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions());
-    assertThat(result.getDocs()).hasSize(2);
-    assertThat(result.getFacets().getNames()).isEmpty();
-
-    result = service.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFacets("actionPlans", "assignees"));
-    assertThat(result.getFacets().getNames()).hasSize(2);
-    assertThat(result.getFacets().get("actionPlans")).hasSize(2);
-    assertThat(result.getFacets().get("assignees")).hasSize(1);
-  }
-
   @Test
   public void list_status() {
     assertThat(service.listStatus()).containsExactly("OPEN", "CONFIRMED", "REOPENED", "RESOLVED", "CLOSED");
@@ -500,17 +478,6 @@ public class IssueServiceMediumTest {
     service.createManualIssue(file.key(), rule.getKey(), 10, "Fix it", null);
   }
 
-  @Test
-  public void search_issues() {
-    RuleDto rule = newRule();
-    ComponentDto project = newProject();
-    ComponentDto file = newFile(project);
-    saveIssue(IssueTesting.newDto(rule, file, project));
-
-    List<IssueDoc> result = service.search(IssueQuery.builder(userSessionRule).build(), new SearchOptions().addFields(IssueIndexDefinition.FIELD_ISSUE_KEY)).getDocs();
-    assertThat(result).hasSize(1);
-  }
-
   @Test
   public void list_tags() {
     RuleDto rule = newRule();