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

DonPerera January 22, 2020

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
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2020

@DonPereraYou can do that. Here is brief idea,

DonPerera January 22, 2020

@DPKJ  

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

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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!!!

DonPerera January 26, 2020

@DPKJ  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
}
DonPerera January 26, 2020

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

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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 :-)

DonPerera January 26, 2020

@DPKJ 

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 DPKJ likes this
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 26, 2020

Nice work @DonPerera 

Like DonPerera likes this

Suggest an answer

Log in or Sign up to answer