diff options
author | Fabrice Bellingard <bellingard@gmail.com> | 2012-05-10 17:42:53 +0200 |
---|---|---|
committer | Fabrice Bellingard <bellingard@gmail.com> | 2012-05-14 15:11:00 +0200 |
commit | 9f98c79be1638dabadc5a15bbf2ef512bbbcb690 (patch) | |
tree | 1e2842bd964dad0d418ad30821577c5cad1e0413 /sonar-core/src | |
parent | e9475e56b36eee4b79b8b73708281426af366416 (diff) | |
download | sonarqube-9f98c79be1638dabadc5a15bbf2ef512bbbcb690.tar.gz sonarqube-9f98c79be1638dabadc5a15bbf2ef512bbbcb690.zip |
SONAR-2541 Add the sonar-reviews-plugin with JiraLinkReviewAction
- Based on SOAP for creating the issue
- For the moment only creates on the FOO project on locahost:8080
with user admin/admin
=> Next step is to get all this from the project or global
properties
Diffstat (limited to 'sonar-core/src')
14 files changed, 341 insertions, 13 deletions
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 5295da36602..58678318d35 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 @@ -26,6 +26,7 @@ import org.sonar.core.properties.PropertiesDao; import org.sonar.core.purge.PurgeDao; import org.sonar.core.resource.ResourceDao; import org.sonar.core.resource.ResourceIndexerDao; +import org.sonar.core.review.ReviewCommentDao; import org.sonar.core.review.ReviewDao; import org.sonar.core.rule.RuleDao; import org.sonar.core.template.LoadedTemplateDao; @@ -42,16 +43,17 @@ public final class DaoUtils { public static List<Class<?>> getDaoClasses() { return Collections.unmodifiableList(Arrays.asList( - ActiveDashboardDao.class, - AuthorDao.class, - DashboardDao.class, - DuplicationDao.class, - LoadedTemplateDao.class, - PropertiesDao.class, - PurgeDao.class, - ResourceIndexerDao.class, - ResourceDao.class, - ReviewDao.class, - RuleDao.class)); + ActiveDashboardDao.class, + AuthorDao.class, + DashboardDao.class, + DuplicationDao.class, + LoadedTemplateDao.class, + PropertiesDao.class, + PurgeDao.class, + ResourceIndexerDao.class, + ResourceDao.class, + ReviewCommentDao.class, + ReviewDao.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 b0e7dec94fd..76bc1663da6 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 @@ -53,6 +53,8 @@ import org.sonar.core.resource.ResourceIndexDto; import org.sonar.core.resource.ResourceIndexerMapper; import org.sonar.core.resource.ResourceMapper; import org.sonar.core.resource.SnapshotDto; +import org.sonar.core.review.ReviewCommentDto; +import org.sonar.core.review.ReviewCommentMapper; import org.sonar.core.review.ReviewDto; import org.sonar.core.review.ReviewMapper; import org.sonar.core.rule.RuleDto; @@ -90,6 +92,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "Property", PropertyDto.class); loadAlias(conf, "PurgeableSnapshot", PurgeableSnapshotDto.class); loadAlias(conf, "Review", ReviewDto.class); + loadAlias(conf, "ReviewComment", ReviewCommentDto.class); loadAlias(conf, "Resource", ResourceDto.class); loadAlias(conf, "ResourceIndex", ResourceIndexDto.class); loadAlias(conf, "Rule", RuleDto.class); @@ -107,6 +110,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadMapper(conf, PurgeMapper.class); loadMapper(conf, PurgeVendorMapper.class); loadMapper(conf, ResourceMapper.class); + loadMapper(conf, ReviewCommentMapper.class); loadMapper(conf, ReviewMapper.class); loadMapper(conf, ResourceIndexerMapper.class); loadMapper(conf, RuleMapper.class); diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDao.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDao.java new file mode 100644 index 00000000000..37330e7c412 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDao.java @@ -0,0 +1,47 @@ +/* + * 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.review; + +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 ReviewCommentDao implements BatchComponent, ServerComponent { + private final MyBatis mybatis; + + public ReviewCommentDao(MyBatis mybatis) { + this.mybatis = mybatis; + } + + public void insert(ReviewCommentDto reviewCommentDto) { + SqlSession session = mybatis.openSession(); + ReviewCommentMapper mapper = session.getMapper(ReviewCommentMapper.class); + try { + mapper.insert(reviewCommentDto); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDto.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDto.java new file mode 100644 index 00000000000..59a0f9494eb --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDto.java @@ -0,0 +1,115 @@ +/* + * 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.review; + +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import java.util.Date; + +/** + * @since 3.1 + */ +public final class ReviewCommentDto { + + private Long id; + private Long reviewId; + private Long userId; + private String text; + private Date createdAt; + private Date updatedAt; + + public Long getId() { + return id; + } + + public ReviewCommentDto setId(Long id) { + this.id = id; + return this; + } + + public Long getUserId() { + return userId; + } + + public ReviewCommentDto setUserId(Long userId) { + this.userId = userId; + return this; + } + + public Long getReviewId() { + return reviewId; + } + + public ReviewCommentDto setReviewId(Long reviewId) { + this.reviewId = reviewId; + return this; + } + + public String getText() { + return text; + } + + public ReviewCommentDto setText(String text) { + this.text = text; + return this; + } + + public Date getCreatedAt() { + return createdAt; + } + + public ReviewCommentDto setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + return this; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public ReviewCommentDto setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + 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; + } + + ReviewCommentDto reviewDto = (ReviewCommentDto) o; + return !(id != null ? !id.equals(reviewDto.id) : reviewDto.id != null); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentMapper.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentMapper.java new file mode 100644 index 00000000000..67fa2c4f448 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewCommentMapper.java @@ -0,0 +1,27 @@ +/* + * 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.review; + +/** + * @since 3.1 + */ +public interface ReviewCommentMapper { + void insert(ReviewCommentDto reviewCommentDto); +} diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java index e4e7fad01a6..ba5572f8560 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java @@ -32,6 +32,7 @@ import org.sonar.api.ServerComponent; import org.sonar.core.persistence.MyBatis; import javax.annotation.Nullable; + import java.util.Collection; public class ReviewDao implements BatchComponent, ServerComponent { @@ -50,6 +51,19 @@ public class ReviewDao implements BatchComponent, ServerComponent { }); } + /** + * @since 3.1 + */ + public ReviewDto findById(long reviewId) { + SqlSession session = mybatis.openSession(); + try { + ReviewMapper mapper = session.getMapper(ReviewMapper.class); + return mapper.findById(reviewId); + } finally { + MyBatis.closeQuietly(session); + } + } + public Collection<ReviewDto> selectOpenByResourceId(long resourceId, @Nullable Predicate<ReviewDto>... predicates) { Collection<ReviewDto> reviews = cacheByResource.getUnchecked(resourceId); if (!reviews.isEmpty() && predicates != null) { @@ -78,7 +92,6 @@ public class ReviewDao implements BatchComponent, ServerComponent { } } - public ReviewDao update(Collection<ReviewDto> reviews) { Preconditions.checkNotNull(reviews); diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java index dacd3ad2b9e..545df801284 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java @@ -27,7 +27,11 @@ import java.util.List; * @since 2.13 */ public interface ReviewMapper { + ReviewDto findById(long reviewId); + List<ReviewDto> selectByResourceId(long resourceId); + void update(ReviewDto review); - List<ReviewDto> selectOnDeletedResources(@Param("rootProjectId")long rootProjectId, @Param("rootSnapshotId") long rootSnapshotId); + + List<ReviewDto> selectOnDeletedResources(@Param("rootProjectId") long rootProjectId, @Param("rootSnapshotId") long rootSnapshotId); } diff --git a/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper-oracle.xml new file mode 100644 index 00000000000..adcd357a9a8 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper-oracle.xml @@ -0,0 +1,15 @@ +<?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.review.ReviewCommentMapper"> + + <insert id="insert" parameterType="ReviewComment" keyColumn="id" useGeneratedKeys="true" keyProperty ="id"> + <selectKey order="BEFORE" resultType="Long" keyProperty="id" > + select review_comments_seq.NEXTVAL from DUAL + </selectKey> + INSERT INTO review_comments (id, review_id, user_id, review_text, created_at, updated_at) + VALUES (#{id}, #{reviewId, jdbcType=BIGINT}, #{userId, jdbcType=BIGINT}, #{text, jdbcType=VARCHAR}, + #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) + </insert> + +</mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper.xml b/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper.xml new file mode 100644 index 00000000000..96a3111f7c1 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper.xml @@ -0,0 +1,12 @@ +<?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.review.ReviewCommentMapper"> + + <insert id="insert" parameterType="ReviewComment" useGeneratedKeys="true" keyProperty ="id"> + INSERT INTO review_comments (review_id, user_id, review_text, created_at, updated_at) + VALUES (#{reviewId, jdbcType=BIGINT}, #{userId, jdbcType=BIGINT}, #{text, jdbcType=VARCHAR}, + #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) + </insert> + +</mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml b/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml index d7e77ceb36d..da2c0f0f668 100644 --- a/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml @@ -10,6 +10,12 @@ r.manual_severity as manualSeverity, r.manual_violation as manualViolation </sql> + <select id="findById" parameterType="long" resultType="Review"> + select <include refid="reviewColumns"/>, apr.action_plan_id as actionPlanId + from reviews r left outer join action_plans_reviews apr on r.id=apr.review_id + where r.id=#{id} + </select> + <select id="selectByResourceId" parameterType="long" resultType="Review"> select <include refid="reviewColumns"/>, apr.action_plan_id as actionPlanId from reviews r left outer join action_plans_reviews apr on r.id=apr.review_id diff --git a/sonar-core/src/test/java/org/sonar/core/review/ReviewCommentDaoTest.java b/sonar-core/src/test/java/org/sonar/core/review/ReviewCommentDaoTest.java new file mode 100644 index 00000000000..5667b8b091c --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/review/ReviewCommentDaoTest.java @@ -0,0 +1,53 @@ +/* + * 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.review; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.core.persistence.DaoTestCase; + +import java.util.Date; + +public class ReviewCommentDaoTest extends DaoTestCase { + + private ReviewCommentDao dao; + + @Before + public void createDao() { + dao = new ReviewCommentDao(getMyBatis()); + } + + @Test + public void shouldFindReviewById() { + setupData("insert"); + + ReviewCommentDto reviewCommentDto = new ReviewCommentDto(); + reviewCommentDto.setReviewId(12L); + reviewCommentDto.setUserId(8L); + reviewCommentDto.setText("Hello"); + Date today = new Date(); + reviewCommentDto.setCreatedAt(today); + reviewCommentDto.setUpdatedAt(today); + + dao.insert(reviewCommentDto); + + checkTables("insert", new String[] {"id", "created_at", "updated_at"}, "review_comments"); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java b/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java index 155ba0f3d76..720ffba77a9 100644 --- a/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/review/ReviewDaoTest.java @@ -40,6 +40,24 @@ public class ReviewDaoTest extends DaoTestCase { } @Test + public void shouldFindReviewById() { + setupData("shared"); + + ReviewDto review = dao.findById(100L); + assertThat(review.getId(), is(100L)); + assertThat(review.getStatus(), is("OPEN")); + assertThat(review.getResolution(), is(nullValue())); + assertThat(review.getProjectId(), is(20)); + assertThat(review.getViolationPermanentId(), is(1)); + assertThat(review.getSeverity(), is("BLOCKER")); + assertThat(review.getUserId(), is(300)); + assertThat(review.getResourceId(), is(400)); + assertThat(review.getRuleId(), is(500)); + assertThat(review.getManualViolation(), is(true)); + assertThat(review.getActionPlanId(), is(1)); + } + + @Test public void shouldSelectOpenByResourceId() { setupData("shared"); diff --git a/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert-result.xml new file mode 100644 index 00000000000..3d798ef5622 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert-result.xml @@ -0,0 +1,9 @@ +<dataset> + + <review_comments + review_id="12" + user_id="8" + review_text="Hello" + /> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert.xml b/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert.xml @@ -0,0 +1,3 @@ +<dataset> + +</dataset> |