@PublicApi
public interface AttributeContext
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.
Modifier and Type | Method and Description |
---|---|
long |
getBaseStructureId()
Returns the ID of the structure for which the attribute is being calculated.
|
String |
getBaseUrl()
Utility method, provides the base URL of the current instance.
|
I18n |
getI18n() |
I18nHelper |
getI18nHelper()
Provides i18n helper.
|
long |
getLoadTimeMillis()
Returns the current wall time at the moment when calculation or export has started.
|
long |
getLoadTimeNanos()
Returns the current system timer value (from
System.nanoTime() ) at the moment when calculation or export has started. |
Locale |
getLocale()
Returns the current user's locale.
|
<T> T |
getObject(Object key)
Retrieves the value associated with a key.
|
TimeZone |
getTimeZone()
Returns the current user's time zone.
|
ApplicationUser |
getUser()
Returns the user performing the calculation or export.
|
void |
putObject(Object key,
Object value)
Associates an arbitrary
value with the given request. |
@Nullable ApplicationUser getUser()
Returns the user performing the calculation or export.
Attribute loaders are required to declare AttributeContextDependency.USER
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
null
if anonymousAttributeLoader.getContextDependencies()
@NotNull I18nHelper getI18nHelper()
Provides i18n helper.
Attribute loaders are required to declare AttributeContextDependency.USER_LOCALE
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
I18nHelper
instance for the current userAttributeLoader.getContextDependencies()
@NotNull Locale getLocale()
Returns the current user's locale.
Attribute loaders are required to declare AttributeContextDependency.USER_LOCALE
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
Locale
@NotNull TimeZone getTimeZone()
Returns the current user's time zone.
Attribute loaders are required to declare AttributeContextDependency.USER_TIMEZONE
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
TimeZone
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.STRUCTURE
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
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_TIME
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
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 to System
.
Attribute loaders are required to declare AttributeContextDependency.CURRENT_TIME
to use this method.
If called by an AttributeLoaderProvider
, makes the returned attribute loader non-cacheable and also requires that
the loader also declares the same dependency.
@NotNull String getBaseUrl()
void putObject(@NotNull Object key, @Nullable Object value)
Associates an arbitrary value
with the given request. The value can be retrieved by passing the same
key
to getObject(Object)
.
Please note that AttributeContext
instances are shared by all attribute loader providers
and export renderer providers from all apps. (See AttributeLoaderProvider
and ExportRendererProvider
).
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.
key
- value keyvalue
- the value; pass null
to clear the object associated with the given key
IllegalArgumentException
- if key
is read-only@Nullable <T> T getObject(@NotNull Object key)
T
- the expected type of the value.key
- value keykey
, or null
if the object is not in the contextClassCastException
- if the value is not an instance of type <T>
Copyright © 2024 Tempo Software. All Rights Reserved.