Search in sources :

Example 21 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class ChangesOnMyIssueNotificationHandlerTest method deliver_checks_by_projectKeys_if_notifications_have_subscribed_assignee_to_ChangesOnMyIssues_notifications.

@Test
public void deliver_checks_by_projectKeys_if_notifications_have_subscribed_assignee_to_ChangesOnMyIssues_notifications() {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Set<ChangedIssue> issues = IntStream.range(0, 1 + new Random().nextInt(2)).mapToObj(i -> new ChangedIssue.Builder("issue_key_" + i).setNewStatus("foo").setAssignee(newUser("" + i)).setRule(newRule()).setProject(newProject(i + "")).build()).collect(toSet());
    IssuesChangesNotificationBuilder builder = new IssuesChangesNotificationBuilder(issues, new UserChange(new Random().nextLong(), new User("user_uuid", "user_login", null)));
    int deliver = underTest.deliver(ImmutableSet.of(serializer.serialize(builder)));
    assertThat(deliver).isZero();
    issues.stream().collect(MoreCollectors.index(ChangedIssue::getProject)).asMap().forEach((key, value) -> {
        String projectKey = key.getKey();
        Set<String> assigneeLogins = value.stream().map(i -> i.getAssignee().get().getLogin()).collect(toSet());
        verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, projectKey, assigneeLogins, ALL_MUST_HAVE_ROLE_USER);
    });
    verifyNoMoreInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verifyNoMoreInteractions(emailNotificationChannel);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) ListMultimap(com.google.common.collect.ListMultimap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) NotificationManager(org.sonar.server.notification.NotificationManager) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) MoreCollectors.unorderedIndex(org.sonar.core.util.stream.MoreCollectors.unorderedIndex) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Stream(java.util.stream.Stream) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Test(org.junit.Test)

Example 22 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class ChangesOnMyIssueNotificationHandlerTest method deliver_creates_a_notification_per_assignee_with_only_his_issues_on_the_single_project.

