Package org.sonar.api.notifications

Examples of org.sonar.api.notifications.Notification


      "See it in SonarQube: http://nemo.sonarsource.org/dashboard/index/org.sonar.foo:foo"));
  }

  @Test
  public void shouldFormatNewAlertWithSeveralMessages() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4, coverage < 75%", "WARN", "true");

    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
    assertThat(message.getMessage(), is("" +
View Full Code Here


      "See it in SonarQube: http://nemo.sonarsource.org/dashboard/index/org.sonar.foo:foo"));
  }

  @Test
  public void shouldFormatNewAlertWithOneMessage() {
    Notification notification = createNotification("Orange (was Red)", "violations > 4", "WARN", "true");

    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
    assertThat(message.getMessage(), is("" +
View Full Code Here

      "See it in SonarQube: http://nemo.sonarsource.org/dashboard/index/org.sonar.foo:foo"));
  }

  @Test
  public void shouldFormatBackToGreenMessage() {
    Notification notification = createNotification("Green (was Red)", "", "OK", "false");

    EmailMessage message = template.format(notification);
    assertThat(message.getMessageId(), is("alerts/45"));
    assertThat(message.getSubject(), is("\"Foo\" is back to green"));
    assertThat(message.getMessage(), is("" +
View Full Code Here

      "\n" +
      "See it in SonarQube: http://nemo.sonarsource.org/dashboard/index/org.sonar.foo:foo"));
  }

  private Notification createNotification(String alertName, String alertText, String alertLevel, String isNewAlert) {
    Notification notification = new Notification("alerts")
        .setFieldValue("projectName", "Foo")
        .setFieldValue("projectKey", "org.sonar.foo:foo")
        .setFieldValue("projectId", "45")
        .setFieldValue("alertName", alertName)
        .setFieldValue("alertText", alertText)
View Full Code Here

  public IssueNotifications(NotificationManager notificationsManager) {
    this.notificationsManager = notificationsManager;
  }

  public Notification sendNewIssues(Project project, IssuesBySeverity newIssues) {
    Notification notification = newNotification(project, "new-issues")
      .setDefaultMessage(newIssues.size() + " new issues on " + project.getLongName() + ".\n")
      .setFieldValue("projectDate", DateUtils.formatDateTime(project.getAnalysisDate()))
      .setFieldValue("projectUuid", project.getUuid())
      .setFieldValue("count", String.valueOf(newIssues.size()));
    for (String severity : Severity.ALL) {
      notification.setFieldValue("count-" + severity, String.valueOf(newIssues.issues(severity)));
    }
    notificationsManager.scheduleForSending(notification);
    return notification;
  }
View Full Code Here

  @CheckForNull
  public List<Notification> sendChanges(Map<DefaultIssue, Rule> issues, IssueChangeContext context, Component project, @Nullable Component component, @Nullable String comment) {
    List<Notification> notifications = Lists.newArrayList();
    for (Entry<DefaultIssue, Rule> entry : issues.entrySet()) {
      Notification notification = createChangeNotification(entry.getKey(), context, entry.getValue(), project, component, comment);
      if (notification != null) {
        notifications.add(notification);
      }
    }
    if (!notifications.isEmpty()) {
View Full Code Here

  }

  @CheckForNull
  private Notification createChangeNotification(DefaultIssue issue, IssueChangeContext context, @Nullable Rule rule, Component project,
    @Nullable Component component, @Nullable String comment) {
    Notification notification = null;
    if (comment != null || issue.mustSendNotifications()) {
      FieldDiffs currentChange = issue.currentChange();
      notification = newNotification(project, "issue-changes");
      notification.setFieldValue("key", issue.key());
      notification.setFieldValue("changeAuthor", context.login());
      notification.setFieldValue("reporter", issue.reporter());
      notification.setFieldValue("assignee", issue.assignee());
      notification.setFieldValue("message", issue.message());
      notification.setFieldValue("ruleName", ruleName(rule));
      notification.setFieldValue("componentKey", issue.componentKey());
      if (component != null) {
        notification.setFieldValue("componentName", component.longName());
      }
      if (comment != null) {
        notification.setFieldValue("comment", comment);
      }

      if (currentChange != null) {
        for (Map.Entry<String, FieldDiffs.Diff> entry : currentChange.diffs().entrySet()) {
          String type = entry.getKey();
          FieldDiffs.Diff diff = entry.getValue();
          Serializable newValue = diff.newValue();
          Serializable oldValue = diff.oldValue();
          notification.setFieldValue("old." + type, oldValue != null ? oldValue.toString() : null);
          notification.setFieldValue("new." + type, newValue != null ? newValue.toString() : null);
        }
      }
    }
    return notification;
  }
View Full Code Here

    }
    return rule.getName();
  }

  private Notification newNotification(Component project, String key) {
    return new Notification(key)
      .setFieldValue("projectName", project.longName())
      .setFieldValue("projectKey", project.key());
  }
View Full Code Here

    measure.setAlertText(label);
    return measure;
  }

  private void verifyNotificationSent(String alertName, String alertText, String alertLevel, String isNewAlert) {
    Notification notification = new Notification("alerts")
      .setDefaultMessage("Alert on " + project.getLongName() + ": " + alertName)
      .setFieldValue("projectName", project.getLongName())
      .setFieldValue("projectKey", project.getKey())
      .setFieldValue("projectId", String.valueOf(project.getId()))
      .setFieldValue("alertName", alertName)
View Full Code Here

TOP

Related Classes of org.sonar.api.notifications.Notification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.