}
@VisibleForTesting
protected void mergeMatched(IssueTrackingResult result) {
for (DefaultIssue issue : result.matched()) {
IssueDto ref = result.matching(issue);
// invariant fields
issue.setKey(ref.getKee());
issue.setCreationDate(ref.getIssueCreationDate());
issue.setUpdateDate(ref.getIssueUpdateDate());
issue.setCloseDate(ref.getIssueCloseDate());
// non-persisted fields
issue.setNew(false);
issue.setEndOfLife(false);
issue.setOnDisabledRule(false);
issue.setSelectedAt(ref.getSelectedAt());
// fields to update with old values
issue.setActionPlanKey(ref.getActionPlanKey());
issue.setResolution(ref.getResolution());
issue.setStatus(ref.getStatus());
issue.setAssignee(ref.getAssignee());
issue.setAuthorLogin(ref.getAuthorLogin());
if (ref.getIssueAttributes() != null) {
issue.setAttributes(KeyValueFormat.parse(ref.getIssueAttributes()));
}
// populate existing changelog
Collection<IssueChangeDto> issueChangeDtos = initialOpenIssues.selectChangelog(issue.key());
for (IssueChangeDto issueChangeDto : issueChangeDtos) {
issue.addChange(issueChangeDto.toFieldDiffs());
}
// fields to update with current values
if (ref.isManualSeverity()) {
issue.setManualSeverity(true);
issue.setSeverity(ref.getSeverity());
} else {
updater.setPastSeverity(issue, ref.getSeverity(), changeContext);
}
updater.setPastLine(issue, ref.getLine());
updater.setPastMessage(issue, ref.getMessage(), changeContext);
updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext);
Long debtInMinutes = ref.getDebt();
Duration previousTechnicalDebt = debtInMinutes != null ? Duration.create(debtInMinutes) : null;
updater.setPastTechnicalDebt(issue, previousTechnicalDebt, changeContext);
updater.setPastProject(issue, ref.getProjectKey(), changeContext);
}
}