3 * Copyright (C) 2009-2021 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program 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.
11 * This program 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.
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.
20 package org.sonar.ce.task.projectanalysis.issue;
22 import com.google.common.annotations.VisibleForTesting;
23 import org.sonar.api.utils.log.Logger;
24 import org.sonar.api.utils.log.Loggers;
25 import org.sonar.core.issue.DefaultIssue;
26 import org.sonar.db.issue.IssueDto;
27 import org.sonar.db.issue.IssueMapper;
30 * Support concurrent modifications on issues made by analysis and users at the same time
31 * See https://jira.sonarsource.com/browse/SONAR-4309
33 public class UpdateConflictResolver {
35 private static final Logger LOG = Loggers.get(UpdateConflictResolver.class);
37 public void resolve(DefaultIssue issue, IssueDto dbIssue, IssueMapper mapper) {
38 LOG.debug("Resolve conflict on issue {}", issue.key());
39 mergeFields(dbIssue, issue);
40 mapper.update(IssueDto.toDtoForUpdate(issue, System.currentTimeMillis()));
44 void mergeFields(IssueDto dbIssue, DefaultIssue issue) {
45 resolveAssignee(dbIssue, issue);
46 resolveSeverity(dbIssue, issue);
47 resolveEffortToFix(dbIssue, issue);
48 resolveResolution(dbIssue, issue);
49 resolveStatus(dbIssue, issue);
52 private void resolveStatus(IssueDto dbIssue, DefaultIssue issue) {
53 issue.setStatus(dbIssue.getStatus());
56 private void resolveResolution(IssueDto dbIssue, DefaultIssue issue) {
57 issue.setResolution(dbIssue.getResolution());
60 private void resolveEffortToFix(IssueDto dbIssue, DefaultIssue issue) {
61 issue.setGap(dbIssue.getGap());
64 private void resolveSeverity(IssueDto dbIssue, DefaultIssue issue) {
65 if (dbIssue.isManualSeverity()) {
66 issue.setManualSeverity(true);
67 issue.setSeverity(dbIssue.getSeverity());
69 // else keep severity as declared in quality profile
72 private void resolveAssignee(IssueDto dbIssue, DefaultIssue issue) {
73 issue.setAssigneeUuid(dbIssue.getAssigneeUuid());