Community moderators have prevented the ability to post new answers.
The answer is in
public SearchRequest retrieveOrMakeSearchRequest(final String projectOrFilterId, final Map<String, Object> params) { SearchRequest sr = null; final User user = authenticationContext.getLoggedInUser(); if (projectOrFilterId.startsWith("filter-")) { Long filterId = new Long(projectOrFilterId.substring(7)); sr = searchRequestService.getFilter( new JiraServiceContextImpl(user, new SimpleErrorCollection()), filterId); if (sr != null) { params.put("searchRequest", sr); } } else if (projectOrFilterId.startsWith("project-")) { Long projectId = new Long(projectOrFilterId.substring(8)); final Project project = projectManager.getProjectObj(projectId); if (project != null) { sr = makeProjectSearchRequest(project.getKey()); params.put("project", project); } } else if(projectOrFilterId.startsWith("jql-")) { final String jql = projectOrFilterId.substring(4); sr = new SearchRequest(); if (StringUtils.isNotBlank(jql)) { final SearchService.ParseResult parseResult = searchService.parseQuery(user, jql); if (parseResult.isValid()) { sr = new SearchRequest(parseResult.getQuery()); } else { throw new IllegalArgumentException("Invalid JQL query specified for chart '" + jql + "'."); } } params.put("searchRequest", sr); } return sr; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If all you have is a name, I 'think' you can locate the underlying query with:
List<SearchRequest> sr=ComponentManager.getInstance().getSearchRequestManager().findByNameIgnoreCase("name");
Query q=sr.iterator().next().getQuery()
Then inject that into the above?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I was looking for extracting jql from a filter. It worked for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paul,
Yo have two choices, either parse a JQL query, or build your own programatically. If you've got a JQL query that you are confident doesnt need to change, parsing the query is fine, saves you doing the timeconsuming conversion to programatically building the same thing in Java:
JIRA Source code is the thing you should look through, use of grep for something like JqlClauseBuilder should pay off. As ane example you codify a query something like:
JqlClauseBuilder subjectBuilder = JqlQueryBuilder.newClauseBuilder().defaultAnd();
JqlClauseBuilder clause = builder.project("ABC").status().notIn(new String[] {"resolved"});
Query q = clause.buildQuery();
SearchResults searchResults = ComponentAccessor.getComponent(SearchService.class).search(user, q,PagerFilter.getUnlimitedFilter());
Its usually not too hard to start with a JQL expression and break it down into sub blocks, which can be mirrored through query building via
clause.and().sub().defaultOr().this().that().theother().endsub();
It certainly more verbose and time consuming to code, but can be done. Some gotchas, dont call buildQuery() more than once, it appends query content internally and wont work.
In the end, what are solving your requirement/ what you are happier maintaining will be the right approach for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andy,
Thanks for the very detailed answer. Unfortunately it does not quite answer my query.
If I pass a name of a filter to a method, how do I get the results of of running that filter, without building a new piece of JQL to be parsed. I am currently producing a piece of JQL that says:
filter = "FilterName"
and running that.
So I build that JQL via the JqlClauseBuilder, is that the best way to do this, or can I directly access the Filter somehow?
Paul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.