Interface StructurePluginHelper
StructurePluginHelper is a helper component that provides a lot of helpful methods and which is extensively
used by Structure plugin itself and by Structure extensions.
As a consumer of Structure API, you can also benefit from using these methods, however, since this class is
marked @Internal, you may need to retest or recompile your code with every new minor or micro release of
the Structure API.
The methods in this class form several groups:
- Quick access to components,
- Permission and access checks,
- Web resource utilities for building pages that include Structure widget,
- Searching and filtering utilities,
- I18n tools,
- Caching and lifecycle tools,
- Miscellaneous helper methods.
-
Method Summary
Modifier and TypeMethodDescriptionvoidfilterInvisibleProjects(LongSizedIterable projects, ApplicationUser user, boolean overrideSecurity, LongCollector invisibleCollector) Used to figure out which projects are not visible to the user.JiraAuthenticationContextList<Group>getAvailableGroups(ApplicationUser user) Retrieves the security groups that the user is allowed to see.default List<Group>Retrieves the security groups that the current user is allowed to see.List<ProjectRole>Retrieves the roles that exist in the system.getCollator(ApplicationUser user) Returns a collator for strings in the user's locale.RetrievesStructureConfigurationdefault QueryRetrieves a query that limits scope to the projects enabled for Structure.CustomFieldManagerPluginEventManagerGlobalPermissionManagerdefault I18nHelpergetI18n()Retrieves i18n helper for the current user.I18nHelpergetI18n(ApplicationUser user) Retrieves i18n helper for a concrete user.IssuegetIssue(long issueId) Retrieves an instance ofIssue.IssueRetrieves an instance of issue by issue key.default StructureErrorgetIssueError(Issue issue, boolean checkEdit) Convenience method to check issue access for the current user.default StructureErrorgetIssueError(Issue issue, boolean checkEdit, boolean checkProjectEnabledForStructure) Convenience method to check issue access for the current user.getIssueError(Issue issue, boolean checkEdit, boolean checkProjectEnabledForStructure, ApplicationUser user) Checks user access to the issue for viewing or editing.default StructureErrorgetIssueError(Long issue, boolean checkEdit) Convenience method to check issue access for the current user.getIssueError(Long issue, boolean checkEdit, ApplicationUser user) Checks user access to the issue for viewing or editing.IssueManagerJqlOperandResolverJqlQueryParserJqlStringSupportReturns the current user's locale.PermissionManagerPluginAccessorProjectManagerProjectRoleManagerList<Project>Retrieves the list of projects that are visible to the current user.SearchRequestManagerSearchServiceReturns a URL prefix for 'system' static resources.getStructureComparator(ApplicationUser user) Returns comparator for sorting structures by name, according to the given user's locale.List<Project>Retrieves the list of projects that are enabled for structure and visible to the current user.TimeTrackingConfigurationApplicationUsergetUser()Retrieves the current user.UserManagerUserPreferencesManagerbooleanhasPermission(GlobalPermissionKey permission, ApplicationUser user) Checks if the given user has the given global permission.booleanhasPermission(ProjectPermissionKey permission, Issue issue, ApplicationUser user) Checks if the given user has the given project-level permission on an issue's project.booleanhasPermission(ProjectPermissionKey permission, Project project, ApplicationUser user) Checks if the given user has the given project-level permission on a project.<T> Tinstantiate(Class<T> clazz) Creates a new instance of the given class, injecting all dependencies into the constructor.default booleanisAdmin()Checks if the current user is a Jira administrator (but not necessarily "System Administrator"!).booleanisAdmin(ApplicationUser user) Checks if the given user is a Jira administrator (but not necessarily "System Administrator"!).booleanisAllowed(StructureAppPermission permission, ApplicationUser user) Checks if the given user allowed to perform the action guarded by the given permission.default booleanChecks if the current user has authenticated in the system.default booleanisAutomationAccessAllowed(ApplicationUser user) Checks if the given user is allowed to create and run generators.default booleanisCreateStructureAllowed(ApplicationUser user) Checks if the given user is allowed to create new structures.booleanisIssueEditable(Issue issue, ApplicationUser user) Checks if the issue can be edited by the given user.default booleanisManageGlobalSavedColumnsAllowed(ApplicationUser user) Checks if the given user is allowed to manage global saved columns.booleanisProjectStructuredForCurrentUser(Project project) Checks if the project is enabled for Structure and the current user can see it.default booleanChecks if the current user is allowed to work with Structure add-on.default booleanisStructureAvailableToUser(ApplicationUser user) Checks if the given user is allowed to work with Structure add-on.booleanReturns true when Structure cannot be used because it is locked, either for full restore or for system startup.default booleanisSynchronizationAllowed(ApplicationUser user) Checks if the given user is allowed to create and run synchronizers.default booleanChecks if the current user is a Jira system administrator.booleanisSystemAdmin(ApplicationUser user) Checks if the given user is a Jira system administrator.booleanisViewCreationAllowed(ApplicationUser user) Checks if the given user can create new views.booleanisViewSharingAllowed(ApplicationUser user) Checks if the given user can share views.voidmatchIssues(LongList issues, Query query, boolean collectMatching, LongCollector collector) Passes the issues through JIRA search engine and lets the caller collect either all matching or non-matching issues.voidmatchIssuesSorted(LongList issuesSorted, Query query, boolean collectMatching, LongCollector collector) Passes the issues, sorted by their IDs, through JIRA search engine to collect matching or non-matching issues.voidmatchIssuesSorted(LongList issuesSorted, Query query, boolean collectMatching, ApplicationUser user, boolean overrideSecurity, LongCollector collector) A variation ofmatchIssuesSorted(LongList, Query, boolean, LongCollector)that lets you specify the user and override security checks.voidLoads resources needed for the issue details layout.voidLoads resources needed for standard JIRA keyboard shortcuts.voidrequireLocalizedResource(String resourceKey) Requires a resource that may be localized.voidLoads resources needed for "quick edit" code to work (dialog with editing / creating an issue).voidrequireResource(String resourceKey) Marks resource as needed for loading.voidrequireResourceIfPresent(String resourceKey) Marks resource as needed for loading, if the resource exists.voidrequireResourcesForContext(String context) Loads resources associated with a contextvoidRequires all resources needed to render Structure Widget.LongArraysearchAndSortQuery(Query query) Runs search with sorting.LongArraysearchAndSortQuery(Query query, int limit) Runs search with sorting and result count limit.LongArraysearchAndSortQuery(String query) Runs JQL search with sorting.LongArraysearchQuery(Query query) Runs search.LongArraysearchQuery(String query) Runs JQL search.MessageSetvalidateQuery(ApplicationUser user, Query query) Checks if the query is valid and that the user has access to all the things mentioned in the query.
-
Method Details
-
getIssueError
@Nullable StructureError getIssueError(@Nullable Long issue, boolean checkEdit, @Nullable ApplicationUser user) Checks user access to the issue for viewing or editing. Edit check includes verifying that issue editing is not prohibited by workflow.- Parameters:
issue- issue IDcheckEdit- if true, edit permissions are required.user- user to check for- Returns:
- specific error or
nullif everything is ok
-
getIssueError
Convenience method to check issue access for the current user.- Parameters:
issue- issue IDcheckEdit- if true, edit permissions are required.- Returns:
- specific error or
nullif everything is ok - See Also:
-
getIssueError
@Contract("null, _, _, _ -> !null") @Nullable StructureError getIssueError(@Nullable Issue issue, boolean checkEdit, boolean checkProjectEnabledForStructure, @Nullable ApplicationUser user) Checks user access to the issue for viewing or editing. Edit check includes verifying that issue editing is not prohibited by workflow. Also can check if the project that the issue belongs to is enabled for Structure.- Parameters:
issue- issuecheckEdit- if true, edit permissions are requiredcheckProjectEnabledForStructure- if true, issue's project must be enabled for Structureuser- user to check for- Returns:
- specific error or
nullif everything is ok
-
getIssueError
@Contract("null, _ -> !null") @Nullable default StructureError getIssueError(@Nullable Issue issue, boolean checkEdit) Convenience method to check issue access for the current user.- Parameters:
issue- issuecheckEdit- if true, edit permissions are required- Returns:
- specific error or
nullif everything is ok - See Also:
-
getIssueError
@Contract("null, _, _ -> !null") @Nullable default StructureError getIssueError(@Nullable Issue issue, boolean checkEdit, boolean checkProjectEnabledForStructure) Convenience method to check issue access for the current user.- Parameters:
issue- issuecheckEdit- if true, edit permissions are requiredcheckProjectEnabledForStructure- if true, issue's project must be enabled for Structure- Returns:
- specific error or
nullif everything is ok - See Also:
-
isProjectStructuredForCurrentUser
boolean isProjectStructuredForCurrentUser(@Nullable Project project) Checks if the project is enabled for Structure and the current user can see it.- Parameters:
project- the project- Returns:
- true if the project is "structured" and visible to the current user
-
isStructureAvailableToUser
default boolean isStructureAvailableToUser(@Nullable ApplicationUser user) Checks if the given user is allowed to work with Structure add-on.- Returns:
- true if the given user can work with Structure
-
isStructureAvailableToCurrentUser
default boolean isStructureAvailableToCurrentUser()Checks if the current user is allowed to work with Structure add-on.- Returns:
- true if the current user can work with Structure
-
isCreateStructureAllowed
default boolean isCreateStructureAllowed(@Nullable ApplicationUser user) Checks if the given user is allowed to create new structures. -
isSynchronizationAllowed
default boolean isSynchronizationAllowed(@Nullable ApplicationUser user) Checks if the given user is allowed to create and run synchronizers. -
isAutomationAccessAllowed
default boolean isAutomationAccessAllowed(@Nullable ApplicationUser user) Checks if the given user is allowed to create and run generators. -
isManageGlobalSavedColumnsAllowed
default boolean isManageGlobalSavedColumnsAllowed(@Nullable ApplicationUser user) Checks if the given user is allowed to manage global saved columns. -
isAllowed
Checks if the given user allowed to perform the action guarded by the given permission.- See Also:
-
isAuthenticated
default boolean isAuthenticated()Checks if the current user has authenticated in the system.- Returns:
- true if the current user is not anonymous
-
isAdmin
boolean isAdmin(@Nullable ApplicationUser user) Checks if the given user is a Jira administrator (but not necessarily "System Administrator"!).- Returns:
- true if the given user is an admin.
-
isAdmin
default boolean isAdmin()Checks if the current user is a Jira administrator (but not necessarily "System Administrator"!).- Returns:
- true if the current user is an admin.
-
isSystemAdmin
boolean isSystemAdmin(@Nullable ApplicationUser user) Checks if the given user is a Jira system administrator.- Parameters:
user- the user to check- Returns:
trueif the given user is notnulland a Jira system administrator.
-
isSystemAdmin
default boolean isSystemAdmin()Checks if the current user is a Jira system administrator.- Returns:
trueif the current user is a Jira system administrator.
-
isViewCreationAllowed
boolean isViewCreationAllowed(@Nullable ApplicationUser user) Checks if the given user can create new views. -
isViewSharingAllowed
boolean isViewSharingAllowed(@Nullable ApplicationUser user) Checks if the given user can share views. -
isIssueEditable
boolean isIssueEditable(@Nullable Issue issue, @Nullable ApplicationUser user) Checks if the issue can be edited by the given user. Besides permissions, the issue may be non-editable because of workflow.- Parameters:
issue- issue in questionuser- user to make the edit- Returns:
- true if the user can now edit the issue
-
hasPermission
boolean hasPermission(@NotNull GlobalPermissionKey permission, @Nullable ApplicationUser user) Checks if the given user has the given global permission.- Parameters:
permission- global permissionuser- user in question- Returns:
- true if permission is granted
-
hasPermission
boolean hasPermission(@NotNull ProjectPermissionKey permission, @Nullable Issue issue, @Nullable ApplicationUser user) Checks if the given user has the given project-level permission on an issue's project.- Parameters:
permission- project permission fromProjectPermissionsissue- an issueuser- user in question- Returns:
- true if permission is granted
-
hasPermission
boolean hasPermission(@NotNull ProjectPermissionKey permission, @Nullable Project project, @Nullable ApplicationUser user) Checks if the given user has the given project-level permission on a project.- Parameters:
permission- project permission fromProjectPermissionsproject- a projectuser- user in question- Returns:
- true if permission is granted
-
getUser
@Nullable ApplicationUser getUser()Retrieves the current user.- Returns:
- current user
- See Also:
-
getAvailableGroups
Retrieves the security groups that the user is allowed to see. JIRA admin is allowed to see all groups. All non-admin users are allowed to see the groups they are in.- Parameters:
user- user- Returns:
- groups that the user is allowed to see
-
getAvailableGroupsForCurrentUser
Retrieves the security groups that the current user is allowed to see. JIRA admin is allowed to see all groups. All non-admin users are allowed to see the groups they are in.- Returns:
- groups that the current user is allowed to see
-
getAvailableRoles
Retrieves the roles that exist in the system. The returned list is owned by the caller and may be modified. -
getStructureProjectsForCurrentUser
Retrieves the list of projects that are enabled for structure and visible to the current user. The returned list is owned by the caller and may be modified. -
getProjectsForCurrentUser
Retrieves the list of projects that are visible to the current user. The returned list is owned by the caller and may be modified. The returned projects may not be enabled for structure. -
getAuthenticationContext
@NotNull JiraAuthenticationContext getAuthenticationContext() -
getIssueManager
@NotNull IssueManager getIssueManager() -
getPermissionManager
@NotNull PermissionManager getPermissionManager() -
getPluginAccessor
@NotNull PluginAccessor getPluginAccessor() -
getEventManager
@NotNull PluginEventManager getEventManager() -
getProjectManager
@NotNull ProjectManager getProjectManager() -
getProjectRoleManager
@NotNull ProjectRoleManager getProjectRoleManager() -
getUserManager
@NotNull UserManager getUserManager() -
getJqlStringSupport
@NotNull JqlStringSupport getJqlStringSupport() -
getJqlQueryParser
@NotNull JqlQueryParser getJqlQueryParser() -
getSearchService
@NotNull SearchService getSearchService() -
getJqlOperandResolver
@NotNull JqlOperandResolver getJqlOperandResolver() -
getSearchRequestManager
@NotNull SearchRequestManager getSearchRequestManager() -
getGlobalPermissionManager
@NotNull GlobalPermissionManager getGlobalPermissionManager() -
getTimeTrackingConfiguration
@NotNull TimeTrackingConfiguration getTimeTrackingConfiguration() -
getUserPreferencesManager
@NotNull UserPreferencesManager getUserPreferencesManager() -
getCustomFieldManager
@NotNull CustomFieldManager getCustomFieldManager() -
requireWidgetResource
void requireWidgetResource()Requires all resources needed to render Structure Widget. -
requireLocalizedResource
Requires a resource that may be localized. A localized version of the resource will have _locale suffix in its key - for example, com.almworks.jira.structure:my-resource_de
The locale of current user is used to load the resource. If such resource is missing, nothing happens.
- Parameters:
resourceKey- base resource key
-
requireResource
Marks resource as needed for loading. Must be called before a page starts being rendered. If resource is missing, JIRA logs a warning but rendering continues.- Parameters:
resourceKey- resource key
-
requireResourceIfPresent
Marks resource as needed for loading, if the resource exists. If the resource is missing, nothing happens. Must be called before a page starts being rendered.- Parameters:
resourceKey- resource key- See Also:
-
requireIssueDetailsResources
void requireIssueDetailsResources()Loads resources needed for the issue details layout. -
requireResourcesForContext
Loads resources associated with a context- Parameters:
context- context name
-
requireQuickEditResources
void requireQuickEditResources()Loads resources needed for "quick edit" code to work (dialog with editing / creating an issue). -
requireIssueShortcuts
void requireIssueShortcuts()Loads resources needed for standard JIRA keyboard shortcuts. -
getStaticResourcePrefix
String getStaticResourcePrefix()Returns a URL prefix for 'system' static resources. -
filterInvisibleProjects
void filterInvisibleProjects(@Nullable LongSizedIterable projects, @Nullable ApplicationUser user, boolean overrideSecurity, @NotNull LongCollector invisibleCollector) Used to figure out which projects are not visible to the user. The list of project IDs may contain non-existent IDs - they will also be reported as invisible.- Parameters:
projects- list of project IDsuser- the useroverrideSecurity- if true, permissions don't matter, only project existence is checkedinvisibleCollector- a collector to get the IDs of invisible projects
-
searchQuery
Runs JQL search.- Parameters:
query- JQL (empty or null string will result in empty result)- Returns:
- IDs of matching issues
- Throws:
SearchException- if search problem happenedJqlParseException- if JQL is invalid
-
searchQuery
@NotNull LongArray searchQuery(@Nullable Query query) throws SearchException Runs search.- Parameters:
query- query- Returns:
- IDs of matching issues
- Throws:
SearchException- if search problem happened
-
searchAndSortQuery
@NotNull LongArray searchAndSortQuery(@Nullable String query) throws SearchException, JqlParseException Runs JQL search with sorting.- Parameters:
query- JQL (empty or null string will result in empty result)- Returns:
- IDs of matching issues
- Throws:
SearchException- if search problem happenedJqlParseException- if JQL is invalid
-
searchAndSortQuery
@NotNull LongArray searchAndSortQuery(@Nullable Query query) throws SearchException Runs search with sorting.- Parameters:
query- query- Returns:
- IDs of matching issues
- Throws:
SearchException- if search problem happened
-
searchAndSortQuery
@NotNull LongArray searchAndSortQuery(@Nullable Query query, int limit) throws SearchException Runs search with sorting and result count limit.- Parameters:
query- querylimit- maximum number of issues in the result- Returns:
- IDs of matching issues
- Throws:
SearchException- if search problem happened
-
matchIssues
void matchIssues(@Nullable LongList issues, @Nullable Query query, boolean collectMatching, @NotNull LongCollector collector) throws SearchException Passes the issues through JIRA search engine and lets the caller collect either all matching or non-matching issues.
The implementation sorts issues and splits them up into chunks (of 100+ ids each) and creates a JQL query for each. This has proven to be a quick method of checking. However, if the number of issues is likely to be the same order of magnitude as the full result of the query, it's better to run the full query and compare result with the list.
The issues are checked to be accessible for the current user - so no need to run additional BROWSE permission checks. You can quickly check which issues among the list are visible to the user by running matchIssues() with
nullquery.If it is certain that the issue list is sorted, it's more efficient to call
matchIssuesSorted(com.almworks.integers.LongList, com.atlassian.query.Query, boolean, com.almworks.integers.LongCollector).If you need to skip checking for the user access or check access for non-current user, use {@link com.almworks.jira.structure.api.auth.StructureAuth#sudo)}.
- Parameters:
query- query to check against. If null, the issues are only checked to be visible to the user and to the Structure pluginissues- issue IDscollectMatching- if true, collector will receive the issues that match query and visible to the user; if false, collector will receive non-matching issuescollector- an instance for receiving the results. Chunks are processed in order, for each chunk the (non-)matching issues are added. No guarantees are made for the order of the results inside the same chunk.- Throws:
SearchException- if a bad thing happens
-
matchIssuesSorted
void matchIssuesSorted(@Nullable LongList issuesSorted, @Nullable Query query, boolean collectMatching, LongCollector collector) throws SearchException Passes the issues, sorted by their IDs, through JIRA search engine to collect matching or non-matching issues.
This is more efficient method than
matchIssues(com.almworks.integers.LongList, com.atlassian.query.Query, boolean, com.almworks.integers.LongCollector)if you already have IDs sorted.- Parameters:
issuesSorted- issues listquery- additional querycollectMatching- if true, collector receives matching issues, if false, collector receives non-matching issues.collector- the collector- Throws:
SearchException- if a bad thing happens- See Also:
-
matchIssuesSorted
void matchIssuesSorted(@Nullable LongList issuesSorted, @Nullable Query query, boolean collectMatching, @Nullable ApplicationUser user, boolean overrideSecurity, LongCollector collector) throws SearchException A variation ofmatchIssuesSorted(LongList, Query, boolean, LongCollector)that lets you specify the user and override security checks.- Parameters:
issuesSorted- issues listquery- additional querycollectMatching- if true, collector receives matching issues, if false, collector receives non-matching issues.user- the user that will be used to check accessoverrideSecurity- if true, user access will not be checkedcollector- the collector- Throws:
SearchException- if a bad thing happens- See Also:
-
validateQuery
@NotNull MessageSet validateQuery(ApplicationUser user, Query query) Checks if the query is valid and that the user has access to all the things mentioned in the query.- Parameters:
user- userquery- query- Returns:
- a collection of error messages
-
getConfigurationScopeQuery
@Nullable default Query getConfigurationScopeQuery()Retrieves a query that limits scope to the projects enabled for Structure. You can use that query to combine with whatever business logic query you have.- Returns:
- configuration query ("project in ...") or
nullif Structure is allowed for all projects - See Also:
-
getI18n
@NotNull I18nHelper getI18n(@Nullable ApplicationUser user) Retrieves i18n helper for a concrete user.- Parameters:
user- the user- Returns:
- i18n helper
-
getI18n
@NotNull default I18nHelper getI18n()Retrieves i18n helper for the current user. -
getStructureComparator
Returns comparator for sorting structures by name, according to the given user's locale.- Parameters:
user- the user to take locale from- Returns:
- a comparator that can be used to sort structures
-
getCollator
Returns a collator for strings in the user's locale.- Parameters:
user- the user- Returns:
- collator
-
getLocale
Returns the current user's locale. -
getCacheHelper
StructureCacheHelper getCacheHelper() -
isStructureLocked
boolean isStructureLocked()Returns true when Structure cannot be used because it is locked, either for full restore or for system startup. -
getIssue
@Nullable Issue getIssue(long issueId) Retrieves an instance ofIssue.- Parameters:
issueId- the ID of the issue- Returns:
- the issue, or null if the issue cannot be found or there is an exception getting it
-
getIssue
Retrieves an instance of issue by issue key.- Parameters:
key- issue key- Returns:
- the issue, or null if the issue cannot be found or there is an exception getting it
-
getConfiguration
RetrievesStructureConfiguration -
instantiate
Creates a new instance of the given class, injecting all dependencies into the constructor. Those dependencies may include other Structure's services or system services.- Type Parameters:
T- type parameter- Parameters:
clazz- class to be instantiated- Returns:
- created instance
-