OverviewA JIRA report can display statistical information based on all elements within JIRA - e.g. issues, projects, users, issue types, etc. The report logic collates and parses the data, which is then presented to the user as required. With JIRA 3.0, the introduction of the plugin system aims to provide a simple point of extensibility for custom features users may wish to add to JIRA. This tutorial will describe how to create a custom report within JIRA 3.0, using this plugin interface. The following articles provide further detailed information on writing a JIRA 3 plugin:
A Report Plugin Module PrimerIn order to make a custom report available within JIRA, it is necessary to create a report plugin module. As with all plugin modules, the report plugin will consist of the following components:
all contained within a single JAR file. Report LogicThe Java classes include the necessary logic to retrieve the data used in configuring and displaying the report. The module class can implement the interface com.atlassian.jira.plugin.report.Report - or it can extend com.atlassian.jira.plugin.report.impl.AbstractReport. The main methods of interest are:
Resource TemplatesThe second component consists of templates used to render the report - Velocity templates can be used here. The templates can include:
The plugin system parses the atlassian-plugin.xml file for any configuration parameters associated with the report - parameters required in order to display the report. The plugin system constructs a suitable configuration screen requesting the user to specify values for these parameters. If an Excel view template is provided, users have the ability to view and further manipulate the data through Excel. If the Excel template is provided please ensure that your report also implements the following method: public boolean isExcelViewSupported() { return true; } Other ResourcesIt is possible to include i18n property files also - so as to allow other users to easily translate the strings used in the report for different languages. The following report examples are fully internationalized and include default property files. Plugin DescriptorThe report module descriptor is the only mandatory part of the plugin. It must be called atlassian-plugin.xml and be located in the root of the JAR file. Here is a sample report module descriptor element: <!-- The "class" attribute here defines the actual report object. This is an implementation of com.atlassian.jira.plugin.report.Report. There is also an abstract implementation which may be useful at com.atlassian.jira.plugin.report.impl.AbstractReport. --> <report key="time-tracking" name="Time Tracking Report" class="com.atlassian.jira.plugin.report.impl.TimeTrackingReport"> <description key="report.timetracking.description"> This report shows the time tracking details for a specific project. </description> <!-- the label of this report, which the user will use to select it --> <label key="report.timetracking.label" /> <!-- the 'view' template is used to render the HTML result --> <resource type="velocity" name="view" location="templates/plugins/jira/reports/time-tracking-report.vm" /> <!-- The 'excel' template is used to render an Excel result. The 'Excel view' of the report will only be visible if this template exists for the plugin module --> <resource type="velocity" name="excel" location="templates/plugins/jira/reports/time-tracking-report-excel.vm" /> <!-- this is a .properties file containin the i18n keys for this report --> <resource type="i18n" name="i18n" location="com.atlassian.jira.plugins.reports.timetracking" /> <!-- the properties of this report which the user must select before running it --> <properties> <property> <key>versionId</key> <name>common.concepts.version</name> <description>report.timetracking.version.description</description> <!-- valid types are string, text, long, select, date --> <type>select</type> <!-- the values generator is a class which will generate values for this select list --> <values class="com.atlassian.jira.portal.VersionOptionalValuesGenerator"/> </property> <property> <key>sortingOrder</key> <name>report.timetracking.sortingorder</name> <description>report.timetracking.sortingorder.description</description> <type>select</type> <values class="com.atlassian.jira.portal.SortingValuesGenerator"/> </property> <property> <key>completedFilter</key> <name>report.timetracking.filter</name> <description>report.timetracking.filter.description</description> <type>select</type> <values class="com.atlassian.jira.portal.FilterValuesGenerator"/> </property> </properties> </report> In this sample, the report logic is encapsulated in the TimeTrackingReport Java class. The view template location is specified in the templates/plugins/jira/reports/time-tracking-report.vm directory. The internationalistaion property files are located at com.atlassian.jira.plugins.reports.timetracking. Following that, the parameters required to configure the report are specifed - in this case, the version, the sort order and a filter. JIRA Plugin Development KitYou can choose to develop your plugins however you wish. However, we recommend using Maven 1.0 and the JIRA Plugin Development Kit. Maven is an ant-like build tool that downloads any specified project dependencies automatically (just one of the many features). The JIRA Plugin Developement Kit consists of a number of examples (including the ones discussed here) to help developers extend JIRA through the plugin interface as easily as possible. Once the development kit has been setup, you need only run the command: maven jar to build the desired plugin. Using Maven is not a requirement - you can use ant or any other build tool, however, it will make your life a lot easier. ExamplesThe following examples detail how to extend an existing sytem report and how to create a custom report. Each example is included in the JIRA Plugin Developement Kit. When compiled, the atlassian-jira-plugin-report-example-1.0.jar file includes each report and can be copied to the JIRA lib directory in order to make the reports available within the system. Example 1 - Extending an Existing System ReportIn this example, an existing system report - 'Single Level Group By Report' - is extended to display the assignee and the last updated time of the issue. The logic and view templates within JIRA are slightly modified in order to achieve this extension. The full source of this example is included in the JIRA Plugin Developement Kit in the examples/plugin-report-sample directory - the files of interest are:
Firstly, the atlassian-plugin.xml file is created/modifed to define the new report module element: <!-- An simple example of customising an exisiting report - adding the admin and updated date of an issue to the template --> <report key="singlelevelgroupbyextended" name="Example: Group By Report Extended" class="com.atlassian.jira.plugin.report.example.singlelevelgroup.SingleLevelGroupByReport"> <description key="report.singlelevelgroupby.description">i18n description</description> <resource type="velocity" name="view" location="templates/groupreport/single-groupby-report-extended.vm" /> <resource type="i18n" name="i18n" location="com.atlassian.jira.plugin.reports.example.singlelevelgroup.singlelevelgroup_report" /> <label key="report.singlelevelgroupby.label.extended" /> <properties> <property> <key>filterid</key> <name>report.singlelevelgroupby.filterId</name> <description>report.singlelevelgroupby.filterId.description</description> <type>select</type> <values class="com.atlassian.jira.portal.SearchRequestValuesGenerator"/> </property> <property> <key>mapper</key> <name>report.singlelevelgroupby.mapper</name> <description>report.singlelevelgroupby.mapper.description</description> <type>select</type> <values class="com.atlassian.jira.issue.statistics.FilterStatisticsValuesGenerator"/> </property> </properties> </report> The report definition specifies the following information:
The logic for the report is encapsulated in the class SingleLevelGroupByReportExtended (a slightly modified version of the original SingleLevelGroupByReport class within JIRA). The view template requires a manager to correctly display the last updated time for the issue - so the class passes the OutLookDateManager OutlookDate object to the velocity template: ... try { I18nHelper i18n = new I18nBean(authenticationContext.getUser()); startingParams = EasyMap.build("action", action, "statsGroup", getOptions(request, authenticationContext.getUser(), mapper), "searchRequest", request, "mapperType", mapperName, "customFieldManager", customFieldManager, "portlet", this); startingParams.put("outlookDate", ManagerFactory.getOutlookDateManager().getOutlookDate(authenticationContext.getLocale())); return descriptor.getHtml("view", startingParams); } ... The last updated time can now appear in the correct date/time format as configured within JIRA. The report view template is also edited from the original to display the assignee and the last updated time for the issue: ...
<td>$issue.getString('assignee')</td>
<td>$outlookDate.format($issue.getTimestamp('updated'))</td>
...
Once the compiled JAR file is placed in the lib directory - the report is available from the report menu on the 'Browse Project' page. Example 2 - Issue Creation ReportIn this example, a custom report is coded to display a histogram of issues created over a specified time. The report will collate all issues created within a specific project over the specifed duration, subdivided by a configurable time interval. The full source of this example is included in the JIRA Plugin Developement Kit - the files of interest are located in the example/plugin-report-sample directory:
Firstly, the atlassian-plugin.xml file is created/modified to include the new report module element: <!-- An 'Issue Creation' Report - displays a histogram of issue create within a specifed project over a specified time --> <report key="issuecreationreport" name="Example: Issue Creation Report" class="com.atlassian.jira.plugin.report.example.creationreport.CreationReport"> <description key="report.issuecreation.description">i18n description</description> <label key="report.issuecreation.label" /> <resource type="velocity" name="view" location="templates/creationreport/issuecreation-report.vm" /> <resource type="i18n" name="i18n" location="com.atlassian.jira.plugin.reports.example.issuecreation.issuecreation_report" /> <properties> <property> <key>projectid</key> <name>report.issuecreation.projectid.name</name> <description>report.issuecreation.projectid.description</description> <type>select</type> <values class="com.atlassian.jira.portal.ProjectValuesGenerator"/> </property> <property> <key>startDate</key> <name>report.issuecreation.startdate</name> <description>report.issuecreation.startdate.description</description> <type>date</type> </property> <property> <key>endDate</key> <name>report.issuecreation.enddate</name> <description>report.issuecreation.enddate.description</description> <type>date</type> </property> <property> <key>interval</key> <name>report.issuecreation.interval</name> <description>report.issuecreation.interval.description</description> <type>long</type> <default>3</default> </property> </properties> </report> The report module element defines that the logic is encapsulated in the class CreationReport. The name and description properties and the location of the i18n files are also specified. In this case, the report requires four parameters to correctly display the data and are specified as follows:
The plugin system will construct a suitable report configuration screen - allowing the user to specify the above parameters. Report LogicThe CreationReport class retrieves the parameters as specified by the user. Next, the relevant issue counts are retrieved from the system for the specified time over the specifed time interval from the specified project. The issue counts are normalised in order to produce a balanced histogram. Finally, the relevant details are passed to the velocity template. ResourcesThe view template displays the histogram constructed from the data passed from the class CreationReport. The i18n property files are also included - allowing the text strings to be internationalised for users in different locales. The report appears within the report section on the 'Browse Project' page. Note: There is no Excel view for this report. |

