From 8e2428ab161d64964e65e434ac785222a0163bc9 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 3 Jan 2014 16:47:08 +0100 Subject: SONAR-4776 Fix new technical debt calculation by using project analysis date in changelog instead of technical date --- .../java/org/sonar/core/issue/IssueUpdater.java | 2 +- .../org/sonar/core/issue/db/IssueChangeDto.java | 19 +++++- .../org/sonar/core/issue/db/IssueChangeMapper.xml | 9 +-- .../org/sonar/core/persistence/rows-h2.sql | 1 + .../org/sonar/core/persistence/schema-h2.ddl | 1 + .../sonar/core/issue/db/IssueChangeDaoTest.java | 4 +- .../sonar/core/issue/db/IssueChangeDtoTest.java | 3 + .../sonar/core/issue/db/IssueChangeMapperTest.java | 1 + .../org/sonar/core/issue/db/IssueStorageTest.java | 6 +- .../issue/db/IssueChangeDaoTest/delete-result.xml | 3 + .../core/issue/db/IssueChangeDaoTest/delete.xml | 3 + .../select_issue_changelog_by_module.xml | 7 +++ ...ngelog_by_module_are_sorted_by_created_date.xml | 64 --------------------- ...gelog_by_module_are_sorted_by_creation_date.xml | 67 ++++++++++++++++++++++ .../core/issue/db/IssueChangeDaoTest/shared.xml | 5 ++ .../issue/db/IssueChangeDaoTest/update-result.xml | 3 + .../core/issue/db/IssueChangeDaoTest/update.xml | 3 + .../insert_comment-result.xml | 3 +- .../IssueChangeMapperTest/insert_diff-result.xml | 3 +- .../should_insert_new_issues-result.xml | 3 +- .../should_update_issues-result.xml | 4 +- .../should_delete_all_closed_issues-result.xml | 10 ++-- .../should_delete_all_closed_issues.xml | 10 ++-- .../should_delete_old_closed_issues-result.xml | 10 ++-- .../should_delete_old_closed_issues.xml | 10 ++-- 25 files changed, 153 insertions(+), 101 deletions(-) delete mode 100644 sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_created_date.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml (limited to 'sonar-core/src') 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 6ed33ddc704..9cbd6c92045 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 @@ -204,7 +204,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent { WorkDayDuration oldValue = issue.technicalDebt(); if (!Objects.equal(value, oldValue)) { issue.setTechnicalDebt(value); - issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toLong() : oldValue, value != null ? value.toLong() : null); + issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toLong() : null, value != null ? value.toLong() : null); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; 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 646fb02b330..d57efd142fc 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 @@ -44,9 +44,14 @@ public final class IssueChangeDto implements Serializable { private String userLogin; private String changeType; private String changeData; + + // technical dates private Date createdAt; private Date updatedAt; + // functional date + private Date issueChangeCreationDate; + public Long getId() { return id; } @@ -120,6 +125,15 @@ public final class IssueChangeDto implements Serializable { return this; } + public Date getIssueChangeCreationDate() { + return issueChangeCreationDate; + } + + public IssueChangeDto setIssueChangeCreationDate(Date issueChangeCreationDate) { + this.issueChangeCreationDate = issueChangeCreationDate; + return this; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); @@ -131,6 +145,7 @@ public final class IssueChangeDto implements Serializable { dto.setChangeType(IssueChangeDto.TYPE_COMMENT); dto.setChangeData(comment.markdownText()); dto.setUserLogin(comment.userLogin()); + dto.setIssueChangeCreationDate(comment.createdAt()); return dto; } @@ -139,6 +154,7 @@ public final class IssueChangeDto implements Serializable { dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); dto.setChangeData(diffs.toString()); dto.setUserLogin(diffs.userLogin()); + dto.setIssueChangeCreationDate(diffs.creationDate()); return dto; } @@ -167,8 +183,7 @@ public final class IssueChangeDto implements Serializable { public FieldDiffs toFieldDiffs() { return FieldDiffs.parse(changeData) .setUserLogin(userLogin) - .setCreatedAt(createdAt) - .setUpdatedAt(updatedAt) + .setCreationDate(issueChangeCreationDate) .setIssueKey(issueKey); } } 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 ce9cb26ce66..c17d5f04f4b 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 @@ -12,12 +12,13 @@ c.change_type as changeType, c.change_data as changeData, c.created_at as createdAt, - c.updated_at as updatedAt + c.updated_at as updatedAt, + c.issue_change_creation_date as issueChangeCreationDate - INSERT INTO issue_changes (kee, issue_key, user_login, change_type, change_data, created_at, updated_at) - VALUES (#{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}) + INSERT INTO issue_changes (kee, issue_key, user_login, change_type, change_data, created_at, updated_at, issue_change_creation_date) + VALUES (#{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt}, #{issueChangeCreationDate}) @@ -49,7 +50,7 @@ and c.change_type=#{changeType} and i.status <> 'CLOSED' - order by c.created_at asc + order by c.issue_change_creation_date asc