@PublicApi public abstract class StructureQuery extends Object
A structure query is a condition on rows and their relationships in a Forest
, such as
rows that are children of issues satisfying JQL 'type = Epic' or
rows at the top level of the forest.
An object of class StructureQuery
lets you search for matching rows in a given Forest
.
It also lets you validate the structure query it represents, returning error messages that you can display
to the user.
This class is the API counterpart of the structure()
JQL function bundled with the Structure plugin,
along with the ability to retrieve Structure
objects from StructureManager
and
structure's Forest
from Structure
.
StructureQuery
is obtained by either parsing
the query
expressed in the StructuredJQL language, or by building it with StructureQueryBuilder
.
If you have obtained this StructureQuery
by parsing a String, you can get this string back
via getQueryString()
. Otherwise, you can use toString()
, which either returns the parsed
query string or generates a query string if this query was built.
StructureQuery
's equals()
and hashCode()
provide structural equality:
if you have a query built by StructureQueryBuilder
and a similar-looking query built by
StructureQueryParser
, they are equal, if they happen to have equal JQL constraints.
That is, if you use JqlQueryParser
instead of JqlQueryBuilder
to create JQL Query
that you put into StructureQueryBuilder
, the resulting Structure query will be equal to the
parsed one; this is due to the way Atlassian's Query.equals()
and Query.hashCode()
work.
Note: this class is not thread-safe.
StructureQueryParser
,
StructureQueryBuilder
Constructor and Description |
---|
StructureQuery() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
checkIndex(int index,
Forest forest)
|
abstract boolean |
checkRow(Long rowId,
Forest forest)
Checks if the specified row matches the query against the specified
Forest . |
abstract LongArray |
execute(Forest forest)
Executes this query against the specified
Forest , returning IDs of all matching rows
in the forest order. |
abstract IntArray |
executeIndices(Forest forest)
|
abstract IntIterator |
executeIndicesUnbuffered(Forest forest)
|
abstract LongIterator |
executeUnbuffered(Forest forest)
Executes this query against the specified
Forest , returning an iterator over all matching row IDs
in the forest order. |
abstract String |
getQueryString() |
abstract String |
getSanitizedQueryString()
Returns a string representation of this query, with all the potential "information leaks" removed,
with regards to the current user.
|
abstract MessageSet |
validate()
Validates this
StructureQuery in the current authentication context. |
@NotNull public abstract MessageSet validate()
Validates this StructureQuery
in the current authentication context. The following things are checked:
SearchService.validateQuery(User, Query).
StructureQueryConstraint.validate(List)
.structure()
JQL function.The resulting human-readable errors and warnings are reported in the returned MessageSet
.
The result of the validation is remembered, so that validation is not repeated at the execution time.
SearchService.validateQuery(ApplicationUser, Query)
,
StructureQueryConstraint.validate(List)
@NotNull public abstract String getSanitizedQueryString()
SearchService.sanitiseSearchQuery(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query)
@NotNull public abstract LongArray execute(@NotNull Forest forest)
Executes this query against the specified Forest
, returning IDs of all matching rows
in the forest order.
This method observes JIRA and Structure permissions in the following ways:
cannot use Structure
,
an empty list is returned.
Prior to execution, validation status is checked. If validate()
hasn't been called on this
object before, validation is carried out. If validation fails, returns an empty list.
If you are doing administrative tasks under a trusted account, and you need to ensure that you know
all certain rows in a forest, override security in the current authentication context
to skip validation and permission checks.
In this case, this method will not require you to call nor call itself validate()
,
and all JIRA searches for nested JQL constraints will be executed without permission checks.
forest
- the forest in which to search the rowsforest
in the forest order,
subject to permission restrictions unless security is overriddenpublic abstract LongIterator executeUnbuffered(@NotNull Forest forest)
Executes this query against the specified Forest
, returning an iterator over all matching row IDs
in the forest order.
Behaves the same as execute(Forest)
with respect to validation and permission checks.
forest
- the forest in which to search the rows@NotNull public abstract IntArray executeIndices(@NotNull Forest forest)
Executes this query against the specified Forest
, returning indices
of all matching rows in the forest order (i.e., the sequence of indices strictly increases.)
Behaves the same as execute(Forest)
with respect to validation and permission
checks.
forest
- the forest in which to search the rowsforest
matching this querypublic abstract IntIterator executeIndicesUnbuffered(@NotNull Forest forest)
Executes this query against the specified Forest
, returning an iterator over indices
of all matching rows in the forest order (i.e., iterator values strictly increase.)
Behaves the same as execute(Forest)
with respect to validation and permission
checks.
forest
- the forest in which to search the rowsforest
matching this querypublic abstract boolean checkRow(Long rowId, @NotNull Forest forest)
Checks if the specified row matches the query against the specified Forest
.
If rowId
is null
or the forest does not contain the row, false
is returned.
Because of possible implementation optimizations, it's better to use this method rather than calling
execute(Forest)
and checking if the row ID is contained in the result.
Behaves the same as execute(Forest)
with respect to validation and permission checks.
rowId
- ID of the row to checkforest
- the forest against which the row should be checkedtrue
if the row matches the query, otherwise false
public abstract boolean checkIndex(int index, Forest forest)
Checks if the row at the given index
in the Forest
matches the query.
If index
is out of the forest bounds, false
is returned.
Because of possible implementation optimizations, it's better to use this method rather than calling
executeIndices(com.almworks.jira.structure.api.forest.raw.Forest)
and checking if the index is contained in the result.
Behaves the same as execute(Forest)
with respect to validation and permission checks.
index
- index in the forestforest
- the forest for which to check the row at the specified indextrue
if the row at the specified index matches the query, otherwise false
Copyright © 2024 Tempo Software. All Rights Reserved.