Class BitpreserveFileState
- java.lang.Object
-
- dk.netarkivet.archive.webinterface.BitpreserveFileState
-
public class BitpreserveFileState extends java.lang.Object
Class encapsulating methods for handling web requests for ActiveBitPreservation.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
The logger for this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
makeCheckbox(java.lang.String command, java.lang.String... args)
Create a generic checkbox as used by processMissingRequest.static java.lang.String
presentChecksum(java.util.List<java.lang.String> csum, java.util.Locale locale)
Present a list of checksums in a human-readable form.static void
printChecksumErrorStateForReplica(javax.servlet.jsp.JspWriter out, Replica replica, java.util.Locale locale)
Print HTML formatted state for checksum errors on a given replica in a given locale.static void
printFileName(javax.servlet.jsp.JspWriter out, java.lang.String filename, int rowCount, java.util.Locale locale)
Print a table row with a file name and a checkbox to request more info.static void
printFileState(javax.servlet.jsp.JspWriter out, PreservationState fs, java.util.Locale locale)
Print a file state table for a file.static void
printMissingFileStateForReplica(javax.servlet.jsp.JspWriter out, Replica replica, java.util.Locale locale)
Print HTML formatted state for missing files on a given replica in a given locale.static void
printToggleCheckboxes(javax.servlet.jsp.JspWriter out, java.util.Locale locale, int numberOfMissingCheckboxes, int numberOfUploadableCheckboxes)
Print checkboxes for changing state for files.static PreservationState
processChecksumRequest(java.lang.StringBuilder res, javax.servlet.jsp.PageContext context)
Processes a checksum request.static java.util.Map<java.lang.String,PreservationState>
processMissingRequest(javax.servlet.jsp.PageContext context, java.lang.StringBuilder res)
Processes a missingFiles request.static java.lang.String
processUpdateRequest(javax.servlet.jsp.PageContext context)
Extract the name of the replica (parameter Constants.BITARCHIVE_NAME_PARAM) and the type of update requested (parameter Constants.UPDATE_TYPE_PARAM).
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
The logger for this class.
-
-
Method Detail
-
processUpdateRequest
public static java.lang.String processUpdateRequest(javax.servlet.jsp.PageContext context) throws ArgumentNotValid, ForwardedToErrorPage
Extract the name of the replica (parameter Constants.BITARCHIVE_NAME_PARAM) and the type of update requested (parameter Constants.UPDATE_TYPE_PARAM). The latter is set to to Constants.FIND_MISSING_FILES_OPTION if the request is to update missing files, or to Constants.CHECKSUM_OPTION if the request is to update the checksum information.- Parameters:
context
- the current JSP context- Returns:
- an I18N string telling which type of update has just been initiated.
- Throws:
ForwardedToErrorPage
- if an unknown bitarchive or update type is posted, or one of the two required parameters are missing.ArgumentNotValid
- If the context is null.
-
processMissingRequest
public static java.util.Map<java.lang.String,PreservationState> processMissingRequest(javax.servlet.jsp.PageContext context, java.lang.StringBuilder res) throws ArgumentNotValid, ForwardedToErrorPage
Processes a missingFiles request.Parameters of the form Constants.ADD_COMMAND=<bitarchive>##<filename> causes the file to be added to that bitarchive, if it is missing.
Parameters of the form Constants.GET_INFO_COMMAND=<filename> causes checksums to be computed for the file in all bitarchives and the information to be shown in the next update (notice that this information disappears when the page is next reloaded).
- Parameters:
context
- the current JSP context.res
- the result object. This is updated with result information, and expected to be printed to the resulting page.- Returns:
- A map of info gathered for files as requested.
- Throws:
ArgumentNotValid
- If the context or res is null.ForwardedToErrorPage
- if the commands have the wrong number of arguments.
-
processChecksumRequest
public static PreservationState processChecksumRequest(java.lang.StringBuilder res, javax.servlet.jsp.PageContext context) throws ArgumentNotValid
Processes a checksum request.The name of a bitarchive must always be given in parameter Constants.BITARCHIVE_NAME_PARAM.
If parameter Constants.FILENAME_PARAM is given, file info for that file will be returned, and all actions will work on that file.
If parameter Constants.FIX_ADMIN_CHECKSUM_PARAM is given, the admin data checksum will be fixed for the file.
If parameter Constants.CREDENTIALS and Constants.CHECKSUM_PARAM is given, removes and reuploads a file with that checksum in the given bitarchive, using the credentials for authorisation.
- Parameters:
res
- the result object. This is updated with result information, and expected to be printed to the resulting page.context
- the current JSP pagecontext.- Returns:
- The file preservation state for a file, if a filename is given in the request. Null otherwise.
- Throws:
ArgumentNotValid
- If the context or res is null.
-
makeCheckbox
public static java.lang.String makeCheckbox(java.lang.String command, java.lang.String... args)
Create a generic checkbox as used by processMissingRequest.- Parameters:
command
- The name of the commandargs
- Arguments to the command- Returns:
- A checkbox with the command and arguments in correct format and with HTML stuff escaped.
-
printMissingFileStateForReplica
public static void printMissingFileStateForReplica(javax.servlet.jsp.JspWriter out, Replica replica, java.util.Locale locale) throws java.io.IOException
Print HTML formatted state for missing files on a given replica in a given locale.- Parameters:
out
- The writer to write state to.replica
- The replica to write state for.locale
- The locale to write state in.- Throws:
java.io.IOException
- On IO trouble writing state to the writer.
-
printChecksumErrorStateForReplica
public static void printChecksumErrorStateForReplica(javax.servlet.jsp.JspWriter out, Replica replica, java.util.Locale locale) throws java.io.IOException
Print HTML formatted state for checksum errors on a given replica in a given locale.- Parameters:
out
- The writer to write state to.replica
- The replica to write state for.locale
- The locale to write state in.- Throws:
java.io.IOException
- On IO trouble writing state to the writer.
-
printFileName
public static void printFileName(javax.servlet.jsp.JspWriter out, java.lang.String filename, int rowCount, java.util.Locale locale) throws java.io.IOException
Print a table row with a file name and a checkbox to request more info.- Parameters:
out
- The stream to print to.filename
- The name of the file.rowCount
- The rowcount, used for styling rows.locale
- The current locale for labels.- Throws:
java.io.IOException
- On trouble writing to stream.
-
printFileState
public static void printFileState(javax.servlet.jsp.JspWriter out, PreservationState fs, java.util.Locale locale) throws java.io.IOException
Print a file state table for a file. This will present the state of the file in admin data and all bitarchives.- Parameters:
out
- The stream to print to.fs
- The file state for the file.locale
- The locale to print labels in.- Throws:
java.io.IOException
- On trouble printing to a stream.
-
printToggleCheckboxes
public static void printToggleCheckboxes(javax.servlet.jsp.JspWriter out, java.util.Locale locale, int numberOfMissingCheckboxes, int numberOfUploadableCheckboxes) throws java.io.IOException
Print checkboxes for changing state for files. This will print two checkboxes for changing a number of checkboxes, one for getting more info, one for reestablishing missing files. This method assumes the file toggleCheckboxes.js to be available in the directory with the page this method is called from.- Parameters:
out
- The stream to print the checkboxes to.locale
- The locale of the labels.numberOfMissingCheckboxes
- The total possible number of missing checkboxes.numberOfUploadableCheckboxes
- The total possible number of reestablish checkboxes.- Throws:
java.io.IOException
- On trouble printing the checkboxes.
-
presentChecksum
public static java.lang.String presentChecksum(java.util.List<java.lang.String> csum, java.util.Locale locale)
Present a list of checksums in a human-readable form. If size of list is 0, it returns "No checksum". If size of list is 1, it returns the one available checksum. Otherwise, it returns toString of the list.- Parameters:
csum
- List of checksum stringslocale
- The given locale.- Returns:
- String presenting the checksums.
-
-