aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java57
-rw-r--r--sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java152
-rw-r--r--sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java29
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java10
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper-oracle.xml20
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper.xml17
-rw-r--r--sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java67
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java11
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldFindFilter.xml27
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml15
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert.xml3
13 files changed, 410 insertions, 13 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java
new file mode 100644
index 00000000000..be2f7b75504
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterDao.java
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.filter;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+/**
+ * @since 3.1
+ */
+public class FilterDao implements BatchComponent, ServerComponent {
+ private MyBatis mybatis;
+
+ public FilterDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public FilterDto findFilter(String name) {
+ SqlSession session = mybatis.openSession();
+ try {
+ FilterMapper mapper = session.getMapper(FilterMapper.class);
+ return mapper.findFilter(name);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(FilterDto filterDto) {
+ SqlSession session = mybatis.openSession();
+ FilterMapper mapper = session.getMapper(FilterMapper.class);
+ try {
+ mapper.insert(filterDto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java
new file mode 100644
index 00000000000..1075788ae1a
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java
@@ -0,0 +1,152 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.filter;
+
+import com.google.common.base.Objects;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+
+/**
+ * @since 3.1
+ */
+public final class FilterDto {
+ private Long id;
+ private String name;
+ private Long userId;
+ private boolean shared;
+ private boolean favourites;
+ private Long resourceId;
+ private String defaultView;
+ private Long pageSize;
+ private Long periodIndex;
+
+ public Long getId() {
+ return id;
+ }
+
+ public FilterDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public FilterDto setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public Long getUserId() {
+ return userId;
+ }
+
+ public FilterDto setUserId(Long userId) {
+ this.userId = userId;
+ return this;
+ }
+
+ public boolean isShared() {
+ return shared;
+ }
+
+ public FilterDto setShared(boolean shared) {
+ this.shared = shared;
+ return this;
+ }
+
+ public boolean isFavourites() {
+ return favourites;
+ }
+
+ public FilterDto setFavourites(boolean favourites) {
+ this.favourites = favourites;
+ return this;
+ }
+
+ public Long getResourceId() {
+ return resourceId;
+ }
+
+ public FilterDto setResourceId(Long resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
+ public String getDefaultView() {
+ return defaultView;
+ }
+
+ public FilterDto setDefaultView(String defaultView) {
+ this.defaultView = defaultView;
+ return this;
+ }
+
+ public Long getPageSize() {
+ return pageSize;
+ }
+
+ public FilterDto setPageSize(Long pageSize) {
+ this.pageSize = pageSize;
+ return this;
+ }
+
+ public Long getPeriodIndex() {
+ return periodIndex;
+ }
+
+ public FilterDto setPeriodIndex(Long periodIndex) {
+ this.periodIndex = periodIndex;
+ return this;
+ }
+
+
+ @Override
+ public String toString() {
+ return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ FilterDto other = (FilterDto) o;
+ return Objects.equal(id, other.id) &&
+ Objects.equal(name, other.name) &&
+ Objects.equal(userId, other.userId) &&
+ Objects.equal(shared, other.shared) &&
+ Objects.equal(favourites, other.favourites) &&
+ Objects.equal(resourceId, other.resourceId) &&
+ Objects.equal(defaultView, other.defaultView) &&
+ Objects.equal(pageSize, other.pageSize) &&
+ Objects.equal(periodIndex, other.periodIndex);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(id);
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java
new file mode 100644
index 00000000000..75920978d57
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java
@@ -0,0 +1,29 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.filter;
+
+/**
+ * @since 3.1
+ */
+public interface FilterMapper {
+ FilterDto findFilter(String name);
+
+ void insert(FilterDto filterDto);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
index 58678318d35..e31a623cc97 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
@@ -19,9 +19,11 @@
*/
package org.sonar.core.persistence;
+import com.google.common.collect.ImmutableList;
import org.sonar.core.dashboard.ActiveDashboardDao;
import org.sonar.core.dashboard.DashboardDao;
import org.sonar.core.duplication.DuplicationDao;
+import org.sonar.core.filter.FilterDao;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.purge.PurgeDao;
import org.sonar.core.resource.ResourceDao;
@@ -32,8 +34,6 @@ import org.sonar.core.rule.RuleDao;
import org.sonar.core.template.LoadedTemplateDao;
import org.sonar.core.user.AuthorDao;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
public final class DaoUtils {
@@ -42,9 +42,10 @@ public final class DaoUtils {
}
public static List<Class<?>> getDaoClasses() {
- return Collections.unmodifiableList(Arrays.asList(
+ return ImmutableList.of(
ActiveDashboardDao.class,
AuthorDao.class,
+ FilterDao.class,
DashboardDao.class,
DuplicationDao.class,
LoadedTemplateDao.class,
@@ -54,6 +55,6 @@ public final class DaoUtils {
ResourceDao.class,
ReviewCommentDao.class,
ReviewDao.class,
- RuleDao.class));
+ RuleDao.class);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index 76bc1663da6..7c71f71ebc1 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -19,6 +19,10 @@
*/
package org.sonar.core.persistence;
+import org.sonar.core.filter.FilterDto;
+import org.sonar.core.filter.FilterMapper;
+
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
@@ -86,6 +90,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
loadAlias(conf, "Author", AuthorDto.class);
+ loadAlias(conf, "Filter", FilterDto.class);
loadAlias(conf, "Dashboard", DashboardDto.class);
loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
@@ -103,6 +108,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadMapper(conf, ActiveDashboardMapper.class);
loadMapper(conf, AuthorMapper.class);
+ loadMapper(conf, FilterMapper.class);
loadMapper(conf, DashboardMapper.class);
loadMapper(conf, DuplicationMapper.class);
loadMapper(conf, LoadedTemplateMapper.class);
diff --git a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
index 443ea7b48d4..eb6d4ef3205 100644
--- a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDto.java
@@ -19,9 +19,12 @@
*/
package org.sonar.core.template;
+import com.google.common.base.Objects;
+
public final class LoadedTemplateDto {
public static final String DASHBOARD_TYPE = "DASHBOARD";
+ public static final String FILTER_TYPE = "FILTER";
private Long id;
private String key;
@@ -70,11 +73,8 @@ public final class LoadedTemplateDto {
if (o == null || getClass() != o.getClass()) {
return false;
}
- LoadedTemplateDto that = (LoadedTemplateDto) o;
- if (id != null ? !id.equals(that.id) : that.id != null) {
- return false;
- }
- return true;
+ LoadedTemplateDto other = (LoadedTemplateDto) o;
+ return Objects.equal(id, other.id) && Objects.equal(key, other.key) && Objects.equal(type, other.type);
}
@Override
diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper-oracle.xml
new file mode 100644
index 00000000000..854b0749ff8
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper-oracle.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.filter.FilterMapper">
+
+ <select id="findFilter" parameterType="string" resultType="Filter">
+ select id, name, user_id as "userId", shared, favourites, resource_id as "resourceId", default_view as "defaultView", page_size as "pageSize", period_index as "periodIndex"
+ from filters WHERE name=#{id}
+ </select>
+
+ <insert id="insert" parameterType="Filter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ <selectKey order="BEFORE" resultType="Long" keyProperty="id">
+ select filters_seq.NEXTVAL from DUAL
+ </selectKey>
+ INSERT INTO filters (id, name, user_id, shared, favourites, resource_id, default_view, page_size, period_index)
+ VALUES (#{id}, #{name, jdbcType=VARCHAR}, #{userId, jdbcType=FLOAT}, #{shared}, #{favourites}, #{resourceId, jdbcType=INTEGER}, #{defaultView, jdbcType=VARCHAR},
+ #{pageSize, jdbcType=INTEGER}, #{periodIndex, jdbcType=INTEGER})
+ </insert>
+
+</mapper>
diff --git a/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper.xml b/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper.xml
new file mode 100644
index 00000000000..bd5859e55f4
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/filter/FilterMapper.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.filter.FilterMapper">
+
+ <select id="findFilter" parameterType="string" resultType="Filter">
+ select id, name, user_id as "userId", shared, favourites, resource_id as "resourceId", default_view as "defaultView", page_size as "pageSize", period_index as "periodIndex"
+ from filters WHERE name=#{id}
+ </select>
+
+ <insert id="insert" parameterType="Filter" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO filters (name, user_id, shared, favourites, resource_id, default_view, page_size, period_index)
+ VALUES (#{name, jdbcType=VARCHAR}, #{userId, jdbcType=FLOAT}, #{shared}, #{favourites}, #{resourceId, jdbcType=INTEGER}, #{defaultView, jdbcType=VARCHAR},
+ #{pageSize, jdbcType=INTEGER}, #{periodIndex, jdbcType=INTEGER})
+ </insert>
+
+</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java
new file mode 100644
index 00000000000..3ba871e4ba8
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java
@@ -0,0 +1,67 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 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.core.filters;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.filter.FilterDao;
+import org.sonar.core.filter.FilterDto;
+import org.sonar.core.persistence.DaoTestCase;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class FilterDaoTest extends DaoTestCase {
+ private FilterDao dao;
+
+ @Before
+ public void createDao() {
+ dao = new FilterDao(getMyBatis());
+ }
+
+ @Test
+ public void should_find_filter() {
+ setupData("shouldFindFilter");
+
+ FilterDto filter = dao.findFilter("Projects");
+
+ assertThat(filter.getId()).isEqualTo(1L);
+ assertThat(filter.getUserId()).isNull();
+ assertThat(dao.findFilter("<UNKNOWN>")).isNull();
+ }
+
+ @Test
+ public void should_insert() {
+ setupData("shouldInsert");
+
+ FilterDto filterDto = new FilterDto();
+ filterDto.setName("Projects");
+ filterDto.setUserId(null);
+ filterDto.setShared(true);
+ filterDto.setFavourites(false);
+ filterDto.setResourceId(null);
+ filterDto.setDefaultView("list");
+ filterDto.setPageSize(10L);
+ filterDto.setPeriodIndex(1L);
+
+ dao.insert(filterDto);
+
+ checkTables("shouldInsert", "filters");
+ }
+} \ No newline at end of file
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java
index a3e97e5d008..760c3e8df32 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/DaoUtilsTest.java
@@ -21,13 +21,16 @@ package org.sonar.core.persistence;
import org.junit.Test;
-import static org.hamcrest.Matchers.greaterThan;
-import static org.junit.Assert.assertThat;
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
public class DaoUtilsTest {
@Test
- public void testGetDaoClasses() {
- assertThat(DaoUtils.getDaoClasses().size(), greaterThan(1));
+ public void should_list_all_dao_classes() {
+ List<Class<?>> daoClasses = DaoUtils.getDaoClasses();
+
+ assertThat(daoClasses.size()).isGreaterThan(1);
}
}
diff --git a/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldFindFilter.xml b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldFindFilter.xml
new file mode 100644
index 00000000000..ae940cc01ab
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldFindFilter.xml
@@ -0,0 +1,27 @@
+<dataset>
+
+ <filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ favourites="[false]"
+ resource_id="[null]"
+ default_view="list"
+ page_size="[null]"
+ period_index="[null]"
+ />
+
+ <filters
+ id="2"
+ name="Treemap"
+ user_id="[null]"
+ shared="[true]"
+ favourites="[false]"
+ resource_id="[null]"
+ default_view="treemap"
+ page_size="[null]"
+ period_index="[null]"
+ />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml
new file mode 100644
index 00000000000..5bef3836c4b
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml
@@ -0,0 +1,15 @@
+<dataset>
+
+ <filters
+ id="1"
+ name="Projects"
+ user_id="[null]"
+ shared="[true]"
+ favourites="[false]"
+ resource_id="[null]"
+ default_view="list"
+ page_size="10"
+ period_index="1"
+ />
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert.xml b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert.xml
new file mode 100644
index 00000000000..871dedcb5e9
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert.xml
@@ -0,0 +1,3 @@
+<dataset>
+
+</dataset>