*/
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);
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);
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));
}
}
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));
}
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
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
#------------------------------------------------------------------------------
# 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
#------------------------------------------------------------------------------
- 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";
}
}
- 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();
}
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);
*/
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;
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;
}
}
public interface DashboardMapper {
+ DashboardDto selectGlobalDashboard(String name);
+
void insert(DashboardDto dashboardDto);
}
<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>
<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>
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;
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),
*/
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 {
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));
}
}
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");
setupData("shouldInsert");
DashboardDto dashboardDto = new DashboardDto();
- dashboardDto.setKey("d-key");
dashboardDto.setUserId(null);
dashboardDto.setName(null);
dashboardDto.setDescription(null);
<dashboards
id="1"
- kee="d-key"
user_id="6"
name="My Dashboard"
description="This is a dashboard"
<dashboards
id="1"
- kee="d-key"
user_id="[null]"
name="[null]"
description="[null]"
--- /dev/null
+<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>
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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
+}
+++ /dev/null
-/*
- * 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();
- }
-}
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;
*/
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();
/**
* 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();
}
/**
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.
*
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;
*/
public abstract Dashboard createDashboard();
+ /**
+ * Dashboard name
+ */
+ public abstract String getName();
}
+++ /dev/null
-/*
- * 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
-}
*/
package org.sonar.api.web;
-import org.hamcrest.core.Is;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
@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));
@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));
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");
@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");
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;
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);
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);
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());
}
}
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
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
<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' -%>
<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>
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
+++ /dev/null
-#
-# 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
--- /dev/null
+#
+# 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
+++ /dev/null
-#
-# 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
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;
import org.sonar.persistence.template.LoadedTemplateDao;
import org.sonar.persistence.template.LoadedTemplateDto;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RegisterNewDashboardsTest {
- private RegisterNewDashboards registerNewDashboards;
+ private RegisterNewDashboards task;
private DashboardDao dashboardDao;
private ActiveDashboardDao activeDashboardDao;
private LoadedTemplateDao loadedTemplateDao;
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)));
@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));
}
@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());
}
@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;
}
}
-
}