public interface

ExportContext

implements ExportSection
com.atlassian.bitbucket.migration.ExportContext

Class Overview

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.

Summary

Public Methods
void abortIfCanceled()
Ensures that the export has not been canceled.
void addError(KeyedMessage message, Object entity)
Report a failed export of the provided entity
void addError(KeyedMessage message, Object entity, Throwable t)
Report an error during an export for the provided entity and with an optional Throwable to log
boolean addSectionIfAbsent(Path path, Consumer<ExportSection> exportSection)
Creates a section with the given relative path inside the export archive.
void addWarning(KeyedMessage message, Object entity)
Report a warning during an export for the provided entity
void addWarning(KeyedMessage message, Object entity, Throwable t)
Report a warning during an export for the provided entity and with an optional Throwable to log
@Nonnull AttributeMap getAttributeMap()
Returns the AttributeMap object for this context.
@Nonnull <T> EntityExportMapping<T> getEntityMapping(MigrationEntityType<T> entityType)
Returns the EntityExportMapping of the MigrationEntityType for this context.
boolean hasErrors()
boolean hasSection(Path path)
Does this export context contain a section with the given path
[Expand]
Inherited Methods
From interface com.atlassian.bitbucket.migration.ExportSection

Public Methods

public 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: 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

public void addError (KeyedMessage message, 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

public void addError (KeyedMessage message, Object entity, 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

public boolean addSectionIfAbsent (Path path, 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 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

public void addWarning (KeyedMessage message, 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

public void addWarning (KeyedMessage message, Object entity, 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

@Nonnull public 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
See Also

@Nonnull public EntityExportMapping<T> getEntityMapping (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.

Parameters
entityType Entity type that this mapping should map, e.g. Repository or Project
Returns

public boolean hasErrors ()

Returns

public boolean hasSection (Path path)

Does this export context contain a section with the given path

Parameters
path the path of the section to check for
Returns