From c4cab0877cca48daa07d3ac6a56b0fb8e7284849 Mon Sep 17 00:00:00 2001 From: Kyle Chaplin Date: Tue, 8 Oct 2013 21:51:50 -0500 Subject: [PATCH] Implement maxResults parameter in search --- src/main/java/net/rcarz/jiraclient/Issue.java | 7 ++- .../java/net/rcarz/jiraclient/JiraClient.java | 51 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/rcarz/jiraclient/Issue.java b/src/main/java/net/rcarz/jiraclient/Issue.java index 2af046d..a1b9d7e 100644 --- a/src/main/java/net/rcarz/jiraclient/Issue.java +++ b/src/main/java/net/rcarz/jiraclient/Issue.java @@ -761,7 +761,7 @@ public class Issue extends Resource { */ public static SearchResult search(RestClient restclient, String jql) throws JiraException { - return search(restclient, jql, null); + return search(restclient, jql, null, null); } /** @@ -786,7 +786,7 @@ public class Issue extends Resource { * * @throws JiraException when the search fails */ - public static SearchResult search(RestClient restclient, String jql, String includedFields) + public static SearchResult search(RestClient restclient, String jql, String includedFields, Integer maxResults) throws JiraException { final String j = jql; @@ -798,6 +798,9 @@ public class Issue extends Resource { put("jql", j); } }; + if(maxResults != null){ + queryParams.put("maxResults", String.valueOf(maxResults)); + } if (includedFields != null) { queryParams.put("fields", includedFields); } diff --git a/src/main/java/net/rcarz/jiraclient/JiraClient.java b/src/main/java/net/rcarz/jiraclient/JiraClient.java index f55b35e..af8d64b 100644 --- a/src/main/java/net/rcarz/jiraclient/JiraClient.java +++ b/src/main/java/net/rcarz/jiraclient/JiraClient.java @@ -22,9 +22,11 @@ package net.rcarz.jiraclient; import java.net.URI; import java.util.ArrayList; import java.util.List; + import net.sf.json.JSON; import net.sf.json.JSONArray; import net.sf.json.JSONObject; + import org.apache.http.impl.client.DefaultHttpClient; /** @@ -124,7 +126,24 @@ public class JiraClient { public Issue.SearchResult searchIssues(String jql) throws JiraException { - return Issue.search(restclient, jql); + return Issue.search(restclient, jql, null, null); + } + + /** + * Search for issues with the given query and max results. + * + * @param jql JQL statement + * @param maxResults limit the number of results + * + * @return a search result structure with results (issues include all + * navigable fields) + * + * @throws JiraException when the search fails + */ + public Issue.SearchResult searchIssues(String jql, Integer maxResults) + throws JiraException { + + return Issue.search(restclient, jql, null, maxResults); } /** @@ -151,7 +170,35 @@ public class JiraClient { public Issue.SearchResult searchIssues(String jql, String includedFields) throws JiraException { - return Issue.search(restclient, jql, includedFields); + return Issue.search(restclient, jql, includedFields, null); + } + + /** + * Search for issues with the given query and specify which fields to + * retrieve. + * + * @param jql JQL statement + * @param maxResults limit the number of results + * + * @param includedFields Specifies which issue fields will be included in + * the result. + *
Some examples how this parameter works: + * + * + * + * @return a search result structure with results + * + * @throws JiraException when the search fails + */ + public Issue.SearchResult searchIssues(String jql, String includedFields, Integer maxResults) + throws JiraException { + + return Issue.search(restclient, jql, includedFields, maxResults); } /**