Interface AttributeContext

All Known Subinterfaces:
AggregateAttributeContext, AttributeLoaderContext, AttributeProviderContext, DerivedAttributeContext, ExportRenderContext, ExportRequestContext, ItemAttributeContext, PropagateAttributeContext, PropagateAttributeContext.Parent, RowAttributeContext, ScanningAttributeContext, SingleRowAttributeContext

@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.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the ID of the structure for which the attribute is being calculated.
    Utility method, provides the base URL of the current instance.
     
    I18nHelper
    Provides i18n helper.
    long
    Returns the current wall time at the moment when calculation or export has started.
    long
    Returns the current system timer value (from System.nanoTime()) at the moment when calculation or export has started.
    Returns the current user's locale.
    <T> T
    Retrieves the value associated with a key.
    Returns the current user's time zone.
    ApplicationUser
    Returns the user performing the calculation or export.
    void
    putObject(Object key, Object value)
    Associates an arbitrary value with the given request.
  • Method Details

    • getUser

      @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.

      Returns:
      the logged-in user, or null if anonymous
      See Also:
    • getI18nHelper

      @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.

      Returns:
      the I18nHelper instance for the current user
      See Also:
    • getI18n

      @NotNull I18n getI18n()
      Returns:
      The I18n instance for the current user.
    • getLocale

      @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.

      Returns:
      the current user's Locale
    • getTimeZone

      @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.

      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.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.

      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_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.

      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 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.

      Returns:
      system nano time counter, fixed at the beginning of the loading process
    • getBaseUrl

      @NotNull String getBaseUrl()
      Utility method, provides the base URL of the current instance.
      Returns:
      base URL of this Jira
    • putObject

      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.

      Parameters:
      key - value key
      value - the value; pass null to clear the object associated with the given key
      Throws:
      IllegalArgumentException - if key is read-only
    • getObject

      @Nullable <T> T getObject(@NotNull Object key)
      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, or null if the object is not in the context
      Throws:
      ClassCastException - if the value is not an instance of type <T>