issue event listener

mehran haghani November 22, 2013

Hi,

when i implement my class from IssueEventListener and impement its methods not happening on issue events. how i can listen to issue events in my class ?

dose my class called even if issue events occures in another page?in the other hand how i can use issue listener to run my class on issue events?

thanks a lot

tis is my simple class code:



package com.atlassian.jira.event.listeners;

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.event.JiraEvent;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.issue.IssueEventListener;
import com.atlassian.jira.event.user.UserEvent;
import com.atlassian.jira.event.user.UserEventListener;

import org.ofbiz.core.entity.GenericEntityException;
import org.ofbiz.core.entity.GenericValue;

import java.util.Iterator;
import java.util.List;
import java.util.Map;


public class my class extends IssueActionSupport implements IssueEventListener
{

...

public void customEvent(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueAssigned(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueClosed(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueCommented(IssueEvent arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.getIssue().getKey() +"comment");


}
public void issueCreated(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueDeleted(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueGenericEvent(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueMoved(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueReopened(IssueEvent arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.getIssue().getKey() +"reopen");


}
public void issueResolved(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueStarted(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueStopped(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void issueUpdated(IssueEvent arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.getChangeLog().modified +"updated");

}
public void issueWorkLogged(IssueEvent arg0) {
// TODO Auto-generated method stub

}
public void workflowEvent(IssueEvent arg0) {
// TODO Auto-generated method stub

}


...

}

4 answers

1 accepted

0 votes
Answer accepted
Onkar Ahire
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 23, 2013

Hi Mehran,

Go to JIRA Administration >> Listeners >> Add fully qualified name of your listener class

OR

in below code you did not required to add listener class explicitly.

public class MyEventListenerClass  implements InitializingBean,DisposableBean 
{
	public MyEventListenerClass()
	{
	}
	public void afterPropertiesSet() throws Exception 
	{
		eventPublisher.register(this);
	}
	public void destroy() throws Exception 
	{		
		eventPublisher.unregister(this);
	}
	@EventListener
	public void onIssueEvent(IssueEvent issueEvent) throws Exception 
	{
		Long eventTypeId = issueEvent.getEventTypeId();
		log.debug("On Issue Event against issue "+issueEvent.getIssue().getKey());
		if(eventTypeId.equals(EventType.ISSUE_CREATED_ID))
		{
				// do stuff on issue created event
		}		
	}
}

atlassian-plugin.xml

<component-import key="eventPublisher" interface="com.atlassian.event.api.EventPublisher"/>

			<component key="eventListener" class="com.ora.sm.MyEventListener">

		    <description>Class that processes the incoming JIRA issue events.</description>

	 </component>

Regards

Onkar Ahire

mehran haghani November 24, 2013

thanks onkar , it works when i added my listener :)

2 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 22, 2013

The basics of writing a listener, explaining how you get the information about the change that fired the event (including issue) is all at https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+Event+Listeners+with+the+atlassian-event+Library

0 votes
mehran haghani November 24, 2013

My jira version is 3.7.2 Andy

0 votes
Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2013

This was the JIRA4.x way of doing things, see the tutorial Nic linked (and /or clarify your JIRA version)

Suggest an answer

Log in or Sign up to answer