@PublicSpi
public interface JqlFunction
Functions in JQL can be used to provide values for search criteria. For example, the membersOf("myGroup") JQL function returns a list of the usernames who are members of the group "myGroup". This function can then be used in any JQL clause that operates on a list of usernames. For example, the JQL clause assignee in membersOf("myGroup") returns all issues assigned to a member of the JIRA group "myGroup". This is very powerful, as it removes the need to enumerate over all the members of the group manually.
Implementations of JQL functions need to know how to validate a FunctionOperand
(which contains their arguments), and also need to know how to produce QueryLiteral
values from that operand. They must also specify whether or not the function produces a list of values or a single
value.
The validate and getValues method take the TerminalClause
that contained the
FunctionOperand
on its left-hand side. This can be used to create advanced functionality,
such as adjusting the functions result or validation based on the clauses right-hand side value or operator.
For plugin developers wishing to write their own JQL functions - you may find it useful to extend from our
provided AbstractJqlFunction
. In addition to implementing this
interface, you must also provide an XML descriptor for your function. For an example, see JqlFunctionModuleDescriptor
.
QueryLiteral
s returned by the getValues(com.atlassian.jira.jql.query.QueryCreationContext,
com.atlassian.query.operand.FunctionOperand, com.atlassian.query.clause.TerminalClause)
method must have the operand
source of the passed in FunctionOperand
.
The function must be thread safe. Only one instance of the function is created to service all JQL queries. As a result the function may have multiple threads calling it at the same time.
The function will be executed each time a query using it is run. A query is only going to run as fast as its slowest part, thus the function must be very fast to ensure that queries run as quickly as possible. The function also needs to perform well under concurrent load.
AbstractJqlFunction
,
JqlFunctionModuleDescriptor
Modifier and Type | Method and Description |
---|---|
JiraDataType |
getDataType()
Provides the
JiraDataType that this function handles and creates values for. |
String |
getFunctionName()
The name of the function.
|
int |
getMinimumNumberOfExpectedArguments()
This method must return the number of arguments that the function expects to perform its operation correctly.
|
List<QueryLiteral> |
getValues(QueryCreationContext queryCreationContext,
FunctionOperand operand,
TerminalClause terminalClause)
Gets the unexpanded values provided by the user on input.
|
void |
init(JqlFunctionModuleDescriptor moduleDescriptor)
Initialises this pluggable function with it's module descriptor.
|
boolean |
isList()
This method should return true if the function is meant to be used with the IN or NOT IN operators, that is, if
the function should be viewed as returning a list.
|
MessageSet |
validate(ApplicationUser searcher,
FunctionOperand operand,
TerminalClause terminalClause)
Will validate the function operand's arguments and report back any errors.
|
void init(@Nonnull JqlFunctionModuleDescriptor moduleDescriptor)
moduleDescriptor
- the module descriptor; will not be null.@Nonnull MessageSet validate(ApplicationUser searcher, @Nonnull FunctionOperand operand, @Nonnull TerminalClause terminalClause)
searcher
- the user performing the searchoperand
- the operand to validateterminalClause
- the terminal clause that contains the operand@Nonnull List<QueryLiteral> getValues(@Nonnull QueryCreationContext queryCreationContext, @Nonnull FunctionOperand operand, @Nonnull TerminalClause terminalClause)
Gets the unexpanded values provided by the user on input. This is the output values that will later be transformed into index values.
For example, a function who returns all the released versions of a specified project should return QueryLiteral
s representing the ids of those versions. For correctness, always opt
to return the most specific identifier for the object; if you can return either the id (which is stored in the
index) or a string name (that would require resolving to get the index value), choose the id.
queryCreationContext
- the context of query creationoperand
- the operand to get values fromterminalClause
- the terminal clause that contains the operandboolean isList()
As a general rule, if a function is going to return more than one value then it should return true here, otherwise it should return false. This does not necessarily need to be the case. For example, it is possible for function that returns false here to return more than one value when it is run.
int getMinimumNumberOfExpectedArguments()
@Nonnull String getFunctionName()
@Nonnull JiraDataType getDataType()
JiraDataType
that this function handles and creates values for. This
allows us to infer some information about how it will interact with other elements in the system.
For example, if this returns JiraDataTypes.DATE
then we know that we can provide
values for any clauses that also specify a data type of DATE.
JiraDataTypes
Copyright © 2002-2024 Atlassian. All Rights Reserved.