I would like to change the notification behavior of JIRA and add additional receivers to certain issue events. I know that I could register the EventPublisher
and catch all necessary events.
public class MyIssueCreatedResolvedListenerImpl implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;
public MyIssueCreatedResolvedListenerImpl(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
// Process the issue events. I'm using the code presented below.
}
}
In the onIssueEvent
I would like to reuse the existing email templates from JIRA and send them with the SMTPMailServer
object to further receivers. At the moment I'm using following code to read and fill the velocity templates.
ApplicationProperties ap = ComponentAccessor.getApplicationProperties();
String baseUrl = ap.getString(APKeys.JIRA_BASEURL);
String webworkEncoding = ap.getString(APKeys.JIRA_WEBWORK_ENCODING);
VelocityManager vm = ComponentAccessor.getVelocityManager();
VelocityParamFactory vp = ComponentAccessor.getVelocityParamFactory();
Map context = vp.getDefaultVelocityParams();
context.put("baseurl", baseUrl);
context.put("currentTimestamp", new Date());
context.put("issue", issueEvent.getIssue());
String renderedText = vm.getEncodedBody("templates/email/html/", "issueclosed.vm", baseUrl, webworkEncoding, context);
SMTPMailServer mailServer = MailFactory.getServerManager().getDefaultSMTPMailServer();
Email email = new Email("<E-Mail-Adress>");
email.setMimeType("text/html");
email.setEncoding("utf-8");
email.setBody(renderedText);
try {
mailServer.send(email);
} catch (MailException e) {
e.printStackTrace();
}
The above code work partial. A couple of fields are filled, but I still miss the CSS, images or i18n in the email notification. Please note, I won't use any additional add-ons from the marketplace.
Is this the correct implementation to reuse the JIRA templates?
How to include the CSS, images, i18n, etc.? Or could I use a different approach?
couple of fields are filled, but I still miss the CSS, images or i18n
How Does Internationalisation Work?
Before you implement internationalisation (also called 'i18n' because there are 18 letters between 'i' and 'n') support for your plugin, it is important to understand how a plugin is internationalised.
First, all messages in the plugin must be moved outside the code into a properties file in the plugin. The properties file stores the default (English) translations for all messages inside the plugin. The properties file format is a key = value format, where the key is used to refer to the resource in the code and the value is the default message in English.
You can't use /images/ in your path unless you map the directory.
Including Javascript and CSS resources:
For each resource, the location of the resource should match the path to the resource in your plugin JAR file. Resource paths are namespaced to your plugin, so they can't conflict with resources in other plugins with the same location (unlike say i18n or Velocity resources). However, you may find it convenient to use a path name which is specific to your plugin to be consistent with these other types.
To include your custom web resource in a page where your plugin is used, you use the #requireResource Velocity macro.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With