<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=299788&amp;fmt=gif">

Useful Atlassian APIs for Plugin Development

Atlassian Tools, Software Solutions

By Robert Hall

Introduction

In a previous post, Atlassian plugin development using the Atlassian SDK was introduced. In this post, we go into more depth with an important aspect of plugin development--Atlassian APIs for Java plugin development. In Atlassian products such as Jira and Confluence, APIs are made available to plugin developers via services exposed via Java interfaces. Implementations of these interfaces (usually named with a prefix and 'Manager') are accessible via the ComponentAccessor (Jira) or ContainerManager (Confluence). Other Atlassian products have similar APIs available. Atlassian APIs are also available via REST web services; those will be discussed in a future post.

Jira APIs

Some key Java APIs for Jira include the ComponentAccessor, IssueManager, ProjectManager and UserManager. First the ComponentAccessor.

ComponentAccessor

ComponentAccessor provides static methods for getting references to Jira's managed components. Think of at as a factory for Jira service APIs. There are get methods for various Manager and Factory interface implementations. There are many Manager, Factory, and Service APIs for programatically managing many aspects of Jira--the lifecycle and workflow of Issues, User permissions and access management, the lifecycle of Projects.

getIssueFactory, getIssueManager and getIssueService

Jira plugins frequently need to work with Issues. The IssueFactory can be used to create new Jira Issues and the IssueManager can be used to search for issues, read and update attributes of an issue.

getProjectFactory and getProjectManager

Jira plugins frequently need to work with Projects. The ProjectManager provides methods to create, read, update and delete (remove) a Jira Project, along with methods for retrieving and updating project categories, etc.

getUserManager

Jira plugins frequently need to work with Users. The User Manager provides methods to get a Jira User object by user name, key, update attributes of user, get user groups, etc.

Example

In the three example code snippets below, first the ProjectManager is obtained and a project retrieved by key, and associated issue types are iterated through. In the second example, a user object is obtained by username through the UserManager and the email address obtained. In the third example, a collection of issue ids are obtained for a Project via the IssueManager. In each of the examples, the result object can be used by the plugin to change values, take action, or retrieve data that can be used for further processing.

ProjectManager pm = ComponentAccessor.getProjectManager();
Project proj = pm.getProjectObjByKey(projectKey);
if (proj != null) {
Collection types = proj.getIssueTypes();
for (IssueType type : types) {
if (issueType != null &amp;amp;amp;amp;&amp;amp;amp;amp; issueType.contains(type.getName())) {
issueType = type.getId();
break;
}
}
}
...
UserManager um = ComponentAccessor.getUserManager();
ApplicationUser user = um.getUserByName(&amp;amp;quot;johndoe&amp;amp;quot;);
String email = user.getEmailAddress();
...
IssueManager issueMgr = ComponentAccessor.getIssueManager();
Collection issueIds = issueMgr.getIssueIdsForProject(projectKey);

Confluence APIs

Some key Java APIs for Confluence include the AttachmentManager, ConfluenceUserManager, CustomContentManager, PageManager and SpaceManager. Many more Confluence Manager service interfaces exist for programmatically customizing many aspects of Confluence, such as icons, spaces, content, content caching, user permissions, etc.

AttachmentManager

The AttachmentManager provides methods for such functionality as getting an attachment, getting all the attachments on a page, getting versions of an attachment, moving an attachment, and removing an attachment.

PageManager

The PageManager is useful for retrieving an individual Page by id, a list of Pages in a Space, renaming a Page, retrieving child pages of a Page, updating page attributes, etc.

SpaceManager

The SpaceManager provides methods to create, read, update and delete (remove) a Confluence Space, get a list of all Spaces, get various statistics about a Space (e.g. the number of blog posts, emails, comments), etc.

Example

In this example, the AttachmentManager is retrieved via the ContainerManager and then a specific Attachment obtained via it's id. Once we have the attachment, we then get the comment from the attachment. We can re-write the comment (using the setComment method on the Attachment) or return it to use elsewhere.

AttachmentManager attachmentManager = (AttachmentManager) ContainerManager.getComponent(&amp;amp;quot;attachmentManager&amp;amp;quot;);
Attachment attach = attachmentManager.getAttachment(id);
String comment = attach.getComment();

Conclusion

In this post we discussed various key Jira and Confluence Java service interfaces/APIs that are useful to plugin developers.
Beyond Java APIs for Jira and Confluence, other Atlassian products (Bamboo, Fisheye and Crucible, Hip Chat,etc) similarly also implement and expose Java APIs for plugin developers. Also, Atlassian has an extensive series of REST APIs for application integration and plugin development. In a future post, we will discuss Atlassian REST APIs and building Atlassian REST plugins.

References

Atlassian Developer API Documentation
Jira Javadocs
Confluence Javadocs

Managing JIRA at Scale White Paper

TAGS: Atlassian Tools, Software Solutions

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Subscribe to Our Newsletter

Recent Blog Posts