Interface ExportContext
- All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptionvoid
Ensures that the export has not been canceled.void
Report a failed export of the provided entityvoid
Report an error during an export for the provided entity and with an optionalThrowable
to logboolean
addSectionIfAbsent
(Path path, Consumer<ExportSection> exportSection) Creates asection
with the given relative path inside the export archive.void
addWarning
(com.atlassian.bitbucket.i18n.KeyedMessage message, Object entity) Report a warning during an export for the provided entityvoid
addWarning
(com.atlassian.bitbucket.i18n.KeyedMessage message, Object entity, Throwable t) Report a warning during an export for the provided entity and with an optionalThrowable
to logcom.atlassian.bitbucket.attribute.AttributeMap
Returns theAttributeMap
object for this context.<T> EntityExportMapping<T>
getEntityMapping
(MigrationEntityType<T> entityType) Returns theEntityExportMapping
of theMigrationEntityType
for this context.boolean
boolean
hasSection
(Path path) Does thisexport context
contain asection
with the given pathMethods inherited from interface com.atlassian.bitbucket.migration.ExportSection
addEntriesAsArchive, addEntry
-
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
Report a failed export of the provided entity- Parameters:
message
- the failure messageentity
- the entity for which export failed, ornull
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 optionalThrowable
to log- Parameters:
message
- the failure messageentity
- the entity for which export failed, ornull
for general failurest
- an optionalThrowable
for the error
-
addSectionIfAbsent
Creates asection
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. UsePaths.get(String, String...)
to use this method efficiently.exportSection
-consumer
that writes the contents of thesection
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 optionalThrowable
to log- Parameters:
message
- the failure messageentity
- the entity for which export failed, ornull
for general failurest
- an optionalThrowable
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 messageentity
- the entity for which export failed, ornull
for general failures
-
getAttributeMap
@Nonnull com.atlassian.bitbucket.attribute.AttributeMap getAttributeMap()Returns theAttributeMap
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
Returns theEntityExportMapping
of theMigrationEntityType
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 theMigrationEntityType
for this context
-
hasErrors
boolean hasErrors()- Returns:
- true if
addError(KeyedMessage, Object)
has been called
-
hasSection
Does thisexport context
contain asection
with the given path- Parameters:
path
- the path of the section to check for- Returns:
- true if this
export context
contain asection
with the given path, false otherwise
-