Need to include functionality after any type of editing issue.

Bharadwaj Jannu
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.
April 9, 2013

After any type of editing issue(Normal Edit,Quick Edit,Inline Edit,SOAP Edit,REST Edit), I need to execute a

functionality immediately when update button is pressed.

How can we achieve this using Events/Listeners?

2 answers

1 accepted

0 votes
Answer accepted
Bharadwaj Jannu
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.
October 24, 2013
Listeners sometimes are not getting called if I do no changes to the form, but required to get called.

e.g: If a customfield is selected then it should create an issue and link with the current issue.

       If I delete that link and simply updated the edit form, then listener should be invoked and it should again create a new issue and link with the current issue.

       but this is not happening with the listeners approach.

Sometimes listeners are getting called(because it is based on ISSUE_UPDATED event) when they is no requirement of call.

e.g: For Issue tab panels change and updations, it is getting called.

      this is unneccessarily happening with listeners approach.

Hence I choose the method in https://answers.atlassian.com/questions/83433/validator-support-for-edit-quick-edit-and-soap for edit, quickedit and inline edit. Although this is little clumpsy, we can perform our expected results if well documented. 

1 vote
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.
April 9, 2013

Events are fired as a post-function on a transition or action.

To use this, write a listener that picks up the event(s) in question and runs your functionality.

Bharadwaj Jannu
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.
April 9, 2013

Thanks Nic,

I tried to use Listener on Edit action in the following way

package com.mycompany.jira.plugins;

import com.atlassian.jira.event.issue.IssueEvent;

import org.springframework.beans.factory.DisposableBean;

import org.springframework.beans.factory.InitializingBean;

import com.atlassian.event.api.EventPublisher;

import com.atlassian.jira.event.type.EventType;

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.event.api.EventListener;

public class GlobalEditPostFunction implements InitializingBean,DisposableBean

{

private final EventPublisher eventPublisher;

public GlobalEditPostFunction(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);

}

@EventListener

public void onIssueEvent(IssueEvent issueEvent)

{

Long eventTypeId = issueEvent.getEventTypeId();

MutableIssue issue = (MutableIssue)issueEvent.getIssue();

System.out.println("Test");

if(eventTypeId.equals(EventType.ISSUE_UPDATED_ID))

{

System.out.println("Issue Testing");

}

}

}

But no changes are seen on console i.e. Sys out

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.
April 9, 2013

Well, that's basically a copy of the code at https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+event+listeners+with+the+atlassian-event+library with a renamed class (I'd suggest changing that name a bit as it implies it's a post-function to me, although it's clearly not when you read it)

As you're not getting "Test" in your output, that implies it's not running at all, so you need to debug why. Check that the listener is loading ok at Jira startup, check it's enabled, and check that you've added and configured it correctly.

Bharadwaj Jannu
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.
April 9, 2013

yes Nic, The plugin installed and enabled successfully and also I placed Sysout stmts

in afterPropertiesSet() and in destroy() , they are executed well;but not in onIssueEvent() method

I guess the EventListener is not called in the plugin.

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.
April 9, 2013

Have you cycled through a range of events for an issue? Create, edit, resolve? (Just a handful of the core ones is a good enough test)

Does your log file really contain absolutely nothing from the listener at all?

Bharadwaj Jannu
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.
April 11, 2013

Yes the log and cmd prompt donot contain any sysouts.

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.
April 11, 2013

Sorry, did you cycle through some edits/transitions on issues?

Bharadwaj Jannu
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.
April 11, 2013

Yes, I checked with transitions as well as edit operation in different ways but it does not show any

effect in logs

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.
April 11, 2013

Are you 100% sure you have configured the listener to execute?

If you are, then I'm completely stumped, as that code works perfectly for me here.

Bharadwaj Jannu
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.
April 11, 2013

Hi NIc,

Now it is working for me by adding <Export-Package>...</Export-Package> in

atlassian-plugin.xml

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.
April 11, 2013

Ahh, well spotted. I guess mine was working fine because I hadn't removed that line!

Suggest an answer

Log in or Sign up to answer