我正在尝试使用API从Jirà获取所有任务。 我找到了working code:
public class CustomJiraRestClient {
private static final String JIRA_URL = "http://jira-dev:8080";
private static final String JIRA_ADMIN_USERNAME = "admin";
private static final String JIRA_ADMIN_PASSWORD = "admin";
public static void main(String[] args) throws Exception {
// Construct the JRJC client
System.out.println(String.format("Logging in to %s with username '%s' and password '%s'", JIRA_URL, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD));
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI uri = new URI(JIRA_URL);
JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
// Invoke the JRJC Client
Promise<User> promise = client.getUserClient().getUser("admin");
User user = promise.claim();
Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("project = MYPURRJECT AND status in (Closed, Completed, Resolved) ORDER BY assignee, resolutiondate");
for (Issue issue : searchJqlPromise.claim().getIssues()) {
System.out.println(issue.getSummary());
}
// Done
System.out.println("Example complete. Now exiting.");
System.exit(0);
}
}
但有一个问题: - 仅显示前50个条目。 与通常的图形界面一样 - 一个包含50个条目的页面。 请帮帮我,我如何获得或所有记录?或者我如何指定所需的页面或项目。
我找到了方法:
searchResult.getMaxResults();
- 所有记录的数量(n)searchResult.getTotal();
每页的条目数(50)searchResult.getStartIndex();
- 第一个元素的编号(0)但我无法将它们放在任何地方使用。我可以认出它们,但它没有任何意义。
以下是我使用的软件版本:
答案 0 :(得分:2)
从快速浏览一下API文档,我会说你需要使用重载searchJql(String jql, int maxResults, int startAt)
并指定maxResults
参数。
答案 1 :(得分:0)
我使用此简单循环进行分页。
List<Issue> issues = new ArrayList<>();
SearchRestClient searchClient = restClient.getSearchClient();
Set<String> set = new HashSet<String>();
set.add("*all"); /* you can use simply null set if you dont need all values */
int start = 0;
int maxPerPage = 25; /* batch size (max 50) */
int total = 0;
do {
SearchResult result = searchClient.searchJql(JQL, maxPerPage, start, set)
.claim();
total = result.getTotal();
start += maxPerPage;
result.getIssues().iterator().forEachRemaining(issues::add);
} while (total > start );
issues
列表中的所有问题。
答案 2 :(得分:0)
我建议使用以下功能。
public List<Issue> getIssuesList(String query) {
boolean flag = false;
int start = 0, end=Constants.MAX_RESULTS_PER_PAGE, totalResults = 0;
List<Issue> issueList = new ArrayList<Issue>();
SearchResult searchResult;
do {
Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql(query,end,start, null);
searchResult = searchJqlPromise.claim();
if(flag==false) {
totalResults = searchResult.getTotal();
flag=true;
};
List<Issue> res = (List<Issue>) searchResult.getIssues();
issueList.addAll(res);
start = start + Constants.MAX_RESULTS_PER_PAGE;
totalResults -= Constants.MAX_RESULTS_PER_PAGE;
} while(totalResults>0);
return issueList;
}