从Jira获得所有工作时间

时间:2016-07-28 09:56:54

标签: java jira jira-rest-api jira-rest-java-api

我想从JIRA获得所有工作时间。我在开始时尝试了这段代码:

import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.NullProgressMonitor;
import com.atlassian.jira.rest.client.domain.BasicProject;
import com.atlassian.jira.rest.client.internal.jersey.JerseyJiraRestClientFactory;
import java.net.URI;

public class JiraImpl
{
    private static final String JIRA_URL = "https://jira.atlassian.com";
    private static final String JIRA_ADMIN_USERNAME = "test";
    private static final String JIRA_ADMIN_PASSWORD = "test";

    public static void main(String[] args) throws Exception
    {
        JiraRestClient jira;
        JerseyJiraRestClientFactory clientFactory = new JerseyJiraRestClientFactory();
        jira = clientFactory.createWithBasicHttpAuthentication(new URI(JIRA_URL),
            JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
        System.out.println("Connection established to >> " + JIRA_URL);

        Iterable<BasicProject> allProjects = jira.getProjectClient().getAllProjects(new NullProgressMonitor());
    }
}

但我明白了:Caused by: com.sun.jersey.api.client.UniformInterfaceException: Client response status: 401

获得所有项目的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

获取所有项目您可以使用此ComponentAccessor.getProjectManager().getProjectObjects();这将返回按名称排序的所有项目。 链接到文档ProjectManager

REST API获取/rest/api/2/project

baseUrl + /rest/api/2/project
  

返回当前登录时可见的所有项目   用户。如果没有用户登录,则返回该项目列表   在使用匿名访问时可见。

Api docs LINK