2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
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.
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.
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.plugins.core.issue.notification;
22 import org.sonar.api.config.EmailSettings;
23 import org.sonar.api.notifications.Notification;
24 import org.sonar.api.utils.DateUtils;
25 import org.sonar.plugins.emailnotifications.api.EmailMessage;
26 import org.sonar.plugins.emailnotifications.api.EmailTemplate;
28 import java.net.URLEncoder;
29 import java.util.Date;
32 * Creates email message for notification "new-issues".
36 public class NewIssuesEmailTemplate extends EmailTemplate {
38 private final EmailSettings settings;
40 public NewIssuesEmailTemplate(EmailSettings settings) {
41 this.settings = settings;
45 public EmailMessage format(Notification notification) {
46 if (!"new-issues".equals(notification.getType())) {
49 String projectName = notification.getFieldValue("projectName");
50 String violationsCount = notification.getFieldValue("count");
52 StringBuilder sb = new StringBuilder();
53 sb.append("Project: ").append(projectName).append('\n');
54 sb.append(violationsCount).append(" new issues").append('\n');
55 appendFooter(sb, notification);
57 EmailMessage message = new EmailMessage()
58 .setMessageId("new-issues/" + notification.getFieldValue("projectKey"))
59 .setSubject("Project " + projectName + ", new issues")
60 .setMessage(sb.toString());
65 private void appendFooter(StringBuilder sb, Notification notification) {
66 String projectKey = notification.getFieldValue("projectKey");
67 String dateString = notification.getFieldValue("projectDate");
68 Date date = DateUtils.parseDateTime(dateString);
69 String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s", settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date));
71 .append("See it in SonarQube: ")