Changes in Evenlilstener in jira6

Nikhil Srivastav November 28, 2013

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
RambanamP
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.
January 8, 2014

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!!

Nikhil Srivastav January 8, 2014

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

1 vote
Timothy
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 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).

Nikhil Srivastav December 26, 2013

Hi,

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

Nikhil Srivastav December 26, 2013

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);
}
}
}

Nikhil Srivastav December 26, 2013
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);
	}
}
}

Nikhil Srivastav January 8, 2014

anyone checked this ?

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.
January 8, 2014

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.

Suggest an answer

Log in or Sign up to answer