@Test
@UseDataProvider("userOrAnalysisChange")
public void deliver_creates_a_notification_per_assignee_with_only_his_issues_on_the_single_project(Change userOrAnalysisChange) {
    when(emailNotificationChannel.isActivated()).thenReturn(true);
    Project project = newProject();
    User assignee1 = newUser("assignee_1");
    User assignee2 = newUser("assignee_2");
    Set<ChangedIssue> assignee1Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("1_issue_key_" + i, assignee1, project)).collect(toSet());
    Set<ChangedIssue> assignee2Issues = IntStream.range(0, 10).mapToObj(i -> newChangedIssue("2_issue_key_" + i, assignee2, project)).collect(toSet());
    Set<IssuesChangesNotification> notifications = Stream.of(// notification with only assignee1 5 notifications
    new IssuesChangesNotificationBuilder(assignee1Issues.stream().limit(5).collect(toSet()), userOrAnalysisChange), // notification with only assignee2 6 notifications
    new IssuesChangesNotificationBuilder(assignee2Issues.stream().limit(6).collect(toSet()), userOrAnalysisChange), // notification with 4 assignee1 and 3 assignee2 notifications
    new IssuesChangesNotificationBuilder(Stream.concat(assignee1Issues.stream().skip(6), assignee2Issues.stream().skip(7)).collect(toSet()), userOrAnalysisChange)).map(t -> serializer.serialize(t)).collect(toSet());
    when(notificationManager.findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project.getKey(), ImmutableSet.of(assignee1.getLogin(), assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER)).thenReturn(ImmutableSet.of(emailRecipientOf(assignee1.getLogin()), emailRecipientOf(assignee2.getLogin())));
    int deliveredCount = new Random().nextInt(100);
    when(emailNotificationChannel.deliverAll(anySet())).thenReturn(deliveredCount);
    int deliver = underTest.deliver(notifications);
    assertThat(deliver).isEqualTo(deliveredCount);
    verify(notificationManager).findSubscribedEmailRecipients(CHANGE_ON_MY_ISSUES_DISPATCHER_KEY, project.getKey(), ImmutableSet.of(assignee1.getLogin(), assignee2.getLogin()), ALL_MUST_HAVE_ROLE_USER);
    verifyNoMoreInteractions(notificationManager);
    verify(emailNotificationChannel).isActivated();
    verify(emailNotificationChannel).deliverAll(emailDeliveryRequestSetCaptor.capture());
    verifyNoMoreInteractions(emailNotificationChannel);
    Set<EmailDeliveryRequest> emailDeliveryRequests = emailDeliveryRequestSetCaptor.getValue();
    assertThat(emailDeliveryRequests).hasSize(4);
    ListMultimap<String, EmailDeliveryRequest> emailDeliveryRequestByEmail = emailDeliveryRequests.stream().collect(index(EmailDeliveryRequest::getRecipientEmail));
    List<EmailDeliveryRequest> assignee1Requests = emailDeliveryRequestByEmail.get(emailOf(assignee1.getLogin()));
    assertThat(assignee1Requests).hasSize(2).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange);
    assertThat(assignee1Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee1Issues.stream().limit(5).collect(unorderedIndex(t -> project, t -> t)), assignee1Issues.stream().skip(6).collect(unorderedIndex(t -> project, t -> t)));
    List<EmailDeliveryRequest> assignee2Requests = emailDeliveryRequestByEmail.get(emailOf(assignee2.getLogin()));
    assertThat(assignee2Requests).hasSize(2).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChange).containsOnly(userOrAnalysisChange);
    assertThat(assignee2Requests).extracting(t -> (ChangesOnMyIssuesNotification) t.getNotification()).extracting(ChangesOnMyIssuesNotification::getChangedIssues).containsOnly(assignee2Issues.stream().limit(6).collect(unorderedIndex(t -> project, t -> t)), assignee2Issues.stream().skip(7).collect(unorderedIndex(t -> project, t -> t)));
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.anySet(org.mockito.ArgumentMatchers.anySet) ALL_MUST_HAVE_ROLE_USER(org.sonar.server.notification.NotificationManager.SubscriberPermissionsOnProject.ALL_MUST_HAVE_ROLE_USER) ListMultimap(com.google.common.collect.ListMultimap) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Random(java.util.Random) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) MoreCollectors.index(org.sonar.core.util.stream.MoreCollectors.index) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) AnalysisChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange) NotificationManager(org.sonar.server.notification.NotificationManager) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Collectors.toSet(java.util.stream.Collectors.toSet) MoreCollectors.unorderedIndex(org.sonar.core.util.stream.MoreCollectors.unorderedIndex) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ImmutableSet(com.google.common.collect.ImmutableSet) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) PER_PROJECT_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.PER_PROJECT_NOTIFICATION) Mockito.verify(org.mockito.Mockito.verify) IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule) Mockito(org.mockito.Mockito) Rule(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule) List(java.util.List) Stream(java.util.stream.Stream) GLOBAL_NOTIFICATION(org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION) Change(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Change) NotificationDispatcherMetadata(org.sonar.server.notification.NotificationDispatcherMetadata) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Random(java.util.Random) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) EmailDeliveryRequest(org.sonar.server.notification.email.EmailNotificationChannel.EmailDeliveryRequest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class FpOrWontFixEmailTemplateTest method formats_returns_html_message_for_single_hotspot_on_master.

@Test
@UseDataProvider("fpOrWontFixValuesByUserOrAnalysisChange")
public void formats_returns_html_message_for_single_hotspot_on_master(Change change, FpOrWontFix fpOrWontFix) {
    Project project = newProject("1");
    String ruleName = randomAlphabetic(8);
    String host = randomAlphabetic(15);
    ChangedIssue changedIssue = newChangedIssue("key", project, ruleName, SECURITY_HOTSPOT);
    when(emailSettings.getServerBaseURL()).thenReturn(host);
    EmailMessage emailMessage = underTest.format(new FPOrWontFixNotification(change, ImmutableSet.of(changedIssue), fpOrWontFix));
    HtmlFragmentAssert.assertThat(emailMessage.getMessage()).hasParagraph().hasParagraph().hasParagraph(project.getProjectName()).hasList("Rule " + ruleName + " - See the single hotspot").withLink("See the single hotspot", host + "/project/issues?id=" + project.getKey() + "&issues=" + changedIssue.getKey() + "&open=" + changedIssue.getKey()).hasParagraph().hasParagraph().noMoreBlock();
}
Also used : Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 24 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class BulkChangeAction method sendNotification.

private void sendNotification(Collection<DefaultIssue> issues, BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, UserDto author) {
    if (!bulkChangeData.sendNotification) {
        return;
    }
    Set<ChangedIssue> changedIssues = issues.stream().filter(issue -> issue.updateDate() != null).map(issue -> toNotification(bulkChangeData, userDtoByUuid, issue)).filter(Objects::nonNull).collect(toSet(issues.size()));
    if (changedIssues.isEmpty()) {
        return;
    }
    IssuesChangesNotificationBuilder builder = new IssuesChangesNotificationBuilder(changedIssues, new UserChange(oldestUpdateDate(issues), new User(author.getUuid(), author.getLogin(), author.getName())));
    notificationService.scheduleForSending(notificationSerializer.serialize(builder));
}
Also used : PARAM_SET_SEVERITY(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_SEVERITY) Date(java.util.Date) ActionContext(org.sonar.server.issue.ActionContext) BUG(org.sonar.api.rules.RuleType.BUG) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Loggers(org.sonar.api.utils.log.Loggers) SET_SEVERITY_KEY(org.sonar.server.issue.SetSeverityAction.SET_SEVERITY_KEY) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PARAM_ADD_TAGS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADD_TAGS) WebService(org.sonar.api.server.ws.WebService) IssueChangePostProcessor(org.sonar.server.issue.IssueChangePostProcessor) Collectors.toMap(java.util.stream.Collectors.toMap) UUID_EXAMPLE_01(org.sonar.core.util.Uuids.UUID_EXAMPLE_01) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) UUID_EXAMPLE_02(org.sonar.core.util.Uuids.UUID_EXAMPLE_02) SET_TYPE_KEY(org.sonar.server.issue.SetTypeAction.SET_TYPE_KEY) TRANSITION_PARAMETER(org.sonar.server.issue.TransitionAction.TRANSITION_PARAMETER) Map(java.util.Map) PARAM_ASSIGN(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGN) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) PARAM_REMOVE_TAGS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REMOVE_TAGS) PARAM_SET_TYPE(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_TYPE) NotificationManager(org.sonar.server.notification.NotificationManager) PARAM_COMMENT(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMMENT) PARAM_DO_TRANSITION(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DO_TRANSITION) TAGS_PARAMETER(org.sonar.server.issue.AbstractChangeTagsAction.TAGS_PARAMETER) System2(org.sonar.api.utils.System2) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) OPEN_AS_VULNERABILITY(org.sonar.api.issue.DefaultTransitions.OPEN_AS_VULNERABILITY) Predicate(java.util.function.Predicate) ASSIGNEE_PARAMETER(org.sonar.server.issue.AssignAction.ASSIGNEE_PARAMETER) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) AddTagsAction(org.sonar.server.issue.AddTagsAction) PARAM_SEND_NOTIFICATIONS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEND_NOTIFICATIONS) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ACTION_BULK_CHANGE(org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_BULK_CHANGE) RuleKey(org.sonar.api.rule.RuleKey) Function.identity(java.util.function.Function.identity) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) Optional(java.util.Optional) IssuesChangesNotificationSerializer(org.sonar.server.issue.notification.IssuesChangesNotificationSerializer) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) BranchDto(org.sonar.db.component.BranchDto) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Issues(org.sonarqube.ws.Issues) MAX_PAGE_SIZE(org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE) SET_AS_IN_REVIEW(org.sonar.api.issue.DefaultTransitions.SET_AS_IN_REVIEW) HashMap(java.util.HashMap) PARAM_ISSUES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES) RuleType(org.sonar.api.rules.RuleType) COMMENT_PROPERTY(org.sonar.server.issue.CommentAction.COMMENT_PROPERTY) HashSet(java.util.HashSet) Action(org.sonar.server.issue.Action) WebIssueStorage(org.sonar.server.issue.WebIssueStorage) RemoveTagsAction(org.sonar.server.issue.RemoveTagsAction) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) Severity(org.sonar.api.rule.Severity) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) Objects.requireNonNull(java.util.Objects.requireNonNull) Response(org.sonar.api.server.ws.Response) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) REOPEN(org.sonar.api.issue.DefaultTransitions.REOPEN) COMMENT_KEY(org.sonar.server.issue.CommentAction.COMMENT_KEY) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) BranchType(org.sonar.db.component.BranchType) DefaultIssue(org.sonar.core.issue.DefaultIssue) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) Consumer(java.util.function.Consumer) UserRole(org.sonar.api.web.UserRole) DO_TRANSITION_KEY(org.sonar.server.issue.TransitionAction.DO_TRANSITION_KEY) DefaultTransitions(org.sonar.api.issue.DefaultTransitions) RESOLVE_AS_REVIEWED(org.sonar.api.issue.DefaultTransitions.RESOLVE_AS_REVIEWED) Change(org.sonar.api.server.ws.Change) AssignAction(org.sonar.server.issue.AssignAction) UserSession(org.sonar.server.user.UserSession) SEVERITY_PARAMETER(org.sonar.server.issue.SetSeverityAction.SEVERITY_PARAMETER) CheckForNull(javax.annotation.CheckForNull) TYPE_PARAMETER(org.sonar.server.issue.SetTypeAction.TYPE_PARAMETER) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder)

