Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Custom JQL - Jira 8.x compatible

Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2019

I have a series of JQLs like:

package com.onresolve.jira.groovy.jql

import com.atlassian.jira.lucenelegacy.NumberTools
import com.atlassian.jira.lucenelegacy.NumericUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.RangeQueryFactory
import com.atlassian.jira.util.MessageSetImpl
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.operand.FunctionOperand
import com.atlassian.query.operator.Operator
import org.apache.log4j.Category
import com.atlassian.jira.util.MessageSet
import com.atlassian.crowd.embedded.api.User
import com.atlassian.query.clause.TerminalClause
import com.atlassian.jira.jql.query.QueryCreationContext
import org.apache.lucene.index.Term
import org.apache.lucene.search.Query
import org.apache.lucene.search.TermQuery
import com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction
import org.apache.lucene.search.BooleanClause
import org.apache.lucene.search.BooleanQuery
import org.apache.lucene.search.Query
import org.apache.lucene.search.TermQuery
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;

 

class HasInactiveAssignee extends AbstractScriptedJqlFunction implements JqlQueryFunction{
@Override
String getDescription() {
"Function to show only the inactive users"
}

@Override
List<Map> getArguments() {
[
[
"description": "Subquery",
"optional": false,
]
]
}

@Override
String getFunctionName() {
"hasInactiveAssignee"
}

def String subquery
//@Override
MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new MessageSetImpl()
return messageSet
}

@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
//User user=ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
JiraAuthenticationContext context = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser applicationUser = context.getUser();
def booleanQuery = new BooleanQuery()
issues = getIssues(operand.args[0], applicationUser)
issues.each {Issue issue ->
try{
def active = issue.assignee.isActive()
if ( !active )
booleanQuery.add(new TermQuery(new Term("issue_id", issue.id as String)), BooleanClause.Occur.SHOULD)
}catch(NullPointerException NPE){

}
}

return booleanQuery
}
}

 

 

------

 

This is not Jira 8.x compatible - and I have added/replaced (as statted on https://confluence.atlassian.com/adminjira/lucene-upgrade-955171970.html)

 

com.atlassian.jira.index.NumberTools
com.atlassian.jira.util.LuceneNumericUtils

moved → com.atlassian.jira.lucenelegacy.NumberTools

moved → com.atlassian.jira.lucenelegacy.NumericUtils

 

But some small code tweaks are missing. Any help out there?

 

Current error:

 

2019-05-03 14:26:42,832 http-nio-6060-exec-1 ERROR npn 866x32109x2 dktr5i 77.243.XX.XX /rest/issueNav/1/issueTable [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: Could not find which method <init>() to invoke from this list:
org.apache.lucene.search.BooleanQuery#<init>(int, [Lorg.apache.lucene.search.BooleanClause;, org.apache.lucene.search.BooleanQuery$1)
private org.apache.lucene.search.BooleanQuery#<init>(int, [Lorg.apache.lucene.search.BooleanClause;)
org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method <init>() to invoke from this list:
org.apache.lucene.search.BooleanQuery#<init>(int, [Lorg.apache.lucene.search.BooleanClause;, org.apache.lucene.search.BooleanQuery$1)
private org.apache.lucene.search.BooleanQuery#<init>(int, [Lorg.apache.lucene.search.BooleanClause;)
at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:3223)
at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:3160)
at groovy.lang.MetaClassImpl.createConstructorSite(MetaClassImpl.java:3467)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:90)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238)

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Guomin Ren January 28, 2021

It is the org.apache.lucene.search.BooleanQuery class, you need .Build() method now

 

 

 

package com.onresolve.jira.groovy.jql

import com.atlassian.jira.lucenelegacy.NumberTools
import com.atlassian.jira.lucenelegacy.NumericUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.RangeQueryFactory
import com.atlassian.jira.util.MessageSetImpl
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.operand.FunctionOperand
import com.atlassian.query.operator.Operator
import org.apache.log4j.Category
import com.atlassian.jira.util.MessageSet
import com.atlassian.crowd.embedded.api.User
import com.atlassian.query.clause.TerminalClause
import com.atlassian.jira.jql.query.QueryCreationContext
import org.apache.lucene.index.Term
import org.apache.lucene.search.Query
import org.apache.lucene.search.TermQuery
import com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction
import org.apache.lucene.search.BooleanClause
import org.apache.lucene.search.BooleanQuery
import org.apache.lucene.search.Query
import org.apache.lucene.search.TermQuery
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;

 

class HasInactiveAssignee extends AbstractScriptedJqlFunction implements JqlQueryFunction{
@Override
String getDescription() {
"Function to show only the inactive users"
}

@Override
List<Map> getArguments() {
[
[
"description": "Subquery",
"optional": false,
]
]
}

@Override
String getFunctionName() {
"hasInactiveAssignee"
}

def String subquery
//@Override
MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new MessageSetImpl()
return messageSet
}

@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
//User user=ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
JiraAuthenticationContext context = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser applicationUser = context.getUser();
//def booleanQuery = new BooleanQuery()

def BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
issues = getIssues(operand.args[0], applicationUser)
issues.each {Issue issue ->
try{
def active = issue.assignee.isActive()
if ( !active )
booleanQuery.add(new TermQuery(new Term("issue_id", issue.id as String)), BooleanClause.Occur.SHOULD)
}catch(NullPointerException NPE){

}
}

//return booleanQuery

return booleanQuery.build()
}
}

TAGS
AUG Leaders

Atlassian Community Events