From 9f98c79be1638dabadc5a15bbf2ef512bbbcb690 Mon Sep 17 00:00:00 2001 From: Fabrice Bellingard Date: Thu, 10 May 2012 17:42:53 +0200 Subject: 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 --- .../java/org/sonar/core/persistence/DaoUtils.java | 24 +++-- .../java/org/sonar/core/persistence/MyBatis.java | 4 + .../org/sonar/core/review/ReviewCommentDao.java | 47 +++++++++ .../org/sonar/core/review/ReviewCommentDto.java | 115 +++++++++++++++++++++ .../org/sonar/core/review/ReviewCommentMapper.java | 27 +++++ .../main/java/org/sonar/core/review/ReviewDao.java | 15 ++- .../java/org/sonar/core/review/ReviewMapper.java | 6 +- .../core/review/ReviewCommentMapper-oracle.xml | 15 +++ .../org/sonar/core/review/ReviewCommentMapper.xml | 12 +++ .../org/sonar/core/review/ReviewMapper.xml | 6 ++ .../sonar/core/review/ReviewCommentDaoTest.java | 53 ++++++++++ .../java/org/sonar/core/review/ReviewDaoTest.java | 18 ++++ .../review/ReviewCommentDaoTest/insert-result.xml | 9 ++ .../core/review/ReviewCommentDaoTest/insert.xml | 3 + 14 files changed, 341 insertions(+), 13 deletions(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDao.java create mode 100644 sonar-core/src/main/java/org/sonar/core/review/ReviewCommentDto.java create mode 100644 sonar-core/src/main/java/org/sonar/core/review/ReviewCommentMapper.java create mode 100644 sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper-oracle.xml create mode 100644 sonar-core/src/main/resources/org/sonar/core/review/ReviewCommentMapper.xml create mode 100644 sonar-core/src/test/java/org/sonar/core/review/ReviewCommentDaoTest.java create mode 100644 sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert-result.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/review/ReviewCommentDaoTest/insert.xml (limited to 'sonar-core/src') 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> 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 selectOpenByResourceId(long resourceId, @Nullable Predicate... predicates) { Collection reviews = cacheByResource.getUnchecked(resourceId); if (!reviews.isEmpty() && predicates != null) { @@ -78,7 +92,6 @@ public class ReviewDao implements BatchComponent, ServerComponent { } } - public ReviewDao update(Collection 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 selectByResourceId(long resourceId); + void update(ReviewDto review); - List selectOnDeletedResources(@Param("rootProjectId")long rootProjectId, @Param("rootSnapshotId") long rootSnapshotId); + + List 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 @@ + + + + + + + + select review_comments_seq.NEXTVAL from DUAL + + 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}) + + + 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 @@ + + + + + + + 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}) + + + 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 + +