dk.netarkivet.archive.arcrepository.bitpreservation
Class FilePreservationState

java.lang.Object
  extended by dk.netarkivet.archive.arcrepository.bitpreservation.FilePreservationState

public class FilePreservationState
extends java.lang.Object

This class collects the available bit preservation information for a file.
This information is the following:
1) admin information for the file for each bitarchive and

2) the actual upload status


Constructor Summary
FilePreservationState(java.lang.String filename, ArcRepositoryEntry admindata, java.util.Map<Replica,java.util.List<java.lang.String>> checksumMap)
          Create new instance of the preservation status for a file.
 
Method Summary
protected  boolean fileIsMissing(Replica bitarchive)
          Check if the file is missing from a bitarchive.
 java.lang.String getAdminBitarchiveState(Replica bitarchive)
          Get the status of the file in a bitarchive, according to the admin data.
 java.lang.String getAdminChecksum()
          Get the MD5 checksum stored in the admin data.
 java.util.List<java.lang.String> getBitarchiveChecksum(Replica bitarchive)
          Get the checksum of this file in a specific bitarchive.
 java.lang.String getFilename()
          Get the filename, this FilePreservationState is about.
 Replica getReferenceBitarchive()
          Returns a reference to a bitarchive that contains a version of the file with the correct checksum.
 java.lang.String getReferenceCheckSum()
          Retrieve checksum that the majority of checksum references (bitarchives+admin) agree upon.
 java.lang.String getUniqueChecksum(Replica r)
          Get a checksum that the whole bitarchive agrees upon, or else "".
 boolean isAdminCheckSumOk()
          Returns true if the checksum reported by admin data is equal to the majority checksum.
 boolean isAdminDataOk()
          Check if the admin data reflect the actual status of the archive.
 java.lang.String toString()
          Returns a human-readable representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilePreservationState

FilePreservationState(java.lang.String filename,
                      ArcRepositoryEntry admindata,
                      java.util.Map<Replica,java.util.List<java.lang.String>> checksumMap)
                throws ArgumentNotValid
Create new instance of the preservation status for a file.

Parameters:
filename - The filename to get status for
admindata - The admin data for the file
checksumMap - The map with the checksums for this file in all bitarchives
Throws:
ArgumentNotValid - if filename is null or empty string, or if admindata is null.
Method Detail

getBitarchiveChecksum

public java.util.List<java.lang.String> getBitarchiveChecksum(Replica bitarchive)
Get the checksum of this file in a specific bitarchive.

Parameters:
bitarchive - The bitarchive to get the checksum from.
Returns:
The file's checksum, if it is present in the bitarchive, or "" if it either is absent or an error occurred.

getAdminChecksum

public java.lang.String getAdminChecksum()
Get the MD5 checksum stored in the admin data.

Returns:
Checksum value as found in the admin data given at creation.

getAdminBitarchiveState

public java.lang.String getAdminBitarchiveState(Replica bitarchive)
Get the status of the file in a bitarchive, according to the admin data. This returns the status as a string for presentation purposes only. TODO Needs localisation.

Parameters:
bitarchive - The bitarchive to get status for
Returns:
Status that the admin data knows for this file in the bitarchive.

isAdminDataOk

public boolean isAdminDataOk()
Check if the admin data reflect the actual status of the archive. Admin State checking: For each bitarchive the admin state is compared to the checksum received from the bitarchive. If no checksum is received from the bitarchive the valid admin states are UPLOAD_STARTED and UPLOAD_FAILED. If a checksum is received from the bitarchive the valid admin state is UPLOAD_COMPLETED Admin checksum checking: The admin checksum must match the majority of reported checksums. Notice that a valid Admin data record does NOT imply that everything is ok. Specifically a file may be missing from a bitarchive, or the checksum of a file in a bitarchive may be wrong.

Returns:
true, if admin data match the state of the bitarchives, false otherwise

fileIsMissing

protected boolean fileIsMissing(Replica bitarchive)
Check if the file is missing from a bitarchive.

Parameters:
bitarchive - the bitarchive to check
Returns:
true if the file is missing from the bitarchive

getReferenceBitarchive

public Replica getReferenceBitarchive()
Returns a reference to a bitarchive that contains a version of the file with the correct checksum. The correct checksum is defined as the checksum that the majority of the bitarchives and admin data agree upon. If no bitarchive exists with a correct version of the file null is returned.

Returns:
the name of the reference bitarchive or null if no reference exists

getUniqueChecksum

public java.lang.String getUniqueChecksum(Replica r)
Get a checksum that the whole bitarchive agrees upon, or else "".

Parameters:
r - A replica to get checksum for this file from
Returns:
The checksum for this file in the replica, if all machines that have that file agree, otherwise "". If no checksums are found, also returns "".

getReferenceCheckSum

public java.lang.String getReferenceCheckSum()
Retrieve checksum that the majority of checksum references (bitarchives+admin) agree upon.

Returns:
the reference checksum or "" if no majority exists

isAdminCheckSumOk

public boolean isAdminCheckSumOk()
Returns true if the checksum reported by admin data is equal to the majority checksum. If no majority checksum exists true is also returned. When this method returns false it is possible to correct the admin checksum using the majority checksum - when true is returned no better checksum exists for admin data.

Returns:
true, if the checksum reported by admin data is equal to the majority checksum

toString

public java.lang.String toString()
Returns a human-readable representation of this object. Do not depend on this format for anything automated, as it may change at any time.

Overrides:
toString in class java.lang.Object
Returns:
Description of this object.

getFilename

public java.lang.String getFilename()
Get the filename, this FilePreservationState is about. Needed to get at the filename given to constructor, and allow for a better datastructure.

Returns:
the filename