1
0
Fork 0

implemented issue searching

master
Bob Carroll 2013-05-29 15:34:21 -07:00
parent db798c8880
commit 46cee16767
3 changed files with 75 additions and 1 deletions

View File

@ -11,6 +11,7 @@ jira-client depends on [Apache HttpComponents](http://hc.apache.org/) and [json-
jira-client is still under heavily development. Here's what works:
* Retrieve issues by key
* Search for issues with JQL
* Create issues
* Update issues (both system fields and custom fields)
* Transition issues to new states
@ -151,6 +152,13 @@ public class Example {
Issue subtask = newIssue.createSubtask()
.field(Field.SUMMARY, "replace lightbulb")
.execute();
/* Search for issues */
Issue.SearchResult sr = jira.searchIssues("assignee=batman");
System.out.println("Total: " + sr.total);
for (Issue i : sr.issues)
System.out.println("Result: " + i);
} catch (JiraException ex) {
System.err.println(ex.getMessage());

View File

@ -149,7 +149,7 @@ public final class Issue extends Resource {
}
/**
* Used to chain fields to an transition action.
* Used to chain fields to a transition action.
*/
public final class FluentTransition {
@ -250,6 +250,16 @@ public final class Issue extends Resource {
}
}
/**
* Issue search results structure.
*/
public static class SearchResult {
public int start = 0;
public int max = 0;
public int total = 0;
public List<Issue> issues = null;
}
private String key = null;
private Map fields = null;
@ -598,6 +608,47 @@ public final class Issue extends Resource {
return new Issue(restclient, realGet(restclient, key));
}
/**
* Search for issues with the given query.
*
* @param restclient REST client instance
* @param jql JQL statement
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public static SearchResult search(RestClient restclient, String jql)
throws JiraException {
final String j = jql;
JSON result = null;
try {
URI searchUri = restclient.buildURI(
RESOURCE_URI + "search",
new HashMap<String, String>() {{
put("jql", j);
}});
result = restclient.get(searchUri);
} catch (Exception ex) {
throw new JiraException("Failed to search issues", ex);
}
if (!(result instanceof JSONObject))
throw new JiraException("JSON payload is malformed");
SearchResult sr = new SearchResult();
Map map = (Map)result;
sr.start = Field.getInteger(map.get("startAt"));
sr.max = Field.getInteger(map.get("maxResults"));
sr.total = Field.getInteger(map.get("total"));
sr.issues = Field.getResourceArray(Issue.class, map.get("issues"), restclient);
return sr;
}
/**
* Reloads issue data from the JIRA server.
*

View File

@ -91,6 +91,21 @@ public class JiraClient {
return Issue.get(restclient, key);
}
/**
* Search for issues with the given query.
*
* @param jql JQL statement
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public Issue.SearchResult searchIssues(String jql)
throws JiraException {
return Issue.search(restclient, jql);
}
public RestClient getRestClient() {
return restclient;
}