Interface AttributeContext
- All Known Subinterfaces:
AggregateAttributeContext,AttributeLoaderContext,AttributeProviderContext,DerivedAttributeContext,ExportRenderContext,ExportRequestContext,ItemAttributeContext,PropagateAttributeContext,PropagateAttributeContext.Parent,RowAttributeContext,ScanningAttributeContext,SingleRowAttributeContext
An AttributeContext is associated with every attribute request and Structure export request. The context
contains some basic information, like the current user and JIRA base URL, and it can also contain other data
associated with the current request by Structure or other plug-ins. The current context is passed into every call
to AttributeLoaderProvider, AttributeLoader,
ExportRendererProvider, and ExportRenderer.
Please note that the context key space is shared by all apps, so we advise you to use app-specific keys (e.g. singleton objects or custom enums) to avoid conflicts.
Note that when attribute loading is performed, the context values, such as current user, require the attribute loader to declare a corresponding context dependency.
-
Method Summary
Modifier and TypeMethodDescriptionlongReturns the ID of the structure for which the attribute is being calculated.Utility method, provides the base URL of the current instance.getI18n()I18nHelperProvides i18n helper.longReturns the current wall time at the moment when calculation or export has started.longReturns the current system timer value (fromSystem.nanoTime()) at the moment when calculation or export has started.Returns the current user's locale.<T> TRetrieves the value associated with a key.Returns the current user's time zone.ApplicationUsergetUser()Returns the user performing the calculation or export.voidAssociates an arbitraryvaluewith the given request.
-
Method Details
-
getUser
@Nullable ApplicationUser getUser()Returns the user performing the calculation or export.
Attribute loaders are required to declare
AttributeContextDependency.USERto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- the logged-in user, or
nullif anonymous - See Also:
-
getI18nHelper
@NotNull I18nHelper getI18nHelper()Provides i18n helper.
Attribute loaders are required to declare
AttributeContextDependency.USER_LOCALEto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- the
I18nHelperinstance for the current user - See Also:
-
getI18n
- Returns:
- The
I18ninstance for the current user.
-
getLocale
Returns the current user's locale.
Attribute loaders are required to declare
AttributeContextDependency.USER_LOCALEto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- the current user's
Locale
-
getTimeZone
Returns the current user's time zone.
Attribute loaders are required to declare
AttributeContextDependency.USER_TIMEZONEto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- the current user's
TimeZone
-
getBaseStructureId
long getBaseStructureId()Returns the ID of the structure for which the attribute is being calculated. Returns 0 if the loading will happen on a query or a structure without an ID.
Attribute loaders are required to declare
AttributeContextDependency.STRUCTUREto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- the ID of the structure being loaded, or 0 if there's no permanent structure
-
getLoadTimeMillis
long getLoadTimeMillis()Returns the current wall time at the moment when calculation or export has started. This value will be consistently the same for all attributes. It is advised to use this value instead of
System.currentTimeMillis().Attribute loaders are required to declare
AttributeContextDependency.CURRENT_TIMEto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- wall time, fixed at the beginning of the loading process
-
getLoadTimeNanos
long getLoadTimeNanos()Returns the current system timer value (from
System.nanoTime()) at the moment when calculation or export has started. This value will be consistently the same for all attributes. It is advised to use this value instead of a call toSystem.Attribute loaders are required to declare
AttributeContextDependency.CURRENT_TIMEto use this method. If called by anAttributeLoaderProvider, makes the returned attribute loader non-cacheable and also requires that the loader also declares the same dependency.- Returns:
- system nano time counter, fixed at the beginning of the loading process
-
getBaseUrl
Utility method, provides the base URL of the current instance.- Returns:
- base URL of this Jira
-
putObject
Associates an arbitrary
valuewith the given request. The value can be retrieved by passing the samekeytogetObject(Object).Please note that
AttributeContextinstances are shared by all attribute loader providers and export renderer providers from all apps. (SeeAttributeLoaderProviderandExportRendererProvider). Therefore, we recommend you to use app-specific keys (e.g. singleton objects or custom enums) to avoid conflicts.Some system keys are read-only and cannot be changed. Only use the keys that your code owns.
- Parameters:
key- value keyvalue- the value; passnullto clear the object associated with the givenkey- Throws:
IllegalArgumentException- ifkeyis read-only
-
getObject
Retrieves the value associated with a key.- Type Parameters:
T- the expected type of the value.- Parameters:
key- value key- Returns:
- the object associated with the
key, ornullif the object is not in the context - Throws:
ClassCastException- if the value is not an instance of type<T>
-