aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-05-22 09:16:05 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-05-22 09:16:05 +0200
commit6f3f992a81ea8b4c91a88dfd668284f0f428f476 (patch)
tree695239cde3cec70b9b208f366e6c1a45356862b8 /sonar-core
parenta0e127fc2ca9c19a562d3e53097f0cc7fc6c261c (diff)
downloadsonarqube-6f3f992a81ea8b4c91a88dfd668284f0f428f476.tar.gz
sonarqube-6f3f992a81ea8b4c91a88dfd668284f0f428f476.zip
SONAR-3755 fix quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java79
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java48
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java8
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java (renamed from sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java)10
5 files changed, 60 insertions, 89 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java b/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java
deleted file mode 100644
index f1b0af58f17..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.issue.db;
-
-import org.sonar.core.issue.DefaultIssueComment;
-import org.sonar.core.issue.FieldDiffs;
-
-import java.util.Date;
-
-public class ChangeDtoConverter {
-
- private ChangeDtoConverter() {
- // only static methods
- }
-
- public static IssueChangeDto commentToDto(DefaultIssueComment comment) {
- IssueChangeDto dto = newDto(comment.issueKey());
- dto.setKey(comment.key());
- dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
- dto.setChangeData(comment.markdownText());
- dto.setUserLogin(comment.userLogin());
- return dto;
- }
-
- public static IssueChangeDto changeToDto(String issueKey, FieldDiffs diffs) {
- IssueChangeDto dto = newDto(issueKey);
- dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
- dto.setChangeData(diffs.toString());
- dto.setUserLogin(diffs.userLogin());
- return dto;
- }
-
- private static IssueChangeDto newDto(String issueKey) {
- IssueChangeDto dto = new IssueChangeDto();
- dto.setIssueKey(issueKey);
-
- // technical dates - do not use the context date
- Date now = new Date();
- dto.setCreatedAt(now);
- dto.setUpdatedAt(new Date());
- return dto;
- }
-
- public static DefaultIssueComment dtoToComment(IssueChangeDto dto) {
- return new DefaultIssueComment()
- .setMarkdownText(dto.getChangeData())
- .setKey(dto.getKey())
- .setCreatedAt(dto.getCreatedAt())
- .setUpdatedAt(dto.getUpdatedAt())
- .setUserLogin(dto.getUserLogin())
- .setIssueKey(dto.getIssueKey())
- .setNew(false);
- }
-
- public static FieldDiffs dtoToChange(IssueChangeDto dto) {
- FieldDiffs diffs = FieldDiffs.parse(dto.getChangeData());
- diffs.setUserLogin(dto.getUserLogin());
- diffs.setCreatedAt(dto.getCreatedAt());
- diffs.setUpdatedAt(dto.getUpdatedAt());
- return diffs;
- }
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
index e4dfa410554..1223f83d989 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
@@ -53,7 +53,7 @@ public class IssueChangeDao implements BatchComponent, ServerComponent {
try {
IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
IssueChangeDto dto = mapper.selectByKeyAndType(commentKey, IssueChangeDto.TYPE_COMMENT);
- return dto != null ? ChangeDtoConverter.dtoToComment(dto) : null;
+ return dto != null ? dto.toComment() : null;
} finally {
MyBatis.closeQuietly(session);
@@ -67,7 +67,7 @@ public class IssueChangeDao implements BatchComponent, ServerComponent {
IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
List<IssueChangeDto> dtos = mapper.selectByIssuesAndType(issueKeys, changeType);
for (IssueChangeDto dto : dtos) {
- result.add(ChangeDtoConverter.dtoToComment(dto));
+ result.add(dto.toComment());
}
}
return result;
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java
index 1f9069d8c44..b1a6321394e 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java
@@ -21,6 +21,8 @@ package org.sonar.core.issue.db;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.core.issue.DefaultIssueComment;
+import org.sonar.core.issue.FieldDiffs;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
@@ -121,4 +123,50 @@ public final class IssueChangeDto {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
+ public static IssueChangeDto of(DefaultIssueComment comment) {
+ IssueChangeDto dto = newDto(comment.issueKey());
+ dto.setKey(comment.key());
+ dto.setChangeType(IssueChangeDto.TYPE_COMMENT);
+ dto.setChangeData(comment.markdownText());
+ dto.setUserLogin(comment.userLogin());
+ return dto;
+ }
+
+ public static IssueChangeDto of(String issueKey, FieldDiffs diffs) {
+ IssueChangeDto dto = newDto(issueKey);
+ dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE);
+ dto.setChangeData(diffs.toString());
+ dto.setUserLogin(diffs.userLogin());
+ return dto;
+ }
+
+ private static IssueChangeDto newDto(String issueKey) {
+ IssueChangeDto dto = new IssueChangeDto();
+ dto.setIssueKey(issueKey);
+
+ // technical dates - do not use the context date
+ Date now = new Date();
+ dto.setCreatedAt(now);
+ dto.setUpdatedAt(new Date());
+ return dto;
+ }
+
+ public DefaultIssueComment toComment() {
+ return new DefaultIssueComment()
+ .setMarkdownText(changeData)
+ .setKey(kee)
+ .setCreatedAt(createdAt)
+ .setUpdatedAt(updatedAt)
+ .setUserLogin(userLogin)
+ .setIssueKey(issueKey)
+ .setNew(false);
+ }
+
+ public FieldDiffs toFieldDiffs() {
+ FieldDiffs diffs = FieldDiffs.parse(changeData);
+ diffs.setUserLogin(userLogin);
+ diffs.setCreatedAt(createdAt);
+ diffs.setUpdatedAt(updatedAt);
+ return diffs;
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
index 1b2af6e383e..e38c4198eec 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
@@ -27,6 +27,7 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.DefaultIssueComment;
+import org.sonar.core.issue.FieldDiffs;
import org.sonar.core.persistence.MyBatis;
import java.util.Arrays;
@@ -82,12 +83,13 @@ public abstract class IssueStorage {
for (IssueComment comment : issue.comments()) {
DefaultIssueComment c = (DefaultIssueComment) comment;
if (c.isNew()) {
- IssueChangeDto changeDto = ChangeDtoConverter.commentToDto(c);
+ IssueChangeDto changeDto = IssueChangeDto.of(c);
mapper.insert(changeDto);
}
}
- if (issue.diffs() != null) {
- IssueChangeDto changeDto = ChangeDtoConverter.changeToDto(issue.key(), issue.diffs());
+ FieldDiffs diffs = issue.diffs();
+ if (diffs != null) {
+ IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
mapper.insert(changeDto);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java
index 8b0e67347d9..c146bf22195 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java
@@ -25,12 +25,12 @@ import org.sonar.core.issue.FieldDiffs;
import static org.fest.assertions.Assertions.assertThat;
-public class ChangeDtoConverterTest {
+public class IssueChangeDtoTest {
@Test
- public void testToChangeDtos() throws Exception {
+ public void create_from_comment() throws Exception {
DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
- IssueChangeDto dto = ChangeDtoConverter.commentToDto(comment);
+ IssueChangeDto dto = IssueChangeDto.of(comment);
assertThat(dto.getChangeData()).isEqualTo("the comment");
assertThat(dto.getChangeType()).isEqualTo("comment");
@@ -41,12 +41,12 @@ public class ChangeDtoConverterTest {
}
@Test
- public void testToDiffsDtos() throws Exception {
+ public void create_from_diff() throws Exception {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "INFO", "BLOCKER");
diffs.setUserLogin("emmerik");
- IssueChangeDto dto = ChangeDtoConverter.changeToDto("ABCDE", diffs);
+ IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
assertThat(dto.getChangeType()).isEqualTo("diff");