1
0
Fork 0

Adding field expansion support into issue search

master
Nikita Salnikov-Tarnovski 2014-12-26 11:15:27 +02:00
parent d4cfdb38d8
commit b86e92a0cb
3 changed files with 118 additions and 5 deletions

View File

@ -837,7 +837,7 @@ public class Issue extends Resource {
*/
public static SearchResult search(RestClient restclient, String jql, String includedFields, Integer maxResults)
throws JiraException {
return search(restclient, jql, includedFields, maxResults, null);
return search(restclient, jql, includedFields, null, maxResults, null);
}
/**
@ -866,12 +866,14 @@ public class Issue extends Resource {
* @param startAt if non-<code>null</code>, defines the first issue to
* return
*
* @param expandFields fields to expand when obtaining the issue
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public static SearchResult search(RestClient restclient, String jql,
String includedFields, Integer maxResults, Integer startAt)
String includedFields, String expandFields, Integer maxResults, Integer startAt)
throws JiraException {
final String j = jql;
@ -889,6 +891,9 @@ public class Issue extends Resource {
if (includedFields != null) {
queryParams.put("fields", includedFields);
}
if (expandFields != null) {
queryParams.put("expand", expandFields);
}
if (startAt != null) {
queryParams.put("startAt", String.valueOf(startAt));
}

View File

@ -198,6 +198,34 @@ public class JiraClient {
return Issue.search(restclient, jql, includedFields, null);
}
/**
* Search for issues with the given query and specify which fields to
* retrieve and expand.
*
* @param jql JQL statement
*
* @param includedFields Specifies which issue fields will be included in
* the result.
* <br>Some examples how this parameter works:
* <ul>
* <li>*all - include all fields</li>
* <li>*navigable - include just navigable fields</li>
* <li>summary,comment - include just the summary and comments</li>
* <li>*all,-comment - include all fields</li>
* </ul>
*
* @param expandFields Specifies with issue fields should be expanded
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public Issue.SearchResult searchIssues(String jql, String includedFields, String expandFields)
throws JiraException {
return Issue.search(restclient, jql, includedFields, expandFields, null, null);
}
/**
* Search for issues with the given query and specify which fields to
@ -233,8 +261,6 @@ public class JiraClient {
* results, then further calls can be made using different values for
* the <code>startAt</code> field to obtain all the results.
*
* @param restclient REST client instance
*
* @param jql JQL statement
*
* @param includedFields Specifies which issue fields will be included in
@ -260,9 +286,46 @@ public class JiraClient {
public Issue.SearchResult searchIssues(String jql, String includedFields,
Integer maxResults, Integer startAt) throws JiraException {
return Issue.search(restclient, jql, includedFields, maxResults,
return Issue.search(restclient, jql, includedFields, null, maxResults,
startAt);
}
/**
* Search for issues with the given query and specify which fields to
* retrieve. If the total results is bigger than the maximum returned
* results, then further calls can be made using different values for
* the <code>startAt</code> field to obtain all the results.
*
* @param jql JQL statement
*
* @param includedFields Specifies which issue fields will be included in
* the result.
* <br>Some examples how this parameter works:
* <ul>
* <li>*all - include all fields</li>
* <li>*navigable - include just navigable fields</li>
* <li>summary,comment - include just the summary and comments</li>
* <li>*all,-comment - include all fields</li>
* </ul>
*
* @param expandFields Specifies with issue fields should be expanded
*
* @param maxResults if non-<code>null</code>, defines the maximum number of
* results that can be returned
*
* @param startAt if non-<code>null</code>, defines the first issue to
* return
*
* @return a search result structure with results
*
* @throws JiraException when the search fails
*/
public Issue.SearchResult searchIssues(String jql, String includedFields, String expandFields,
Integer maxResults, Integer startAt) throws JiraException {
return Issue.search(restclient, jql, includedFields, null, maxResults,
startAt);
}
/**
*
* @return a list of all priorities available in the Jira installation

View File

@ -0,0 +1,45 @@
package net.rcarz.jiraclient;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class SearchTest {
@Test
public void testSimpleSearch() throws JiraException {
JiraClient jira = new JiraClient("https://jira.atlassian.com/", null);
String key = "JRA-1";
Issue.SearchResult searchResult = jira.searchIssues("key = " + key);
assertNotNull(searchResult);
assertEquals("should return exactly 1 issue", 1, searchResult.issues.size());
assertEquals("with key " + key, key, searchResult.issues.get(0).getKey());
assertEquals("and resolution Fixed", "Fixed", searchResult.issues.get(0).getResolution().getName());
}
@Test
public void testExpandingChangeLogInSearch() throws JiraException {
JiraClient jira = new JiraClient("https://jira.atlassian.com/", null);
String key = "JRA-2048";
Issue.SearchResult searchResult = jira.searchIssues("key = " + key, null, "changelog");
assertEquals("should return exactly 1 issue", 1, searchResult.issues.size());
ChangeLog changeLog = searchResult.issues.get(0).getChangeLog();
assertNotNull("returned issue should have a changeLog", changeLog);
boolean closedStatusFound = false;
for (ChangeLogEntry entry : changeLog.getEntries()) {
for (ChangeLogItem item : entry.getItems()) {
closedStatusFound |= "Closed".equals(item.getToString());
}
}
assertTrue("ChangeLog should contain Closed entry", closedStatusFound);
}
}