aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-29 07:37:20 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-29 07:59:35 +0200
commit07158ad5ddc2aef18ad9f3ab816dee2f3a08bcff (patch)
tree1ab9e95c0bf2cc6772edbfe7d48801ab2231fc00 /sonar-core
parent3bd60acafe0020c0de4f8f29eff70876176fdcb1 (diff)
downloadsonarqube-07158ad5ddc2aef18ad9f3ab816dee2f3a08bcff.tar.gz
sonarqube-07158ad5ddc2aef18ad9f3ab816dee2f3a08bcff.zip
SONAR-5646 add WS api/dashboards/show
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDto.java29
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/DashboardMapper.java24
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java57
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/WidgetMapper.java20
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyDto.java65
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyMapper.java21
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/BadDatabaseVersion.java31
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml11
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml6
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/dashboard/DashboardDaoTest.java12
11 files changed, 118 insertions, 163 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDto.java b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDto.java
index 2ac01903514..d0f05ba3f52 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDto.java
@@ -20,12 +20,12 @@
package org.sonar.core.dashboard;
import com.google.common.collect.Lists;
+import org.sonar.core.persistence.Dto;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
-public final class DashboardDto {
+public final class DashboardDto extends Dto<Long> {
private Long id;
private Long userId;
@@ -34,14 +34,17 @@ public final class DashboardDto {
private String columnLayout;
private boolean shared;
private boolean global;
- private Date createdAt;
- private Date updatedAt;
private List<WidgetDto> widgetDtos = Lists.newArrayList();
public Long getId() {
return id;
}
+ @Override
+ public Long getKey() {
+ return id;
+ }
+
public DashboardDto setId(Long id) {
this.id = id;
return this;
@@ -101,24 +104,6 @@ public final class DashboardDto {
return this;
}
- public Date getCreatedAt() {
- return createdAt;
- }
-
- public DashboardDto setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- public Date getUpdatedAt() {
- return updatedAt;
- }
-
- public DashboardDto setUpdatedAt(Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
public Collection<WidgetDto> getWidgets() {
return widgetDtos;
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardMapper.java b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardMapper.java
index 00a3573a84e..52e69a16816 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardMapper.java
@@ -19,11 +19,33 @@
*/
package org.sonar.core.dashboard;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import javax.annotation.CheckForNull;
public interface DashboardMapper {
+ String COLUMNS = "id, user_id as \"userId\", name, description, column_layout as \"columnLayout\", " +
+ "shared, is_global as \"global\", created_at as \"createdAt\", updated_at as \"updatedAt\"";
+
+ @CheckForNull
+ @Select("select " + COLUMNS + " from dashboards where id=#{id}")
+ DashboardDto selectById(long id);
+
+ @CheckForNull
+ @Select("select " + COLUMNS + " from dashboards where id=#{id} and (shared=${_true} or user_id=${userId})")
+ DashboardDto selectAllowedById(@Param("id") long id, @Param("userId") long userId);
+
+ @CheckForNull
+ @Select("select " + COLUMNS + " from dashboards WHERE name=#{id} and user_id is null")
DashboardDto selectGlobalDashboard(String name);
+ @Insert("INSERT INTO dashboards (user_id, name, description, column_layout, shared, is_global, created_at, " +
+ "updated_at) VALUES (#{userId}, #{name}, #{description}, #{columnLayout}, #{shared}, " +
+ "#{global}, #{createdAt}, #{updatedAt})")
+ @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id")
void insert(DashboardDto dashboardDto);
-
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java
index 1e85708bf96..989ff9e0eb8 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetDto.java
@@ -20,22 +20,20 @@
package org.sonar.core.dashboard;
import com.google.common.collect.Lists;
+import org.sonar.core.persistence.Dto;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
-public final class WidgetDto {
+public class WidgetDto extends Dto<Long> {
private Long id;
private Long dashboardId;
- private String key;
+ private String widgetKey;
private String name;
private String description;
private Integer columnIndex;
private Integer rowIndex;
private boolean configured;
- private Date createdAt;
- private Date updatedAt;
private Integer resourceId;
private List<WidgetPropertyDto> widgetPropertyDtos = Lists.newArrayList();
@@ -69,18 +67,12 @@ public final class WidgetDto {
return this;
}
- /**
- * @return the key
- */
- public String getKey() {
- return key;
+ public String getWidgetKey() {
+ return widgetKey;
}
- /**
- * @param key the key to set
- */
- public WidgetDto setKey(String key) {
- this.key = key;
+ public WidgetDto setWidgetKey(String s) {
+ this.widgetKey = s;
return this;
}
@@ -160,36 +152,6 @@ public final class WidgetDto {
}
/**
- * @return the createdAt
- */
- public Date getCreatedAt() {
- return createdAt;
- }
-
- /**
- * @param createdAt the createdAt to set
- */
- public WidgetDto setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- /**
- * @return the updatedAt
- */
- public Date getUpdatedAt() {
- return updatedAt;
- }
-
- /**
- * @param updatedAt the updatedAt to set
- */
- public WidgetDto setUpdatedAt(Date updatedAt) {
- this.updatedAt = updatedAt;
- return this;
- }
-
- /**
* @return the widgetProperties
*/
public Collection<WidgetPropertyDto> getWidgetProperties() {
@@ -220,4 +182,9 @@ public final class WidgetDto {
this.resourceId = resourceId;
return this;
}
+
+ @Override
+ public Long getKey() {
+ return id;
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetMapper.java b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetMapper.java
index 51945271945..4cb08989823 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetMapper.java
@@ -19,8 +19,28 @@
*/
package org.sonar.core.dashboard;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.Collection;
+
public interface WidgetMapper {
+ String COLUMNS = "ID, DASHBOARD_ID as \"dashboardId\", WIDGET_KEY as \"widgetKey\", NAME, DESCRIPTION, " +
+ "COLUMN_INDEX as \"columnIndex\", ROW_INDEX as \"rowIndex\", CONFIGURED, CREATED_AT as \"createdAt\", " +
+ "UPDATED_AT as \"updatedAt\", RESOURCE_ID as \"resourceId\"";
+
+ @Insert("insert into widgets (dashboard_id, widget_key, name, description, column_index, " +
+ " row_index, configured, created_at, updated_at, resource_id)" +
+ " values (#{dashboardId}, #{widgetKey}, #{name}, #{description}, #{columnIndex}, " +
+ " #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId})")
+ @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id")
void insert(WidgetDto widgetDto);
+ @Select("select " + COLUMNS + " from widgets where id=#{id}")
+ WidgetDto selectById(long widgetId);
+
+ @Select("select " + COLUMNS + " from widgets where dashboard_id=#{id}")
+ Collection<WidgetDto> selectByDashboard(long dashboardKey);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyDto.java b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyDto.java
index f3c4b7c4321..352b531bb43 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyDto.java
@@ -19,69 +19,64 @@
*/
package org.sonar.core.dashboard;
-public final class WidgetPropertyDto {
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import org.sonar.core.persistence.Dto;
+
+import java.util.Collection;
+
+public class WidgetPropertyDto extends Dto<Long> {
private Long id;
private Long widgetId;
- private String key;
- private String value;
+ private String propertyKey;
+ private String textValue;
- /**
- * @return the id
- */
public Long getId() {
return id;
}
- /**
- * @param id the id to set
- */
public WidgetPropertyDto setId(Long id) {
this.id = id;
return this;
}
- /**
- * @return the widgetId
- */
public Long getWidgetId() {
return widgetId;
}
- /**
- * @param widgetId the widgetId to set
- */
public WidgetPropertyDto setWidgetId(Long widgetId) {
this.widgetId = widgetId;
return this;
}
- /**
- * @return the key
- */
- public String getKey() {
- return key;
+ public String getPropertyKey() {
+ return propertyKey;
}
- /**
- * @param key the key to set
- */
- public WidgetPropertyDto setKey(String key) {
- this.key = key;
+ public WidgetPropertyDto setPropertyKey(String s) {
+ this.propertyKey = s;
return this;
}
- /**
- * @return the value
- */
- public String getValue() {
- return value;
+ public String getTextValue() {
+ return textValue;
}
- /**
- * @param value the value to set
- */
- public WidgetPropertyDto setValue(String value) {
- this.value = value;
+ public WidgetPropertyDto setTextValue(String s) {
+ this.textValue = s;
return this;
}
+
+ @Override
+ public Long getKey() {
+ return id;
+ }
+
+ public static ListMultimap<Long, WidgetPropertyDto> groupByWidgetId(Collection<WidgetPropertyDto> properties) {
+ ListMultimap<Long, WidgetPropertyDto> group = ArrayListMultimap.create();
+ for (WidgetPropertyDto property : properties) {
+ group.put(property.getWidgetId(), property);
+ }
+ return group;
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyMapper.java b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyMapper.java
index 5b515aa4bdb..214d95f0da4 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/WidgetPropertyMapper.java
@@ -19,8 +19,27 @@
*/
package org.sonar.core.dashboard;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Options;
+import org.apache.ibatis.annotations.Select;
+
+import javax.annotation.CheckForNull;
+
+import java.util.Collection;
+
public interface WidgetPropertyMapper {
- void insert(WidgetPropertyDto widgetPropertyDto);
+ String COLUMNS = "wp.id, wp.widget_id as \"widgetId\", wp.key as \"propertyKey\", wp.text_value as \"textValue\"";
+
+ @Insert("insert into widget_properties (widget_id, kee, text_value) values (#{widgetId}, #{propertyKey}, #{textValue})")
+ @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id")
+ void insert(WidgetPropertyDto dto);
+
+ @CheckForNull
+ @Select("select " + COLUMNS + " from widget_properties wp where wp.id=#{id}")
+ WidgetPropertyDto selectById(long propertyId);
+ @Select("select " + COLUMNS + " from widget_properties wp " +
+ "inner join widgets w on w.id=wp.widget_id where w.dashboard_id=#{id}")
+ Collection<WidgetPropertyDto> selectByDashboard(long dashboardKey);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/BadDatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/BadDatabaseVersion.java
deleted file mode 100644
index d1449eb0ecc..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/persistence/BadDatabaseVersion.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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 this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.core.persistence;
-
-public final class BadDatabaseVersion extends RuntimeException {
- public BadDatabaseVersion(String s) {
- super(s);
- }
-
- @Override
- public synchronized Throwable fillInStackTrace() {
- return this;
- }
-}
diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml
index 9c3b1864e02..be61c330b73 100644
--- a/sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml
@@ -3,15 +3,4 @@
<mapper namespace="org.sonar.core.dashboard.DashboardMapper">
- <select id="selectGlobalDashboard" parameterType="string" resultType="Dashboard" >
- select id, user_id as "userId", name, description, column_layout as "columnLayout", shared, is_global, 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" >
- INSERT INTO dashboards (user_id, name, description, column_layout, shared, is_global, created_at, updated_at)
- VALUES (#{userId}, #{name}, #{description},
- #{columnLayout}, #{shared}, #{global}, #{createdAt}, #{updatedAt})
- </insert>
-
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml
index fd37b23df5f..73669cb6807 100644
--- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml
@@ -3,10 +3,4 @@
<mapper namespace="org.sonar.core.dashboard.WidgetMapper">
- <insert id="insert" parameterType="Widget" keyColumn="id" useGeneratedKeys="true" keyProperty="id" >
- INSERT INTO widgets (dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id)
- VALUES (#{dashboardId}, #{key}, #{name}, #{description}, #{columnIndex},
- #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId})
- </insert>
-
</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml
index b9ad3a48dee..ed1109dc856 100644
--- a/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml
@@ -3,9 +3,4 @@
<mapper namespace="org.sonar.core.dashboard.WidgetPropertyMapper">
- <insert id="insert" parameterType="WidgetProperty" keyColumn="id" useGeneratedKeys="true" keyProperty="id" >
- INSERT INTO widget_properties (widget_id, kee, text_value)
- VALUES (#{widgetId}, #{key}, #{value})
- </insert>
-
</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/dashboard/DashboardDaoTest.java b/sonar-core/src/test/java/org/sonar/core/dashboard/DashboardDaoTest.java
index d7e6fc1f92e..76afb09d54b 100644
--- a/sonar-core/src/test/java/org/sonar/core/dashboard/DashboardDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/dashboard/DashboardDaoTest.java
@@ -65,7 +65,7 @@ public class DashboardDaoTest extends AbstractDaoTestCase {
dashboardDto.setUpdatedAt(aDate);
WidgetDto widgetDto = new WidgetDto();
- widgetDto.setKey("code_coverage");
+ widgetDto.setWidgetKey("code_coverage");
widgetDto.setName("Code coverage");
widgetDto.setDescription("Widget for code coverage");
widgetDto.setColumnIndex(13);
@@ -76,8 +76,8 @@ public class DashboardDaoTest extends AbstractDaoTestCase {
dashboardDto.addWidget(widgetDto);
WidgetPropertyDto property = new WidgetPropertyDto();
- property.setKey("displayITs");
- property.setValue("true");
+ property.setPropertyKey("displayITs");
+ property.setTextValue("true");
widgetDto.addWidgetProperty(property);
dao.insert(dashboardDto);
@@ -100,7 +100,7 @@ public class DashboardDaoTest extends AbstractDaoTestCase {
dashboardDto.setUpdatedAt(null);
WidgetDto widgetDto = new WidgetDto();
- widgetDto.setKey("code_coverage");
+ widgetDto.setWidgetKey("code_coverage");
widgetDto.setName(null);
widgetDto.setDescription(null);
widgetDto.setColumnIndex(null);
@@ -111,8 +111,8 @@ public class DashboardDaoTest extends AbstractDaoTestCase {
dashboardDto.addWidget(widgetDto);
WidgetPropertyDto property = new WidgetPropertyDto();
- property.setKey(null);
- property.setValue(null);
+ property.setPropertyKey(null);
+ property.setTextValue(null);
widgetDto.addWidgetProperty(property);
dao.insert(dashboardDto);