aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-webapi/src
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2024-11-08 17:38:54 +0100
committersonartech <sonartech@sonarsource.com>2024-11-11 20:02:44 +0000
commit60d28c06f872cfa30bd2399a977dfbc02063079d (patch)
tree3434de1723e3cee817f01c736497e0afc1be60ec /server/sonar-webserver-webapi/src
parent5fdc55ea9f2d4678dc491058f27f12a3a5607525 (diff)
downloadsonarqube-60d28c06f872cfa30bd2399a977dfbc02063079d.tar.gz
sonarqube-60d28c06f872cfa30bd2399a977dfbc02063079d.zip
SONAR-23287 add issue changed event and bulk action changes
Diffstat (limited to 'server/sonar-webserver-webapi/src')
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/AssignActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java36
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java17
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java6
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ActionContext.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/SetSeverityAction.java23
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java11
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java25
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java3
13 files changed, 108 insertions, 38 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/AssignActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/AssignActionIT.java
index 8cf7b9c6a9e..5bb806f7b1f 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/AssignActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/AssignActionIT.java
@@ -32,6 +32,7 @@ import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.IssueDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
@@ -55,6 +56,7 @@ public class AssignActionIT {
private final IssueChangeContext issueChangeContext = issueChangeContextByUserBuilder(new Date(), "user_uuid").build();
private final DefaultIssue issue = new DefaultIssue().setKey("ABC").setAssigneeUuid(ISSUE_CURRENT_ASSIGNEE_UUID);
+ private final IssueDto issueDto = new IssueDto().setKee("ABC").setAssigneeUuid(ISSUE_CURRENT_ASSIGNEE_UUID);
private Action.Context context;
private final AssignAction underTest = new AssignAction(db.getDbClient(), new IssueFieldsSetter());
@@ -62,7 +64,7 @@ public class AssignActionIT {
@Before
public void setUp() {
ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
- context = new ActionContext(issue, issueChangeContext, project);
+ context = new ActionContext(issue, issueDto, issueChangeContext, project);
}
@Test
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java
index be8303ae0a8..c1048119a6f 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetSeverityActionIT.java
@@ -22,16 +22,21 @@ package org.sonar.server.issue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.Date;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.issue.Issue;
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rules.RuleType;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.ImpactDto;
import org.sonar.db.issue.IssueDto;
import org.sonar.db.issue.IssueTesting;
import org.sonar.db.project.ProjectDto;
@@ -54,7 +59,6 @@ public class SetSeverityActionIT {
private static final Date NOW = new Date(10_000_000_000L);
private static final String USER_LOGIN = "john";
-
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@@ -70,7 +74,7 @@ public class SetSeverityActionIT {
IssueDto issueDto = newIssue().setSeverity(MAJOR);
DefaultIssue issue = issueDto.toDefaultIssue();
setUserWithBrowseAndAdministerIssuePermission(issueDto);
- Action.Context context = new ActionContext(issue, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null);
+ Action.Context context = new ActionContext(issue, issueDto, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null);
action.execute(ImmutableMap.of("severity", MINOR), context);
@@ -85,6 +89,34 @@ public class SetSeverityActionIT {
}
@Test
+ public void set_severity_whenImpactsIsMissing_shouldCreateImpactsAndImpactSeverityAreUpdated() {
+ IssueDto issueDto = newIssue().setSeverity(MAJOR).replaceAllImpacts(List.of())
+ .setRuleDefaultImpacts(Set.of(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.HIGH)));
+ DefaultIssue issue = issueDto.toDefaultIssue();
+ assertThat(issue.impacts()).isEmpty();
+
+ setUserWithBrowseAndAdministerIssuePermission(issueDto);
+ Action.Context context = new ActionContext(issue, issueDto, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null);
+
+ action.execute(ImmutableMap.of("severity", MINOR), context);
+
+ assertThat(issue.impacts()).containsEntry(SoftwareQuality.MAINTAINABILITY, Severity.LOW);
+ }
+
+ @Test
+ public void set_severity_whenSeverityHasChanged_shouldUpdateMatchingImpactSeverity() {
+ IssueDto issueDto = newIssue().setSeverity(MAJOR).replaceAllImpacts(Set.of(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.HIGH)));
+ DefaultIssue issue = issueDto.toDefaultIssue();
+
+ setUserWithBrowseAndAdministerIssuePermission(issueDto);
+ Action.Context context = new ActionContext(issue, issueDto, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null);
+
+ action.execute(ImmutableMap.of("severity", MINOR), context);
+
+ assertThat(issue.impacts()).containsEntry(SoftwareQuality.MAINTAINABILITY, Severity.LOW);
+ }
+
+ @Test
public void fail_if_parameter_not_found() {
assertThatThrownBy(() -> action.verify(ImmutableMap.of("unknwown", MINOR), Lists.newArrayList(), new AnonymousMockUserSession()))
.isInstanceOf(IllegalArgumentException.class)
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java
index b4b901181c4..09ae8d18696 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/SetTypeActionIT.java
@@ -52,7 +52,6 @@ public class SetTypeActionIT {
private static final Date NOW = new Date(10_000_000_000L);
private static final String USER_LOGIN = "john";
-
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@@ -70,7 +69,7 @@ public class SetTypeActionIT {
setUserWithBrowseAndAdministerIssuePermission(issueDto);
action.execute(ImmutableMap.of("type", VULNERABILITY.name()),
- new ActionContext(issue, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null));
+ new ActionContext(issue, issueDto, issueChangeContextByUserBuilder(NOW, userSession.getUuid()).build(), null));
assertThat(issue.type()).isEqualTo(VULNERABILITY);
assertThat(issue.isChanged()).isTrue();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java
index c740e978cc5..4e557120ac2 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/DoTransitionActionIT.java
@@ -127,7 +127,7 @@ public class DoTransitionActionIT {
verify(responseWriter).write(eq(issue.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issue);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
IssueDto issueReloaded = db.getDbClient().issueDao().selectByKey(db.getSession(), issue.getKey()).get();
assertThat(issueReloaded.getStatus()).isEqualTo(STATUS_CONFIRMED);
assertThat(issueChangePostProcessor.calledComponents()).containsExactlyInAnyOrder(file);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java
index d8b532d7965..bfb5e53a138 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetSeverityActionIT.java
@@ -20,6 +20,7 @@
package org.sonar.server.issue.ws;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
@@ -112,14 +113,15 @@ class SetSeverityActionIT {
@Test
void set_severity_whenSetSeverity_shouldAlsoUpdateImpactSeverity() {
- IssueDto issueDto = issueDbTester.insertIssue(i -> i.setSeverity(MAJOR).setType(CODE_SMELL));
+ IssueDto issueDto = issueDbTester.insertIssue(i -> i.setSeverity(MAJOR).setType(CODE_SMELL)
+ .replaceAllImpacts(List.of(new ImpactDto(SoftwareQuality.MAINTAINABILITY, Severity.MEDIUM, false))));
setUserWithBrowseAndAdministerIssuePermission(issueDto);
call(issueDto.getKey(), MINOR, null);
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issueDto);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), eq(MINOR), eq(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.LOW)), any(), any(), any(), any());
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(MINOR);
@@ -145,7 +147,7 @@ class SetSeverityActionIT {
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class),
any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issueDto);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(MINOR);
@@ -169,7 +171,7 @@ class SetSeverityActionIT {
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class),
any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issueDto);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(MINOR);
@@ -184,6 +186,7 @@ class SetSeverityActionIT {
.extracting(ComponentDto::uuid)
.containsExactlyInAnyOrder(issueDto.getComponentUuid());
}
+
@Test
void set_severity_whenSetImpactSeverity_shouldAlsoUpdateSeverity() {
IssueDto issueDto = issueDbTester.insertIssue(i -> i.setSeverity(MAJOR).setType(CODE_SMELL));
@@ -194,7 +197,7 @@ class SetSeverityActionIT {
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class),
any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issueDto);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), eq(MINOR), eq(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.LOW)), any(), any(), any(), any());
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(MINOR);
@@ -220,7 +223,7 @@ class SetSeverityActionIT {
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class),
any(Response.class), eq(true));
verifyContentOfPreloadedSearchResponseData(issueDto);
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getSeverity()).isEqualTo(MAJOR);
@@ -247,7 +250,7 @@ class SetSeverityActionIT {
verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class),
any(Response.class), eq(true));
- verify(issueChangeEventService, times(0)).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService, times(0)).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
}
@Test
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java
index 80be6b3d1a1..fd3c1a782a6 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SetTypeActionIT.java
@@ -136,7 +136,7 @@ public class SetTypeActionIT {
assertThat(issueChangePostProcessor.calledComponents())
.extracting(ComponentDto::uuid)
.containsExactlyInAnyOrder(issueDto.getComponentUuid());
- verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any());
+ verify(issueChangeEventService).distributeIssueChangeEvent(any(), any(), any(), any(), any(), any(), any());
} else {
assertThat(issueChangePostProcessor.wasCalled())
.isFalse();
@@ -304,7 +304,7 @@ public class SetTypeActionIT {
return EnumSet.allOf(RuleType.class)
.stream()
.filter(ruleType -> SECURITY_HOTSPOT != ruleType)
- .map(t -> new Object[]{t})
+ .map(t -> new Object[] {t})
.toArray(Object[][]::new);
}
@@ -316,7 +316,7 @@ public class SetTypeActionIT {
.collect(Collectors.toSet());
return Sets.cartesianProduct(set, set)
.stream()
- .map(ruleTypes -> new Object[]{ruleTypes.get(0), ruleTypes.get(1)})
+ .map(ruleTypes -> new Object[] {ruleTypes.get(0), ruleTypes.get(1)})
.toArray(Object[][]::new);
}
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java
index 1042dc61781..0980245dd62 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java
@@ -29,6 +29,7 @@ import org.sonar.api.server.ServerSide;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.IssueDto;
import org.sonar.server.issue.workflow.Condition;
import org.sonar.server.user.UserSession;
@@ -80,6 +81,8 @@ public abstract class Action {
public interface Context {
DefaultIssue issue();
+ IssueDto issueDto();
+
IssueChangeContext issueChangeContext();
ComponentDto project();
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ActionContext.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ActionContext.java
index 4432173c778..0f9ef8c7db6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ActionContext.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ActionContext.java
@@ -22,14 +22,17 @@ package org.sonar.server.issue;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.IssueDto;
public class ActionContext implements Action.Context {
private final DefaultIssue issue;
+ private final IssueDto issueDto;
private final IssueChangeContext changeContext;
private final ComponentDto project;
- public ActionContext(DefaultIssue issue, IssueChangeContext changeContext, ComponentDto project) {
+ public ActionContext(DefaultIssue issue, IssueDto issueDto, IssueChangeContext changeContext, ComponentDto project) {
this.issue = issue;
+ this.issueDto = issueDto;
this.changeContext = changeContext;
this.project = project;
}
@@ -40,6 +43,11 @@ public class ActionContext implements Action.Context {
}
@Override
+ public IssueDto issueDto() {
+ return issueDto;
+ }
+
+ @Override
public IssueChangeContext issueChangeContext() {
return changeContext;
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/SetSeverityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/SetSeverityAction.java
index 4f65a8e3ad4..b3b4215b6f2 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/SetSeverityAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/SetSeverityAction.java
@@ -22,10 +22,13 @@ package org.sonar.server.issue;
import java.util.Collection;
import java.util.Map;
import org.sonar.api.issue.Issue;
-import org.sonar.server.issue.workflow.IsUnResolved;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ServerSide;
+import org.sonar.api.server.rule.internal.ImpactMapper;
import org.sonar.core.issue.DefaultIssue;
+import org.sonar.core.rule.ImpactSeverityMapper;
+import org.sonar.server.issue.workflow.IsUnResolved;
import org.sonar.server.user.UserSession;
import static com.google.common.base.Preconditions.checkArgument;
@@ -61,7 +64,23 @@ public class SetSeverityAction extends Action {
@Override
public boolean execute(Map<String, Object> properties, Context context) {
- return issueUpdater.setManualSeverity(context.issue(), verifySeverityParameter(properties), context.issueChangeContext());
+ String severity = verifySeverityParameter(properties);
+ boolean updated = issueUpdater.setManualSeverity(context.issue(), severity, context.issueChangeContext());
+
+ SoftwareQuality softwareQuality = ImpactMapper.convertToSoftwareQuality(context.issue().type());
+ if (updated
+ && context.issueDto().getEffectiveImpacts().containsKey(softwareQuality)) {
+ createImpactsIfMissing(context.issue(), context.issueDto().getEffectiveImpacts());
+ issueUpdater.setImpactManualSeverity(context.issue(), softwareQuality, ImpactSeverityMapper.mapImpactSeverity(severity), context.issueChangeContext());
+ }
+ return updated;
+ }
+
+ private static void createImpactsIfMissing(DefaultIssue issue, Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> effectiveImpacts) {
+ if (issue.impacts().isEmpty()) {
+ issue.replaceImpacts(effectiveImpacts);
+ issue.setChanged(true);
+ }
}
@Override
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
index 8e61d80bf9c..08d673ba893 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
@@ -151,7 +151,7 @@ public class BulkChangeAction implements IssuesWsAction {
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_BULK_CHANGE)
.setDescription("Bulk change on issues. Up to 500 issues can be updated. <br/>" +
- "Requires authentication.")
+ "Requires authentication.")
.setSince("3.7")
.setChangelog(
new Change("10.4", ("Transitions '%s' and '%s' are now deprecated. Use transition '%s' instead. " +
@@ -195,7 +195,7 @@ public class BulkChangeAction implements IssuesWsAction {
.setExampleValue("security,java8");
action.createParam(PARAM_COMMENT)
.setDescription("Add a comment. "
- + "The comment will only be added to issues that are affected either by a change of type or a change of severity as a result of the same WS call.")
+ + "The comment will only be added to issues that are affected either by a change of type or a change of severity as a result of the same WS call.")
.setExampleValue("Here is my comment");
action.createParam(PARAM_SEND_NOTIFICATIONS)
.setSince("4.0")
@@ -252,7 +252,8 @@ public class BulkChangeAction implements IssuesWsAction {
private static Predicate<DefaultIssue> bulkChange(IssueChangeContext issueChangeContext, BulkChangeData bulkChangeData, BulkChangeResult result) {
return issue -> {
- ActionContext actionContext = new ActionContext(issue, issueChangeContext, bulkChangeData.branchComponentByUuid.get(issue.projectUuid()));
+ ActionContext actionContext = new ActionContext(issue, bulkChangeData.originalIssueByKey.get(issue.key()), issueChangeContext,
+ bulkChangeData.branchComponentByUuid.get(issue.projectUuid()));
bulkChangeData.getActionsWithoutComment().forEach(applyAction(actionContext, bulkChangeData, result));
addCommentIfNeeded(actionContext, bulkChangeData);
return result.success.contains(issue);
@@ -405,9 +406,9 @@ public class BulkChangeAction implements IssuesWsAction {
this.issues = toDefaultIssues(authorizedIssues);
this.componentsByUuid = getComponents(dbSession,
issues.stream().map(DefaultIssue::componentUuid).collect(Collectors.toSet())).stream()
- .collect(toMap(ComponentDto::uuid, identity()));
+ .collect(toMap(ComponentDto::uuid, identity()));
this.rulesByKey = dbClient.ruleDao().selectByKeys(dbSession,
- issues.stream().map(DefaultIssue::ruleKey).collect(Collectors.toSet())).stream()
+ issues.stream().map(DefaultIssue::ruleKey).collect(Collectors.toSet())).stream()
.collect(toMap(RuleDto::getKey, identity()));
this.availableActions = actions.stream()
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
index 13c43f018fd..9fc2b63e97c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/DoTransitionAction.java
@@ -21,6 +21,7 @@ package org.sonar.server.issue.ws;
import com.google.common.io.Resources;
import java.util.Date;
+import java.util.Map;
import org.sonar.api.issue.DefaultTransitions;
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.server.ws.Change;
@@ -134,7 +135,7 @@ public class DoTransitionAction implements IssuesWsAction {
SearchResponseData response = issueUpdater.saveIssueAndPreloadSearchResponseData(session, issueDto, defaultIssue, context, branch);
if (branch.getBranchType().equals(BRANCH) && response.getComponentByUuid(defaultIssue.projectUuid()) != null) {
- issueChangeEventService.distributeIssueChangeEvent(defaultIssue, null, null, transitionKey, branch,
+ issueChangeEventService.distributeIssueChangeEvent(defaultIssue, null, Map.of(), null, transitionKey, branch,
response.getComponentByUuid(defaultIssue.projectUuid()).getKey());
}
return response;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
index f973d24a00c..83fea43fa58 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetSeverityAction.java
@@ -81,12 +81,12 @@ public class SetSeverityAction implements IssuesWsAction {
public void define(WebService.NewController controller) {
WebService.NewAction action = controller.createAction(ACTION_SET_SEVERITY)
.setDescription("Change severity.<br/>" +
- "Requires the following permissions:" +
- "<ul>" +
- " <li>'Authentication'</li>" +
- " <li>'Browse' rights on project of the specified issue</li>" +
- " <li>'Administer Issues' rights on project of the specified issue</li>" +
- "</ul>")
+ "Requires the following permissions:" +
+ "<ul>" +
+ " <li>'Authentication'</li>" +
+ " <li>'Browse' rights on project of the specified issue</li>" +
+ " <li>'Administer Issues' rights on project of the specified issue</li>" +
+ "</ul>")
.setSince("3.6")
.setChangelog(
new Change("10.8", "Add 'impact' parameter to the request."),
@@ -161,15 +161,15 @@ public class SetSeverityAction implements IssuesWsAction {
createImpactsIfMissing(issue, effectiveImpacts);
if (issueFieldsSetter.setImpactManualSeverity(issue, softwareQuality, manualImpactSeverity, context)) {
String manualSeverity = null;
- boolean severityUpdated = false;
+ boolean severityHasChanged = false;
if (convertToRuleType(softwareQuality).equals(issue.type())) {
manualSeverity = convertToDeprecatedSeverity(manualImpactSeverity);
- severityUpdated = issueFieldsSetter.setManualSeverity(issue, manualSeverity, context);
+ severityHasChanged = issueFieldsSetter.setManualSeverity(issue, manualSeverity, context);
}
BranchDto branch = issueUpdater.getBranch(session, issue);
SearchResponseData response = issueUpdater.saveIssueAndPreloadSearchResponseData(session, issueDto, issue, context, branch);
if (branch.getBranchType().equals(BRANCH) && response.getComponentByUuid(issue.projectUuid()) != null) {
- issueChangeEventService.distributeIssueChangeEvent(issue, severityUpdated ? manualSeverity : null, null, null,
+ issueChangeEventService.distributeIssueChangeEvent(issue, severityHasChanged ? manualSeverity : null, Map.of(softwareQuality, manualImpactSeverity), null, null,
branch, getProjectKey(issue, response));
}
return response;
@@ -181,14 +181,15 @@ public class SetSeverityAction implements IssuesWsAction {
IssueChangeContext context) {
if (issueFieldsSetter.setManualSeverity(issue, severity, context)) {
SoftwareQuality softwareQuality = convertToSoftwareQuality(issue.type());
+ boolean impactHasChanged = false;
if (issueDto.getEffectiveImpacts().containsKey(softwareQuality)) {
createImpactsIfMissing(issue, issueDto.getEffectiveImpacts());
- issueFieldsSetter.setImpactManualSeverity(issue, softwareQuality, mapImpactSeverity(severity), context);
+ impactHasChanged = issueFieldsSetter.setImpactManualSeverity(issue, softwareQuality, mapImpactSeverity(severity), context);
}
BranchDto branch = issueUpdater.getBranch(session, issue);
SearchResponseData response = issueUpdater.saveIssueAndPreloadSearchResponseData(session, issueDto, issue, context, branch);
if (branch.getBranchType().equals(BRANCH) && response.getComponentByUuid(issue.projectUuid()) != null) {
- issueChangeEventService.distributeIssueChangeEvent(issue, severity, null, null,
+ issueChangeEventService.distributeIssueChangeEvent(issue, severity, impactHasChanged ? Map.of(softwareQuality, mapImpactSeverity(severity)) : Map.of(), null, null,
branch, getProjectKey(issue, response));
}
return response;
@@ -205,7 +206,7 @@ public class SetSeverityAction implements IssuesWsAction {
}
private static void createImpactsIfMissing(DefaultIssue issue, Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> effectiveImpacts) {
- if(issue.impacts().isEmpty()){
+ if (issue.impacts().isEmpty()) {
issue.replaceImpacts(effectiveImpacts);
issue.setChanged(true);
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
index 126c3550e94..ba6bf3430ef 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SetTypeAction.java
@@ -22,6 +22,7 @@ package org.sonar.server.issue.ws;
import com.google.common.io.Resources;
import java.util.Date;
import java.util.EnumSet;
+import java.util.Map;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
@@ -128,7 +129,7 @@ public class SetTypeAction implements IssuesWsAction {
BranchDto branch = issueUpdater.getBranch(session, issue);
SearchResponseData response = issueUpdater.saveIssueAndPreloadSearchResponseData(session, issueDto, issue, context, branch);
if (branch.getBranchType().equals(BRANCH) && response.getComponentByUuid(issue.projectUuid()) != null) {
- issueChangeEventService.distributeIssueChangeEvent(issue, null, ruleType.name(), null, branch,
+ issueChangeEventService.distributeIssueChangeEvent(issue, null, Map.of(), ruleType.name(), null, branch,
response.getComponentByUuid(issue.projectUuid()).getKey());
}
return response;