You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UpdateConflictResolver.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.core.issue.db;
  21. import com.google.common.annotations.VisibleForTesting;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.sonar.api.issue.internal.DefaultIssue;
  25. /**
  26. * Support concurrent modifications on issues made by analysis and users at the same time
  27. * See https://jira.sonarsource.com/browse/SONAR-4309
  28. */
  29. public class UpdateConflictResolver {
  30. private static final Logger LOG = LoggerFactory.getLogger(IssueStorage.class);
  31. public void resolve(DefaultIssue issue, IssueMapper mapper) {
  32. LOG.debug("Resolve conflict on issue " + issue.key());
  33. IssueDto dbIssue = mapper.selectByKey(issue.key());
  34. if (dbIssue != null) {
  35. mergeFields(dbIssue, issue);
  36. mapper.update(IssueDto.toDtoForUpdate(issue, System.currentTimeMillis()));
  37. }
  38. }
  39. @VisibleForTesting
  40. void mergeFields(IssueDto dbIssue, DefaultIssue issue) {
  41. resolveAssignee(dbIssue, issue);
  42. resolvePlan(dbIssue, issue);
  43. resolveSeverity(dbIssue, issue);
  44. resolveEffortToFix(dbIssue, issue);
  45. resolveResolution(dbIssue, issue);
  46. resolveStatus(dbIssue, issue);
  47. }
  48. private void resolveStatus(IssueDto dbIssue, DefaultIssue issue) {
  49. issue.setStatus(dbIssue.getStatus());
  50. }
  51. private void resolveResolution(IssueDto dbIssue, DefaultIssue issue) {
  52. issue.setResolution(dbIssue.getResolution());
  53. }
  54. private void resolveEffortToFix(IssueDto dbIssue, DefaultIssue issue) {
  55. issue.setEffortToFix(dbIssue.getEffortToFix());
  56. }
  57. private void resolveSeverity(IssueDto dbIssue, DefaultIssue issue) {
  58. if (dbIssue.isManualSeverity()) {
  59. issue.setManualSeverity(true);
  60. issue.setSeverity(dbIssue.getSeverity());
  61. }
  62. // else keep severity as declared in quality profile
  63. }
  64. private void resolvePlan(IssueDto dbIssue, DefaultIssue issue) {
  65. issue.setActionPlanKey(dbIssue.getActionPlanKey());
  66. }
  67. private void resolveAssignee(IssueDto dbIssue, DefaultIssue issue) {
  68. issue.setAssignee(dbIssue.getAssignee());
  69. }
  70. }