Question

I wrote a JIRA gadget that makes AJAX calls to JIRA REST API then uses the data; created date, resolutiondate, and status to create two separate arrays that holds data as followed:

var dateCreated;
dateCreated =[[<created>, <daily total>],...];

So, if there were two issues created on a ‘2011-1-1’ the element block of the array would be

[ [‘2011-1-1’, 2],...]

The other array is:

var statusDate;
statusDate=[[<resolutiondate>, <daily total>],...]

So, if there were two issues created on a ‘2011-1-1’ the element block of the array would be

[ [‘2011-1-1’, 2],...]

I used the ajaxOptions from within the JIRA gadget to make the AJAX calls and I was able to get the data and do array manipulation using Javascript and plot the data as total issues created and closed on a time series graph. However, some projects had more issues than the others and it took about 30 seconds to load data into charts. With JIRA is there a backend server script that I can use, that can do the array manipulations on the server side before it ports the data to the charts that are html based and loaded onto client machines? I’ve heard of Velocity templates in JIRA but I’m not sure if this is one of the solutions, plus it is so difficult to find examples on JIRA and Velocity templates.

Any help is appreciated.

Thanks in advance

Was it helpful?

Solution

Here is example of usage Velocity templates for JIRA (or your own REST service).
Make ajax call from UI to REST service and you will get html content (or other data) that you needed. HtmlPresentationHelper class used as wrapper for html data.
You can use Jira integrated tool for debugging this (or yours) REST service: REST API Browser: https://developer.atlassian.com/display/DOCS/Using+the+REST+API+Browser/
And don't forget add your Velocity templates!

@Path("/")
public class CustomRestResource
{
    private String pathToTemplate = "templates/reports/timesheet-report/";
    private String templateFileName = "view.vm";

    @GET
    @Path("someMethod")
    @AnonymousAllowed
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Response anyName(@QueryParam("param") String param)
    {
        VelocityManager vm = ComponentAccessor.getVelocityManager();
        try
        {
            return Response.ok(new HtmlPresentationHelper(
                    vm.getBody(pathToTemplate, templateFileName, prepareVelocityParams(param))
            )).build();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return Response.serverError().build();
        }
    }

    Map<String, Object> prepareVelocityParams(String x)
    {
        Map<String, Object> velocityParams = new HashMap<String, Object>();
        velocityParams.put("someParam", x);
        velocityParams.put(...);
        ...  

        return velocityParams;
    }
}

@XmlRootElement
public class HtmlPresentationHelper
{
    @XmlElement
    private String html;

    private HtmlPresentationHelper()
    {
        // for JAXB
    }

    public HtmlPresentationHelper(String html)
    {
        this.html = html;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top