1
votes

I need to automatically make some changes to a JIRA-ticket's field, whenever certain events happen. It was recommended, that I write a custom event listener -- to be invoked by JIRA.

However, I'm somewhat unclear as to how to do it properly -- an online tutorial hosted by Atlassian creates a bean, whereas the Atlassian's own DebugListener.java and MailListener.java (from the current JIRA source-tree) use classes extending AbstractIssueEventListener without any mention of the beans-framework.

I used the tutorial's example, and can not make it work. Should I keep struggling, or should I change over to the other method? Which of them is the currently-recommended and official and which is "legacy"?

The JIRA we currently have in production is version 6.1.7 -- I do not need my plugin to work with anything before that.

2

2 Answers

2
votes

For anyone seeing this in JIRA 7.1, I have a solution documented at Atlassian's answer site itself. My solution does not extend AbstractIssueEventListener. I don't claim one approach is better or worse. However, my approach does not require manually loading the listener (as with the extend AbstractIssueEventListener approach). It works automatically.

https://answers.atlassian.com/questions/51997/answers/37520082?flashId=17814304

1
votes

Code sample of the EventListener, that actually works for me:

public class TestEventListener extends AbstractIssueEventListener implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;

public TestEventListener(
        EventPublisher eventPublisher
) {
    this.eventPublisher = eventPublisher;
}

@EventListener
public void onIssueEvent(IssueEvent issueEvent) throws JiraException, IOException, URISyntaxException {
}

/**
 * Called when the plugin has been enabled.
 *
 * @throws Exception
 */
@Override
public void afterPropertiesSet() throws Exception {
    // register ourselves with the EventPublisher
    eventPublisher.register(this);
}

/**
 * Called when the plugin is being disabled or removed.
 *
 * @throws Exception
 */
@Override
public void destroy() throws Exception {
    // unregister ourselves with the EventPublisher
    eventPublisher.unregister(this);
}

}