diff options
Diffstat (limited to 'sonar-server/src')
9 files changed, 40 insertions, 18 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java index d33f3089aea..d87e499e3e2 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueChangelogFormatter.java @@ -22,6 +22,7 @@ package org.sonar.server.issue; import org.sonar.api.ServerComponent; import org.sonar.api.i18n.I18n; import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.api.utils.Duration; import org.sonar.core.issue.IssueUpdater; import org.sonar.server.user.UserSession; @@ -71,10 +72,10 @@ public class IssueChangelogFormatter implements ServerComponent { String oldValueString = oldValue != null && !"".equals(oldValue) ? oldValue.toString() : null; if (IssueUpdater.TECHNICAL_DEBT.equals(key)) { if (newValueString != null) { - newValueString = i18n.formatWorkDuration(UserSession.get().locale(), Long.parseLong(newValueString)); + newValueString = i18n.formatWorkDuration(UserSession.get().locale(), Duration.create(Long.parseLong(newValueString))); } if (oldValueString != null) { - oldValueString = i18n.formatWorkDuration(UserSession.get().locale(), Long.parseLong(oldValueString)); + oldValueString = i18n.formatWorkDuration(UserSession.get().locale(), Duration.create(Long.parseLong(oldValueString))); } } return new IssueChangelogDiffFormat(oldValueString, newValueString); diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java index 0f588f7fd47..116b32da940 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueShowWsHandler.java @@ -33,6 +33,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.technicaldebt.server.Characteristic; import org.sonar.api.user.User; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.Duration; import org.sonar.api.utils.text.JsonWriter; import org.sonar.api.web.UserRole; import org.sonar.core.component.ComponentDto; @@ -98,7 +99,7 @@ public class IssueShowWsHandler implements RequestHandler { private void writeIssue(IssueQueryResult result, DefaultIssue issue, JsonWriter json) { String actionPlanKey = issue.actionPlanKey(); ActionPlan actionPlan = result.actionPlan(issue); - Long technicalDebt = issue.debt(); + Duration debt = issue.debt(); Date updateDate = issue.updateDate(); Date closeDate = issue.closeDate(); @@ -114,7 +115,7 @@ public class IssueShowWsHandler implements RequestHandler { .prop("author", issue.authorLogin()) .prop("actionPlan", actionPlanKey) .prop("actionPlanName", actionPlan != null ? actionPlan.name() : null) - .prop("debt", technicalDebt != null ? i18n.formatWorkDuration(UserSession.get().locale(), technicalDebt) : null) + .prop("debt", debt != null ? i18n.formatWorkDuration(UserSession.get().locale(), debt) : null) .prop("creationDate", DateUtils.formatDateTime(issue.creationDate())) .prop("fCreationDate", formatDate(issue.creationDate())) .prop("updateDate", updateDate != null ? DateUtils.formatDateTime(updateDate) : null) diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java index 3931567b6fb..80a6ba85320 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyI18n.java @@ -23,6 +23,7 @@ import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerComponent; import org.sonar.api.i18n.I18n; +import org.sonar.api.utils.Duration; import org.sonar.core.i18n.GwtI18n; import org.sonar.server.user.UserSession; @@ -86,8 +87,12 @@ public class JRubyI18n implements ServerComponent { return i18n.ageFromNow(UserSession.get().locale(), date); } - public String formatWorkDuration(long duration) { + public String formatWorkDuration(Duration duration) { return i18n.formatWorkDuration(UserSession.get().locale(), duration); } + public String formatLongWorkDuration(long duration) { + return formatWorkDuration(Duration.create(duration)); + } + } 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 59b3edb73d6..2c99796de44 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 @@ -75,8 +75,8 @@ class Issue hash_diff = {} hash_diff[:key] = key if key == 'technicalDebt' - hash_diff[:newValue] = debt_to_hash(diff.newValue()) if diff.newValue.present? - hash_diff[:oldValue] = debt_to_hash(diff.oldValue()) if diff.oldValue.present? + hash_diff[:newValue] = long_debt_to_hash(diff.newValue()) if diff.newValue.present? + hash_diff[:oldValue] = long_debt_to_hash(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? @@ -93,6 +93,11 @@ class Issue private def self.debt_to_hash(debt) + long_debt_to_hash(debt.toMinutes) + end + + def self.long_debt_to_hash(debt) + # TODO do not use toWorkDuration() but calculate days, hours and minutes from the duration and from hoursInDay property work_duration = Internal.technical_debt.toWorkDuration(debt.to_i) { :days => work_duration.days(), diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb index f600e43430d..0198b35e57a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/project_measure.rb @@ -164,7 +164,7 @@ class ProjectMeasure < ActiveRecord::Base end def work_duration_formatted_value(value) - Internal.i18n.formatWorkDuration(value.to_i) + Internal.i18n.formatLongWorkDuration(value.to_i) end def color diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java index f35b8b0cd7f..33c965d5113 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java @@ -33,6 +33,7 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rules.Rule; import org.sonar.api.user.User; import org.sonar.api.user.UserFinder; +import org.sonar.api.utils.Duration; import org.sonar.core.component.ComponentDto; import org.sonar.core.issue.DefaultActionPlan; import org.sonar.core.issue.db.IssueChangeDao; @@ -333,7 +334,7 @@ public class assertThat(results.issues()).hasSize(1); DefaultIssue result = (DefaultIssue) results.issues().iterator().next(); - assertThat(result.debt()).isEqualTo(10L); + assertThat(result.debt()).isEqualTo(Duration.create(10L)); } } diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java index 1dcb81c46c7..98323c582b6 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java @@ -26,6 +26,7 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.i18n.I18n; import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.api.utils.Duration; import java.util.List; import java.util.Locale; @@ -127,8 +128,8 @@ public class IssueChangelogFormatterTest { FieldDiffs diffs = new FieldDiffs(); diffs.setDiff("technicalDebt", "18000", "28800"); - when(i18n.formatWorkDuration(any(Locale.class), eq(18000L))).thenReturn("5 hours"); - when(i18n.formatWorkDuration(any(Locale.class), eq(28800L))).thenReturn("1 days"); + when(i18n.formatWorkDuration(any(Locale.class), eq(Duration.create(18000L)))).thenReturn("5 hours"); + when(i18n.formatWorkDuration(any(Locale.class), eq(Duration.create(28800L)))).thenReturn("1 days"); when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); @@ -145,7 +146,7 @@ public class IssueChangelogFormatterTest { FieldDiffs diffs = new FieldDiffs(); diffs.setDiff("technicalDebt", null, "28800"); - when(i18n.formatWorkDuration(any(Locale.class), eq(28800L))).thenReturn("1 days"); + when(i18n.formatWorkDuration(any(Locale.class), eq(Duration.create(28800L)))).thenReturn("1 days"); when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt"); when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days"); diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java index cf27de1d585..2dc944f5534 100644 --- a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java @@ -42,6 +42,7 @@ import org.sonar.api.technicaldebt.server.Characteristic; import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic; import org.sonar.api.user.User; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.Duration; import org.sonar.api.web.UserRole; import org.sonar.core.component.ComponentDto; import org.sonar.core.issue.DefaultActionPlan; @@ -302,11 +303,11 @@ public class IssueShowWsHandlerTest { @Test public void show_issue_with_technical_debt() throws Exception { - Long technicalDebt = 7260L; - Issue issue = createStandardIssue().setDebt(technicalDebt); + Duration debt = (Duration.create(7260L)); + Issue issue = createStandardIssue().setDebt(debt); issues.add(issue); - when(i18n.formatWorkDuration(any(Locale.class), eq(technicalDebt))).thenReturn("2 hours 1 minutes"); + when(i18n.formatWorkDuration(any(Locale.class), eq(debt))).thenReturn("2 hours 1 minutes"); MockUserSession.set(); WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key()); @@ -315,7 +316,7 @@ public class IssueShowWsHandlerTest { @Test public void show_issue_with_characteristics() throws Exception { - Issue issue = createStandardIssue().setDebt(7260L); + Issue issue = createStandardIssue().setDebt(Duration.create(7260L)); issues.add(issue); Characteristic requirement = new DefaultCharacteristic().setId(5).setParentId(2).setRootId(1); diff --git a/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java b/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java index 1060704e119..ef26d5c0209 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/JRubyI18nTest.java @@ -25,6 +25,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.i18n.I18n; +import org.sonar.api.utils.Duration; import org.sonar.core.i18n.GwtI18n; import java.util.Date; @@ -94,8 +95,14 @@ public class JRubyI18nTest { @Test public void format_work_duration() throws Exception { - jRubyI18n.formatWorkDuration(10L); - verify(i18n).formatWorkDuration(any(Locale.class), eq(10L)); + jRubyI18n.formatWorkDuration(Duration.create(10L)); + verify(i18n).formatWorkDuration(any(Locale.class), eq(Duration.create(10L))); + } + + @Test + public void format_long_work_duration() throws Exception { + jRubyI18n.formatLongWorkDuration(10L); + verify(i18n).formatWorkDuration(any(Locale.class), eq(Duration.create(10L))); } } |