Interface ExportContext

All Superinterfaces:
ExportSection

public interface ExportContext extends ExportSection
Represents the context for the current export job. An Exporter that wishes to make state available for the lifetime of an export will use the facilities provided by this class such as getAttributeMap() and getEntityMapping(MigrationEntityType). This class also provides a facility for storing error and warning messages that an Exporter may raise during the export process.
Since:
5.13
  • Method Details

    • abortIfCanceled

      void abortIfCanceled()
      Ensures that the export has not been canceled. This should be called occasionally during long running operations in order to react to cancellation requests quickly. Cleanup code can be handled in a try-catch block, but the exception should be re-thrown without modifications.

      Note: Exporter.onEnd(ExportContext) will always be called, even if this method throws an exception. Additional cleanup can be done there as well.

      Example:

       try {
           context.abortIfCanceled();
       } catch (Exception e) {
           // cleanup code
           throw e;
       }
       
      Throws:
      CanceledMigrationException - if the job for this context has been canceled
    • addError

      void addError(@Nonnull com.atlassian.bitbucket.i18n.KeyedMessage message, @Nullable Object entity)
      Report a failed export of the provided entity
      Parameters:
      message - the failure message
      entity - the entity for which export failed, or null for general failures
    • addError

      void addError(@Nonnull com.atlassian.bitbucket.i18n.KeyedMessage message, @Nullable Object entity, @Nullable Throwable t)
      Report an error during an export for the provided entity and with an optional Throwable to log
      Parameters:
      message - the failure message
      entity - the entity for which export failed, or null for general failures
      t - an optional Throwable for the error
    • addSectionIfAbsent

      boolean addSectionIfAbsent(@Nonnull Path path, @Nonnull Consumer<ExportSection> exportSection)
      Creates a section with the given relative path inside the export archive. If a section with this name has already been added in the export, it will not be added.
      Parameters:
      path - a path relative to the export root directory specific to the caller, inside the export archive. Use Paths.get(String, String...) to use this method efficiently.
      exportSection - consumer that writes the contents of the section relative to the section path
      Returns:
      true if the section did not exist and has been created as a result of this call, false otherwise
    • addWarning

      void addWarning(@Nonnull com.atlassian.bitbucket.i18n.KeyedMessage message, @Nullable Object entity, @Nullable Throwable t)
      Report a warning during an export for the provided entity and with an optional Throwable to log
      Parameters:
      message - the failure message
      entity - the entity for which export failed, or null for general failures
      t - an optional Throwable for the warning
    • addWarning

      void addWarning(@Nonnull com.atlassian.bitbucket.i18n.KeyedMessage message, @Nullable Object entity)
      Report a warning during an export for the provided entity
      Parameters:
      message - the failure message
      entity - the entity for which export failed, or null for general failures
    • getAttributeMap

      @Nonnull com.atlassian.bitbucket.attribute.AttributeMap getAttributeMap()
      Returns the AttributeMap object for this context. This allows storage of attributes associated with this context for the lifetime of this context.
      Returns:
      the AttributeMap object for this context
      See Also:
      • AttributeMap
    • getEntityMapping

      @Nonnull <T> EntityExportMapping<T> getEntityMapping(@Nonnull MigrationEntityType<T> entityType)
      Returns the EntityExportMapping of the MigrationEntityType for this context. If the mapping does not exist for the type, it'll be created.
      Type Parameters:
      T - Type of the IDs in the mapping
      Parameters:
      entityType - Entity type that this mapping should map, e.g. Repository or Project
      Returns:
      The EntityExportMapping of the MigrationEntityType for this context
    • hasErrors

      boolean hasErrors()
      Returns:
      true if addError(KeyedMessage, Object) has been called
    • hasSection

      boolean hasSection(@Nonnull Path path)
      Does this export context contain a section with the given path
      Parameters:
      path - the path of the section to check for
      Returns:
      true if this export context contain a section with the given path, false otherwise