Hello,
I wanted to create a Jira Event Listener with this Tutorial (https://developer.atlassian.com/server/jira/platform/writing-jira-event-listeners-with-the-atlassian-event-library/), but it is outdated and the listener won't work.
I found some posts with the same topic, but nothing helps me to get the listener working. I always create some errors, because there's nowhere a step by step instruction how to do it.
Could you please help me in saying what I have to change from the above linked tutorial to get it working in Jira 7+? Or do you have a downloadable source that I can use and that is working?
I know that all component-tags must disappear in the "atlassian-plugin.xml".
But how should the "IssueCreatedResolvedListener.java" file look like? And all the files beneath that. The pom.xml and stuff?
My last try with the "IssueCreatedResolvedListener.java" was this one:
package com.example.tutorial.plugins;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.Issue;
//import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.sal.api.lifecycle.LifecycleAware;
//import javax.inject.Named;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
/**
* Simple JIRA listener using the atlassian-event library and demonstrating
* plugin lifecycle integration.
*/
//@ExportAsService
@Component
//@Named("IssueCreatedResolvedListener")
public class IssueCreatedResolvedListener implements InitializingBean, DisposableBean, LifecycleAware {
private static final Logger log = LoggerFactory.getLogger(IssueCreatedResolvedListener.class);
private final EventPublisher eventPublisher;
/**
* Constructor.
* @param eventPublisher injected {@code EventPublisher} implementation.
*/
public IssueCreatedResolvedListener(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
/**
* 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);
}
/**
* Receives any {@code IssueEvent}s sent by JIRA.
* @param issueEvent the IssueEvent passed to us
*/
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
Long eventTypeId = issueEvent.getEventTypeId();
Issue issue = issueEvent.getIssue();
// if it's an event we're interested in, log it
if (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
log.info("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
} else if (eventTypeId.equals(EventType.ISSUE_RESOLVED_ID)) {
log.info("Issue {} has been resolved at {}.", issue.getKey(), issue.getResolutionDate());
} else if (eventTypeId.equals(EventType.ISSUE_CLOSED_ID)) {
log.info("Issue {} has been closed at {}.", issue.getKey(), issue.getUpdated());
}
}
@Override
public void onStart() {
// TODO Auto-generated method stub
}
@Override
public void onStop() {
// TODO Auto-generated method stub
}
}
But it is not working.
Thank you very much. I hope that you can help me out a bit. I'm totally confused what to do here...
Best regards,
Hauke