@@ -20,13 +20,12 @@ | |||
package org.sonar.server.issue; | |||
import com.google.common.collect.Maps; | |||
import org.sonar.core.issue.FieldDiffs; | |||
import org.sonar.api.user.User; | |||
import javax.annotation.CheckForNull; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import org.sonar.api.user.User; | |||
import org.sonar.core.issue.FieldDiffs; | |||
/** | |||
* @since 3.6 | |||
@@ -38,6 +37,7 @@ public class IssueChangelog { | |||
public IssueChangelog(List<FieldDiffs> changes, Collection<User> users) { | |||
this.changes = changes; | |||
replacedTechnicalDebtByEffort(changes); | |||
this.usersByLogin = Maps.newHashMap(); | |||
for (User user : users) { | |||
usersByLogin.put(user.login(), user); | |||
@@ -48,6 +48,19 @@ public class IssueChangelog { | |||
return changes; | |||
} | |||
private static void replacedTechnicalDebtByEffort(List<FieldDiffs> changes) { | |||
for (FieldDiffs fieldDiffs : changes) { | |||
Map<String, FieldDiffs.Diff> diffs = fieldDiffs.diffs(); | |||
for (Map.Entry<String, FieldDiffs.Diff> entry : diffs.entrySet()) { | |||
// As "technicalDebt" couldn't been updated to "effort" in db, we need to convert it here to correctly display "effort" in WS/UI | |||
if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { | |||
diffs.put("effort", entry.getValue()); | |||
diffs.remove(entry.getKey()); | |||
} | |||
} | |||
} | |||
} | |||
@CheckForNull | |||
public User user(FieldDiffs change) { | |||
if (change.userLogin() == null) { |
@@ -59,6 +59,10 @@ public class IssueUpdater { | |||
public static final String STATUS = "status"; | |||
public static final String AUTHOR = "author"; | |||
public static final String ACTION_PLAN = "actionPlan"; | |||
/** | |||
* It should be renamed to 'effort', but it hasn't been done to prevent a massive update in database | |||
*/ | |||
public static final String TECHNICAL_DEBT = "technicalDebt"; | |||
public static final String TAGS = "tags"; | |||
@@ -6,7 +6,7 @@ | |||
"creationDate": "2014-03-04T23:03:44+0100", | |||
"diffs": [ | |||
{ | |||
"key": "technicalDebt", | |||
"key": "effort", | |||
"newValue": "2min" | |||
} | |||
] |
@@ -27,12 +27,12 @@ import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.mockito.Mock; | |||
import org.mockito.runners.MockitoJUnitRunner; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.core.issue.FieldDiffs; | |||
import org.sonar.api.user.User; | |||
import org.sonar.api.user.UserFinder; | |||
import org.sonar.db.issue.IssueChangeDao; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.core.issue.FieldDiffs; | |||
import org.sonar.core.user.DefaultUser; | |||
import org.sonar.db.issue.IssueChangeDao; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -84,6 +84,21 @@ public class IssueChangelogServiceTest { | |||
assertThat(changelog.user(userChange)).isSameAs(arthur); | |||
} | |||
@Test | |||
public void rename_technical_debt_change_to_effort() { | |||
FieldDiffs userChange = new FieldDiffs().setUserLogin("arthur").setDiff("technicalDebt", "10min", "30min"); | |||
when(changeDao.selectChangelogByIssue("ABCDE")).thenReturn(Arrays.asList(userChange)); | |||
User arthur = new DefaultUser().setLogin("arthur").setName("Arthur"); | |||
when(userFinder.findByLogins(Arrays.asList("arthur"))).thenReturn(Arrays.asList(arthur)); | |||
when(issueService.getByKey("ABCDE")).thenReturn(new DefaultIssue().setKey("ABCDE")); | |||
IssueChangelog changelog = service.changelog("ABCDE"); | |||
assertThat(changelog).isNotNull(); | |||
assertThat(changelog.changes()).hasSize(1); | |||
assertThat(changelog.changes().get(0).diffs()).containsKeys("effort"); | |||
} | |||
@Test | |||
public void format_diffs() { | |||
FieldDiffs diffs = new FieldDiffs().setUserLogin("arthur").setDiff("severity", "MAJOR", "BLOCKER"); |
@@ -83,8 +83,8 @@ class Issue | |||
diff = entry.getValue() | |||
hash_diff = {} | |||
hash_diff[:key] = key | |||
if key == 'technicalDebt' | |||
# debt is store as a number of minutes in the changelog, so we first create a Duration from the value then we decode it | |||
if key == 'effort' | |||
# effort is store as a number of minutes in the changelog, so we first create a Duration from the value then we decode it | |||
hash_diff[:newValue] = Internal.durations.encode(Internal.durations.create(diff.newValue().to_i)) if diff.newValue.present? | |||
hash_diff[:oldValue] = Internal.durations.encode(Internal.durations.create(diff.oldValue().to_i)) if diff.oldValue.present? | |||
else |
@@ -760,7 +760,7 @@ issue.changelog.field.actionPlan=Action Plan | |||
issue.changelog.field.assignee=Assignee | |||
issue.changelog.field.author=Author | |||
issue.changelog.field.resolution=Resolution | |||
issue.changelog.field.technicalDebt=Technical Debt | |||
issue.changelog.field.effort=Effort | |||
issue.changelog.field.status=Status | |||
issue.changelog.field.tags=Tags | |||
issue.changelog.field.type=Type |