Interface Structure
This interface lets you inspect and change properties of a structure.
Structures are named hierarchical lists of issues and other items; they are the main entities in the Structure add-on.
But Structure interface does not provide access to the hierarchy itself — that can be done via ForestService.
You typically get an instance of Structure by calling
one of the StructureManager methods. There are get... methods
to retrieve the existing structures, and StructureManager.createStructure()
method to create a new structure.
To change properties of a structure, you need to get the instance of
Structure, call some of the set... methods and then
call saveChanges(). Until you call saveChanges() the modifications
are made only to the copy of the structure in memory.
To create a new structure, call StructureManager.createStructure() to get
an empty Structure instance, call set... methods to set
properties (at least structure name must be set) and then call saveChanges().
When saveChanges is completed, the new Structure has been created and
you can use getId() to get the new structure's ID.
Note that the maximum length of a structure name is 190 (see Limits.MAX_NAME_LENGTH).
Longer names will be truncated.
Instances of classes implementing this interface have reference equality: their equals()
and hashCode() behave in the same way as Object's.
The implementations of this interface are not thread-safe. Every thread must obtain their
own copy of the Structure instance. Moreover, every time you need an
instance of Structure, you should get it from the StructureManager
because the properties might have changed or the structure might have been deleted.
- Author:
- Igor Sereda
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the description of the structure, or empty string if the description has not been set.Calculates permission level for this structure based on the current user.longgetId()Returns the ID of the structure, or0if the structure has no ID (when it's new and hasn't been saved yet).getName()Returns the name of the structure or empty string if the name has not been yet set.default ApplicationUsergetOwner()Returns the owner of the structure.Returns the user key of the owner of the structure.Returns a list of permissions for this structure.booleanReturns true if structure is archived.booleanReturns true if modification of the forest requires that the user has Edit Issue permission to the parent issue of the items being moved, added or deleted.Call this method to save the changes made withset...methods and update the database.setArchived(boolean archived) Changes the archived flag.setDescription(String description) Sets the description of the structure.setEditRequiresParentIssuePermission(boolean flag) Changes the security flag that requires the user to have Edit Issue permission on parent issues of the issues being moved, added or deleted from structure.Sets the name of the structure.default StructuresetOwner(ApplicationUser owner) Sets the owner of the structure.setOwnerUserKey(String ownerUserKey) Sets the owner of the structure.setPermissions(Collection<? extends PermissionRule> permissions) Sets the permission rules for this structure.
-
Method Details
-
getId
long getId()Returns the ID of the structure, or0if the structure has no ID (when it's new and hasn't been saved yet).- Returns:
- the ID of the structure, or 0 if it doesn't yet have an ID
-
getName
Returns the name of the structure or empty string if the name has not been yet set. -
getDescription
Returns the description of the structure, or empty string if the description has not been set. -
getOwner
@Nullable default ApplicationUser getOwner()Returns the owner of the structure.nullis returned if there's no owner, or if the owner has been removed from JIRA. -
getOwnerUserKey
Returns the user key of the owner of the structure.nullis returned if there's no owner. Note that the user is not guaranteed to exist. UsegetOwner()to retrieve only an existing user. -
getPermissions
Returns a list of permissions for this structure. User's access level is defined by applying those rules in the order they are returned from this method. The last matching rule has precedence. -
isEditRequiresParentIssuePermission
boolean isEditRequiresParentIssuePermission()Returns true if modification of the forest requires that the user has Edit Issue permission to the parent issue of the items being moved, added or deleted.
Note: currently this flag works only with parent issues. In the future, it may be extended to work with any item types that support edit permission checking.
Only the immediate parent issue is checked, higher-level ancestors are not considered.
-
isArchived
boolean isArchived()Returns true if structure is archived. -
setName
Sets the name of the structure. Although it is possible to set name to null, it is an invalid value and
saveChangeswill throw an error when called, unless a non-null name is set.To store the changed information in the database, use
saveChanges().Structure name cannot be longer than 190 characters.
- Parameters:
name- structure name- Returns:
- this structure
-
setDescription
Sets the description of the structure.
To store the changed information in the database, use
saveChanges().- Parameters:
description- structure description- Returns:
- this structure
-
setOwner
Sets the owner of the structure.
To store the changed information in the database, use
saveChanges().- Parameters:
owner- new owner- Returns:
- this structure
-
setOwnerUserKey
Sets the owner of the structure.
To store the changed information in the database, use
saveChanges().- Parameters:
ownerUserKey- new owner's user key- Returns:
- this structure
-
setPermissions
Sets the permission rules for this structure. Permission rules are evaluated in the specified order and the last matching rule defines the access level to the structure for the given user.
Structure owner and JIRA administrators always have
PermissionLevel.ADMINaccess level.To store the changed information in the database, use
saveChanges(). At this point, the specified rules are validated, andStructureExceptionis thrown if any of them fails to validate.- Parameters:
permissions- a collection of permissions, null means empty list- Returns:
- this structure
- See Also:
-
setEditRequiresParentIssuePermission
Changes the security flag that requires the user to have Edit Issue permission on parent issues of the issues being moved, added or deleted from structure.
To store the changed information in the database, use
saveChanges().- Parameters:
flag- if true, Edit Issue permission is required- Returns:
- this structure
- See Also:
-
setArchived
Changes the archived flag.
- Parameters:
archived- if true, the structure is archived- Returns:
- this structure
-
saveChanges
Call this method to save the changes made with
set...methods and update the database.Before this method is called, all changes are only stored in this instance of Structure and have no other effect. After this method has successfully executed, the changes are stored in the database and applied.
The changes are done under the current user. Current user can be changed with
StructureAuth.sudo(com.atlassian.jira.user.ApplicationUser, boolean, com.almworks.jira.structure.api.util.CallableE<R, E>). The updater must havePermissionLevel.ADMINaccess level to the structure, and be allowed to use Structure plugin inStructureConfiguration. Additionally, if this is a new structure being saved, the user must have permissions to create new structures.All security checks are bypassed if
overrideSecurityflag is set viaStructureAuth.Permission rules validation
Permission rules (set through
setPermissions(java.util.Collection)or existing if this method was not used) are validated before changing the database. If any of the rules is not valid, StructureException is thrown.- Returns:
- this structure
- Throws:
StructureException- if there's a permissions problem, if required fields (name) are not set, or if there are other problems
-
getEffectivePermission
Calculates permission level for this structure based on the current user. WhenoverrideSecurityflag is set, this method returnsADMIN. For instances representing new structures (not yet saved in the database), this method returnsNONE.- Returns:
- effective permission
-