Example 25 with ChangedIssue

use of org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue in project sonarqube by SonarSource.

the class BulkChangeAction method toNotification.

@CheckForNull
private ChangedIssue toNotification(BulkChangeData bulkChangeData, Map<String, UserDto> userDtoByUuid, DefaultIssue issue) {
    BranchDto branchDto = bulkChangeData.branchesByProjectUuid.get(issue.projectUuid());
    if (!hasNotificationSupport(branchDto)) {
        return null;
    }
    RuleDefinitionDto ruleDefinitionDto = bulkChangeData.rulesByKey.get(issue.ruleKey());
    ComponentDto projectDto = bulkChangeData.projectsByUuid.get(issue.projectUuid());
    if (ruleDefinitionDto == null || projectDto == null) {
        return null;
    }
    Optional<UserDto> assignee = Optional.ofNullable(issue.assignee()).map(userDtoByUuid::get);
    return new ChangedIssue.Builder(issue.key()).setNewStatus(issue.status()).setNewResolution(issue.resolution()).setAssignee(assignee.map(u -> new User(u.getUuid(), u.getLogin(), u.getName())).orElse(null)).setRule(new IssuesChangesNotificationBuilder.Rule(ruleDefinitionDto.getKey(), RuleType.valueOfNullable(ruleDefinitionDto.getType()), ruleDefinitionDto.getName())).setProject(new Project.Builder(projectDto.uuid()).setKey(projectDto.getKey()).setProjectName(projectDto.name()).setBranchName(branchDto.isMain() ? null : branchDto.getKey()).build()).build();
}
Also used : PARAM_SET_SEVERITY(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_SEVERITY) Date(java.util.Date) ActionContext(org.sonar.server.issue.ActionContext) BUG(org.sonar.api.rules.RuleType.BUG) DbSession(org.sonar.db.DbSession) Request(org.sonar.api.server.ws.Request) Loggers(org.sonar.api.utils.log.Loggers) SET_SEVERITY_KEY(org.sonar.server.issue.SetSeverityAction.SET_SEVERITY_KEY) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PARAM_ADD_TAGS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADD_TAGS) WebService(org.sonar.api.server.ws.WebService) IssueChangePostProcessor(org.sonar.server.issue.IssueChangePostProcessor) Collectors.toMap(java.util.stream.Collectors.toMap) UUID_EXAMPLE_01(org.sonar.core.util.Uuids.UUID_EXAMPLE_01) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) UUID_EXAMPLE_02(org.sonar.core.util.Uuids.UUID_EXAMPLE_02) SET_TYPE_KEY(org.sonar.server.issue.SetTypeAction.SET_TYPE_KEY) TRANSITION_PARAMETER(org.sonar.server.issue.TransitionAction.TRANSITION_PARAMETER) Map(java.util.Map) PARAM_ASSIGN(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGN) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) PARAM_REMOVE_TAGS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REMOVE_TAGS) PARAM_SET_TYPE(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_TYPE) NotificationManager(org.sonar.server.notification.NotificationManager) PARAM_COMMENT(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMMENT) PARAM_DO_TRANSITION(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DO_TRANSITION) TAGS_PARAMETER(org.sonar.server.issue.AbstractChangeTagsAction.TAGS_PARAMETER) System2(org.sonar.api.utils.System2) Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) OPEN_AS_VULNERABILITY(org.sonar.api.issue.DefaultTransitions.OPEN_AS_VULNERABILITY) Predicate(java.util.function.Predicate) ASSIGNEE_PARAMETER(org.sonar.server.issue.AssignAction.ASSIGNEE_PARAMETER) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) DbClient(org.sonar.db.DbClient) AddTagsAction(org.sonar.server.issue.AddTagsAction) PARAM_SEND_NOTIFICATIONS(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEND_NOTIFICATIONS) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ACTION_BULK_CHANGE(org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_BULK_CHANGE) RuleKey(org.sonar.api.rule.RuleKey) Function.identity(java.util.function.Function.identity) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) Optional(java.util.Optional) IssuesChangesNotificationSerializer(org.sonar.server.issue.notification.IssuesChangesNotificationSerializer) WsUtils.writeProtobuf(org.sonar.server.ws.WsUtils.writeProtobuf) BranchDto(org.sonar.db.component.BranchDto) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Issues(org.sonarqube.ws.Issues) MAX_PAGE_SIZE(org.sonar.server.es.SearchOptions.MAX_PAGE_SIZE) SET_AS_IN_REVIEW(org.sonar.api.issue.DefaultTransitions.SET_AS_IN_REVIEW) HashMap(java.util.HashMap) PARAM_ISSUES(org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES) RuleType(org.sonar.api.rules.RuleType) COMMENT_PROPERTY(org.sonar.server.issue.CommentAction.COMMENT_PROPERTY) HashSet(java.util.HashSet) Action(org.sonar.server.issue.Action) WebIssueStorage(org.sonar.server.issue.WebIssueStorage) RemoveTagsAction(org.sonar.server.issue.RemoveTagsAction) MoreCollectors.toSet(org.sonar.core.util.stream.MoreCollectors.toSet) Severity(org.sonar.api.rule.Severity) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) Objects.requireNonNull(java.util.Objects.requireNonNull) Response(org.sonar.api.server.ws.Response) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) REOPEN(org.sonar.api.issue.DefaultTransitions.REOPEN) COMMENT_KEY(org.sonar.server.issue.CommentAction.COMMENT_KEY) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) BranchType(org.sonar.db.component.BranchType) DefaultIssue(org.sonar.core.issue.DefaultIssue) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) Consumer(java.util.function.Consumer) UserRole(org.sonar.api.web.UserRole) DO_TRANSITION_KEY(org.sonar.server.issue.TransitionAction.DO_TRANSITION_KEY) DefaultTransitions(org.sonar.api.issue.DefaultTransitions) RESOLVE_AS_REVIEWED(org.sonar.api.issue.DefaultTransitions.RESOLVE_AS_REVIEWED) Change(org.sonar.api.server.ws.Change) AssignAction(org.sonar.server.issue.AssignAction) UserSession(org.sonar.server.user.UserSession) SEVERITY_PARAMETER(org.sonar.server.issue.SetSeverityAction.SEVERITY_PARAMETER) CheckForNull(javax.annotation.CheckForNull) TYPE_PARAMETER(org.sonar.server.issue.SetTypeAction.TYPE_PARAMETER) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) BranchDto(org.sonar.db.component.BranchDto) User(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.User) UserDto(org.sonar.db.user.UserDto) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) CheckForNull(javax.annotation.CheckForNull)

Aggregations

ChangedIssue (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue)71 Test (org.junit.Test)65 Project (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project)54 UserChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange)47 Random (java.util.Random)45 AnalysisChange (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.AnalysisChange)44 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)43 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)43 Mockito.mock (org.mockito.Mockito.mock)40 IntStream (java.util.stream.IntStream)39 Rule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule)39 ImmutableSet (com.google.common.collect.ImmutableSet)38 Collections (java.util.Collections)38 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)37 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)37 List (java.util.List)37 RunWith (org.junit.runner.RunWith)37 IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule (org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.newRandomNotAHotspotRule)37 Set (java.util.Set)36 Stream (java.util.stream.Stream)36