use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class NewEffortCalculator method calculateFromChangelog.
private static long calculateFromChangelog(DefaultIssue issue, Collection<IssueChangeDto> debtChangelog, long periodDate) {
List<FieldDiffs> debtDiffs = from(debtChangelog).transform(ToFieldDiffs.INSTANCE).filter(HasDebtChange.INSTANCE).toSortedList(CHANGE_ORDERING);
FieldDiffs currentChange = issue.currentChange();
if (currentChange != null && HasDebtChange.INSTANCE.apply(currentChange)) {
debtDiffs = Lists.newArrayList(debtDiffs);
debtDiffs.add(currentChange);
}
long newDebt = issue.effortInMinutes();
for (Iterator<FieldDiffs> it = debtDiffs.iterator(); it.hasNext(); ) {
FieldDiffs diffs = it.next();
Date date = diffs.creationDate();
// TODO use longs
if (isBeforeOrEqual(date, new Date(periodDate))) {
// return new value from the change that is just before the period date
return subtract(newDebt, debtDiff(diffs).newValueLong());
}
if (!it.hasNext()) {
// return old value from the change that is just after the period date when there's no more element in changelog
return subtract(newDebt, debtDiff(diffs).oldValueLong());
}
}
// no changelog
return 0L;
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeNotification method setIssue.
public IssueChangeNotification setIssue(DefaultIssue issue) {
setFieldValue("key", issue.key());
setFieldValue("assignee", issue.assignee());
setFieldValue("message", issue.message());
setFieldValue("componentKey", issue.componentKey());
FieldDiffs currentChange = issue.currentChange();
if (currentChange != null) {
for (Map.Entry<String, FieldDiffs.Diff> entry : currentChange.diffs().entrySet()) {
String type = entry.getKey();
FieldDiffs.Diff diff = entry.getValue();
setFieldValue("old." + type, neverEmptySerializableToString(diff.oldValue()));
setFieldValue("new." + type, neverEmptySerializableToString(diff.newValue()));
}
}
return this;
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class PersistIssuesStepTest method add_change.
@Test
public void add_change() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
issueCache.newAppender().append(new DefaultIssue().setKey("ISSUE").setType(RuleType.CODE_SMELL).setRuleKey(RuleKey.of("xoo", "S01")).setComponentUuid("COMPONENT").setProjectUuid("PROJECT").setSeverity(Severity.BLOCKER).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED).setNew(false).setChanged(true).setCurrentChange(new FieldDiffs().setIssueKey("ISSUE").setUserLogin("john").setDiff("technicalDebt", null, 1L))).close();
step.execute();
dbTester.assertDbUnit(getClass(), "add_change-result.xml", new String[] { "id", "created_at", "updated_at" }, "issue_changes");
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeNotificationTest method set_issue_with_current_change_having_no_old_value.
@Test
public void set_issue_with_current_change_having_no_old_value() {
DefaultIssue issue = new DefaultIssue().setKey("ABCD").setAssignee("simon").setMessage("Remove this useless method").setComponentKey("MyService");
IssueChangeNotification result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", null, "FIXED")));
assertThat(result.getFieldValue("old.resolution")).isNull();
assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
result = notification.setIssue(issue.setCurrentChange(new FieldDiffs().setDiff("resolution", "", "FIXED")));
assertThat(result.getFieldValue("old.resolution")).isNull();
assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
}
use of org.sonar.core.issue.FieldDiffs in project sonarqube by SonarSource.
the class IssueChangeNotificationTest method set_issue.
@Test
public void set_issue() {
DefaultIssue issue = new DefaultIssue().setKey("ABCD").setAssignee("simon").setMessage("Remove this useless method").setComponentKey("MyService").setCurrentChange(new FieldDiffs().setDiff("resolution", "FALSE-POSITIVE", "FIXED"));
IssueChangeNotification result = notification.setIssue(issue);
assertThat(result.getFieldValue("key")).isEqualTo("ABCD");
assertThat(result.getFieldValue("assignee")).isEqualTo("simon");
assertThat(result.getFieldValue("message")).isEqualTo("Remove this useless method");
assertThat(result.getFieldValue("componentKey")).isEqualTo("MyService");
assertThat(result.getFieldValue("old.resolution")).isEqualTo("FALSE-POSITIVE");
assertThat(result.getFieldValue("new.resolution")).isEqualTo("FIXED");
}
Aggregations