Searching issues

Searching an issue is another important operation in JIRA. As you would expect, JRJC provides a SearchRestClient to do this.

Getting ready

Create a JIRA REST client as mentioned in the Writing Java client for REST API recipe.

How to do it...

Similar to other REST clients, you can retrieve the SearchRestClient from JiraRestClient using a getter method, as shown below:

SearchRestClientsearchClient = jiraRestClient.getSearchClient(); 

SearchRestClient uses JIRA Query Language (JQL) to search for issues in JIRA. If you already know JQL, you can search for the issues using the searchJql method, as shown below:

Promise<SearchResult> result = searchClient.searchJql("project = DEMO"); 

We can then iterate on the search results and retrieve the field values, as we have seen in the Working with issues recipe:

SearchResultresultObject = result.get(); 
Iterable<Issue> issues = resultObject.getIssues(); 
for (Issue issue : issues) { 
    System.out.println("Got issue:"+issue.getKey()); 
} 

It is also possible to implement paging by passing maxResults and startAt parameters, along with the set of field names that we want to retrieve:

Set<String> fields = new HashSet<String>(); 
fields.add("*all"); 
Promise<SearchResult> 
result = searchClient.searchJql("project = DEMO", 1, 0, fields); 

The above example retrieves the first issue but we can adjust the maxResults and startAt parameters, as needed. For fields, we can specify *all for all fields or *navigable (which is the default value, used when null is given) which will cause only navigable fields to be included in the result. To ignore a specific field, you can use "-" before the field's name. Note that the following fields are required: summary, issuetype, created, updated, project, and status.

SearchRestClient also exposes a method to retrieve the favorite filters as shown below:

Promise<Iterable<Filter>> 
filters = searchClient.getFavouriteFilters(); 
Iterable<Filter>filterList = filters.get(); 
for (Filter filter : filterList) { 
    System.out.println("Got filter:" 
    + filter.getName() 
    + " with JQL:" 
    + filter.getJql()); 
} 

It is also possible to get a filter by id or URI using the getFilter method.

From a filter, we can get JQL using the getJql method and use it for searching, as we detailed earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.106