]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 fix quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 22 May 2013 07:16:05 +0000 (09:16 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 22 May 2013 07:16:05 +0000 (09:16 +0200)
sonar-core/src/main/java/org/sonar/core/issue/db/ChangeDtoConverter.java [deleted file]
sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueStorage.java
sonar-core/src/test/java/org/sonar/core/issue/db/ChangeDtoConverterTest.java [deleted file]
sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java

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 (file)
index f1b0af5..0000000
+++ /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;
-  }
-}
index e4dfa410554b2816ade85530d544aaf636db8e56..1223f83d9890974ff17c2b4d08d34b9539d29b61 100644 (file)
@@ -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;
index 1f9069d8c447fffbbbb48ff440fefa82771a6d2a..b1a6321394eb688ac0e969b0c0aeb987071d83fe 100644 (file)
@@ -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;
+  }
 }
index 1b2af6e383ecef42324a59a3a5e28d1f3a317123..e38c4198eecf29adec579f27f7e4c48ccf293ecc 100644 (file)
@@ -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/ChangeDtoConverterTest.java
deleted file mode 100644 (file)
index 8b0e673..0000000
+++ /dev/null
@@ -1,58 +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.junit.Test;
-import org.sonar.core.issue.DefaultIssueComment;
-import org.sonar.core.issue.FieldDiffs;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ChangeDtoConverterTest {
-  @Test
-  public void testToChangeDtos() throws Exception {
-    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
-
-    IssueChangeDto dto = ChangeDtoConverter.commentToDto(comment);
-
-    assertThat(dto.getChangeData()).isEqualTo("the comment");
-    assertThat(dto.getChangeType()).isEqualTo("comment");
-    assertThat(dto.getCreatedAt()).isNotNull();
-    assertThat(dto.getUpdatedAt()).isNotNull();
-    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
-    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
-  }
-
-  @Test
-  public void testToDiffsDtos() throws Exception {
-    FieldDiffs diffs = new FieldDiffs();
-    diffs.setDiff("severity", "INFO", "BLOCKER");
-    diffs.setUserLogin("emmerik");
-
-    IssueChangeDto dto = ChangeDtoConverter.changeToDto("ABCDE", diffs);
-
-    assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
-    assertThat(dto.getChangeType()).isEqualTo("diff");
-    assertThat(dto.getCreatedAt()).isNotNull();
-    assertThat(dto.getUpdatedAt()).isNotNull();
-    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
-    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
-  }
-}
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java
new file mode 100644 (file)
index 0000000..c146bf2
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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.junit.Test;
+import org.sonar.core.issue.DefaultIssueComment;
+import org.sonar.core.issue.FieldDiffs;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class IssueChangeDtoTest {
+  @Test
+  public void create_from_comment() throws Exception {
+    DefaultIssueComment comment = DefaultIssueComment.create("ABCDE", "emmerik", "the comment");
+
+    IssueChangeDto dto = IssueChangeDto.of(comment);
+
+    assertThat(dto.getChangeData()).isEqualTo("the comment");
+    assertThat(dto.getChangeType()).isEqualTo("comment");
+    assertThat(dto.getCreatedAt()).isNotNull();
+    assertThat(dto.getUpdatedAt()).isNotNull();
+    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
+    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+  }
+
+  @Test
+  public void create_from_diff() throws Exception {
+    FieldDiffs diffs = new FieldDiffs();
+    diffs.setDiff("severity", "INFO", "BLOCKER");
+    diffs.setUserLogin("emmerik");
+
+    IssueChangeDto dto = IssueChangeDto.of("ABCDE", diffs);
+
+    assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER");
+    assertThat(dto.getChangeType()).isEqualTo("diff");
+    assertThat(dto.getCreatedAt()).isNotNull();
+    assertThat(dto.getUpdatedAt()).isNotNull();
+    assertThat(dto.getIssueKey()).isEqualTo("ABCDE");
+    assertThat(dto.getUserLogin()).isEqualTo("emmerik");
+  }
+}
index 4a74dedf0fbafe058f9fdeb6a561adf17336701e..158cba4c32965818e0e27f29cc431c413c5a71d2 100644 (file)
@@ -131,30 +131,37 @@ public class IssueQuery {
     return assignees;
   }
 
+  @CheckForNull
   public Boolean assigned() {
     return assigned;
   }
 
+  @CheckForNull
   public Boolean planned() {
     return planned;
   }
 
+  @CheckForNull
   public Boolean resolved() {
     return resolved;
   }
 
+  @CheckForNull
   public Date createdAfter() {
     return createdAfter;
   }
 
+  @CheckForNull
   public Date createdBefore() {
     return createdBefore;
   }
 
+  @CheckForNull
   public Sort sort() {
     return sort;
   }
 
+  @CheckForNull
   public Boolean asc() {
     return asc;
   }
@@ -260,8 +267,8 @@ public class IssueQuery {
      * If true, it will return all issues assigned to someone
      * If false, it will return all issues not assigned to someone
      */
-    public Builder assigned(Boolean assigned) {
-      this.assigned = assigned;
+    public Builder assigned(@Nullable Boolean b) {
+      this.assigned = b;
       return this;
     }
 
@@ -278,18 +285,18 @@ public class IssueQuery {
      * If true, it will return all resolved issues
      * If false, it will return all none resolved issues
      */
-    public Builder resolved(Boolean resolved) {
+    public Builder resolved(@Nullable Boolean resolved) {
       this.resolved = resolved;
       return this;
     }
 
-    public Builder createdAfter(Date createdAfter) {
-      this.createdAfter = createdAfter;
+    public Builder createdAfter(@Nullable Date d) {
+      this.createdAfter = d;
       return this;
     }
 
-    public Builder createdBefore(Date createdBefore) {
-      this.createdBefore = createdBefore;
+    public Builder createdBefore(@Nullable Date d) {
+      this.createdBefore = d;
       return this;
     }
 
@@ -298,7 +305,7 @@ public class IssueQuery {
       return this;
     }
 
-    public Builder asc(Boolean asc) {
+    public Builder asc(@Nullable Boolean asc) {
       this.asc = asc;
       return this;
     }
index ad68816b633f2c73ac729a65e0e5f67a37c243a8..5095ce59d3747c4fc3d0b76227b0aa4dc4d4a258 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.DefaultIssueComment;
 import org.sonar.core.issue.IssueChangeContext;
 import org.sonar.core.issue.IssueUpdater;
-import org.sonar.core.issue.db.ChangeDtoConverter;
 import org.sonar.core.issue.db.IssueChangeDao;
 import org.sonar.core.issue.db.IssueChangeDto;
 import org.sonar.core.issue.db.IssueStorage;
@@ -96,7 +95,7 @@ public class IssueCommentService implements ServerComponent {
     // check authorization
     finder.findByKey(comment.issueKey(), UserRole.USER);
 
-    IssueChangeDto dto = ChangeDtoConverter.commentToDto(comment);
+    IssueChangeDto dto = IssueChangeDto.of(comment);
     dto.setUpdatedAt(new Date());
     dto.setChangeData(text);
     changeDao.update(dto);