Commits

Robert Massaioli [Atlassian] committed dde6b98

Notifications are now sent by the mail handler.

Now to clean up all of the places that errors appear in the code.

  • Participants
  • Parent commits aba62bb

Comments (0)

Files changed (5)

File src/main/java/com/atlassian/jira/extension/scheduled/PingNotificationJob.java

 package com.atlassian.jira.extension.scheduled;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import com.atlassian.jira.issue.Issue;
+import com.atlassian.jira.issue.IssueManager;
+import com.atlassian.sal.api.ApplicationProperties;
+import org.joda.time.DateTime;
+import org.joda.time.format.ISODateTimeFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 		
 		final MailService mailService = (MailService) jobObjects.get(PingSchedulerImpl.MAIL_SERVICE);
 		final UserManager userManager = (UserManager) jobObjects.get(PingSchedulerImpl.USER_MANAGER);
+        final IssueManager issueManager = (IssueManager) jobObjects.get(PingSchedulerImpl.ISSUE_MANAGER);
+        final ApplicationProperties applicationProperties = (ApplicationProperties) jobObjects.get(PingSchedulerImpl.APPLICATION_PROPERTIES);
 		log.info("Running the Ping Notification Job...");
 		for(PingEntity ping : duePings) {
 			log.info("Sending notification for: " + ping.getIssueId());
+            final Map<String, Object> velocityContext = new HashMap<String, Object>();
 			final User toAndFromUser = userManager.getUser(ping.getUsername());
+            final Issue issue = issueManager.getIssueObject(Long.valueOf(ping.getIssueId()));
 			final NotificationRecipient recipient = new NotificationRecipient(toAndFromUser);
+
+            final DateTime created = new DateTime(ping.getCreated());
+
+            velocityContext.put("user", toAndFromUser);
+            velocityContext.put("issue", issue);
+            velocityContext.put("ping", ping);
+            velocityContext.put("baseURL", applicationProperties.getBaseUrl());
+            velocityContext.put("prettyCreatedDate", created.toString(ISODateTimeFormat.dateTime()));
 			
 			final String subjectTemplate = "templates/email/subject/ping-notification.vm";
 			final String bodyTemplate = "templates/email/" + recipient.getFormat() + "/ping-notification.vm";
 			// TODO finish of the last of this...
-			mailService.sendRenderedMail(toAndFromUser, recipient, subjectTemplate, bodyTemplate, null);
+            if(toAndFromUser != null && issue != null) {
+			    mailService.sendRenderedMail(toAndFromUser, recipient, subjectTemplate, bodyTemplate, velocityContext);
+            }
 			// TODO send an email notification here
 			pingService.removePing(ping.getID());
 		}

File src/main/java/com/atlassian/jira/extension/scheduled/PingSchedulerImpl.java

 import java.util.HashMap;
 import java.util.concurrent.TimeUnit;
 
+import com.atlassian.jira.issue.IssueManager;
+import com.atlassian.sal.api.ApplicationProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
     static final String PING_SERVICE = PingSchedulerImpl.class.getName() + ":" + PingService.class.getName();
     static final String MAIL_SERVICE = PingSchedulerImpl.class.getName() + ":" + MailService.class.getName();
     static final String USER_MANAGER = PingSchedulerImpl.class.getName() + ":" + UserManager.class.getName();
+    static final String ISSUE_MANAGER = PingSchedulerImpl.class.getName() + ":" + IssueManager.class.getName();
+    static final String APPLICATION_PROPERTIES = PingSchedulerImpl.class.getName() + ":" + ApplicationProperties.class.getName();
     private static final String JOB_NAME = PingSchedulerImpl.class.getName() + ":job";
     
     private final PluginScheduler pluginScheduler;
     private final PingService pingService;
     private final MailService mailService;
     private final UserManager userManager;
+    private final IssueManager issueManager;
+    private final ApplicationProperties applicationProperties;
     private final I18nResolver i18nResolver;
 	
 	public PingSchedulerImpl(
-			PluginScheduler pluginScheduler, 
-			PingService pingService, 
-			MailService mailService,
-			UserManager userManager,
-			I18nResolver i18nResolver) {
+            PluginScheduler pluginScheduler,
+            PingService pingService,
+            MailService mailService,
+            UserManager userManager,
+            IssueManager issueManager, ApplicationProperties applicationProperties, I18nResolver i18nResolver) {
 		super();
 		this.pluginScheduler = pluginScheduler;
 		this.pingService = pingService;
 		this.mailService = mailService;
 		this.userManager = userManager;
-		this.i18nResolver = i18nResolver;
+        this.issueManager = issueManager;
+        this.applicationProperties = applicationProperties;
+        this.i18nResolver = i18nResolver;
 	}
 
 	@Override
                     put(PING_SERVICE, pingService);
                     put(MAIL_SERVICE, mailService);
                     put(USER_MANAGER, userManager);
+                    put(ISSUE_MANAGER, issueManager);
+                    put(APPLICATION_PROPERTIES, applicationProperties);
                 }},                         // data that needs to be passed to the job
                 new Date(),                 // the time the job is to start
                 interval);                  // interval between repeats, in milliseconds

File src/main/resources/atlassian-plugin.xml

         <resource name="list-user-pings.js" type="download" location="js/list-user-pings.js" />
         <context>com.atlassian.jira.pingme.list-user-pings</context>
     </web-resource>
-    
+
+    <component-import key="applicationPropertiesKey" name="SAL Application Properties" interface="com.atlassian.sal.api.ApplicationProperties">
+        <description>SAL Applications properties so that we can get common properties about the application.</description>
+    </component-import>
     <component-import key="i18nresolver-key" name="I18nResolver Import" interface="com.atlassian.sal.api.message.I18nResolver">
         <description>I18nResolver so that we can get internationalised text.</description>
     </component-import>

File src/main/resources/templates/email/html/ping-notification.vm

 Hi ${user.displayName},
 
 <p>
-	On the ${ping.created} you set a ping on <strong><a href="${baseURL}/browse/${ping.issue.key}">${ping.issue.key}</a></strong>.
+	On the ${prettyCreatedDate} you set a ping on <strong><a href="${baseURL}/browse/${issue.key}">${issue.key}</a></strong>.
 </p>
 
 <ul>
-	<li>Summary: <strong>${ping.issue.summary}<strong></li>
-	<li>Link: <a href="${baseURL}/browse/${ping.issue.key}">${ping.issue.key}</a></li>
+	<li>Summary: <strong>${issue.summary}<strong></li>
+	<li>Link: <a href="${baseURL}/browse/${issue.key}">${issue.key}</a></li>
 </ul>
 
 <p>You can follow the link to find out more about this issue.</p>

File src/main/resources/templates/email/text/ping-notification.vm

 Hi ${user.displayName},
 
-On the ${ping.created} you set a ping on ${ping.issue.key}.
+On the ${prettyCreatedDate} you set a ping on ${issue.key}.
 
-Issue Summary: ${ping.issue.summary}
-Issue Link: ${baseURL}/browse/${ping.issue.key}
+Issue Summary: ${issue.summary}
+Issue Link: ${baseURL}/browse/${issue.key}
 
 You can follow the link to find out more about this issue.