Comments (10)
Nov 09, 2004
Aggelos T. Paraskevopoulos says:
Are the sample examples you are mentioning here really inside the devkit (v0.2)?...Are the sample examples you are mentioning here really inside the devkit (v0.2)? It seems that plugin-portlet-sample folder didn't made it to the jira-development-kit-0.2-src.zip file.
Nov 09, 2004
Keith says:
Yes the devkit is being updated at the moment and will include all the examples ...Yes - the devkit is being updated at the moment and will include all the examples referred to in the tutorials.
Oct 03, 2005
Thomas Peter Berntsen says:
Hi I've been looking for a builtin method from the Jira API which enables me to ...Hi
I've been looking for a built-in method from the Jira API which enables me to get a list of users belonging to a certain group but I've been unsuccessful this far.
Does anyone know if such functionality exists out of the box or do I need to eg. do a entity search instead?
Oct 04, 2005
Scott Farquhar says:
Thomas, Can you use Group.getUsers() ? Cheers, ScottThomas,
Can you use Group.getUsers() ?
Cheers,
Scott
Oct 06, 2005
Peter Roth says:
Hello, I will try to read work logs to a Jira report. My idea is to read all wor...Hello,
I will try to read work logs to a Jira report. My idea is to read all work logs for one month for one user or the complete project. At the moment we are using Jira Professional Edition, Version: 3.0.3-#75 .
I don't know if it is possible to retrieve work logs from Jira to the reporting extent.
I would appreciate some hints how to start and which API functions could be use for retrieving such data from Jira.
Thanks in advance
Peter
Oct 06, 2005
Brian Nguyen says:
Hi Peter, The best option is to download the source code fromHi Peter,
The best option is to download the source code from http://www.atlassian.com/software/jira/JIRASourceDownloads.jspa and take a look at the Developer Workload and Time Tracking Reports.
To obtain the worklogs of an issue just run the following command:
ManagerFactory.getIssueManager().getEntitiesByIssue(IssueRelationConstants.TYPE_WORKLOG, issue);
In the future it would be best to send any questions to jira-support@atlassian.com
Thanks,
Brian
Sep 12, 2006
Hank Roark says:
Is there a way to specify the properties at runtime instead of in an xml configu...Is there a way to specify the properties at runtime instead of in an xml configuration file?
Mar 07, 2007
Shannon O'Dell says:
Hello, I am trying to create a combo box in the velocity template that contains ...Hello,
I am trying to create a combo box in the velocity template that contains all the the projects. I want the user to select a project and the corresponding project report is displayed. I am just having trouble figuring out how to create the combo box using the velocity templates/ Jira API. Does anyone have any suggestions?
Thanks,
Shannon
Dec 19, 2007
Matt Doar says:
Someone on the forums noted one reason why Excel output might not appear: in t...Someone on the forums noted one reason why Excel output might not appear:
in the vm page, the table 's border properties should be "1",
not "0", in this way , we can export a excel file with lines!
http://forums.atlassian.com/message.jspa?messageID=257260662&tstart=0
Apr 25
Harry Wong says:
Hi, I'm new to developing for jira and was able to get my report to work.&...Hi,
I'm new to developing for jira and was able to get my report to work. I would like to know if there is a way to limit that only certain people or groups are allowed to use my report?
Harry