]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6428 Apply feedback from PR
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 27 Apr 2015 09:51:19 +0000 (11:51 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Tue, 28 Apr 2015 07:02:06 +0000 (09:02 +0200)
server/sonar-server/src/main/java/org/sonar/server/measure/persistence/MeasureDao.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentConfigurationPages.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentConfigurationPagesTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentNavigationActionTest.java
sonar-core/src/main/resources/org/sonar/core/measure/db/MeasureMapper.xml

index 9e0f38d405ea3a1645ad44a14b2cfbd1875f2f11..c1b2bc5516da95f3cc7eedb514e11a3b6074f9fa 100644 (file)
@@ -56,7 +56,7 @@ public class MeasureDao implements ServerComponent, DaoComponent {
     mapper(session).insert(measureDto);
   }
 
-  public List<String> selectMetricKeysForSnapshot(DbSession session, Long snapshotId) {
+  public List<String> selectMetricKeysForSnapshot(DbSession session, long snapshotId) {
     return mapper(session).selectMetricKeysForSnapshot(snapshotId);
   }
 
index 4f0edc62578ec82fe5e4abf545509aaefc104322..b8b8fbebc422c0dfb51e9497827af0997c3f7ec6 100644 (file)
 package org.sonar.server.ui.ws;
 
 import com.google.common.base.Charsets;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.i18n.I18n;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.ResourceType;
 import org.sonar.api.resources.ResourceTypes;
-import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.server.user.UserSession;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 
@@ -53,7 +55,7 @@ public class ComponentConfigurationPages implements ServerComponent {
     this.resourceTypes = resourceTypes;
   }
 
-  List<ConfigPage> getConfigPages(ComponentDto component, UserSession userSession) {
+  Collection<ConfigPage> getConfigPages(ComponentDto component, UserSession userSession) {
     boolean isAdmin = userSession.hasProjectPermissionByUuid(UserRole.ADMIN, component.projectUuid());
     boolean isProject = Qualifiers.PROJECT.equals(component.qualifier());
     Locale locale = userSession.locale();
@@ -89,7 +91,7 @@ public class ComponentConfigurationPages implements ServerComponent {
     configPages.add(new ConfigPage(
       isAdmin && isProject,
       String.format("/project/links?id=%s", componentKey),
-      i18n.message(locale, "action_plans.page", null)));
+      i18n.message(locale, "project_links.page", null)));
 
     configPages.add(new ConfigPage(
       componentTypeHasProperty(component, PROPERTY_HAS_ROLE_POLICY),
@@ -111,7 +113,12 @@ public class ComponentConfigurationPages implements ServerComponent {
       String.format("/project/deletion?id=%s", componentKey),
       i18n.message(locale, "deletion.page", null)));
 
-    return configPages;
+    return Collections2.filter(configPages, new Predicate<ConfigPage>() {
+      @Override
+      public boolean apply(ConfigPage input) {
+        return input.visible;
+      }
+    });
   }
 
   static String encodeComponentKey(ComponentDto component) {
@@ -143,13 +150,12 @@ public class ComponentConfigurationPages implements ServerComponent {
       this.name = name;
     }
 
-    void write(JsonWriter json) {
-      if (visible) {
-        json.beginObject()
-          .prop("url", url)
-          .prop("name", name)
-          .endObject();
-      }
+    String url() {
+      return url;
+    }
+
+    String name() {
+      return name;
     }
   }
 
index 8da3efa94556d9b4c8964e44c25e243895d5533d..7192ae1d5c1b391c205752cc4f9907b26db76eca 100644 (file)
@@ -182,7 +182,10 @@ public class ComponentNavigationAction implements NavigationAction {
 
     json.name("configuration").beginArray();
     for (ConfigPage page : projectConfiguration.getConfigPages(component, userSession)) {
-      page.write(json);
+      json.beginObject()
+        .prop("url", page.url())
+        .prop("name", page.name())
+        .endObject();
     }
 
     if (isAdmin) {
index 1cfbe7d316b5b263d28aa5ed1c914e9af2500cbb..391ee96239c471216991aa93bf02c6de813e5768 100644 (file)
@@ -37,7 +37,7 @@ import org.sonar.server.ui.ws.ComponentConfigurationPages.ConfigPage;
 import org.sonar.server.user.MockUserSession;
 import org.sonar.server.user.UserSession;
 
-import java.util.List;
+import java.util.Collection;
 import java.util.Locale;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -68,20 +68,20 @@ public class ComponentConfigurationPagesTest {
     ComponentDto component = ComponentTesting.newProjectDto(uuid).setKey("org.codehaus.sonar:sonar");
     UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
 
-    List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
-    assertThat(pages).extracting("visible").containsExactly(
-      false, true, true, true, true, true, false, false, false, false);
+    Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+    assertThat(pages).extracting("name").containsExactly(
+      "project_quality_profiles.page",
+      "project_quality_gate.page",
+      "manual_measures.page",
+      "action_plans.page",
+      "project_links.page"
+      );
     assertThat(pages).extracting("url").containsExactly(
-        "/project/settings?id=org.codehaus.sonar%3Asonar",
         "/project/profile?id=org.codehaus.sonar%3Asonar",
         "/project/qualitygate?id=org.codehaus.sonar%3Asonar",
         "/manual_measures/index?id=org.codehaus.sonar%3Asonar",
         "/action_plans/index?id=org.codehaus.sonar%3Asonar",
-        "/project/links?id=org.codehaus.sonar%3Asonar",
-        "/project_roles/index?id=org.codehaus.sonar%3Asonar",
-        "/project/history?id=org.codehaus.sonar%3Asonar",
-        "/project/key?id=org.codehaus.sonar%3Asonar",
-        "/project/deletion?id=org.codehaus.sonar%3Asonar"
+        "/project/links?id=org.codehaus.sonar%3Asonar"
       );
   }
 
@@ -93,9 +93,15 @@ public class ComponentConfigurationPagesTest {
     when(resourceTypes.get(component.qualifier())).thenReturn(
       ResourceType.builder(component.qualifier()).setProperty("configurable", true).build());
 
-    List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
-    assertThat(pages).extracting("visible").containsExactly(
-      true, true, true, true, true, true, false, false, false, false);
+    Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+    assertThat(pages).extracting("name").containsExactly(
+      "project_settings.page",
+      "project_quality_profiles.page",
+      "project_quality_gate.page",
+      "manual_measures.page",
+      "action_plans.page",
+      "project_links.page"
+      );
   }
 
   @Test
@@ -105,9 +111,8 @@ public class ComponentConfigurationPagesTest {
     ComponentDto module = ComponentTesting.newModuleDto(project);
     UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
 
-    List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(module, userSession);
-    assertThat(pages).extracting("visible").containsExactly(
-      false, false, false, true, false, false, false, false, false, false);
+    Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(module, userSession);
+    assertThat(pages).extracting("name").containsExactly("manual_measures.page");
   }
 
   @Test
@@ -116,8 +121,39 @@ public class ComponentConfigurationPagesTest {
     ComponentDto project = ComponentTesting.newProjectDto(uuid);
     UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.USER, uuid);
 
-    List<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(project, userSession);
-    assertThat(pages).extracting("visible").containsExactly(
-      false, true, true, false, false, false, false, false, false, false);
+    Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(project, userSession);
+    assertThat(pages).extracting("name").containsExactly(
+      "project_quality_profiles.page",
+      "project_quality_gate.page"
+      );
+  }
+
+  @Test
+  public void pages_for_project_with_all_resource_type_properties() throws Exception {
+    String uuid = "abcd";
+    ComponentDto component = ComponentTesting.newProjectDto(uuid);
+    UserSession userSession = MockUserSession.set().setLogin("obiwan").addProjectUuidPermissions(UserRole.ADMIN, uuid);
+    when(resourceTypes.get(component.qualifier())).thenReturn(
+      ResourceType.builder(component.qualifier())
+        .setProperty("configurable", true)
+        .setProperty("hasRolePolicy", true)
+        .setProperty("modifiable_history", true)
+        .setProperty("updatable_key", true)
+        .setProperty("deletable", true)
+        .build());
+
+    Collection<ConfigPage> pages = new ComponentConfigurationPages(i18n, resourceTypes).getConfigPages(component, userSession);
+    assertThat(pages).extracting("name").containsExactly(
+      "project_settings.page",
+      "project_quality_profiles.page",
+      "project_quality_gate.page",
+      "manual_measures.page",
+      "action_plans.page",
+      "project_links.page",
+      "permissions.page",
+      "project_history.page",
+      "update_key.page",
+      "deletion.page"
+      );
   }
 }
index 1479c6ee3b6ef36e210b9cead5165922cf0e7c1e..bac4048828113faedaae1a14ed71ac434217008d 100644 (file)
@@ -421,8 +421,7 @@ public class ComponentNavigationActionTest {
     @Override
     List<ConfigPage> getConfigPages(ComponentDto component, UserSession userSession) {
       return Arrays.asList(
-        new ConfigPage(true, "/visible/page", "Visible Config Page"),
-        new ConfigPage(false, "/invisible/page", "Invisible Config Page"));
+        new ConfigPage(true, "/visible/page", "Visible Config Page"));
     }
   }
 }
index 110a48de4e87916ce3948db2b875bdb599d94669..a1a0276bfc69df1b3bf316994eecd9fd0bd501e8 100644 (file)
@@ -84,7 +84,7 @@
   </insert>
 
   <select id="selectMetricKeysForSnapshot" parameterType="long" resultType="string">
-  SELECT m.name
+  SELECT DISTINCT m.name
   FROM project_measures pm
   INNER JOIN metrics m ON m.id=pm.metric_id
   WHERE pm.snapshot_id=#{snapshotId}