It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to create issue types on addon installation on jira cloud.

Im currently trying to create custom issue types on addon installation, is there any way i can listen to events like in the jira server (life cycle events).Im writing the plugin using Spring boot connect app framework.

1 answer

1 accepted

1 vote
Answer accepted
DPK J Community Leader Jan 22, 2020

@DonPereraYou can do that. Here is brief idea,

@DPK J  

Can you post a sample method signature for the particular , i tried with admin scope but it goes and hits on the following 

Mapped to public org.springframework.http.ResponseEntity<java.lang.Void> com.atlassian.connect.spring.internal.lifecycle.LifecycleController.installed(com.atlassian.connect.spring.internal.lifecycle.LifecycleEvent,com.atlassian.connect.spring.AtlassianHostUser)

not to the endpoint i defined.

Thanks!!!

DPK J Community Leader Jan 22, 2020

@DonPerera Two things,

  1. You don't have to create a controller for this, as atlassian-connect-spring-boot comes with LifecycleController that deal with endpoints like '/installed', '/uninstalled'.
  2. You have to listen to the Custom Spring Application Events (i.e. AddonInstalledEvent, AddonUninstalledEvent) generated by LifecycleController, to do something after add-on installation.

If you are not familiar with listening to custom events in Sprint framework, checkout this,

Your sample method code will look like this,

@EventListener
public void processAddonInstalledEvent(AddonInstalledEvent event) {
//Do event processing here
}

make sure you put this method in a bean.


Happy coding!!!

@DPK J  Thank you very much.

Works like a charm.

@Component
public class EventManager {

@EventListener
public void processAddonInstalledEvent(AddonInstalledEvent event) {
//logic
}

@EventListener
public void processAddonUninstalledEvent(AddonUninstalledEvent event) {
//logic
}

@DPK J 

Im able hit the Event Listener but when i send the rest call to create the issue type i get unauthorized exception.I already have the admin privileges.

atlassianHostRestClients.authenticatedAsAddon(host).postForObject("/rest/api/3/issuetype", dataObj, Boolean.class);

 I have added the following scope to the descriptor as well,

"READ", "WRITE", "ACT_AS_USER","ADMIN"

 but unable to create the issue type.How can i authenticate the request.

Thanks !!!!.

DPK J Community Leader Jan 26, 2020

@DonPerera  Have you tried removing addon and reinstalling it with fresh DB?

If not please try this.

Also take a look at this question, it have some related info - https://community.atlassian.com/t5/Answers-Developer-Questions/Cannot-set-avatar-for-issue-type-using-REST-API-with-JWT/qaq-p/568931

 

If all these things doesn't work do let me know, I will try this out on my sample site, and will get back to you. Or you can open another question for this :-)

@DPK J 

I was able to make it work. The problem had been the plugin needed to finish installing inoder to create the issue types,

Map<String, String> dataObj = new HashMap<>();
dataObj.put("name", "");
dataObj.put("description", "");
dataObj.put("type", "standard");

Executor.executorService.schedule(() -> {
String object = atlassianHostRestClients.authenticatedAsAddon(event.getHost()).postForObject("/rest/api/3/issuetype", dataObj, String.class);
assert object != null;
LOGGER.info("IssueType Created ".concat(object));

}, 15, TimeUnit.SECONDS);


So i put the issue type creation in to schedule thread to run after 15s.

Thanks!!! 

Like DPK J likes this
DPK J Community Leader Jan 26, 2020

Nice work @DonPerera 

Like DonPerera likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you