+++ /dev/null
-/*
- * 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;
- }
-}
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);
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;
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;
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;
+ }
}
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;
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);
}
}
+++ /dev/null
-/*
- * 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");
- }
-}
--- /dev/null
+/*
+ * 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");
+ }
+}
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;
}
* 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;
}
* 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;
}
return this;
}
- public Builder asc(Boolean asc) {
+ public Builder asc(@Nullable Boolean asc) {
this.asc = asc;
return this;
}
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;
// 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);