com.atlassian.jira.plugin.jql.function.JqlFunction |
Clients of @PublicSpi
can expect
that programs compiled against a given version will remain binary compatible with later versions of the
@PublicSpi
as per each product's API policy (clients should refer to each product's API policy for
the exact guarantee -- usually binary compatibility is guaranteed at least across minor versions).
@PublicSpi
interfaces and classes are specifically designed to be implemented/extended by clients.
Hence, the guarantee of binary compatibility is different to that of @PublicApi
elements (if an element
is both @PublicApi
and @PublicSpi
, both guarantees apply).
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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Provides the
JiraDataType that this function handles and creates values for. | |||||||||||
The name of the function.
| |||||||||||
This method must return the number of arguments that the function expects to perform its operation correctly.
| |||||||||||
Gets the unexpanded values provided by the user on input. | |||||||||||
Initialises this pluggable function with it's module descriptor.
| |||||||||||
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.
| |||||||||||
Will validate the function operand's arguments and report back any errors.
|
Provides the 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 DATE
then we know that we can provide
values for any clauses that also specify a data type of DATE.
The name of the function. Multiple calls to this method must return the same result. This means that the function name cannot be internationalised with respect to the searcher.
This method must return the number of arguments that the function expects to perform its operation correctly. If the function can accept a variable number of arguments this value should be the lower limit. It is perfectly legal for a function to take no arguments and return 0 for this method.
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 creation |
---|---|
operand | the operand to get values from |
terminalClause | the terminal clause that contains the operand |
Initialises this pluggable function with it's module descriptor.
moduleDescriptor | the module descriptor; will not be null. |
---|
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. The method should return false when it is to be used with the other relational operators (e.g. =, !=, <, >, ...) that only work with single values.
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.
Will validate the function operand's arguments and report back any errors.
searcher | the user performing the search |
---|---|
operand | the operand to validate |
terminalClause | the terminal clause that contains the operand |