简体   繁体   English

Atlassian JIRA小工具REST API

[英]Atlassian JIRA gadget REST API

I wrote a JIRA gadget that makes AJAX calls to JIRA REST API then uses the data; 我编写了一个JIRA小工具,该工具会先对JIRA REST API进行AJAX调用,然后再使用数据。 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”上创建了两个问题,则数组的元素块为

[ [‘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”上创建了两个问题,则数组的元素块为

[ [‘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. 我使用JIRA小工具中的ajaxOptions进行AJAX调用,并且能够使用Javascript获取数据并进行数组操作,并将数据绘制为在时序图上创建和关闭的全部问题。 However, some projects had more issues than the others and it took about 30 seconds to load data into charts. 但是,有些项目比其他项目有更多问题,将数据加载到图表中大约需要30秒。 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? 有了JIRA,我可以使用后端服务器脚本,该脚本可以在将数据移植到基于html的图表并加载到客户端计算机上的数据之前,在服务器端进行数组操作? 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. 我听说过JIRA中的Velocity模板,但是我不确定这是否是解决方案之一,而且很难找到有关JIRA和Velocity模板的示例。

Any help is appreciated. 任何帮助表示赞赏。

Thanks in advance 提前致谢

Here is example of usage Velocity templates for JIRA (or your own REST service). 这是JIRA(或您自己的REST服务)的使用速度模板的示例。
Make ajax call from UI to REST service and you will get html content (or other data) that you needed. 从UI到REST服务进行ajax调用,您将获得所需的html内容(或其他数据)。 HtmlPresentationHelper class used as wrapper for html data. HtmlPresentationHelper类用作html数据的包装。
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/ 您可以使用Jira集成工具调试此(或您的)REST服务: REST API浏览器https : //developer.atlassian.com/display/DOCS/Using+the+REST+API+Browser/
And don't forget add your Velocity templates! 并且不要忘记添加您的Velocity模板!

@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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM