Changes in Evenlilstener in jira6

We are using below code for listning the events from jira but its not working . It was working fine with jira 5.2.4 but when jira is upgarded to 6.0 it stopped working.:

"deployFileStage" and "deployFileProd" are the events which we have configured in jira

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.event.type.EventTypeManager;
import org.apache.log4j.Logger;

public class DeployEventListener extends AbstractIssueEventListener
{

    private static Logger LOG = Logger.getLogger(DeployEventListener.class);

    public DeployEventListener()
    {
    }

    public void customEvent(IssueEvent event)
    {
       // We are not able to get the event name
        String eventName = ComponentAccessor.getEventTypeManager().getEventType(event.getEventTypeId()).getName();
        if(eventName.contains("deployFileStage"))
        {
            DeployManager.initiateDeployment(event, "stage");
        } else
        if(eventName.contains("deployFileProd"))
        {
            DeployManager.initiateDeployment(event, "prod");
        } 
    }

}

2 answers

1 vote
Timothy Chin Community Champion Nov 29, 2013

You might want to change the code to use the latest way of listening to events (https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+Event+Listeners+with+the+atlassian-event+Library).

Hi,

I have changed the code as per the documentation but still its not working.

package com.blah.blah.eventlisteners;

import com.atlassian.jira.component.*;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventTypeManager;
import com.blah.blah.commentutil.CommentsUtil;
import com.blah.blah.deploymanager.DeployManager;
import com.blah.blah.jira.commentutil.*;
import org.apache.log4j.Logger;
import com.atlassian.event.api.EventPublisher;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class DeployEventListener implements InitializingBean, DisposableBean {
private static Logger LOG = Logger.getLogger(DeployEventListener.class);
private final EventTypeManager eventTypeManager;
private final EventPublisher eventPublisher;
private final DeployManager deployManager;
public DeployEventListener(DeployManager deployManager, EventPublisher eventPublisher, EventTypeManager eventTypeManager){
this.deployManager = deployManager;
this.eventPublisher = eventPublisher;
this.eventTypeManager = eventTypeManager;

}
public void customEvent(IssueEvent event){
Long eventTypeId = event.getEventTypeId();
String eventName = eventTypeManager.getEventType(eventTypeId).getName();
if(eventName.contains("Stage_Deployment")){
DeployManager.initiateDeployment(event, "stage");
}
public void afterPropertiesSet()
throws Exception
{
eventPublisher.register(this);
}

public void destroy()
throws Exception
{
eventPublisher.unregister(this);
}
}
}

package com.blah.blah.eventlisteners;

import com.atlassian.jira.component.*;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventTypeManager;
import com.blah.blah.commentutil.CommentsUtil;
import com.blah.blah.deploymanager.DeployManager;
import com.blah.blah.jira.commentutil.*;
import org.apache.log4j.Logger;
import com.atlassian.event.api.EventPublisher;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class DeployEventListener implements InitializingBean, DisposableBean {
	private static Logger LOG = Logger.getLogger(DeployEventListener.class);
	private final EventTypeManager eventTypeManager;
	private final EventPublisher eventPublisher;
	private final DeployManager deployManager;
	public DeployEventListener(DeployManager deployManager, EventPublisher eventPublisher, EventTypeManager eventTypeManager){
		this.deployManager = deployManager;
		this.eventPublisher = eventPublisher;
		this.eventTypeManager = eventTypeManager;
	
	}
  	public void customEvent(IssueEvent event){
		Long eventTypeId = event.getEventTypeId();
		String eventName = eventTypeManager.getEventType(eventTypeId).getName();
		if(eventName.contains("Stage_Deployment")){
			DeployManager.initiateDeployment(event, "stage");
		}
	public void afterPropertiesSet()
	throws Exception
	{
		eventPublisher.register(this);
	}

	public void destroy()
	throws Exception
	{
		eventPublisher.unregister(this);
	}
}
}

anyone checked this ?

Forget your code for now, follow the tutorial that have now been suggested twice by two people :D you are trying to use the customEvent method, which isnt what the tutorial shows.

i suggest to delete and reconfigure listener so it may work!!

and also give prints inside your listener so you can debug that which part is not working!

and also you need to write like as follows

@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
   Long eventTypeId = issueEvent.getEventTypeId();
   Issue issue = issueEvent.getIssue();
 
   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());
   }
}

and also i suggest to go through the document as above people suggested!!

Thanks Rambanam ... The error was with log file .. I put sysouts and it worked .

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

167 views 1 17
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you