]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5747 Replace componentRootUuids (modules) facet with projectUuids (project...
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 4 Nov 2014 09:34:50 +0000 (10:34 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 4 Nov 2014 14:05:18 +0000 (15:05 +0100)
12 files changed:
server/sonar-server/src/main/java/org/sonar/server/component/db/ComponentDao.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQuery.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueQueryService.java
server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/display_facets.json
server/sonar-web/src/main/coffee/issues/controller.coffee
server/sonar-web/src/main/coffee/issues/facets-view.coffee
sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 66952cc3f4689f771bf7c3634c6a0e780bbb7322..7359066af743a653856955ddf47783ec6e84784f 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.server.db.BaseDao;
 import org.sonar.server.exceptions.NotFoundException;
 
 import javax.annotation.CheckForNull;
+
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
index 7f8a5e28b7335120f1a13c217d30039b328b7aef..865bedc73a2eb8538d50d7971e8cab9a6c3a16cc 100644 (file)
@@ -59,6 +59,7 @@ public class IssueQuery {
   private final Collection<String> resolutions;
   private final Collection<String> components;
   private final Collection<String> componentRoots;
+  private final Collection<String> projects;
   private final Collection<RuleKey> rules;
   private final Collection<String> actionPlans;
   private final Collection<String> reporters;
@@ -81,6 +82,7 @@ public class IssueQuery {
     this.resolutions = defaultCollection(builder.resolutions);
     this.components = defaultCollection(builder.components);
     this.componentRoots = defaultCollection(builder.componentRoots);
+    this.projects = defaultCollection(builder.projects);
     this.rules = defaultCollection(builder.rules);
     this.actionPlans = defaultCollection(builder.actionPlans);
     this.reporters = defaultCollection(builder.reporters);
@@ -121,6 +123,10 @@ public class IssueQuery {
     return componentRoots;
   }
 
+  public Collection<String> projectUuids() {
+    return projects;
+  }
+
   public Collection<RuleKey> rules() {
     return rules;
   }
@@ -205,6 +211,7 @@ public class IssueQuery {
     private Collection<String> resolutions;
     private Collection<String> components;
     private Collection<String> componentRoots;
+    private Collection<String> projects;
     private Collection<RuleKey> rules;
     private Collection<String> actionPlans;
     private Collection<String> reporters;
@@ -253,6 +260,11 @@ public class IssueQuery {
       return this;
     }
 
+    public Builder projectUuids(@Nullable Collection<String> l) {
+      this.projects = l;
+      return this;
+    }
+
     public Builder rules(@Nullable Collection<RuleKey> rules) {
       this.rules = rules;
       return this;
index a69321e813986c10cfab5ae0810b7f66c9a6ac2d..931e15fc88825204ea0473a156c69973e196e847 100644 (file)
@@ -75,6 +75,8 @@ public class IssueQueryService implements ServerComponent {
         .createdAt(RubyUtils.toDate(params.get(IssueFilterParameters.CREATED_AT)))
         .createdAfter(RubyUtils.toDate(params.get(IssueFilterParameters.CREATED_AFTER)))
         .createdBefore(RubyUtils.toDate(params.get(IssueFilterParameters.CREATED_BEFORE)));
+      addProjectUuids(builder, session,
+        RubyUtils.toStrings(params.get(IssueFilterParameters.PROJECT_UUIDS)), RubyUtils.toStrings(params.get(IssueFilterParameters.PROJECTS)));
       addComponentUuids(builder, session,
         RubyUtils.toStrings(params.get(IssueFilterParameters.COMPONENT_UUIDS)), RubyUtils.toStrings(params.get(IssueFilterParameters.COMPONENTS)));
       addComponentRootUuids(builder, session,
@@ -110,6 +112,8 @@ public class IssueQueryService implements ServerComponent {
         .createdAt(request.paramAsDateTime(IssueFilterParameters.CREATED_AT))
         .createdAfter(request.paramAsDateTime(IssueFilterParameters.CREATED_AFTER))
         .createdBefore(request.paramAsDateTime(IssueFilterParameters.CREATED_BEFORE));
+      addProjectUuids(builder, session,
+        request.paramAsStrings(IssueFilterParameters.PROJECT_UUIDS), request.paramAsStrings(IssueFilterParameters.PROJECTS));
       addComponentUuids(builder, session,
         request.paramAsStrings(IssueFilterParameters.COMPONENT_UUIDS), request.paramAsStrings(IssueFilterParameters.COMPONENTS));
       addComponentRootUuids(builder, session,
@@ -126,6 +130,17 @@ public class IssueQueryService implements ServerComponent {
     }
   }
 
+  private void addProjectUuids(IssueQuery.Builder builder, DbSession session, @Nullable Collection<String> projectUuids, @Nullable Collection<String> projects) {
+    if (projectUuids != null) {
+      if (projects != null) {
+        throw new IllegalArgumentException("projects and projectUuids cannot be set simultaneously");
+      }
+      builder.projectUuids(projectUuids);
+    } else {
+      builder.projectUuids(componentUuids(session, projects));
+    }
+  }
+
   private void addComponentUuids(IssueQuery.Builder builder, DbSession session, @Nullable Collection<String> componentUuids, @Nullable Collection<String> components) {
     if (componentUuids != null) {
       if (components != null) {
index 1e3ec734057c80da6bbc585699fdc9e2f98b392c..2993965d56f58a1cfa199a160e1c7b27e596bc1d 100644 (file)
@@ -42,6 +42,8 @@ public class IssueFilterParameters {
   public static final String COMPONENT_UUIDS = "componentUuids";
   public static final String COMPONENT_ROOTS = "componentRoots";
   public static final String COMPONENT_ROOT_UUIDS = "componentRootUuids";
+  public static final String PROJECTS = "projects";
+  public static final String PROJECT_UUIDS = "projectUuids";
   public static final String RULES = "rules";
   public static final String ACTION_PLANS = "actionPlans";
   public static final String REPORTERS = "reporters";
@@ -59,7 +61,8 @@ public class IssueFilterParameters {
   public static final String ASC = "asc";
 
   public static final List<String> ALL = ImmutableList.of(ISSUES, SEVERITIES, STATUSES, RESOLUTIONS, RESOLVED, COMPONENTS, COMPONENT_ROOTS, RULES, ACTION_PLANS, REPORTERS,
-    ASSIGNEES, LANGUAGES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC, COMPONENT_UUIDS, COMPONENT_ROOT_UUIDS);
+    ASSIGNEES, LANGUAGES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, PAGE_SIZE, PAGE_INDEX, SORT, ASC, COMPONENT_UUIDS, COMPONENT_ROOT_UUIDS,
+    PROJECTS, PROJECT_UUIDS);
 
   public static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
     @Override
index a9f0b3903e237d3ef184c85f59c77d1a0c14e8a1..d348c3e6a7d4e0c5bd4b0022e53532e8c947c126 100644 (file)
@@ -285,6 +285,7 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> {
     filters.put(IssueNormalizer.IssueField.ASSIGNEE.field(), matchFilter(IssueNormalizer.IssueField.ASSIGNEE, query.assignees()));
     filters.put(IssueNormalizer.IssueField.MODULE_PATH.field(), matchFilter(IssueNormalizer.IssueField.MODULE_PATH, query.componentRootUuids()));
     filters.put(IssueNormalizer.IssueField.COMPONENT.field(), matchFilter(IssueNormalizer.IssueField.COMPONENT, query.componentUuids()));
+    filters.put(IssueNormalizer.IssueField.PROJECT.field(), matchFilter(IssueNormalizer.IssueField.PROJECT, query.projectUuids()));
     filters.put(IssueNormalizer.IssueField.LANGUAGE.field(), matchFilter(IssueNormalizer.IssueField.LANGUAGE, query.languages()));
     filters.put(IssueNormalizer.IssueField.RESOLUTION.field(), matchFilter(IssueNormalizer.IssueField.RESOLUTION, query.resolutions()));
     filters.put(IssueNormalizer.IssueField.REPORTER.field(), matchFilter(IssueNormalizer.IssueField.REPORTER, query.reporters()));
@@ -345,10 +346,10 @@ public class IssueIndex extends BaseIndex<Issue, IssueDto, String> {
         IssueFilterParameters.STATUSES, IssueNormalizer.IssueField.STATUS.field(), 0);
       addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
         IssueFilterParameters.ACTION_PLANS, IssueNormalizer.IssueField.ACTION_PLAN.field(), 1, query.actionPlans().toArray());
-      addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
-        IssueFilterParameters.COMPONENT_ROOT_UUIDS, IssueNormalizer.IssueField.MODULE_PATH.field(), 1, query.componentRootUuids().toArray());
       addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
         IssueFilterParameters.COMPONENT_UUIDS, IssueNormalizer.IssueField.COMPONENT.field(), 1, query.componentUuids().toArray());
+      addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
+        IssueFilterParameters.PROJECT_UUIDS, IssueNormalizer.IssueField.PROJECT.field(), 1, query.projectUuids().toArray());
       addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
         IssueFilterParameters.LANGUAGES, IssueNormalizer.IssueField.LANGUAGE.field(), 0, query.languages().toArray());
       addSimpleStickyFacetIfNeeded(options, stickyFacetBuilder, esSearch,
index 7c55aa257bfee3b2fb7609ef83c81533f55ce097..eae90769d0a1839e8d08467e7c2c6b4d2b7947a4 100644 (file)
@@ -140,6 +140,10 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
         "Issues associated to its sub-components (such as files, packages, etc.) are not retrieved. See also componentRoots. " +
         "If this parameter is set, componentUuids must not be set.")
       .setExampleValue("org.apache.struts:struts:org.apache.struts.Action");
+    action.createParam(IssueFilterParameters.PROJECTS)
+      .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project keys). " +
+        "If this parameter is set, projectUuids must not be set.")
+      .setExampleValue("org.apache.struts:struts:org.apache.struts.Action");
     action.createParam(IssueFilterParameters.COMPONENT_ROOTS)
       .setDescription("To retrieve issues associated to a specific list of components and their sub-components (comma-separated list of component keys). " +
         "Views are not supported. If this parameter is set, componentRootUuids must not be set.")
@@ -154,6 +158,10 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       .setDescription("To retrieve issues associated to a specific list of components and their sub-components (comma-separated list of component UUIDs). " +
         "Views are not supported. If this parameter is set, componentRoots must not be set.")
       .setExampleValue("7d8749e8-3070-4903-9188-bdd82933bb92");
+    action.createParam(IssueFilterParameters.PROJECT_UUIDS)
+      .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project UUIDs). " +
+        "Views are not supported. If this parameter is set, projects must not be set.")
+      .setExampleValue("7d8749e8-3070-4903-9188-bdd82933bb92");
     action.createParam(IssueFilterParameters.RULES)
       .setDescription("Comma-separated list of coding rule keys. Format is <repository>:<rule>")
       .setExampleValue("squid:AvoidCycles");
@@ -231,7 +239,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       IssueFilterParameters.STATUSES,
       IssueFilterParameters.RESOLUTIONS,
       IssueFilterParameters.ACTION_PLANS,
-      IssueFilterParameters.COMPONENT_ROOT_UUIDS,
+      IssueFilterParameters.PROJECT_UUIDS,
       IssueFilterParameters.RULES,
       IssueFilterParameters.ASSIGNEES,
       IssueFilterParameters.REPORTERS,
@@ -277,7 +285,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       }
     }
 
-    collectFacetKeys(result, IssueFilterParameters.COMPONENT_ROOT_UUIDS, projectUuids);
+    collectFacetKeys(result, IssueFilterParameters.PROJECT_UUIDS, projectUuids);
     collectFacetKeys(result, IssueFilterParameters.COMPONENT_UUIDS, componentUuids);
     collectFacetKeys(result, IssueFilterParameters.ASSIGNEES, userLogins);
     collectFacetKeys(result, IssueFilterParameters.REPORTERS, userLogins);
@@ -293,11 +301,15 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
 
       List<ComponentDto> fileDtos = dbClient.componentDao().getByUuids(session, componentUuids);
       List<ComponentDto> subProjectDtos = dbClient.componentDao().findSubProjectsByComponentUuids(session, componentUuids);
-      projectDtos = dbClient.componentDao().getByUuids(session, projectUuids);
       componentDtos.addAll(fileDtos);
       componentDtos.addAll(subProjectDtos);
-      componentDtos.addAll(projectDtos);
 
+      for (ComponentDto component: componentDtos) {
+        projectUuids.add(component.projectUuid());
+      }
+
+      projectDtos = dbClient.componentDao().getByUuids(session, projectUuids);
+      componentDtos.addAll(projectDtos);
       for (ComponentDto componentDto : componentDtos) {
         componentsByUuid.put(componentDto.uuid(), componentDto);
       }
@@ -595,7 +607,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
         throw new IllegalStateException("Component has no UUID: " + component.getKey());
       }
       if (!projectsByUuid.containsKey(component.projectUuid())) {
-        throw new IllegalStateException("Project cannot be found for component: " + component.getKey());
+        throw new IllegalStateException("Project cannot be found for component: " + component.getKey() + " / " + component.uuid());
       }
       projectsByComponentUuid.put(component.uuid(), projectsByUuid.get(component.projectUuid()));
     }
index b8b20f2155545b877163c74b94cb798e58247d86..58b57a54c50410f16054dc5c2f36238b1adc01a9 100644 (file)
@@ -128,7 +128,7 @@ public class SearchActionMediumTest {
     assertThat(show.isPost()).isFalse();
     assertThat(show.isInternal()).isFalse();
     assertThat(show.responseExampleAsString()).isNotEmpty();
-    assertThat(show.params()).hasSize(28);
+    assertThat(show.params()).hasSize(30);
   }
 
   @Test
@@ -378,7 +378,7 @@ public class SearchActionMediumTest {
 
     WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
       .setParam("resolved", "false")
-      .setParam(SearchAction.PARAM_FACETS, "statuses,severities,resolutions,componentRootUuids,rules,componentUuids,assignees,languages")
+      .setParam(SearchAction.PARAM_FACETS, "statuses,severities,resolutions,projectUuids,rules,componentUuids,assignees,languages")
       .execute();
     result.assertJson(this.getClass(), "display_facets.json", false);
   }
index 11b25073b4b74e5ccadba4def28d0b53053d16fa..fae2761ffcc63905215c002251809692fdb4e9b5 100644 (file)
       ]
     },
     {
-      "property": "componentRootUuids",
+      "property": "projectUuids",
       "values": [
         {
-          "val": "abcd",
+          "val": "ABCD",
           "count": 1
         }
       ]
index 2c00adf1641fad3b5ffb7f02e4b9b3ee126beee2..44f4a4d133b8cc490b609183e71a20131d6fcf8e 100644 (file)
@@ -13,10 +13,10 @@ define [
   $ = jQuery
   EXTRA_FIELDS = 'actions,transitions,assigneeName,reporterName,actionPlanName'
   PAGE_SIZE = 50
-  ALL_FACETS = ['severities', 'statuses', 'resolutions', 'componentRootUuids', 'assignees', 'reporters', 'rules',
+  ALL_FACETS = ['severities', 'statuses', 'resolutions', 'projectUuids', 'assignees', 'reporters', 'rules',
                 'languages', 'actionPlans', 'componentUuids', 'creationDate']
   FACET_DATA_FIELDS = ['components', 'projects', 'users', 'rules', 'actionPlans', 'languages']
-  FACETS_FROM_SERVER = ['severities', 'statuses', 'resolutions', 'actionPlans', 'componentRootUuids', 'rules',
+  FACETS_FROM_SERVER = ['severities', 'statuses', 'resolutions', 'actionPlans', 'projectUuids', 'rules',
                         'assignees', 'reporters', 'componentUuids', 'languages']
 
 
index a36652b06a1e3256d2405179ca1eb40f2e3943bc..6ffd106f9473f45b31cbf44f134b641c071632b6 100644 (file)
@@ -40,7 +40,7 @@ define [
         when 'assignees' then AssigneeFacet
         when 'resolutions' then ResolutionFacet
         when 'creationDate' then CreationDateFacet
-        when 'componentRootUuids' then ProjectFacet
+        when 'projectUuids' then ProjectFacet
         when 'rules' then RuleFacet
         when 'actionPlans' then ActionPlanFacet
         when 'componentUuids' then ComponentFacet
@@ -61,4 +61,3 @@ define [
       enabledFacets = @collection.filter (model) -> model.get('enabled')
       enabledFacetIds = enabledFacets.map (model) -> model.id
       @options.app.state.set facets: enabledFacetIds
-
index 4f25ede6e8fdc5f9227e46991be47501bed8c990..37c0a894ae8c95316597d7c0979400dc86aee7e3 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.ibatis.annotations.Param;
 import org.sonar.core.component.ComponentDto;
 
 import javax.annotation.CheckForNull;
+
 import java.util.Collection;
 import java.util.List;
 
index 61e917b5c76fabc31e828e1f15541a4b5f89dae1..6ab436ff08a8686c9dcec555e2c2a1293020e4c5 100644 (file)
@@ -773,7 +773,7 @@ issues.found=Found
 #
 #------------------------------------------------------------------------------
 issues.facet.severities=Severity
-issues.facet.componentRootUuids=Project
+issues.facet.projectUuids=Project
 issues.facet.statuses=Status
 issues.facet.actionPlans=Action Plan
 issues.facet.assignees=Assignee