Hi,
We are getting below error while running custom JQL function in ScriptRunner:
------------------------------------------------------
------------------------------------------------------
Here is the script for reference:
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.LuceneQueryBuilder
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import org.apache.lucene.search.Query
import java.text.MessageFormat
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.web.bean.PagerFilter
class IssuesMovedToProject extends AbstractScriptedJqlFunction implements JqlQueryFunction {
/**
* Modify this query as appropriate.
* See {@link java.text.MessageFormat} for details
*/
public static final String TEMPLATE_QUERY =
"project = {0}"
@Override
String getDescription() {
"Issues moved to specified project"
}
@Override
List<? extends Map> getArguments() {
[
[
description: "Target Project",
optional : false,
]
]
}
@Override
String getFunctionName() {
"issuesMovedToProject"
}
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder)
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
def query = mergeQuery(operand)
def searchService = ComponentAccessor.getComponent(SearchService.class)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
List<Issue> issues = null
def parseResult = searchService.parseQuery(user, query.getQueryString())
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.results
} else {
log.error("Invalid JQL: " + TEMPLATE_QUERY)
}
def issueManager = ComponentAccessor.issueManager
def issueList = new ArrayList<String>()
issues.each{ Issue issue ->
def allOtherKeys = issueManager.getAllIssueKeys(issue.id)?.findAll{it != issue.key}
if (allOtherKeys?.size() > 0) {
// hit, the issue had another key than the current one
issueList.add(issue.key)
}
}
def queryString = "issueKey in (" + issueList.join(",") + ")"
def actualQuery = jqlQueryParser.parseQuery(queryString)
return luceneQueryBuilder.createLuceneQuery(queryCreationContext, actualQuery.whereClause) //getting error here
}
private com.atlassian.query.Query mergeQuery(FunctionOperand operand) {
def queryStr = MessageFormat.format(TEMPLATE_QUERY, operand.args.first())
jqlQueryParser.parseQuery(queryStr)
}
}
Can you please look into it and share your thoughts?
Note: This script was working before JIRA upgrade (v8.13.24 from v7.*.*)
-DJ
Ok,
We'll start debugging :-).
First, change these lines:
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder)
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
To:
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
Because further in the code there are references to an unitialized variable.
Regards,
Jeroen
After changing these line, we get below errors now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Never mind the red lines :-), does the code run?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you:
Regards,
Jeroen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Jeroen.
Have updated code block. Please have a look.
I am getting error on below line
return luceneQueryBuilder.createLuceneQuery(queryCreationContext, actualQuery.whereClause)
-DJ
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.