Create an event in Jira from plugin

Hi All,

I am trying to create a plugin which requires an event to be created.  
We need this event in the notification schemes to configure notifications to users on an issue when this event is triggered.

For now i have manually created the event from Jira UI but that will not be possible to do it in all the instances where this plugin is uploaded in Jira.

So I would like to know how all the following could be done

1. Create an event in Jira programmatically from plugin

2. Make sure that this create event code runs only once.
Although we can check if the event exists or not and then ignore creation, i would prefer the code does not get executed more than once.

3. How can i fetch who all should the notification be sent on this event for an issue?

Any pointers and help is greatly appreciated.

Thanks,
Parashar

1 answer

1 accepted

This widget could not be displayed.

#1 was fairly simple :)

Following snippet should create the event.

EventTypeManager eventTypeManager = ComponentAccessor.getEventTypeManager();
EventType newEvent = new EventType("New Test Event ", "Test event", 0l)
eventTypeManager.addEventType(newEvent);

Will keep looking for #2 & #3.

Found a way for #2. 
We can use com.atlassian.sal.api.lifecycle.LifecycleAware and override the methods to do the job. The job runs only on Startup (i.e. On Jira Start up or the plugin enabled)

Will keep looking for #3.

#3 can be done provided the issue and issue event details are available by accessing the notification manager.

Following snippet should allow one to do that.

IssueEvent issueEvent = new IssueEvent(issue, null, null, 2l);
Set<NotificationRecipient> recipients = notificationSchemeManager.getRecipients(issueEvent);

Marking the question as answered.
Please let me know if any of this can be done any better.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

112 views 2 0
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