Hey everyone,
I’m trying to make a new chart gadget for Jira with jfreechart. I need some help figuring out how to get all the issues of a certain type for my chart. Does anyone know how to do this in Java?
Also, I want to use jQuery, but I’m not sure how to get the current user’s info. How can I grab the user object for the person who’s logged in right now?
I’m pretty new to Jira development, so any tips or code examples would be super helpful. Thanks in advance!
public class IssueTypeChart {
private String issueType;
private User currentUser;
public void fetchIssues() {
// How to get issues of specific type?
}
public void getCurrentUser() {
// How to get logged-in user?
}
public void createChart() {
// Use jfreechart here
}
}
hey there! i’ve done some jira dev work before. for getting issues by type, try using the IssueService. it’s easier than IssueManager imo. something like:
IssueService.IssueResult result = issueService.getIssue(user, issueKey);
for user stuff, the UserManager is ur friend:
UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser user = userManager.getUser(username);
hope that helps! lmk if u need anything else
As someone who’s worked on Jira customizations, I can share some insights. For fetching issues of a specific type, you’ll want to use the JQL (Jira Query Language) with the IssueManager. Something like:
JqlQueryBuilder.newBuilder().where().issueType(issueType).buildQuery()
Then use IssueManager to execute this query.
For getting the current user, in a Java context, you can use ComponentAccessor:
User currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
If you’re using jQuery on the client side, you might need to set up a REST endpoint to fetch user info.
For charting, JFreeChart is powerful but has a steep learning curve. Consider using a more modern library like Chart.js if you have flexibility.
Remember to handle permissions carefully - not all users should be able to see all issues. Good luck with your project!
Having worked on similar Jira projects, I can offer some advice. For issue retrieval, consider using the SearchService instead of IssueManager. It’s more efficient for complex queries. Here’s a basic example:
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);
SearchResults results = searchService.search(user, jqlQueryObj, PagerFilter.getUnlimitedFilter());
Regarding user information, if you’re developing a plugin, you can access the current user through the PluginSettingsFactory:
User user = authenticationContext.getLoggedInUser();
For charting, while JFreeChart works, you might find Highcharts more user-friendly and visually appealing for Jira. It integrates well with the Atlassian UI.
Remember to thoroughly test your code with different user roles and permissions to ensure data security.