diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-07 15:03:28 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-07 15:04:56 +0200 |
commit | 93cb18b0a9e9e2ea9613e28d1b1538c7e51ff806 (patch) | |
tree | e58933b660a2f4d15ed8c9c1f07da52e0bc0d150 | |
parent | 9ac6a6125cf9c67759858223dc65cf8176e849f9 (diff) | |
download | sonarqube-93cb18b0a9e9e2ea9613e28d1b1538c7e51ff806.tar.gz sonarqube-93cb18b0a9e9e2ea9613e28d1b1538c7e51ff806.zip |
SONAR-3755 refactor comments
45 files changed, 525 insertions, 127 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java index 51a7d80e398..e0538e3f713 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java @@ -341,12 +341,12 @@ public class IssueTracking implements BatchExtension { } private boolean isSameKey(DefaultIssue newIssue, IssueDto pastIssue) { - return Objects.equal(newIssue.key(), pastIssue.getKey()); + return Objects.equal(newIssue.key(), pastIssue.getKee()); } private void mapIssue(DefaultIssue newIssue, IssueDto pastIssue, Multimap<Integer, IssueDto> lastIssuesByRule, Map<DefaultIssue, IssueDto> issueMap) { if (pastIssue != null) { - newIssue.setKey(pastIssue.getKey()); + newIssue.setKey(pastIssue.getKee()); if (pastIssue.isManualSeverity()) { newIssue.setManualSeverity(true); newIssue.setSeverity(pastIssue.getSeverity()); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java index a63877d8001..0b74ff29986 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java @@ -116,7 +116,7 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase { // INPUT : one issue, one open issue during previous scan, no filtering when(scanIssues.issues("struts:Action.java")).thenReturn(Arrays.asList(openIssue)); when(filters.accept(openIssue)).thenReturn(true); - IssueDto unmatchedIssue = new IssueDto().setKey("ABCDE").setResolution("OPEN").setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle"); + IssueDto unmatchedIssue = new IssueDto().setKee("ABCDE").setResolution("OPEN").setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle"); List<IssueDto> unmatchedIssues = Arrays.asList(unmatchedIssue); when(tracking.track(eq(file), anyCollection(), anyCollection())).thenReturn(Sets.newHashSet(unmatchedIssues)); @@ -141,7 +141,7 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase { DefaultIssue openIssue = new DefaultIssue(); when(scanIssues.issues("struts")).thenReturn(Arrays.asList(openIssue)); when(filters.accept(openIssue)).thenReturn(true); - IssueDto deadIssue = new IssueDto().setKey("ABCDE").setResolution("OPEN").setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle"); + IssueDto deadIssue = new IssueDto().setKee("ABCDE").setResolution("OPEN").setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle"); when(initialOpenIssues.getAllIssues()).thenReturn(Arrays.asList(deadIssue)); decorator.decorate(project, mock(DecoratorContext.class, Mockito.RETURNS_MOCKS)); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java index bd3045632ee..61f105a4e5e 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java @@ -80,8 +80,8 @@ public class IssueTrackingTest { @Test public void key_should_be_the_prioritary_field_to_check() { - IssueDto referenceIssue1 = newReferenceIssue("message", 10, 1, "checksum1").setKey("100"); - IssueDto referenceIssue2 = newReferenceIssue("message", 10, 1, "checksum2").setKey("200"); + IssueDto referenceIssue1 = newReferenceIssue("message", 10, 1, "checksum1").setKee("100"); + IssueDto referenceIssue2 = newReferenceIssue("message", 10, 1, "checksum2").setKee("200"); // exactly the fields of referenceIssue1 but not the same key DefaultIssue newIssue = newDefaultIssue("message", 10, RuleKey.of("squid", "AvoidCycle"), "checksum1").setKey("200"); @@ -387,7 +387,7 @@ public class IssueTrackingTest { IssueDto referenceIssue = new IssueDto(); Long id = violationId++; referenceIssue.setId(id); - referenceIssue.setKey(Long.toString(id)); + referenceIssue.setKee(Long.toString(id)); referenceIssue.setLine(lineId); referenceIssue.setDescription(message); referenceIssue.setRuleId(ruleId); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index 1fc3d764244..b3cd2510cae 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -29,6 +29,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.issue.Issue; +import org.sonar.api.issue.IssueComment; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; @@ -343,7 +344,7 @@ public class DefaultIssue implements Issue { return diffs; } - public DefaultIssue addComment(IssueComment comment) { + public DefaultIssue addComment(DefaultIssueComment comment) { if (comments == null) { comments = Lists.newArrayList(); } @@ -351,6 +352,7 @@ public class DefaultIssue implements Issue { return this; } + @SuppressWarnings("unchcked") public List<IssueComment> comments() { return Objects.firstNonNull(comments, Collections.<IssueComment>emptyList()); } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueComment.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java index c944f656436..c248c2097a8 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueComment.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueComment.java @@ -19,13 +19,15 @@ */ package org.sonar.core.issue; +import org.sonar.api.issue.IssueComment; + import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.io.Serializable; import java.util.Date; import java.util.UUID; -public class IssueComment implements Serializable { +public class DefaultIssueComment implements Serializable, IssueComment { private String userLogin; private Date createdAt, updatedAt; @@ -33,20 +35,22 @@ public class IssueComment implements Serializable { private String text; private boolean isNew; + @Override public String text() { return text; } - public IssueComment setText(String s) { + public DefaultIssueComment setText(String s) { this.text = s; return this; } + @Override public String key() { return key; } - public IssueComment setKey(String key) { + public DefaultIssueComment setKey(String key) { this.key = key; return this; } @@ -54,30 +58,33 @@ public class IssueComment implements Serializable { /** * The user who created the comment. Null if it was automatically generated during project scan. */ + @Override @CheckForNull public String userLogin() { return userLogin; } - public IssueComment setUserLogin(@Nullable String userLogin) { + public DefaultIssueComment setUserLogin(@Nullable String userLogin) { this.userLogin = userLogin; return this; } + @Override public Date createdAt() { return createdAt; } - public IssueComment setCreatedAt(Date createdAt) { + public DefaultIssueComment setCreatedAt(Date createdAt) { this.createdAt = createdAt; return this; } + @Override public Date updatedAt() { return updatedAt; } - public IssueComment setUpdatedAt(Date updatedAt) { + public DefaultIssueComment setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; return this; } @@ -86,13 +93,13 @@ public class IssueComment implements Serializable { return isNew; } - public IssueComment setNew(boolean b) { + public DefaultIssueComment setNew(boolean b) { isNew = b; return this; } - public static IssueComment create(@Nullable String login, String text) { - IssueComment comment = new IssueComment(); + public static DefaultIssueComment create(@Nullable String login, String text) { + DefaultIssueComment comment = new DefaultIssueComment(); comment.setKey(UUID.randomUUID().toString()); Date now = new Date(); comment.setUserLogin(login); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java index 5283ec842bd..f42780fe36e 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java @@ -100,7 +100,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent { } public void addComment(DefaultIssue issue, String text, IssueChangeContext context) { - issue.addComment(IssueComment.create(context.login(), text)); + issue.addComment(DefaultIssueComment.create(context.login(), text)); } public void setCloseDate(DefaultIssue issue, @Nullable Date d) { 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 index 52e729a874d..d2cfeefdc8b 100644 --- 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 @@ -19,8 +19,8 @@ */ package org.sonar.core.issue.db; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.core.issue.IssueComment; import java.util.Date; @@ -30,10 +30,10 @@ class ChangeDtoConverter { // only static methods } - static final String TYPE_FIELD_CHANGE = "change"; + static final String TYPE_FIELD_CHANGE = "diff"; static final String TYPE_COMMENT = "comment"; - static IssueChangeDto commentToDto(String issueKey, IssueComment comment) { + static IssueChangeDto commentToDto(String issueKey, DefaultIssueComment comment) { IssueChangeDto dto = newDto(issueKey); dto.setKey(comment.key()); dto.setChangeType(TYPE_COMMENT); @@ -61,8 +61,8 @@ class ChangeDtoConverter { return dto; } - public static IssueComment dtoToComment(IssueChangeDto dto) { - return new IssueComment() + public static DefaultIssueComment dtoToComment(IssueChangeDto dto) { + return new DefaultIssueComment() .setText(dto.getChangeData()) .setKey(dto.getKey()) .setCreatedAt(dto.getCreatedAt()) 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 2399ccd6425..b355ac4ebc0 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 @@ -23,10 +23,11 @@ package org.sonar.core.issue.db; import org.apache.ibatis.session.SqlSession; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.core.issue.IssueComment; import org.sonar.core.persistence.MyBatis; +import java.util.Collection; import java.util.List; /** @@ -40,9 +41,9 @@ public class IssueChangeDao implements BatchComponent, ServerComponent { this.mybatis = mybatis; } - public IssueComment[] selectIssueComments(String issueKey) { + public DefaultIssueComment[] selectIssueComments(String issueKey) { List<IssueChangeDto> dtos = selectByIssue(issueKey, ChangeDtoConverter.TYPE_COMMENT); - IssueComment[] result = new IssueComment[dtos.size()]; + DefaultIssueComment[] result = new DefaultIssueComment[dtos.size()]; for (int index = 0; index < dtos.size(); index++) { result[index] = ChangeDtoConverter.dtoToComment(dtos.get(index)); } @@ -59,7 +60,7 @@ public class IssueChangeDao implements BatchComponent, ServerComponent { } /** - * Issue changes ordered by descending creation date. + * Issue changes by chronological date of creation */ private List<IssueChangeDto> selectByIssue(String issueKey, String changeType) { SqlSession session = mybatis.openSession(); 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 389f7c697ad..d74d1b2dcdc 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 @@ -22,6 +22,7 @@ package org.sonar.core.issue.db; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.Date; @@ -48,11 +49,12 @@ public final class IssueChangeDto { return this; } + @CheckForNull public String getKey() { return kee; } - public IssueChangeDto setKey(String key) { + public IssueChangeDto setKey(@Nullable String key) { this.kee = key; return this; } @@ -61,8 +63,8 @@ public final class IssueChangeDto { return issueKey; } - public IssueChangeDto setIssueKey(String issueKey) { - this.issueKey = issueKey; + public IssueChangeDto setIssueKey(String s) { + this.issueKey = s; return this; } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java index 7f54bc0899b..9c049b38b65 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java @@ -32,7 +32,7 @@ public interface IssueChangeMapper { void insert(IssueChangeDto dto); /** - * Issue changes ordered by descending creation date. + * Issue changes by chronological date of creation */ List<IssueChangeDto> selectByIssueAndType(@Param("issueKey") String issueKey, @Param("changeType") String changeType); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index c3cf96168d2..54ea3ef4795 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -29,7 +29,6 @@ import org.sonar.core.issue.DefaultIssue; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.Date; /** @@ -41,7 +40,6 @@ public final class IssueDto { private String kee; private Integer resourceId; private Integer ruleId; - private String actionPlanKey; private String severity; private boolean manualSeverity; private boolean manualIssue; @@ -54,6 +52,7 @@ public final class IssueDto { private String userLogin; private String assignee; private String authorLogin; + private String actionPlanKey; private String attributes; // functional dates @@ -79,12 +78,12 @@ public final class IssueDto { return this; } - public String getKey() { + public String getKee() { return kee; } - public IssueDto setKey(String key) { - this.kee = key; + public IssueDto setKee(String s) { + this.kee = s; return this; } @@ -106,12 +105,13 @@ public final class IssueDto { return this; } + @CheckForNull public String getActionPlanKey() { return actionPlanKey; } - public IssueDto setActionPlanKey(String actionPlanKey) { - this.actionPlanKey = actionPlanKey; + public IssueDto setActionPlanKey(@Nullable String s) { + this.actionPlanKey = s; return this; } @@ -187,8 +187,8 @@ public final class IssueDto { return resolution; } - public IssueDto setResolution(@Nullable String resolution) { - this.resolution = resolution; + public IssueDto setResolution(@Nullable String s) { + this.resolution = s; return this; } @@ -322,7 +322,7 @@ public final class IssueDto { public static IssueDto toDto(DefaultIssue issue, Integer componentId, Integer ruleId) { return new IssueDto() - .setKey(issue.key()) + .setKee(issue.key()) .setLine(issue.line()) .setDescription(issue.description()) .setEffortToFix(issue.effortToFix()) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java new file mode 100644 index 00000000000..4e65007e824 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java @@ -0,0 +1,27 @@ +/* + * 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; + +public interface IssueMapper { + + void insert(IssueDto issue); + int update(IssueDto issue); + +} 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 0a33e145c0f..7bf78f6af1d 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 @@ -22,10 +22,11 @@ package org.sonar.core.issue.db; import com.google.common.collect.Lists; import org.apache.ibatis.session.SqlSession; import org.sonar.api.issue.Issue; +import org.sonar.api.issue.IssueComment; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.core.issue.DefaultIssue; -import org.sonar.core.issue.IssueComment; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.persistence.MyBatis; import java.util.Arrays; @@ -33,10 +34,6 @@ import java.util.List; public abstract class IssueStorage { - private static final String MYBATIS_INSERT_CHANGE = "org.sonar.core.issue.db.IssueChangeMapper.insert"; - private static final String MYBATIS_INSERT_ISSUE = "org.sonar.core.issue.db.IssueMapper.insert"; - private static final String MYBATIS_UPDATE_ISSUE = "org.sonar.core.issue.db.IssueMapper.update"; - private final MyBatis mybatis; private final RuleFinder ruleFinder; @@ -50,24 +47,27 @@ public abstract class IssueStorage { } public void save(Iterable<DefaultIssue> issues) { - SqlSession session = mybatis.openSession(); + SqlSession session = mybatis.openBatchSession(); + IssueMapper issueMapper = session.getMapper(IssueMapper.class); + IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class); try { List<DefaultIssue> conflicts = Lists.newArrayList(); + for (DefaultIssue issue : issues) { int ruleId = ruleId(issue); int componentId = componentId(issue); IssueDto dto = IssueDto.toDto(issue, componentId, ruleId); if (issue.isNew()) { - session.insert(MYBATIS_INSERT_ISSUE, dto); + issueMapper.insert(dto); } else /* TODO if hasChanges */ { // TODO manage condition on update date - int count = session.update(MYBATIS_UPDATE_ISSUE, dto); + int count = issueMapper.update(dto); if (count < 1) { conflicts.add(issue); } } - insertChanges(session, issue); + insertChanges(issueChangeMapper, issue); } session.commit(); @@ -77,16 +77,17 @@ public abstract class IssueStorage { } } - private void insertChanges(SqlSession session, DefaultIssue issue) { + private void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) { for (IssueComment comment : issue.comments()) { - if (comment.isNew()) { - IssueChangeDto changeDto = ChangeDtoConverter.commentToDto(issue.key(), comment); - session.insert(MYBATIS_INSERT_CHANGE, changeDto); + DefaultIssueComment c = (DefaultIssueComment) comment; + if (c.isNew()) { + IssueChangeDto changeDto = ChangeDtoConverter.commentToDto(issue.key(), c); + mapper.insert(changeDto); } } if (issue.diffs() != null) { IssueChangeDto changeDto = ChangeDtoConverter.changeToDto(issue.key(), issue.diffs()); - session.insert(MYBATIS_INSERT_CHANGE, changeDto); + mapper.insert(changeDto); } } diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml index 5ca7dd30001..c54639a2c2d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml @@ -35,18 +35,18 @@ c.updated_at as updatedAt </sql> - <insert id="insert" parameterType="IssueChange" useGeneratedKeys="true" keyProperty="id"> + <insert id="insert" parameterType="IssueChange" useGeneratedKeys="false" keyProperty="id"> INSERT INTO issue_changes (kee, issue_key, user_login, change_type, change_data, created_at, updated_at) - VALUES (#{key}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) + VALUES (#{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) </insert> <!-- Oracle --> - <insert id="insert" databaseId="oracle" parameterType="IssueChange" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + <insert id="insert" databaseId="oracle" parameterType="IssueChange" keyColumn="id" useGeneratedKeys="false" keyProperty="id"> <selectKey order="BEFORE" resultType="Long" keyProperty="id"> select issue_changes_seq.NEXTVAL from DUAL </selectKey> INSERT INTO issue_changes (id, kee, issue_key, user_login, change_type, change_data, created_at, updated_at) - VALUES (#{id}, #{key}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) + VALUES (#{id}, #{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) </insert> <select id="selectByIssueAndType" parameterType="map" resultType="IssueChange"> @@ -54,7 +54,7 @@ <include refid="issueChangeColumns"/> from issue_changes c where c.issue_key=#{issueKey} and c.change_type=#{changeType} - order by c.created_at desc + order by c.created_at </select> </mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index b66f6fb9d54..0b5f70aa77d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -43,7 +43,7 @@ </insert> <!-- Oracle --> - <insert id="insert" databaseId="oracle" parameterType="Issue" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + <insert id="insert" databaseId="oracle" parameterType="Issue" keyColumn="id" useGeneratedKeys="false" keyProperty="id"> <selectKey order="BEFORE" resultType="Long" keyProperty="id"> select issues_seq.NEXTVAL from DUAL </selectKey> diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index c55b7a381ab..a3c6e57e61d 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -519,10 +519,9 @@ CREATE TABLE "GRAPHS" ( CREATE TABLE "ISSUES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "KEE" VARCHAR(100) NOT NULL, + "KEE" VARCHAR(50) UNIQUE NOT NULL, "RESOURCE_ID" INTEGER NOT NULL, - "RULE_ID" INTEGER NULL, - "ACTION_PLAN_KEY" VARCHAR(100) NULL, + "RULE_ID" INTEGER, "SEVERITY" VARCHAR(10), "MANUAL_SEVERITY" BOOLEAN NOT NULL, "MANUAL_ISSUE" BOOLEAN NOT NULL, @@ -535,6 +534,7 @@ CREATE TABLE "ISSUES" ( "USER_LOGIN" VARCHAR(40), "ASSIGNEE_LOGIN" VARCHAR(40), "AUTHOR_LOGIN" VARCHAR(100), + "ACTION_PLAN_KEY" VARCHAR(50) NULL, "ATTRIBUTES" VARCHAR(4000), "ISSUE_CREATION_DATE" TIMESTAMP, "ISSUE_CLOSE_DATE" TIMESTAMP, @@ -545,8 +545,8 @@ CREATE TABLE "ISSUES" ( CREATE TABLE "ISSUE_CHANGES" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "KEE" VARCHAR(100), - "ISSUE_KEY" VARCHAR(100) NOT NULL, + "KEE" VARCHAR(50), + "ISSUE_KEY" VARCHAR(50) NOT NULL, "USER_LOGIN" VARCHAR(40), "CHANGE_TYPE" VARCHAR(40), "CHANGE_DATA" VARCHAR(16777215), @@ -676,10 +676,12 @@ CREATE INDEX "MEASURE_FILTER_FAVS_USERID" ON "MEASURE_FILTER_FAVOURITES" ("USER_ CREATE UNIQUE INDEX "GRAPHS_PERSPECTIVES" ON "GRAPHS" ("SNAPSHOT_ID", "PERSPECTIVE"); -CREATE INDEX "ISSUES_KEE" ON "ISSUES" ("KEE"); +CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES" ("KEE"); CREATE INDEX "ISSUES_RESOURCE_ID" ON "ISSUES" ("RESOURCE_ID"); +CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES" ("KEE"); + CREATE INDEX "ISSUE_CHANGES_ISSUE_KEY" ON "ISSUE_CHANGES" ("ISSUE_KEY"); -CREATE INDEX "ISSUE_CHANGES_KEE" ON "ISSUE_CHANGES" ("KEE"); + 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 index 3868e04c236..e7f5ff2b26c 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/ChangeDtoConverterTest.java @@ -20,20 +20,15 @@ package org.sonar.core.issue.db; import org.junit.Test; -import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.core.issue.IssueChangeContext; -import org.sonar.core.issue.IssueComment; - -import java.util.Date; -import java.util.List; import static org.fest.assertions.Assertions.assertThat; public class ChangeDtoConverterTest { @Test public void testToChangeDtos() throws Exception { - IssueComment comment = IssueComment.create("emmerik", "the comment"); + DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment"); IssueChangeDto dto = ChangeDtoConverter.commentToDto("ABCDE", comment); @@ -54,7 +49,7 @@ public class ChangeDtoConverterTest { IssueChangeDto dto = ChangeDtoConverter.changeToDto("ABCDE", diffs); assertThat(dto.getChangeData()).isEqualTo("severity=INFO|BLOCKER"); - assertThat(dto.getChangeType()).isEqualTo("change"); + assertThat(dto.getChangeType()).isEqualTo("diff"); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); assertThat(dto.getIssueKey()).isEqualTo("ABCDE"); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java index a777e227e79..426ea6b2e14 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java @@ -21,10 +21,14 @@ package org.sonar.core.issue.db; import org.junit.Before; import org.junit.Test; +import org.sonar.api.utils.DateUtils; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.core.issue.IssueComment; import org.sonar.core.persistence.AbstractDaoTestCase; +import java.util.Arrays; +import java.util.Date; + import static org.fest.assertions.Assertions.assertThat; public class IssueChangeDaoTest extends AbstractDaoTestCase { @@ -32,7 +36,7 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { IssueChangeDao dao; @Before - public void createDao() { + public void setUp() { dao = new IssueChangeDao(getMyBatis()); } @@ -40,15 +44,18 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { public void should_select_issue_comments() { setupData("shared"); - IssueComment[] comments = dao.selectIssueComments("1000"); + DefaultIssueComment[] comments = dao.selectIssueComments("1000"); assertThat(comments).hasSize(2); - IssueComment first = comments[0]; - assertThat(first.text()).isEqualTo("recent comment"); - assertThat(first.userLogin()).isEqualTo("arthur"); - assertThat(first.key()).isEqualTo("FGHIJ"); - IssueComment second = comments[1]; - assertThat(second.text()).isEqualTo("old comment"); + // chronological order + DefaultIssueComment first = comments[0]; + assertThat(first.text()).isEqualTo("old comment"); + + + DefaultIssueComment second = comments[1]; + assertThat(second.userLogin()).isEqualTo("arthur"); + assertThat(second.key()).isEqualTo("FGHIJ"); + assertThat(second.text()).isEqualTo("recent comment"); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java new file mode 100644 index 00000000000..9c320bf12cd --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java @@ -0,0 +1,73 @@ +/* + * 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.apache.ibatis.session.SqlSession; +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.utils.DateUtils; +import org.sonar.core.persistence.AbstractDaoTestCase; + +import java.util.Date; + +public class IssueChangeMapperTest extends AbstractDaoTestCase { + SqlSession session; + IssueChangeMapper mapper; + + @Before + public void setUp() { + session = getMyBatis().openSession(); + mapper = session.getMapper(IssueChangeMapper.class); + } + + @Test + public void testInsertDiff() throws Exception { + IssueChangeDto dto = new IssueChangeDto(); + dto.setKey(null /* no key on field changes */); + dto.setUserLogin("emmerik"); + dto.setIssueKey("ABCDE"); + dto.setChangeType(ChangeDtoConverter.TYPE_FIELD_CHANGE); + dto.setChangeData("severity=INFO|BLOCKER"); + Date d = DateUtils.parseDate("2013-05-18"); + dto.setCreatedAt(d); + dto.setUpdatedAt(d); + mapper.insert(dto); + session.commit(); + + checkTables("testInsertDiff", new String[]{"id"}, "issue_changes"); + } + + @Test + public void testInsertComment() throws Exception { + IssueChangeDto dto = new IssueChangeDto(); + dto.setKey("COMMENT-1234"); + dto.setUserLogin("emmerik"); + dto.setIssueKey("ABCDE"); + dto.setChangeType(ChangeDtoConverter.TYPE_COMMENT); + dto.setChangeData("the comment"); + Date d = DateUtils.parseDate("2013-05-18"); + dto.setCreatedAt(d); + dto.setUpdatedAt(d); + mapper.insert(dto); + session.commit(); + + checkTables("testInsertComment", new String[]{"id"}, "issue_changes"); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java index a8ddecf4c49..0d35a9b5327 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java @@ -48,9 +48,8 @@ public class IssueDaoTest extends AbstractDaoTestCase { setupData("shared", "should_select_by_key"); IssueDto issue = dao.selectByKey("ABCDE"); - assertThat(issue.getKey()).isEqualTo("ABCDE"); + assertThat(issue.getKee()).isEqualTo("ABCDE"); assertThat(issue.getId()).isEqualTo(100L); - assertThat(issue.getKey()).isEqualTo("ABCDE"); assertThat(issue.getResourceId()).isEqualTo(400); assertThat(issue.getRuleId()).isEqualTo(500); assertThat(issue.getSeverity()).isEqualTo("BLOCKER"); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java index 539229136ab..54be128bc42 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java @@ -54,7 +54,7 @@ public class IssueDtoTest { Date closedAt = DateUtils.addDays(new Date(), -1); IssueDto dto = new IssueDto() - .setKey("100") + .setKee("100") .setRuleId(1) .setRuleKey_unit_test_only("squid", "AvoidCycle") .setComponentKey_unit_test_only("component-key") diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java new file mode 100644 index 00000000000..b7e1513678c --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueMapperTest.java @@ -0,0 +1,102 @@ +/* + * 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.apache.ibatis.session.SqlSession; +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.utils.DateUtils; +import org.sonar.core.persistence.AbstractDaoTestCase; + +public class IssueMapperTest extends AbstractDaoTestCase { + + SqlSession session; + IssueMapper mapper; + + @Before + public void setUp() { + session = getMyBatis().openSession(); + mapper = session.getMapper(IssueMapper.class); + } + + @Test + public void testInsert() throws Exception { + IssueDto dto = new IssueDto(); + dto.setResourceId(123); + dto.setRuleId(200); + dto.setKee("ABCDE"); + dto.setLine(500); + dto.setEffortToFix(3.14); + dto.setResolution("FIXED"); + dto.setStatus("RESOLVED"); + dto.setSeverity("BLOCKER"); + dto.setUserLogin("emmerik"); + dto.setAuthorLogin("morgan"); + dto.setAssignee("karadoc"); + dto.setActionPlanKey("current_sprint"); + dto.setAttributes("JIRA=FOO-1234"); + dto.setChecksum("123456789"); + dto.setDescription("the description"); + + dto.setIssueCreationDate(DateUtils.parseDate("2013-05-18")); + dto.setIssueUpdateDate(DateUtils.parseDate("2013-05-19")); + dto.setIssueCloseDate(DateUtils.parseDate("2013-05-20")); + dto.setCreatedAt(DateUtils.parseDate("2013-05-21")); + dto.setUpdatedAt(DateUtils.parseDate("2013-05-22")); + + mapper.insert(dto); + session.commit(); + + checkTables("testInsert", new String[]{"id"}, "issues"); + } + + @Test + public void testUpdate() throws Exception { + setupData("testUpdate"); + + IssueDto dto = new IssueDto(); + dto.setResourceId(123); + dto.setRuleId(200); + dto.setKee("ABCDE"); + dto.setLine(500); + dto.setEffortToFix(3.14); + dto.setResolution("FIXED"); + dto.setStatus("RESOLVED"); + dto.setSeverity("BLOCKER"); + dto.setUserLogin("emmerik"); + dto.setAuthorLogin("morgan"); + dto.setAssignee("karadoc"); + dto.setActionPlanKey("current_sprint"); + dto.setAttributes("JIRA=FOO-1234"); + dto.setChecksum("123456789"); + dto.setDescription("the description"); + + dto.setIssueCreationDate(DateUtils.parseDate("2013-05-18")); + dto.setIssueUpdateDate(DateUtils.parseDate("2013-05-19")); + dto.setIssueCloseDate(DateUtils.parseDate("2013-05-20")); + dto.setCreatedAt(DateUtils.parseDate("2013-05-21")); + dto.setUpdatedAt(DateUtils.parseDate("2013-05-22")); + + mapper.update(dto); + session.commit(); + + checkTables("testUpdate", new String[]{"id"}, "issues"); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java index edf5cb15856..1aa38f19657 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueStorageTest.java @@ -26,8 +26,8 @@ import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.RuleQuery; import org.sonar.api.utils.DateUtils; import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.IssueChangeContext; -import org.sonar.core.issue.IssueComment; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.persistence.MyBatis; @@ -42,7 +42,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { public void should_insert_new_issues() throws Exception { FakeSaver saver = new FakeSaver(getMyBatis(), new FakeRuleFinder()); - IssueComment comment = IssueComment.create("emmerik", "the comment"); + DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment"); // override generated key comment.setKey("FGHIJ"); @@ -71,7 +71,7 @@ public class IssueStorageTest extends AbstractDaoTestCase { FakeSaver saver = new FakeSaver(getMyBatis(), new FakeRuleFinder()); - IssueComment comment = IssueComment.create("emmerik", "the comment"); + DefaultIssueComment comment = DefaultIssueComment.create("emmerik", "the comment"); // override generated key comment.setKey("FGHIJ"); diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml index e9d0022f889..ae1bcb0b328 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml @@ -16,7 +16,7 @@ kee="[null]" issue_key="1000" user_login="arthur" - change_type="change" + change_type="diff" change_data="severity=MAJOR|BLOCKER" created_at="2013-02-02" updated_at="2013-02-02" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml new file mode 100644 index 00000000000..c1f10296b62 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertComment-result.xml @@ -0,0 +1,12 @@ +<dataset> + <issue_changes + id="1" + kee="COMMENT-1234" + issue_key="ABCDE" + user_login="emmerik" + change_type="comment" + change_data="the comment" + created_at="2013-05-18" + updated_at="2013-05-18" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml new file mode 100644 index 00000000000..4d7045179e9 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/testInsertDiff-result.xml @@ -0,0 +1,12 @@ +<dataset> + <issue_changes + id="1" + kee="[null]" + issue_key="ABCDE" + user_login="emmerik" + change_type="diff" + change_data="severity=INFO|BLOCKER" + created_at="2013-05-18" + updated_at="2013-05-18" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml index 285456d07fe..b4bd5440f19 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_all.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" @@ -55,7 +55,7 @@ <!-- rule 501 --> <issues id="102" - kee="ABCDE" + kee="ABCDE-3" resource_id="400" rule_id="501" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml index e09cf89e7a8..11a1b1e6c0b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_assigned.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" @@ -55,7 +55,7 @@ <!-- rule 501 --> <issues id="102" - kee="ABCDE" + kee="ABCDE-3" resource_id="400" rule_id="501" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml index dc3dce23a04..79562aa6c38 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_date_creation.xml @@ -2,7 +2,7 @@ <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -27,7 +27,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml index 285456d07fe..b96e48f1db9 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_ids.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml index 9fbab6fea10..1c355d2a550 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_by_rules.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" @@ -55,7 +55,7 @@ <!-- rule 501 --> <issues id="102" - kee="ABCDE" + kee="ABCDE-3" resource_id="400" rule_id="501" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml index 285456d07fe..b4bd5440f19 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_issue_ids_and_components_ids.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" @@ -55,7 +55,7 @@ <!-- rule 501 --> <issues id="102" - kee="ABCDE" + kee="ABCDE-3" resource_id="400" rule_id="501" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result.xml index f6d9e75ea16..7c3272bc171 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_returned_sorted_result.xml @@ -3,7 +3,7 @@ <!-- rule 500 --> <issues id="100" - kee="ABCDE" + kee="ABCDE-1" resource_id="400" rule_id="500" severity="BLOCKER" @@ -28,7 +28,7 @@ <issues id="101" - kee="ABCDE" + kee="ABCDE-2" resource_id="400" rule_id="500" severity="BLOCKER" @@ -55,7 +55,7 @@ <!-- rule 501 --> <issues id="102" - kee="ABCDE" + kee="ABCDE-3" resource_id="400" rule_id="501" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml new file mode 100644 index 00000000000..87f0a290699 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testInsert-result.xml @@ -0,0 +1,27 @@ +<dataset> + <issues + id="100" + kee="ABCDE" + resource_id="123" + rule_id="200" + severity="BLOCKER" + manual_severity="[false]" + manual_issue="[false]" + description="the description" + line="500" + effort_to_fix="3.14" + status="RESOLVED" + resolution="FIXED" + checksum="123456789" + user_login="emmerik" + author_login="morgan" + assignee_login="karadoc" + attributes="JIRA=FOO-1234" + issue_creation_date="2013-05-18" + issue_update_date="2013-05-19" + issue_close_date="2013-05-20" + created_at="2013-05-21" + updated_at="2013-05-22" + action_plan_key="current_sprint" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml new file mode 100644 index 00000000000..9385a08792c --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate-result.xml @@ -0,0 +1,46 @@ +<!-- + ~ 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. + --> +<dataset> + <issues + id="100" + kee="ABCDE" + resource_id="123" + rule_id="200" + severity="BLOCKER" + manual_severity="[false]" + manual_issue="[false]" + description="the description" + line="500" + effort_to_fix="3.14" + status="RESOLVED" + resolution="FIXED" + checksum="123456789" + user_login="emmerik" + author_login="morgan" + assignee_login="karadoc" + attributes="JIRA=FOO-1234" + issue_creation_date="2013-05-18" + issue_update_date="2013-05-19" + issue_close_date="2013-05-20" + created_at="2013-05-21" + updated_at="2013-05-22" + action_plan_key="current_sprint" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml new file mode 100644 index 00000000000..38b64d7f53d --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueMapperTest/testUpdate.xml @@ -0,0 +1,46 @@ +<!-- + ~ 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. + --> +<dataset> + <issues + id="100" + kee="ABCDE" + resource_id="123" + rule_id="200" + severity="INFO" + manual_severity="[false]" + manual_issue="[false]" + description="old" + line="[null]" + effort_to_fix="[null]" + status="OPEN" + resolution="[null]" + checksum="[null]" + user_login="[null]" + author_login="[null]" + assignee_login="[null]" + attributes="[null]" + issue_creation_date="[null]" + issue_update_date="[null]" + issue_close_date="[null]" + created_at="[null]" + updated_at="[null]" + action_plan_key="[null]" + /> +</dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml index 6328fa6f38c..5d67bd4602f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueStorageTest/should_update_issues-result.xml @@ -26,6 +26,6 @@ <issue_changes id="1" kee="FGHIJ" issue_key="ABCDE" change_type="comment" user_login="emmerik" change_data="the comment" created_at="[null]" updated_at="[null]"/> - <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="change" user_login="emmerik" + <issue_changes id="2" kee="[null]" issue_key="ABCDE" change_type="diff" user_login="emmerik" change_data="severity=INFO|BLOCKER" created_at="[null]" updated_at="[null]"/> </dataset>
\ No newline at end of file diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java index 15ebeb82905..61bfe64f6b1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java @@ -25,6 +25,7 @@ import javax.annotation.CheckForNull; import java.io.Serializable; import java.util.Date; +import java.util.List; import java.util.Map; /** @@ -105,4 +106,5 @@ public interface Issue extends Serializable { @CheckForNull String actionPlanKey(); + List<IssueComment> comments(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java new file mode 100644 index 00000000000..3b32b6d6c19 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueComment.java @@ -0,0 +1,36 @@ +/* + * 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.api.issue; + +import javax.annotation.CheckForNull; +import java.util.Date; + +public interface IssueComment { + String text(); + + String key(); + + @CheckForNull + String userLogin(); + + Date createdAt(); + + Date updatedAt(); +} diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueActions.java b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueActions.java index 4c155b7d0f0..931839eb6a0 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueActions.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueActions.java @@ -22,6 +22,7 @@ package org.sonar.server.issue; import com.google.common.base.Strings; import org.sonar.api.ServerComponent; import org.sonar.api.issue.Issue; +import org.sonar.api.issue.IssueComment; import org.sonar.api.web.UserRole; import org.sonar.core.issue.*; import org.sonar.core.issue.db.IssueChangeDao; @@ -34,7 +35,6 @@ import org.sonar.core.user.AuthorizationDao; import org.sonar.server.platform.UserSession; import javax.annotation.Nullable; - import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -131,7 +131,7 @@ public class ServerIssueActions implements ServerComponent { return issue.comments().get(0); } - public IssueComment[] comments(String issueKey, UserSession userSession) { + public DefaultIssueComment[] comments(String issueKey, UserSession userSession) { // TODO verify authorization return issueChangeDao.selectIssueComments(issueKey); } diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java index 3230a06c28c..74f12493283 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java @@ -27,15 +27,13 @@ import org.apache.ibatis.session.SqlSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.component.Component; -import org.sonar.api.issue.ActionPlan; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.IssueFinder; -import org.sonar.api.issue.IssueQuery; +import org.sonar.api.issue.*; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.utils.Paging; import org.sonar.core.issue.ActionPlanFinder; import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.db.IssueChangeDao; import org.sonar.core.issue.db.IssueDao; import org.sonar.core.issue.db.IssueDto; import org.sonar.core.persistence.MyBatis; diff --git a/sonar-server/src/main/java/org/sonar/server/issue/WebIssuesInternal.java b/sonar-server/src/main/java/org/sonar/server/issue/WebIssuesInternal.java index c87cabcc822..c58222e50d4 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/WebIssuesInternal.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/WebIssuesInternal.java @@ -22,6 +22,7 @@ package org.sonar.server.issue; import org.sonar.api.ServerComponent; import org.sonar.api.issue.ActionPlan; import org.sonar.api.issue.Issue; +import org.sonar.api.issue.IssueComment; import org.sonar.api.rule.RuleKey; import org.sonar.core.issue.*; import org.sonar.core.issue.workflow.Transition; @@ -68,7 +69,7 @@ public class WebIssuesInternal implements ServerComponent { return actions.addComment(issueKey, comment, UserSession.get()); } - public IssueComment[] comments(String issueKey) { + public DefaultIssueComment[] comments(String issueKey) { return actions.comments(issueKey, UserSession.get()); } diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb index 9d7b987b8a0..08f39487443 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/395_create_issues.rb @@ -25,10 +25,9 @@ class CreateIssues < ActiveRecord::Migration def self.up create_table :issues do |t| - t.column :kee, :string, :null => false, :limit => 100 + t.column :kee, :string, :null => false, :limit => 50 t.column :resource_id, :integer, :null => false t.column :rule_id, :integer, :null => true - t.column :action_plan_key, :string, :null => true, :limit => 100 t.column :severity, :string, :null => true, :limit => 10 t.column :manual_severity, :boolean, :null => false t.column :manual_issue, :boolean, :null => false @@ -41,6 +40,7 @@ class CreateIssues < ActiveRecord::Migration t.column :user_login, :string, :null => true, :limit => 40 t.column :assignee_login, :string, :null => true, :limit => 40 t.column :author_login, :string, :null => true, :limit => 100 + t.column :action_plan_key, :string, :null => true, :limit => 50 t.column :attributes, :string, :null => true, :limit => 4000 # functional dates @@ -53,7 +53,7 @@ class CreateIssues < ActiveRecord::Migration t.column :updated_at, :datetime, :null => true end - add_index :issues, :kee, :name => 'issues_kee' + add_index :issues, :kee, :name => 'issues_kee', :unique => true add_index :issues, :resource_id, :name => 'issues_resource_id' end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb index ea2ee651a72..016380cf8f6 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/396_create_issue_changes.rb @@ -25,10 +25,10 @@ class CreateIssueChanges < ActiveRecord::Migration def self.up create_table :issue_changes do |t| - t.column :kee, :string, :null => true, :limit => 100 - t.column :issue_key, :string, :null => false, :limit => 100 + t.column :kee, :string, :null => true, :limit => 50 + t.column :issue_key, :string, :null => false, :limit => 50 t.column :user_login, :string, :null => true, :limit => 40 - t.column :change_type, :string, :null => true, :limit => 40 + t.column :change_type, :string, :null => true, :limit => 20 t.column :change_data, :text, :null => true t.column :created_at, :datetime, :null => true t.column :updated_at, :datetime, :null => true diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java index c0a1c0880b0..11e1821c352 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java @@ -217,11 +217,11 @@ public class ServerIssueFinderTest { grantAccessRights(); IssueQuery query = IssueQuery.builder().build(); - IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setResourceId(123).setKey("ABC").setActionPlanKey("A") + IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setResourceId(123).setKee("ABC").setActionPlanKey("A") .setComponentKey_unit_test_only("Action.java") .setRuleKey_unit_test_only("squid", "AvoidCycle") .setStatus("OPEN").setResolution("OPEN"); - IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setResourceId(123).setKey("DEF").setActionPlanKey("B") + IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setResourceId(123).setKee("DEF").setActionPlanKey("B") .setComponentKey_unit_test_only("Action.java") .setRuleKey_unit_test_only("squid", "AvoidCycle") .setStatus("OPEN").setResolution("OPEN"); |