Parsing a JQL query in plugins
In the previous recipe, we saw how to build a Query to search within JIRA. In this recipe, we will see searching again, but without building a Query using the APIs. We will use the JQL Query as it is written in the Issue Navigator in advanced mode and search using the same.
How to do it...
Suppose we know the query that we want to execute. Let us assume it is the same we saw in the previous recipe: project = "DEMO" and assignee = currentUser()
.
The following is how we do it:
Parse the JQL query:
String jqlQuery = "project = \"DEMO\" and assignee = currentUser()"; SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);
Check if the parsed result is valid or not:
if (parseResult.isValid()){ // Carry On } else { // Log the error and exit! }
If the result is valid, get the
Query
object from theParseResult
:Query query = parseResult.getQuery()
Search for the issues and retrieve the
SearchResults
, as we have seen in the previous recipe:SearchResults...