From 0e4fedebee2ab25fcdf8e90104fae836aa460dec Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 19 Feb 2014 18:26:02 +0100 Subject: [PATCH] SONAR-4996 Update issue debt to seconds (backend + display) --- .../org/sonar/core/issue/IssueUpdater.java | 11 +------ .../sonar/core/issue/IssueUpdaterTest.java | 32 ++++++------------- .../main/webapp/WEB-INF/app/models/issue.rb | 23 +++++-------- 3 files changed, 18 insertions(+), 48 deletions(-) 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 4d39dccb915..754ad01f50b 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 @@ -29,7 +29,6 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.user.User; -import org.sonar.api.utils.WorkDurationFactory; import javax.annotation.Nullable; import java.util.Calendar; @@ -49,12 +48,6 @@ public class IssueUpdater implements BatchComponent, ServerComponent { public static final String ACTION_PLAN = "actionPlan"; public static final String TECHNICAL_DEBT = "technicalDebt"; - private final WorkDurationFactory workDurationFactory; - - public IssueUpdater(WorkDurationFactory workDurationFactory) { - this.workDurationFactory = workDurationFactory; - } - public boolean setSeverity(DefaultIssue issue, String severity, IssueChangeContext context) { if (issue.manualSeverity()) { throw new IllegalStateException("Severity can't be changed"); @@ -209,9 +202,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent { Long oldValue = issue.debt(); if (!Objects.equal(value, oldValue)) { issue.setDebt(value); - Long oldValueInLong = oldValue != null ? workDurationFactory.createFromSeconds(oldValue).toLong() : null; - Long newValueInLong = value != null ? workDurationFactory.createFromSeconds(value).toLong() : null; - issue.setFieldChange(context, TECHNICAL_DEBT, oldValueInLong, newValueInLong); + issue.setFieldChange(context, TECHNICAL_DEBT, oldValue, value); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java index e1263611418..67666485d44 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java @@ -19,17 +19,12 @@ */ package org.sonar.core.issue; -import org.junit.Before; import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; import org.sonar.api.issue.ActionPlan; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.user.User; -import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; import org.sonar.core.user.DefaultUser; import java.util.Date; @@ -39,19 +34,10 @@ import static org.sonar.core.issue.IssueUpdater.*; public class IssueUpdaterTest { + IssueUpdater updater = new IssueUpdater(); DefaultIssue issue = new DefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); - IssueUpdater updater; - - @Before - public void setUp() throws Exception { - Settings settings = new Settings(); - settings.setProperty(CoreProperties.HOURS_IN_DAY, 8); - - updater = new IssueUpdater(new WorkDurationFactory(settings)); - } - @Test public void assign() throws Exception { User user = new DefaultUser().setLogin("emmerik").setName("Emmerik"); @@ -379,8 +365,8 @@ public class IssueUpdaterTest { @Test public void set_past_technical_debt() throws Exception { - long newDebt = 15 * 8 * 60 * 60; - long previousDebt = 10 * 8 * 60 * 60; + long newDebt = 15; + long previousDebt = 10; issue.setDebt(newDebt); boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); assertThat(updated).isTrue(); @@ -388,13 +374,13 @@ public class IssueUpdaterTest { assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); - assertThat(diff.oldValue()).isEqualTo(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.DAYS, 8).toLong()); - assertThat(diff.newValue()).isEqualTo(WorkDuration.createFromValueAndUnit(15, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.oldValue()).isEqualTo(previousDebt); + assertThat(diff.newValue()).isEqualTo(newDebt); } @Test public void set_past_technical_debt_without_previous_value() throws Exception { - long newDebt = 15 * 8 * 60 * 60; + long newDebt = 15; issue.setDebt(newDebt); boolean updated = updater.setPastTechnicalDebt(issue, null, context); assertThat(updated).isTrue(); @@ -403,20 +389,20 @@ public class IssueUpdaterTest { FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); assertThat(diff.oldValue()).isNull(); - assertThat(diff.newValue()).isEqualTo(WorkDuration.createFromValueAndUnit(15, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.newValue()).isEqualTo(newDebt); } @Test public void set_past_technical_debt_with_null_new_value() throws Exception { issue.setDebt(null); - long previousDebt = 10 * 8 * 60 * 60; + long previousDebt = 10; boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); assertThat(updated).isTrue(); assertThat(issue.debt()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); - assertThat(diff.oldValue()).isEqualTo(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.oldValue()).isEqualTo(previousDebt); assertThat(diff.newValue()).isNull(); } diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb index da4b0a7a636..f0a93bd3067 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/issue.rb @@ -20,7 +20,7 @@ class Issue - def self.to_hash(issue) + def self.to_hash(issue, rule_name=nil) hash = { :key => issue.key, :component => issue.componentKey, @@ -33,7 +33,7 @@ class Issue hash[:message] = issue.message if issue.message hash[:line] = issue.line.to_i if issue.line hash[:effortToFix] = issue.effortToFix.to_f if issue.effortToFix - hash[:technicalDebt] = debt_to_hash(issue.debt) if issue.debt + hash[:technicalDebt] = technical_debt_to_hash(issue.debt) if issue.debt hash[:reporter] = issue.reporter if issue.reporter hash[:assignee] = issue.assignee if issue.assignee hash[:author] = issue.authorLogin if issue.authorLogin @@ -74,8 +74,8 @@ class Issue hash_diff = {} hash_diff[:key] = key if key == 'technicalDebt' - hash_diff[:newValue] = work_duration_to_hash(Internal.technical_debt.toTechnicalDebt(diff.newValue())) if diff.newValue.present? - hash_diff[:oldValue] = work_duration_to_hash(Internal.technical_debt.toTechnicalDebt(diff.oldValue())) if diff.oldValue.present? + hash_diff[:newValue] = technical_debt_to_hash(Internal.technical_debt.toTechnicalDebt(diff.newValue())) if diff.newValue.present? + hash_diff[:oldValue] = technical_debt_to_hash(Internal.technical_debt.toTechnicalDebt(diff.oldValue())) if diff.oldValue.present? else hash_diff[:newValue] = diff.newValue() if diff.newValue.present? hash_diff[:oldValue] = diff.oldValue() if diff.oldValue.present? @@ -88,18 +88,11 @@ class Issue hash end - - private - - def self.debt_to_hash(debt) - work_duration_to_hash(Internal.technical_debt.toWorkDuration(debt)) - end - - def self.work_duration_to_hash(work_duration) + def self.technical_debt_to_hash(technical_debt) { - :days => work_duration.days(), - :hours => work_duration.hours(), - :minutes => work_duration.minutes() + :days => technical_debt.days(), + :hours => technical_debt.hours(), + :minutes => technical_debt.minutes() } end -- 2.39.5