]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1929 do not register dashboards which name already exits
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 16 Dec 2011 12:08:40 +0000 (13:08 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 16 Dec 2011 12:08:40 +0000 (13:08 +0100)
+ remove the useless column DASHBOARDS.KEE

35 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java
plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-core/src/main/java/org/sonar/persistence/dashboard/ActiveDashboardDao.java
sonar-core/src/main/java/org/sonar/persistence/dashboard/DashboardDao.java
sonar-core/src/main/java/org/sonar/persistence/dashboard/DashboardDto.java
sonar-core/src/main/java/org/sonar/persistence/dashboard/DashboardMapper.java
sonar-core/src/main/resources/org/sonar/persistence/dashboard/DashboardMapper-oracle.xml
sonar-core/src/main/resources/org/sonar/persistence/dashboard/DashboardMapper.xml
sonar-core/src/main/resources/org/sonar/persistence/rows-derby.sql
sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl
sonar-core/src/test/java/org/sonar/persistence/dashboard/ActiveDashboardDaoTest.java
sonar-core/src/test/java/org/sonar/persistence/dashboard/DashboardDaoTest.java
sonar-core/src/test/resources/org/sonar/persistence/dashboard/DashboardDaoTest/shouldInsert-result.xml
sonar-core/src/test/resources/org/sonar/persistence/dashboard/DashboardDaoTest/shouldInsertWithNullableColumns-result.xml
sonar-core/src/test/resources/org/sonar/persistence/dashboard/DashboardDaoTest/shouldSelectGlobalDashboard.xml [new file with mode: 0644]
sonar-deprecated/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java [new file with mode: 0644]
sonar-deprecated/src/main/java/org/sonar/api/web/Section.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/web/Dashboard.java
sonar-plugin-api/src/main/java/org/sonar/api/web/DashboardTemplate.java
sonar-plugin-api/src/main/java/org/sonar/api/web/Section.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java
sonar-server/src/main/webapp/WEB-INF/app/models/dashboard.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/reviews/index.html.erb
sonar-server/src/main/webapp/WEB-INF/db/migrate/235_create_loaded_templates.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/db/migrate/236_delete_value_type_from_widget_properties.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/237_delete_value_type_from_widget_properties.rb [deleted file]
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java

index 7b935de8a70777f54df5f56f7070a9a5fbf12a20..68ba5c20735746fa0c520ba4c8b6261b85feef84 100644 (file)
@@ -30,9 +30,14 @@ import org.sonar.api.web.DashboardTemplate;
  */
 public final class DefaultDashboard extends DashboardTemplate {
 
+  @Override
+  public String getName() {
+    return "Dashboard";
+  }
+
   @Override
   public Dashboard createDashboard() {
-    Dashboard dashboard = Dashboard.create("dashboard", "Dashboard");
+    Dashboard dashboard = Dashboard.create();
     dashboard.setLayout(DashboardLayout.TWO_COLUMNS);
     addFirstColumn(dashboard);
     addSecondColumn(dashboard);
index 0def3bd740b86ca4679e755cf317fec5e1e62f85..5241d62215fe3fd94926a387270fa2ce54420749 100644 (file)
@@ -34,9 +34,14 @@ public final class HotspotsDashboard extends DashboardTemplate {
   private static final String TITLE_PROPERTY = "title";
   private static final String METRIC_PROPERTY = "metric";
 
+  @Override
+  public String getName() {
+    return "Hotspots";
+  }
+
   @Override
   public Dashboard createDashboard() {
-    Dashboard dashboard = Dashboard.createByName("Hotspots");
+    Dashboard dashboard = Dashboard.create();
     dashboard.setLayout(DashboardLayout.TWO_COLUMNS);
 
     addFirstColumn(dashboard);
index bd4c5bd895bc81aae79796da00311b2899524fb5..3d27bae2f3fb9127ba6fbc7693a3f07671019329 100644 (file)
@@ -29,10 +29,10 @@ import static org.junit.Assert.assertThat;
 public class DefaultDashboardTest {
   @Test
   public void shouldCreateDashboard() {
-    Dashboard main = new DefaultDashboard().createDashboard();
-    assertThat(main.getId(), Is.is("dashboard"));
-    assertThat(main.getName(), Is.is("Dashboard"));
-    assertThat(main.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS));
-    assertThat(main.getWidgets().size(), Is.is(11));
+    DefaultDashboard template = new DefaultDashboard();
+    Dashboard dashboard = template.createDashboard();
+    assertThat(template.getName(), Is.is("Dashboard"));
+    assertThat(dashboard.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS));
+    assertThat(dashboard.getWidgets().size(), Is.is(11));
   }
 }
index 83042ef59fc57bd91dd2f1f35342417409d55c0d..e5e4c211ba29fce1ae0af064f09d8665ff2a8ff8 100644 (file)
@@ -29,9 +29,9 @@ import static org.junit.Assert.assertThat;
 public class HotspotsDashboardTest {
   @Test
   public void shouldCreateDashboard() {
-    Dashboard hotspots = new HotspotsDashboard().createDashboard();
-    assertThat(hotspots.getId(), Is.is("hotspots"));
-    assertThat(hotspots.getName(), Is.is("Hotspots"));
+    HotspotsDashboard template = new HotspotsDashboard();
+    Dashboard hotspots = template.createDashboard();
+    assertThat(template.getName(), Is.is("Hotspots"));
     assertThat(hotspots.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS));
     assertThat(hotspots.getWidgets().size(), Is.is(8));
   }
index fed078cfa23e66b1f1eba84b8653d387a44840a3..98922d6175e8a5e6111874fe60807b48f39416d0 100644 (file)
@@ -167,8 +167,8 @@ delta_since_version=&Delta; since version {0}
 disable_treemap=Disable treemap
 enable_treemap=Enable treemap
 equals=Equals
-false_positive=False-Positive
-false_positives_only=False-Positives only
+false_positive=False-positive
+false_positives_only=False-positives only
 full_source=Full source
 greater_or_equals=Greater or equals
 greater_than=Greater than
@@ -396,6 +396,7 @@ reviews.reopen_submit=Reopen
 reviews.status.REOPENED=Reopened
 reviews.status.RESOLVED=Resolved
 reviews.status.OPEN=Open
+reviews.status.CLOSED=Closed
 reviews.resolution.FALSE-POSITIVE=False-positive
 reviews.resolution.FIXED=Fixed
 
@@ -460,11 +461,11 @@ property.category.server_id=Server ID
 #------------------------------------------------------------------------------
 
 # Default dashboard
-dashboard.dashboard.name=Dashboard
-dashboard.dashboard.description=Default dashboard
+dashboard.Dashboard.name=Dashboard
+dashboard.Dashboard.description=Default dashboard
 
-dashboard.hotspots.name=Hotspots
-dashboard.hotspots.description=Most useful hotspots widgets
+dashboard.Hotspots.name=Hotspots
+dashboard.Hotspots.description=Most useful hotspots widgets
 
 
 #------------------------------------------------------------------------------
index 1b69803b7c855acced8db6a23265706fdf3cea65..81e9315bedb3ce7d75846aed3ce42b7837a1f8dc 100644 (file)
@@ -42,7 +42,7 @@ public class SchemaMigration {
       - complete the Derby DDL file used for unit tests : sonar-testing-harness/src/main/resources/org/sonar/test/persistence/sonar-test.ddl
 
    */
-  public static final int LAST_VERSION = 237;
+  public static final int LAST_VERSION = 236;
 
   public final static String TABLE_NAME = "schema_migrations";
 
index 543949668400d41f2038fa9f6321cedcae1dbb69..1005824af097d2c84eae44117dea4a7f6542f160 100644 (file)
@@ -43,11 +43,12 @@ public class ActiveDashboardDao implements BatchComponent, ServerComponent {
     }
   }
 
-  public Integer selectMaxOrderIndexForNullUser() {
+  public int selectMaxOrderIndexForNullUser() {
     SqlSession session = mybatis.openSession();
     ActiveDashboardMapper mapper = session.getMapper(ActiveDashboardMapper.class);
     try {
-      return mapper.selectMaxOrderIndexForNullUser();
+      Integer max = mapper.selectMaxOrderIndexForNullUser();
+      return (max != null ? max.intValue() : 0);
     } finally {
       session.close();
     }
index edacc692d9e6e0f1749d937eb9d5b6ad3b4a9a5a..8c3754295df03c4becb3323cac7740b1b76dfdd9 100644 (file)
@@ -32,6 +32,16 @@ public class DashboardDao implements BatchComponent, ServerComponent {
     this.mybatis = mybatis;
   }
 
+  public DashboardDto selectGlobalDashboard(String name) {
+    SqlSession sqlSession = mybatis.openSession();
+    try {
+      DashboardMapper mapper = sqlSession.getMapper(DashboardMapper.class);
+      return mapper.selectGlobalDashboard(name);
+    } finally {
+      sqlSession.close();
+    }
+  }
+
   public void insert(DashboardDto dashboardDto) {
     SqlSession session = mybatis.openSession();
     DashboardMapper dashboardMapper = session.getMapper(DashboardMapper.class);
index c32f401c2cdca0cbdc317d7c39846899feb7ffcd..efe7a2f3407005bce3da63154225a9b3ba879b45 100644 (file)
  */
 package org.sonar.persistence.dashboard;
 
+import com.google.common.collect.Lists;
+
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 
-
-import com.google.common.collect.Lists;
-
-public class DashboardDto {
+public final class DashboardDto {
 
   private Long id;
-  private String key;
   private Long userId;
   private String name;
   private String description;
@@ -39,154 +37,85 @@ public class DashboardDto {
   private Date updatedAt;
   private List<WidgetDto> widgetDtos = Lists.newArrayList();
 
-  /**
-   * @return the id
-   */
   public Long getId() {
     return id;
   }
 
-  /**
-   * @param id
-   *          the id to set
-   */
-  public void setId(Long id) {
+  public DashboardDto setId(Long id) {
     this.id = id;
+    return this;
   }
 
-  /**
-   * @return the key
-   */
-  public String getKey() {
-    return key;
-  }
-
-  /**
-   * @param key
-   *          the key to set
-   */
-  public void setKey(String key) {
-    this.key = key;
-  }
-
-  /**
-   * @return the userId
-   */
   public Long getUserId() {
     return userId;
   }
 
-  /**
-   * @param userId
-   *          the userId to set
-   */
-  public void setUserId(Long userId) {
+  public DashboardDto setUserId(Long userId) {
     this.userId = userId;
+    return this;
   }
 
-  /**
-   * @return the name
-   */
   public String getName() {
     return name;
   }
 
-  /**
-   * @param name
-   *          the name to set
-   */
-  public void setName(String name) {
+  public DashboardDto setName(String name) {
     this.name = name;
+    return this;
   }
 
-  /**
-   * @return the description
-   */
   public String getDescription() {
     return description;
   }
 
-  /**
-   * @param description
-   *          the description to set
-   */
-  public void setDescription(String description) {
+  public DashboardDto setDescription(String description) {
     this.description = description;
+    return this;
   }
 
-  /**
-   * @return the columnLayout
-   */
   public String getColumnLayout() {
     return columnLayout;
   }
 
-  /**
-   * @param columnLayout
-   *          the columnLayout to set
-   */
-  public void setColumnLayout(String columnLayout) {
+  public DashboardDto setColumnLayout(String columnLayout) {
     this.columnLayout = columnLayout;
+    return this;
   }
 
-  /**
-   * @return the shared
-   */
   public boolean getShared() {
     return shared;
   }
 
-  /**
-   * @param shared
-   *          the shared to set
-   */
-  public void setShared(boolean shared) {
+  public DashboardDto setShared(boolean shared) {
     this.shared = shared;
+    return this;
   }
 
-  /**
-   * @return the createdAt
-   */
   public Date getCreatedAt() {
     return createdAt;
   }
 
-  /**
-   * @param createdAt
-   *          the createdAt to set
-   */
-  public void setCreatedAt(Date createdAt) {
+  public DashboardDto setCreatedAt(Date createdAt) {
     this.createdAt = createdAt;
+    return this;
   }
 
-  /**
-   * @return the updatedAt
-   */
   public Date getUpdatedAt() {
     return updatedAt;
   }
 
-  /**
-   * @param updatedAt
-   *          the updatedAt to set
-   */
-  public void setUpdatedAt(Date updatedAt) {
+  public DashboardDto setUpdatedAt(Date updatedAt) {
     this.updatedAt = updatedAt;
+    return this;
   }
 
-  /**
-   * @return the widgets
-   */
   public Collection<WidgetDto> getWidgets() {
     return widgetDtos;
   }
 
-  /**
-   * @param widgetDto
-   *          the widget to add
-   */
-  public void addWidget(WidgetDto widgetDto) {
+  public DashboardDto addWidget(WidgetDto widgetDto) {
     widgetDtos.add(widgetDto);
+    return this;
   }
 
 }
index c1d89860e7e2225fc6909f28a51eef0de3fcebf7..1dce842f43a47fc632a3ca30f2577ab766cf4e23 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.persistence.dashboard;
 
 public interface DashboardMapper {
 
+  DashboardDto selectGlobalDashboard(String name);
+
   void insert(DashboardDto dashboardDto);
 
 }
index 4f287e953bc45779e62c9ba484eae70574d2250a..3e7a66ff070055bd59fd2ee14a1a57e22d68ebed 100644 (file)
@@ -3,13 +3,18 @@
 
 <mapper namespace="org.sonar.persistence.dashboard.DashboardMapper">
 
-  <insert id="insert" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id" >
-        select dashboards_seq.NEXTVAL from DUAL
+  <select id="selectGlobalDashboard" parameterType="string" resultType="Dashboard">
+    select id, user_id as "userId", name, description, column_layout as "columnLayout", shared, created_at as "createdAt", updated_at as "updatedAt"
+    from dashboards WHERE name=#{id} and user_id is null
+  </select>
+
+  <insert id="insert" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+      select dashboards_seq.NEXTVAL from DUAL
     </selectKey>
-    INSERT INTO dashboards (id, kee, user_id, name, description, column_layout, shared, created_at, updated_at)
-    VALUES (#{id}, #{key}, #{userId, jdbcType=FLOAT}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, 
-            #{columnLayout, jdbcType=INTEGER}, #{shared}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
+    INSERT INTO dashboards (id, user_id, name, description, column_layout, shared, created_at, updated_at)
+    VALUES (#{id}, #{userId, jdbcType=FLOAT}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR},
+    #{columnLayout, jdbcType=INTEGER}, #{shared}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
   </insert>
 
 </mapper>
index 8c1a7c3f8c41c65417002e00e2213624880b1929..3cb07d02a728a8932ba46028dfad16c69b3d18ef 100644 (file)
@@ -3,10 +3,15 @@
 
 <mapper namespace="org.sonar.persistence.dashboard.DashboardMapper">
 
-  <insert id="insert" parameterType="Dashboard" useGeneratedKeys="true" keyProperty ="id">
-    INSERT INTO dashboards (kee, user_id, name, description, column_layout, shared, created_at, updated_at)
-    VALUES (#{key}, #{userId, jdbcType=FLOAT}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR}, 
-            #{columnLayout, jdbcType=INTEGER}, #{shared}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
+  <select id="selectGlobalDashboard" parameterType="string" resultType="Dashboard">
+    select id, user_id as "userId", name, description, column_layout as "columnLayout", shared, created_at as "createdAt", updated_at as "updatedAt"
+    from dashboards WHERE name=#{id} and user_id is null
+  </select>
+
+  <insert id="insert" parameterType="Dashboard" useGeneratedKeys="true" keyProperty="id">
+    INSERT INTO dashboards (user_id, name, description, column_layout, shared, created_at, updated_at)
+    VALUES (#{userId, jdbcType=FLOAT}, #{name, jdbcType=VARCHAR}, #{description, jdbcType=VARCHAR},
+    #{columnLayout, jdbcType=INTEGER}, #{shared}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP})
   </insert>
 
 </mapper>
index fa0381c613cbc10ba3d698c8ad2ebe9ed170a28c..294d38fd1556c32eab357173461e5ab410d097ee 100644 (file)
@@ -165,7 +165,6 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('233');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('234');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('235');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('236');
-INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('237');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 010332f89b6a2cb78503f1f17004d6df34cf5001..47c09d21f4826225761655117ca3e353d1ed32ad 100644 (file)
@@ -412,7 +412,6 @@ CREATE TABLE "FILTERS" (
 
 CREATE TABLE "DASHBOARDS" (
   "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "KEE" VARCHAR(256) NOT NULL,
   "USER_ID" INTEGER,
   "NAME" VARCHAR(256),
   "DESCRIPTION" VARCHAR(1000),
index 6bc5eaf4977051888ab86939fac212db9e3fa993..4f68be3ef85d55115c6763c981b7f8aa72cc947c 100644 (file)
  */
 package org.sonar.persistence.dashboard;
 
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.persistence.DaoTestCase;
-import org.sonar.persistence.dashboard.ActiveDashboardDao;
-import org.sonar.persistence.dashboard.ActiveDashboardDto;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
 
 public class ActiveDashboardDaoTest extends DaoTestCase {
 
@@ -67,18 +64,18 @@ public class ActiveDashboardDaoTest extends DaoTestCase {
   public void shouldGetMaxOrderIndexForNullUser() throws Exception {
     setupData("shouldGetMaxOrderIndexForNullUser");
 
-    Integer index = dao.selectMaxOrderIndexForNullUser();
+    int index = dao.selectMaxOrderIndexForNullUser();
 
     assertThat(index, is(15));
   }
 
   @Test
-  public void shouldGetEmptyMaxOrderIndex() throws Exception {
+  public void shouldGetZeroMaxOrderIndex() throws Exception {
     setupData("empty");
 
-    Integer index = dao.selectMaxOrderIndexForNullUser();
+    int index = dao.selectMaxOrderIndexForNullUser();
 
-    assertThat(index, is(nullValue()));
+    assertThat(index, is(0));
   }
 
 }
index e7160dd02945a102f71d487e379f98f4d49f9c00..d63bfb871e587b67f6494349f023f335512fbdef 100644 (file)
@@ -25,22 +25,36 @@ import org.sonar.persistence.DaoTestCase;
 
 import java.util.Date;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
 public class DashboardDaoTest extends DaoTestCase {
 
   private DashboardDao dao;
 
   @Before
-  public void createDao() throws Exception {
+  public void createDao() {
     dao = new DashboardDao(getMyBatis());
   }
 
   @Test
-  public void shouldInsert() throws Exception {
+  public void shouldSelectGlobalDashboard() {
+    setupData("shouldSelectGlobalDashboard");
+    DashboardDto dashboard = dao.selectGlobalDashboard("SQALE");
+    assertThat(dashboard.getId(), is(2L));
+    assertThat(dashboard.getUserId(), nullValue());
+
+    assertNull(dao.selectGlobalDashboard("unknown"));
+  }
+
+  @Test
+  public void shouldInsert() {
     setupData("shouldInsert");
     Date aDate = new Date();
 
     DashboardDto dashboardDto = new DashboardDto();
-    dashboardDto.setKey("d-key");
     dashboardDto.setUserId(6L);
     dashboardDto.setName("My Dashboard");
     dashboardDto.setDescription("This is a dashboard");
@@ -75,7 +89,6 @@ public class DashboardDaoTest extends DaoTestCase {
     setupData("shouldInsert");
 
     DashboardDto dashboardDto = new DashboardDto();
-    dashboardDto.setKey("d-key");
     dashboardDto.setUserId(null);
     dashboardDto.setName(null);
     dashboardDto.setDescription(null);
index 91f73beae633f9ddcf72ee4c5feb5ab64da0a98e..8c4415d36576120f6e7281cd94a7dbeceefcbca7 100644 (file)
@@ -2,7 +2,6 @@
 
   <dashboards
     id="1"
-    kee="d-key"
     user_id="6"
     name="My Dashboard"
     description="This is a dashboard"
diff --git a/sonar-core/src/test/resources/org/sonar/persistence/dashboard/DashboardDaoTest/shouldSelectGlobalDashboard.xml b/sonar-core/src/test/resources/org/sonar/persistence/dashboard/DashboardDaoTest/shouldSelectGlobalDashboard.xml
new file mode 100644 (file)
index 0000000..ab98303
--- /dev/null
@@ -0,0 +1,20 @@
+<dataset>
+
+  <dashboards
+    id="1"
+    user_id="6"
+    name="SQALE"
+    description="User SQALE dashboard"
+    column_layout="100%"
+    shared="[true]"/>
+
+  <dashboards
+    id="2"
+    user_id="[null]"
+    name="SQALE"
+    description="Global SQALE dashboard"
+    column_layout="100%"
+    shared="[true]"/>
+
+
+</dataset>
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java b/sonar-deprecated/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java
new file mode 100644 (file)
index 0000000..78be6e1
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.api.web;
+
+/**
+ * @since 1.10
+ * @deprecated override org.sonar.api.web.AbstractRubyTemplate and implement org.sonar.api.web.RubyRailsWidget
+ */
+@Deprecated
+public abstract class AbstractDashboardWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+
+  public String getId() {
+    return getClass().getSimpleName();
+  }
+
+  public String getTitle() {
+    return getClass().getSimpleName();
+  }
+}
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/web/Section.java b/sonar-deprecated/src/main/java/org/sonar/api/web/Section.java
new file mode 100644 (file)
index 0000000..2a678aa
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.api.web;
+
+/**
+ * @since 1.10
+ * @deprecated add annotation org.sonar.api.web.NavigationSection to View extensions
+ */
+@Deprecated
+public enum Section {
+  HOME, PROJECT, CONFIGURATION
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/AbstractDashboardWidget.java
deleted file mode 100644 (file)
index 78be6e1..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.api.web;
-
-/**
- * @since 1.10
- * @deprecated override org.sonar.api.web.AbstractRubyTemplate and implement org.sonar.api.web.RubyRailsWidget
- */
-@Deprecated
-public abstract class AbstractDashboardWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-
-  public String getId() {
-    return getClass().getSimpleName();
-  }
-
-  public String getTitle() {
-    return getClass().getSimpleName();
-  }
-}
index 8e709bd8e4b10977f0427ef373b15dfdbe1bd444..ca0602a6f92dcfe6f5c697f0deb894ad2d604e99 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.api.web;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Maps;
-import org.apache.commons.lang.StringUtils;
 
 import java.util.Collection;
 import java.util.List;
@@ -38,8 +37,6 @@ import java.util.Map;
  */
 public final class Dashboard {
 
-  private String id;
-  private String name;
   private String description;
   private DashboardLayout layout = DashboardLayout.TWO_COLUMNS;
   private ListMultimap<Integer, Widget> widgetsByColumn = ArrayListMultimap.create();
@@ -50,22 +47,8 @@ public final class Dashboard {
   /**
    * Creates a new {@link Dashboard}.
    */
-  public static Dashboard create(String id, String name) {
-    return new Dashboard()
-      .setId(id)
-      .setName(name);
-  }
-
-  /**
-   * The id is deduced from the name.
-   */
-  public static Dashboard createByName(String name) {
-    String id = StringUtils.trimToEmpty(name);
-    id = StringUtils.lowerCase(id);
-    id = StringUtils.replaceChars(id, ' ', '_');
-    return new Dashboard()
-      .setId(id)
-      .setName(name);
+  public static Dashboard create() {
+    return new Dashboard();
   }
 
   /**
@@ -92,40 +75,6 @@ public final class Dashboard {
     return widgetsByColumn.get(columnId);
   }
 
-  /**
-   * Returns the identifier of the dashboard.
-   *
-   * @return the id
-   */
-  public String getId() {
-    return id;
-  }
-
-  private Dashboard setId(String id) {
-    if (StringUtils.isBlank(id)) {
-      throw new IllegalArgumentException("Dashboard id can not be blank");
-    }
-    this.id = id;
-    return this;
-  }
-
-  /**
-   * Returns the name of the dashboard.
-   *
-   * @return the name
-   */
-  public String getName() {
-    return name;
-  }
-
-  /**
-   * @param name the name to set
-   */
-  private Dashboard setName(String name) {
-    this.name = name;
-    return this;
-  }
-
   /**
    * Returns the description of the dashboard.
    *
@@ -158,7 +107,7 @@ public final class Dashboard {
 
   public Dashboard setLayout(DashboardLayout dl) {
     if (dl == null) {
-      throw new IllegalArgumentException("The layout of the dashboard '" + getId() + "' can not be null");
+      throw new IllegalArgumentException("The layout can not be null");
     }
     this.layout = dl;
     return this;
index ead4a5223df3b06b5c28148eed6a52ebed5fd971..897685fcf09c47efb540e354ff5cd7212d7ef7b7 100644 (file)
@@ -35,4 +35,8 @@ public abstract class DashboardTemplate implements ServerExtension {
    */
   public abstract Dashboard createDashboard();
 
+  /**
+   * Dashboard name
+   */
+  public abstract String getName();
 }
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/Section.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/Section.java
deleted file mode 100644 (file)
index 2a678aa..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.api.web;
-
-/**
- * @since 1.10
- * @deprecated add annotation org.sonar.api.web.NavigationSection to View extensions
- */
-@Deprecated
-public enum Section {
-  HOME, PROJECT, CONFIGURATION
-}
index ecc09898b8c9e8a1230b5ea4f11bf465ba4579c6..b5db3019272266c1a37288286024c52eef340f25 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.api.web;
 
-import org.hamcrest.core.Is;
 import org.junit.Test;
 
 import static org.hamcrest.Matchers.is;
@@ -30,16 +29,15 @@ public class DashboardTest {
 
   @Test
   public void shouldCreateDashboard() {
-    Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake");
-    assertThat(dashboard.getId(), is("fake-dashboard"));
-    assertThat(dashboard.getName(), is("Fake"));
+    Dashboard dashboard = Dashboard.create();
     assertThat(dashboard.getLayout(), is(DashboardLayout.TWO_COLUMNS));
     assertThat(dashboard.getDescription(), nullValue());
+    assertThat(dashboard.getWidgets().size(), is(0));
   }
 
   @Test
   public void shouldAddWidgets() {
-    Dashboard dashboard = Dashboard.createByName("Fake");
+    Dashboard dashboard = Dashboard.create();
     Dashboard.Widget mostViolatedRules = dashboard.addWidget("most_violated_rules", 1);
     assertThat(mostViolatedRules.getId(), is("most_violated_rules"));
     assertThat(dashboard.getWidgets().size(), is(1));
@@ -55,7 +53,7 @@ public class DashboardTest {
 
   @Test
   public void shouldAddWidgetsOnDifferentColumns() {
-    Dashboard dashboard = Dashboard.createByName("Fake");
+    Dashboard dashboard = Dashboard.create();
 
     dashboard.addWidget("most_violated_rules", 1);
     assertThat(dashboard.getWidgets().size(), is(1));
@@ -66,28 +64,9 @@ public class DashboardTest {
     assertThat(dashboard.getWidgetsOfColumn(2).size(), is(1));
   }
 
-  @Test(expected = IllegalArgumentException.class)
-  public void shouldFailIfBlankId() {
-    Dashboard.create("  ", "Fake");
-  }
-
-  @Test(expected = IllegalArgumentException.class)
-  public void shouldFailToDeduceIdFromName() {
-    Dashboard.createByName("  ");
-  }
-
-  @Test
-  public void shouldCreateByName() {
-    Dashboard dashboard = Dashboard.createByName("Fake");
-    assertThat(dashboard.getId(), Is.is("fake"));
-
-    dashboard = Dashboard.createByName("  Fake You  ");
-    assertThat(dashboard.getId(), Is.is("fake_you"));
-  }
-
   @Test
   public void shouldAddSeveralTimesTheSameWidget() {
-    Dashboard dashboard = Dashboard.createByName("Fake");
+    Dashboard dashboard = Dashboard.create();
     dashboard.addWidget("most_violated_rules", 1);
     dashboard.addWidget("most_violated_rules", 1).setProperty("foo", "bar");
 
@@ -98,7 +77,7 @@ public class DashboardTest {
 
   @Test
   public void shouldSetWidgetProperty() {
-    Dashboard dashboard = Dashboard.createByName("Fake");
+    Dashboard dashboard = Dashboard.create();
     Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
     widget.setProperty("foo", "bar");
 
index c8cc09c9a03611b28b6c77955d7ace73a8b21ba9..f46dad792b50a9ce2dfc10f705e473bf60b45a03 100644 (file)
@@ -41,7 +41,7 @@ import java.util.Map.Entry;
 public final class RegisterNewDashboards {
 
   private static final Logger LOG = LoggerFactory.getLogger(RegisterNewDashboards.class);
-  static final String DEFAULT_DASHBOARD_ID = "dashboard";
+  static final String DEFAULT_DASHBOARD_NAME = "Dashboard";
 
   private List<DashboardTemplate> dashboardTemplates;
   private DashboardDao dashboardDao;
@@ -63,41 +63,31 @@ public final class RegisterNewDashboards {
   public void start() {
     TimeProfiler profiler = new TimeProfiler().start("Register dashboards");
 
-    // load the dashboards that need to be loaded
-    List<DashboardDto> loadedDashboards = Lists.newArrayList();
-    DashboardDto defaultDashboard = null;
-    for (DashboardTemplate dashboardTemplate : dashboardTemplates) {
-      Dashboard dashboard = dashboardTemplate.createDashboard();
-      if (shouldRegister(dashboard)) {
-        DashboardDto dashboardDto = registerDashboard(dashboard);
-        if (DEFAULT_DASHBOARD_ID.equals(dashboard.getId())) {
-          defaultDashboard = dashboardDto;
-        } else {
-          loadedDashboards.add(dashboardDto);
+    List<DashboardDto> registeredDashboards = Lists.newArrayList();
+    for (DashboardTemplate template : dashboardTemplates) {
+      if (shouldRegister(template.getName())) {
+        Dashboard dashboard = template.createDashboard();
+        DashboardDto dto = register(template.getName(), dashboard);
+        if (dto != null) {
+          registeredDashboards.add(dto);
         }
       }
     }
-    // and activate them
-    activateDashboards(loadedDashboards, defaultDashboard);
+
+    activate(registeredDashboards);
 
     profiler.stop();
   }
 
-  protected void activateDashboards(List<DashboardDto> loadedDashboards, DashboardDto defaultDashboard) {
-    int nextOrderIndex;
-    if (defaultDashboard != null) {
-      activateDashboard(defaultDashboard, 1);
-      nextOrderIndex = 2;
-    } else {
-      nextOrderIndex = activeDashboardDao.selectMaxOrderIndexForNullUser() + 1;
-    }
+  protected void activate(List<DashboardDto> loadedDashboards) {
+    int nextOrderIndex = activeDashboardDao.selectMaxOrderIndexForNullUser() + 1;
     Collections.sort(loadedDashboards, new DashboardComparator());
     for (DashboardDto dashboardDto : loadedDashboards) {
-      activateDashboard(dashboardDto, nextOrderIndex++);
+      activate(dashboardDto, nextOrderIndex++);
     }
   }
 
-  private void activateDashboard(DashboardDto dashboardDto, int index) {
+  private void activate(DashboardDto dashboardDto, int index) {
     ActiveDashboardDto activeDashboardDto = new ActiveDashboardDto();
     activeDashboardDto.setDashboardId(dashboardDto.getId());
     activeDashboardDto.setOrderIndex(index);
@@ -105,20 +95,21 @@ public final class RegisterNewDashboards {
     LOG.info("New dashboard '" + dashboardDto.getName() + "' registered");
   }
 
-  protected DashboardDto registerDashboard(Dashboard dashboard) {
-    DashboardDto dto = createDtoFromExtension(dashboard);
-    // save the new dashboard
-    dashboardDao.insert(dto);
+  protected DashboardDto register(String name, Dashboard dashboard) {
+    DashboardDto dto = null;
+    if (dashboardDao.selectGlobalDashboard(name) == null) {
+      dto = createDtoFromExtension(name, dashboard);
+      dashboardDao.insert(dto);
+    }
     // and save the fact that is has now already been loaded
-    loadedTemplateDao.insert(new LoadedTemplateDto(dashboard.getId(), LoadedTemplateDto.DASHBOARD_TYPE));
+    loadedTemplateDao.insert(new LoadedTemplateDto(name, LoadedTemplateDto.DASHBOARD_TYPE));
     return dto;
   }
 
-  protected DashboardDto createDtoFromExtension(Dashboard dashboard) {
+  protected DashboardDto createDtoFromExtension(String name, Dashboard dashboard) {
     Date now = new Date();
     DashboardDto dashboardDto = new DashboardDto();
-    dashboardDto.setKey(dashboard.getId());
-    dashboardDto.setName(dashboard.getName());
+    dashboardDto.setName(name);
     dashboardDto.setDescription(dashboard.getDescription());
     dashboardDto.setColumnLayout(dashboard.getLayout().getCode());
     dashboardDto.setShared(true);
@@ -150,12 +141,19 @@ public final class RegisterNewDashboards {
     return dashboardDto;
   }
 
-  protected boolean shouldRegister(Dashboard dashboard) {
-    return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, dashboard.getId()) == 0;
+  protected boolean shouldRegister(String dashboardName) {
+    return loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, dashboardName) == 0;
   }
 
   protected static class DashboardComparator implements Comparator<DashboardDto> {
     public int compare(DashboardDto d1, DashboardDto d2) {
+      // the default dashboard must be the first one to be activated
+      if (d1.getName().equals(DEFAULT_DASHBOARD_NAME)) {
+        return -1;
+      }
+      if (d2.getName().equals(DEFAULT_DASHBOARD_NAME)) {
+        return 1;
+      }
       return d1.getName().compareTo(d2.getName());
     }
   }
index c48acf060f046002975cc2aa503e6aeeaf116d37..1ed552fc661e9e084fa5c0b254870dab9bfb437e 100644 (file)
@@ -30,25 +30,25 @@ class Dashboard < ActiveRecord::Base
   validates_length_of :description, :maximum => 1000, :allow_blank => true, :allow_nil => true
   validates_length_of :column_layout, :maximum => 20, :allow_blank => false, :allow_nil => false
   validates_uniqueness_of :name, :scope => :user_id
-  
-  before_create { |dashboard| dashboard.kee=dashboard.name.strip.downcase.sub(/\s+/, '_') }
-    
+
   def name(l10n=true)
+    n=read_attribute(:name)
     if l10n
-      Api::Utils.message("dashboard.#{kee}.name", :default => read_attribute(:name))
+      Api::Utils.message("dashboard.#{n}.name", :default => n)
     else
-      read_attribute(:name)
+      n
     end
   end
 
   def description(l10n=true)
+    n=name(false)
     if l10n
-      Api::Utils.message("dashboard.#{kee}.description", :default => read_attribute(:description))
+      Api::Utils.message("dashboard.#{n}.description", :default => read_attribute(:description))
     else
       read_attribute(:description)
     end
   end
-  
+
   def shared?
     read_attribute(:shared) || false
   end
@@ -74,7 +74,7 @@ class Dashboard < ActiveRecord::Base
   end
 
   def column_size(column_index)
-    last_widget=widgets.select{|w| w.column_index==column_index}.max{|x,y| x.row_index <=> y.row_index}
+    last_widget=widgets.select { |w| w.column_index==column_index }.max { |x, y| x.row_index <=> y.row_index }
     last_widget ? last_widget.row_index : 0
   end
 
index 5af5c6c4058dced8acca139afab4bee6d950efca..7a150b1fe12f2cdf08cac89719aee609e874cead 100644 (file)
@@ -59,7 +59,7 @@
     <div class="discussionComment first" id="vBody<%= violation.id -%>">
       <% if current_user %>
         <div style="display: none" class="vActions" id="vActions<%= violation.id -%>">
-          <%= button_to_function message('reviews.comment'), "sCF(#{violation.id})", :name => 'bFComment' -%>
+          <%= button_to_function message('reviews.comment'), "sCF(#{violation.id})", :name => 'bComment' -%>
 
           <% unless violation.review && violation.review.resolved? %>
             <%= button_to_function message('reviews.assign'), "sAF(#{violation.id})", :name => 'bAssign' -%>
index 1c3e1a5a45e67791f1afef8f5bea1a3a4fc8a843..31648dc70e27cc2678736a9161d8a03c48cd33b6 100644 (file)
           <span class="note"><%= message('status') -%></span><br/>
           <select size="6" name="statuses[]" multiple="multiple" id="statuses" class="withIcons">
             <option <%= 'selected' if @statuses.include?('') -%> value=""><%= message('any') -%></option>
-            <option value="<%= Review::STATUS_OPEN -%>" class="status_open" <%= 'selected' if @statuses.include?(Review::STATUS_OPEN) -%>><%= message('open') -%></option>
-            <option value="<%= Review::STATUS_REOPENED -%>" class="status_reopened" <%= 'selected' if @statuses.include?(Review::STATUS_REOPENED) -%>><%= message('reopened') -%></option>
-            <option value="<%= Review::STATUS_RESOLVED -%>" class="status_resolved" <%= 'selected' if @statuses.include?(Review::STATUS_RESOLVED) -%>><%= message('resolved') -%></option>
-            <option value="<%= Review::STATUS_CLOSED -%>" class="status_closed" <%= 'selected' if @statuses.include?(Review::STATUS_CLOSED) -%>><%= message('closed') -%></option>
+            <option value="<%= Review::STATUS_OPEN -%>" class="status_open" <%= 'selected' if @statuses.include?(Review::STATUS_OPEN) -%>><%= message('reviews.status.OPEN') -%></option>
+            <option value="<%= Review::STATUS_REOPENED -%>" class="status_reopened" <%= 'selected' if @statuses.include?(Review::STATUS_REOPENED) -%>><%= message('reviews.status.REOPENED') -%></option>
+            <option value="<%= Review::STATUS_RESOLVED -%>" class="status_resolved" <%= 'selected' if @statuses.include?(Review::STATUS_RESOLVED) -%>><%= message('reviews.status.RESOLVED') -%></option>
+            <option value="<%= Review::STATUS_CLOSED -%>" class="status_closed" <%= 'selected' if @statuses.include?(Review::STATUS_CLOSED) -%>><%= message('reviews.status.CLOSED') -%></option>
           </select>
         </td>
         <td width="1%" nowrap>
index 88a50a17a47e58aa83fb83bafe3532a5f63e2a22..d1e3c0001b5da9a4b95fbe8f1e842102558ca0d5 100644 (file)
@@ -25,14 +25,14 @@ class CreateLoadedTemplates < ActiveRecord::Migration
 
   def self.up
     create_table 'loaded_templates' do |t|
-      t.column 'kee',     :string,    :null => true,    :limit => 200
-      t.column 'template_type',    :string,    :null => true,    :limit => 15      
+      t.column 'kee', :string, :null => true, :limit => 200
+      t.column 'template_type', :string, :null => true, :limit => 15
     end
-    
+
     # if this is a migration, then the default dashboard already exists in the DB so it should not be loaded again
     default_dashboard = Dashboard.find(:first, :conditions => {:name => 'Dashboard', :user_id => nil})
     if default_dashboard
-      LoadedTemplate.create({:kee => 'dashboard', :template_type => 'DASHBOARD'})
+      LoadedTemplate.create({:template_type => 'DASHBOARD', :kee => 'Dashboard'})
     end
   end
 
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_add_key_to_dashboards.rb
deleted file mode 100644 (file)
index 3650036..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2011 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
-#
-
-#
-# Sonar 2.13
-#
-class AddKeyToDashboards < ActiveRecord::Migration
-
-  def self.up
-    add_column 'dashboards', 'kee', :string, :limit => 200, :null => true
-    Dashboard.reset_column_information
-
-    Dashboard.find(:all).each do |d|
-      key = d.name(false).strip.downcase.sub(/\s+/, '_')
-      Dashboard.update_all "kee = '#{key}'", ["id = ?", d.id]
-    end
-
-    change_column 'dashboards', 'kee', :string, :limit => 200, :null => false
-    Dashboard.reset_column_information
-  end
-
-end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_delete_value_type_from_widget_properties.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/236_delete_value_type_from_widget_properties.rb
new file mode 100644 (file)
index 0000000..874312d
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2011 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+#
+
+#
+# Sonar 2.13
+#
+class DeleteValueTypeFromWidgetProperties < ActiveRecord::Migration
+
+  def self.up
+    remove_column('widget_properties', 'value_type')
+    WidgetProperty.reset_column_information()
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_delete_value_type_from_widget_properties.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/237_delete_value_type_from_widget_properties.rb
deleted file mode 100644 (file)
index 874312d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2011 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
-#
-
-#
-# Sonar 2.13
-#
-class DeleteValueTypeFromWidgetProperties < ActiveRecord::Migration
-
-  def self.up
-    remove_column('widget_properties', 'value_type')
-    WidgetProperty.reset_column_information()
-  end
-
-end
index ae51e4b9701b18efc14e3eabe2fb961a7255f6fc..95132c0f29364a384f28f88abd57edcffc8da5cf 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.server.startup;
 
 import com.google.common.collect.Lists;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
 import org.junit.Before;
 import org.junit.Test;
 import org.sonar.api.web.Dashboard;
@@ -29,7 +31,6 @@ import org.sonar.persistence.dashboard.*;
 import org.sonar.persistence.template.LoadedTemplateDao;
 import org.sonar.persistence.template.LoadedTemplateDto;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -43,7 +44,7 @@ import static org.mockito.Mockito.*;
 
 public class RegisterNewDashboardsTest {
 
-  private RegisterNewDashboards registerNewDashboards;
+  private RegisterNewDashboards task;
   private DashboardDao dashboardDao;
   private ActiveDashboardDao activeDashboardDao;
   private LoadedTemplateDao loadedTemplateDao;
@@ -57,32 +58,34 @@ public class RegisterNewDashboardsTest {
 
     fakeDashboardTemplate = new FakeDashboard();
 
-    registerNewDashboards = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
+    task = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao,
       activeDashboardDao, loadedTemplateDao);
   }
 
   @Test
-  public void testStart() throws Exception {
-    registerNewDashboards.start();
-    verify(dashboardDao).insert(any(org.sonar.persistence.dashboard.DashboardDto.class));
+  public void testStart() {
+    task.start();
+    verify(dashboardDao).insert(any(DashboardDto.class));
     verify(loadedTemplateDao).insert(any(LoadedTemplateDto.class));
     verify(activeDashboardDao).insert(any(ActiveDashboardDto.class));
   }
 
   @Test
-  public void testShouldNotBeRegistered() throws Exception {
-    when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, "fake-dashboard")).thenReturn(1);
-    assertThat(registerNewDashboards.shouldRegister(fakeDashboardTemplate.createDashboard()), is(false));
+  public void shouldNotRegister() {
+    when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, "Fake")).thenReturn(1);
+    assertThat(task.shouldRegister("Fake"), is(false));
   }
 
   @Test
-  public void testShouldBeLoaded() throws Exception {
-    assertThat(registerNewDashboards.shouldRegister(fakeDashboardTemplate.createDashboard()), is(true));
+  public void shouldRegisterDashboard() {
+    when(loadedTemplateDao.countByTypeAndKey(LoadedTemplateDto.DASHBOARD_TYPE, "Fake")).thenReturn(0);
+    assertThat(task.shouldRegister("Fake"), is(true));
   }
 
   @Test
-  public void shouldLoadDasboard() throws Exception {
-    DashboardDto dashboardDto = registerNewDashboards.registerDashboard(fakeDashboardTemplate.createDashboard());
+  public void testRegisterDashboard() {
+    DashboardDto dashboardDto = task.register("Fake", fakeDashboardTemplate.createDashboard());
+
     assertNotNull(dashboardDto);
     verify(dashboardDao).insert(dashboardDto);
     verify(loadedTemplateDao).insert(eq(new LoadedTemplateDto("fake-dashboard", LoadedTemplateDto.DASHBOARD_TYPE)));
@@ -90,9 +93,9 @@ public class RegisterNewDashboardsTest {
 
   @Test
   public void shouldCreateDtoFromExtension() {
-    DashboardDto dto = registerNewDashboards.createDtoFromExtension(fakeDashboardTemplate.createDashboard());
+    DashboardDto dto = task.createDtoFromExtension("Fake", fakeDashboardTemplate.createDashboard());
     assertThat(dto.getUserId(), is(nullValue()));
-    assertThat(dto.getKey(), is("fake-dashboard"));
+    assertThat(dto.getName(), is("Fake"));
     assertThat(dto.getDescription(), nullValue());
     assertThat(dto.getColumnLayout(), is("30%-70%"));
     assertThat(dto.getShared(), is(true));
@@ -114,11 +117,9 @@ public class RegisterNewDashboardsTest {
   }
 
   @Test
-  public void shouldCompareDashboardForSorting() throws Exception {
-    DashboardDto d1 = mock(DashboardDto.class);
-    when(d1.getName()).thenReturn("Foo");
-    DashboardDto d2 = mock(DashboardDto.class);
-    when(d2.getName()).thenReturn("Bar");
+  public void shouldCompareDashboards() throws Exception {
+    DashboardDto d1 = new DashboardDto().setName("Foo");
+    DashboardDto d2 = new DashboardDto().setName("Bar");
     List<DashboardDto> dashboardDtos = Lists.newArrayList(d1, d2);
     Collections.sort(dashboardDtos, new RegisterNewDashboards.DashboardComparator());
 
@@ -126,61 +127,60 @@ public class RegisterNewDashboardsTest {
   }
 
   @Test
-  public void shouldActivateAllDashboards() throws Exception {
-    DashboardDto d1 = mock(DashboardDto.class);
-    when(d1.getName()).thenReturn("Foo");
-    when(d1.getId()).thenReturn(14L);
-    DashboardDto d2 = mock(DashboardDto.class);
-    when(d2.getName()).thenReturn("Bar");
-    when(d2.getId()).thenReturn(16L);
-    ArrayList<DashboardDto> loadedDashboards = Lists.newArrayList(d1, d2);
+  public void shouldActivateDashboards() throws Exception {
+    DashboardDto d1 = new DashboardDto().setName("Foo").setId(14L);
+    DashboardDto d2 = new DashboardDto().setName("Bar").setId(16L);
+    List<DashboardDto> loadedDashboards = Lists.newArrayList(d1, d2);
 
     when(activeDashboardDao.selectMaxOrderIndexForNullUser()).thenReturn(4);
 
-    registerNewDashboards.activateDashboards(loadedDashboards, null);
+    task.activate(loadedDashboards);
 
-    ActiveDashboardDto ad1 = new ActiveDashboardDto();
-    ad1.setDashboardId(16L);
-    ad1.setOrderIndex(5);
-    verify(activeDashboardDao).insert(eq(ad1));
-    ActiveDashboardDto ad2 = new ActiveDashboardDto();
-    ad2.setDashboardId(14L);
-    ad2.setOrderIndex(6);
-    verify(activeDashboardDao).insert(eq(ad2));
+    verify(activeDashboardDao).insert(argThat(matchActiveDashboard(16L, 5)));
+    verify(activeDashboardDao).insert(argThat(matchActiveDashboard(14L, 6)));
   }
 
   @Test
-  public void shouldActivateDefaultDashboard() throws Exception {
-    DashboardDto defaultDashboard = mock(DashboardDto.class);
-    when(defaultDashboard.getName()).thenReturn(RegisterNewDashboards.DEFAULT_DASHBOARD_ID);
-    when(defaultDashboard.getId()).thenReturn(1L);
-    DashboardDto d1 = mock(DashboardDto.class);
-    when(d1.getName()).thenReturn("Bar");
-    when(d1.getId()).thenReturn(16L);
-    List<DashboardDto> loadedDashboards = Lists.newArrayList(d1);
-
-    registerNewDashboards.activateDashboards(loadedDashboards, defaultDashboard);
-
-    ActiveDashboardDto ad1 = new ActiveDashboardDto();
-    ad1.setDashboardId(1L);
-    ad1.setOrderIndex(1);
-    verify(activeDashboardDao).insert(eq(ad1));
-    ActiveDashboardDto ad2 = new ActiveDashboardDto();
-    ad2.setDashboardId(16L);
-    ad2.setOrderIndex(2);
-    verify(activeDashboardDao).insert(eq(ad2));
+  public void defaultDashboardShouldBeTheFirstActivatedDashboard() throws Exception {
+    DashboardDto defaultDashboard = new DashboardDto()
+      .setName(RegisterNewDashboards.DEFAULT_DASHBOARD_NAME)
+      .setId(10L);
+    DashboardDto other = new DashboardDto()
+      .setName("Bar")
+      .setId(11L);
+    List<DashboardDto> dashboards = Lists.newArrayList(other, defaultDashboard);
+
+    task.activate(dashboards);
+
+    verify(activeDashboardDao).insert(argThat(matchActiveDashboard(10L, 1)));
+    verify(activeDashboardDao).insert(argThat(matchActiveDashboard(11L, 2)));
+  }
+
+  private BaseMatcher<ActiveDashboardDto> matchActiveDashboard(final long dashboardId, final int orderId) {
+    return new BaseMatcher<ActiveDashboardDto>() {
+      public boolean matches(Object o) {
+        ActiveDashboardDto dto = (ActiveDashboardDto) o;
+        return dto.getDashboardId() == dashboardId && dto.getOrderIndex() == orderId;
+      }
+
+      public void describeTo(Description description) {
+      }
+    };
   }
 
   public class FakeDashboard extends DashboardTemplate {
+    @Override
+    public String getName() {
+      return "Fake";
+    }
 
     @Override
     public Dashboard createDashboard() {
-      Dashboard dashboard = Dashboard.create("fake-dashboard", "Fake");
+      Dashboard dashboard = Dashboard.create();
       dashboard.setLayout(DashboardLayout.TWO_COLUMNS_30_70);
       Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1);
       widget.setProperty("fake-property", "fake_metric");
       return dashboard;
     }
   }
-
 }