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 TypeMethodDescriptionvoidEnsures that the export has not been canceled.voidReport a failed export of the provided entityvoidReport an error during an export for the provided entity and with an optionalThrowableto logbooleanaddSectionIfAbsent(Path path, Consumer<ExportSection> exportSection) Creates asectionwith the given relative path inside the export archive.voidaddWarning(com.atlassian.bitbucket.i18n.KeyedMessage message, Object entity) Report a warning during an export for the provided entityvoidaddWarning(com.atlassian.bitbucket.i18n.KeyedMessage message, Object entity, Throwable t) Report a warning during an export for the provided entity and with an optionalThrowableto logcom.atlassian.bitbucket.attribute.AttributeMapReturns theAttributeMapobject for this context.<T> EntityExportMapping<T>getEntityMapping(MigrationEntityType<T> entityType) Returns theEntityExportMappingof theMigrationEntityTypefor this context.booleanbooleanhasSection(Path path) Does thisexport contextcontain asectionwith 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, ornullfor 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 optionalThrowableto log- Parameters:
message- the failure messageentity- the entity for which export failed, ornullfor general failurest- an optionalThrowablefor the error
-
addSectionIfAbsent
Creates asectionwith 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-consumerthat writes the contents of thesectionrelative to the section path- Returns:
- true if the
sectiondid 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 optionalThrowableto log- Parameters:
message- the failure messageentity- the entity for which export failed, ornullfor general failurest- an optionalThrowablefor 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, ornullfor general failures
-
getAttributeMap
@Nonnull com.atlassian.bitbucket.attribute.AttributeMap getAttributeMap()Returns theAttributeMapobject for this context. This allows storage of attributes associated with this context for the lifetime of this context.- Returns:
- the
AttributeMapobject for this context - See Also:
-
AttributeMap
-
getEntityMapping
Returns theEntityExportMappingof theMigrationEntityTypefor 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
EntityExportMappingof theMigrationEntityTypefor this context
-
hasErrors
boolean hasErrors()- Returns:
- true if
addError(KeyedMessage, Object)has been called
-
hasSection
Does thisexport contextcontain asectionwith the given path- Parameters:
path- the path of the section to check for- Returns:
- true if this
export contextcontain asectionwith the given path, false otherwise
-