com.atlassian.confluence.upgrade.upgradetask
Class AttachmentFileNameUpgradeTask

java.lang.Object
  extended by com.atlassian.confluence.upgrade.upgradetask.AttachmentFileNameUpgradeTask
All Implemented Interfaces:
UpgradeTask

public class AttachmentFileNameUpgradeTask
extends Object
implements UpgradeTask

Upgrade confluence file system based attachment storage to use new ID naming strategy for attachments [CONF-2948]


Field Summary
 String[] mangledEncodings
           
static int UPDATE_BUILD_NUMBER
           
 
Constructor Summary
AttachmentFileNameUpgradeTask()
           
 
Method Summary
 void doUpgrade()
          Upgrade the attachment files to use the new naming strategy
 String getBuildNumber()
           
 Collection<UpgradeError> getErrors()
          Return any errors that occur.
 String[] getMangledEncodings()
           
 String getShortDescription()
          A short (<50 chars) description of the upgrade action
 boolean isSearchForMissingAttachmentFiles()
           
protected  void logMissingAttachments(Collection missingAttachments)
          Report any attachments that were not upgraded successfully
protected  void processAttachments(Iterator attachmentIterator, Collection missingAttachments)
          Update attachment names on disk
protected  void processMissingAttachments(Collection missingAttachments)
          Try and fix any attachment files that were not found
protected  void processStagedUpdates()
          Process all of the staged updates
 void setAttachmentDao(AttachmentDao attachmentDao)
           
 void setBootstrap(BootstrapManager bootstrap)
           
 void setMangledEncodings(String[] mangledEncodings)
          Set the list of character encodings to use when looking for missing attachment files on disk
 void setSearchForMissingAttachmentFiles(boolean searchForMissingAttachmentFiles)
          Sets whether to try and find missing attachment files during upgrade (true by default)
 void setSettingsManager(SettingsManager settingsManager)
           
protected  void stageUpdatedAttachment(File originalAttachment, File updatedFile)
          Stage an update for later processing - used for name collision resolution
protected  boolean tryToFixFile(File attachmentDir, Attachment attachment, String nativeEncoding)
          Try and locate and update a file which may have a badly encoded file name This method will run through all the configured mangled encodings
protected  boolean tryToFixFile(File attachmentDir, Attachment attachment, String nativeEncoding, String fileSystemEncoding)
          Try to fix an attachment file by looking for a file name encoded with the specified encoding
protected  boolean updateAttachmentFile(Attachment attachment, File attachmentFile)
          Map an attachment to the new ID based naming scheme
 void validate()
          Validates that this upgrade task can be performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UPDATE_BUILD_NUMBER

public static final int UPDATE_BUILD_NUMBER
See Also:
Constant Field Values

mangledEncodings

public String[] mangledEncodings
Constructor Detail

AttachmentFileNameUpgradeTask

public AttachmentFileNameUpgradeTask()
Method Detail

isSearchForMissingAttachmentFiles

public boolean isSearchForMissingAttachmentFiles()

setSearchForMissingAttachmentFiles

public void setSearchForMissingAttachmentFiles(boolean searchForMissingAttachmentFiles)
Sets whether to try and find missing attachment files during upgrade (true by default)

Parameters:
searchForMissingAttachmentFiles -

setBootstrap

public void setBootstrap(BootstrapManager bootstrap)

getMangledEncodings

public String[] getMangledEncodings()

setMangledEncodings

public void setMangledEncodings(String[] mangledEncodings)
Set the list of character encodings to use when looking for missing attachment files on disk

Parameters:
mangledEncodings - An array of character encoding strings as used by String.getBytes()

getBuildNumber

public String getBuildNumber()
Specified by:
getBuildNumber in interface UpgradeTask
Returns:
The build number that this upgrade is applicable to

getShortDescription

public String getShortDescription()
Description copied from interface: UpgradeTask
A short (<50 chars) description of the upgrade action

Specified by:
getShortDescription in interface UpgradeTask

validate

public void validate()
Description copied from interface: UpgradeTask
Validates that this upgrade task can be performed.

Specified by:
validate in interface UpgradeTask

doUpgrade

public void doUpgrade()
               throws Exception
Upgrade the attachment files to use the new naming strategy

Specified by:
doUpgrade in interface UpgradeTask
Throws:
Exception

processAttachments

protected void processAttachments(Iterator attachmentIterator,
                                  Collection missingAttachments)
Update attachment names on disk

Parameters:
attachmentIterator - An Iterator over attachments to process
missingAttachments - A collection to hold any attachment objects which could not be matched to a file on disk

processMissingAttachments

protected void processMissingAttachments(Collection missingAttachments)
Try and fix any attachment files that were not found

Parameters:
missingAttachments -

logMissingAttachments

protected void logMissingAttachments(Collection missingAttachments)
Report any attachments that were not upgraded successfully

Parameters:
missingAttachments - Collection of missed attachments

updateAttachmentFile

protected boolean updateAttachmentFile(Attachment attachment,
                                       File attachmentFile)
Map an attachment to the new ID based naming scheme

Parameters:
attachment - The attachment to process
attachmentFile - The expected location of the attachment
Returns:
true if the rename succeeded

stageUpdatedAttachment

protected void stageUpdatedAttachment(File originalAttachment,
                                      File updatedFile)
Stage an update for later processing - used for name collision resolution

Parameters:
originalAttachment - The original attachment file
updatedFile - The file we want to rename it to

processStagedUpdates

protected void processStagedUpdates()
Process all of the staged updates


tryToFixFile

protected boolean tryToFixFile(File attachmentDir,
                               Attachment attachment,
                               String nativeEncoding)
Try and locate and update a file which may have a badly encoded file name This method will run through all the configured mangled encodings

Parameters:
attachmentDir - Root attachment directory
attachment - Attachment to fix
nativeEncoding - Encoding to use to decode the Attachment object's getFileName()
Returns:
true if a file was found and updated

tryToFixFile

protected boolean tryToFixFile(File attachmentDir,
                               Attachment attachment,
                               String nativeEncoding,
                               String fileSystemEncoding)
                        throws UnsupportedEncodingException
Try to fix an attachment file by looking for a file name encoded with the specified encoding

Parameters:
attachmentDir -
attachment -
nativeEncoding -
fileSystemEncoding - Encoding to use when looking on disk
Returns:
true if a file was found and updated
Throws:
UnsupportedEncodingException - When fileSystemEncoding is not recognised

getErrors

public Collection<UpgradeError> getErrors()
Description copied from interface: UpgradeTask
Return any errors that occur. Each entry is an UpgradeError.

Specified by:
getErrors in interface UpgradeTask
Returns:
a collection of UpgradeError objects, sometimes null.

setAttachmentDao

public void setAttachmentDao(AttachmentDao attachmentDao)

setSettingsManager

public void setSettingsManager(SettingsManager settingsManager)


Copyright © 2003-2011 Atlassian. All Rights Reserved.