Class StructureQuery
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.
- Since:
- 8.1.0 (Structure 2.4)
- Author:
- Igor Baltiyskiy
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancheckIndex(int index, Forest forest) abstract booleanChecks if the specified row matches the query against the specifiedForest.abstract LongArrayExecutes this query against the specifiedForest, returning IDs of all matching rows in the forest order.abstract IntArrayexecuteIndices(Forest forest) abstract IntIteratorexecuteIndicesUnbuffered(Forest forest) abstract LongIteratorexecuteUnbuffered(Forest forest) Executes this query against the specifiedForest, returning an iterator over all matching row IDs in the forest order.abstract Stringabstract StringReturns a string representation of this query, with all the potential "information leaks" removed, with regards to the current user.abstract MessageSetvalidate()Validates thisStructureQueryin the current authentication context.
-
Constructor Details
-
StructureQuery
public StructureQuery()
-
-
Method Details
-
validate
@NotNull public abstract MessageSet validate()Validates this
StructureQueryin the current authentication context. The following things are checked:- Whether all nested JQL constraints are valid, as per
SearchService.validateQuery(User, Query). - Whether referenced items exist and are accessible to the current user.
- Whether all nested constraints have valid arguments, as per
StructureQueryConstraint.validate(List). - Whether all saved filters (aka search requests) referenced in the nested JQL constraints don't
reference themselves through the
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.
- Returns:
- human-readable validation error messages and warnings in the current user's locale; if there are no error messages, this query has passed the validation
- See Also:
-
SearchService.validateQuery(ApplicationUser, Query)StructureQueryConstraint.validate(List)
- Whether all nested JQL constraints are valid, as per
-
getSanitizedQueryString
Returns a string representation of this query, with all the potential "information leaks" removed, with regards to the current user.- Returns:
- sanitized string representation of this query
- Since:
- 8.5.0 (Structure 2.8)
- See Also:
-
SearchService.sanitiseSearchQuery(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query)
-
execute
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:
- Only rows visible to the current user are returned.
- All JIRA searches for nested JQL constraints are executed under the current user.
- If the current user
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.- Parameters:
forest- the forest in which to search the rows- Returns:
- the list of IDs of rows matching this query in
forestin the forest order, subject to permission restrictions unless security is overridden
-
executeUnbuffered
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.- Parameters:
forest- the forest in which to search the rows- Returns:
- an iterator over matching row IDs in the forest order, subject to permission restrictions unless security is overridden
-
executeIndices
Executes this query against the specified
Forest, returningindicesof 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.- Parameters:
forest- the forest in which to search the rows- Returns:
- increasing positions of rows in
forestmatching this query
-
executeIndicesUnbuffered
Executes this query against the specified
Forest, returning an iterator overindicesof 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.- Parameters:
forest- the forest in which to search the rows- Returns:
- an iterator over increasing positions of rows in
forestmatching this query
-
checkRow
Checks if the specified row matches the query against the specified
Forest.If
rowIdisnullor the forest does not contain the row,falseis 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.- Parameters:
rowId- ID of the row to checkforest- the forest against which the row should be checked- Returns:
trueif the row matches the query, otherwisefalse
-
checkIndex
Checks if the row at the given
indexin theForestmatches the query.If
indexis out of the forest bounds,falseis 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.- Parameters:
index- index in the forestforest- the forest for which to check the row at the specified index- Returns:
trueif the row at the specified index matches the query, otherwisefalse
-
getQueryString
- Returns:
- If this query was created by
parsinga String, returns that String. Otherwise, returnsnull.
-