Fix dspace-api module per new code style

This commit is contained in:
Tim Donohue
2018-02-14 10:53:46 -06:00
parent 8ffc97f7f9
commit 8a48f782ea
1051 changed files with 53347 additions and 63373 deletions

View File

@@ -7,6 +7,11 @@
*/
package org.dspace.checker;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.apache.log4j.Logger;
import org.dspace.checker.factory.CheckerServiceFactory;
@@ -18,34 +23,32 @@ import org.dspace.core.Context;
import org.dspace.storage.bitstore.factory.StorageServiceFactory;
import org.dspace.storage.bitstore.service.BitstreamStorageService;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.Map;
/**
* <p>
* Main class for the checksum checker tool, which calculates checksums for each
* bitstream whose ID is in the most_recent_checksum table, and compares it
* against the last calculated checksum for that bitstream.
* </p>
*
*
* @author Jim Downing
* @author Grace Carpenter
* @author Nathan Sarr
*
*
*
*
* TODO the accessor methods are currently unused - are they useful?
* TODO check for any existing resource problems
*/
public final class CheckerCommand
{
/** Usual Log4J logger. */
public final class CheckerCommand {
/**
* Usual Log4J logger.
*/
private static final Logger LOG = Logger.getLogger(CheckerCommand.class);
private Context context;
/** BitstreamInfoDAO dependency. */
/**
* BitstreamInfoDAO dependency.
*/
private MostRecentChecksumService checksumService = null;
/**
@@ -55,7 +58,9 @@ public final class CheckerCommand
private BitstreamStorageService bitstreamStorageService = null;
private ChecksumResultService checksumResultService = null;
/** start time for current process. */
/**
* start time for current process.
*/
private Date processStartDate = null;
/**
@@ -68,15 +73,17 @@ public final class CheckerCommand
*/
private ChecksumResultsCollector collector = null;
/** Report all processing */
/**
* Report all processing
*/
private boolean reportVerbose = false;
/**
* Default constructor uses DSpace plugin manager to construct dependencies.
*
* @param context Context
*/
public CheckerCommand(Context context)
{
public CheckerCommand(Context context) {
checksumService = CheckerServiceFactory.getInstance().getMostRecentChecksumService();
checksumHistoryService = CheckerServiceFactory.getInstance().getChecksumHistoryService();
bitstreamStorageService = StorageServiceFactory.getInstance().getBitstreamStorageService();
@@ -90,23 +97,22 @@ public final class CheckerCommand
* and then accepts bitstream ids from the dispatcher and checks their
* bitstreams against the db records.
* </p>
*
*
* <p>
* N.B. a valid BitstreamDispatcher must be provided using
* setBitstreamDispatcher before calling this method
* </p>
*
* @throws SQLException if database error
*/
public void process() throws SQLException {
LOG.debug("Begin Checker Processing");
if (dispatcher == null)
{
if (dispatcher == null) {
throw new IllegalStateException("No BitstreamDispatcher provided");
}
if (collector == null)
{
if (collector == null) {
collector = new ResultsLogger(processStartDate);
}
@@ -116,14 +122,12 @@ public final class CheckerCommand
Bitstream bitstream = dispatcher.next();
while (bitstream != null)
{
while (bitstream != null) {
LOG.debug("Processing bitstream id = " + bitstream.getID());
MostRecentChecksum info = checkBitstream(bitstream);
if (reportVerbose
|| !ChecksumResultCode.CHECKSUM_MATCH.equals(info.getChecksumResult().getResultCode()))
{
|| !ChecksumResultCode.CHECKSUM_MATCH.equals(info.getChecksumResult().getResultCode())) {
collector.collect(context, info);
}
@@ -134,10 +138,8 @@ public final class CheckerCommand
/**
* Check a specified bitstream.
*
* @param bitstream
* the bitstream
*
*
* @param bitstream the bitstream
* @return the information about the bitstream and its checksum data
* @throws SQLException if database error
*/
@@ -147,29 +149,22 @@ public final class CheckerCommand
// requested id was not found in bitstream
// or most_recent_checksum table
if (info == null)
{
if (info == null) {
// Note: this case should only occur if id is requested at
// command line, since ref integrity checks should
// prevent id from appearing in most_recent_checksum
// but not bitstream table, or vice versa
info = checksumService.getNonPersistedObject();
processNullInfoBitstream(info);
}
else if (!info.isToBeProcessed())
{
} else if (!info.isToBeProcessed()) {
// most_recent_checksum.to_be_processed is marked
// 'false' for this bitstream id.
// Do not do any db updates
info.setChecksumResult(getChecksumResultByCode(ChecksumResultCode.BITSTREAM_NOT_PROCESSED));
}
else if (info.getBitstream().isDeleted())
{
} else if (info.getBitstream().isDeleted()) {
// bitstream id is marked 'deleted' in bitstream table.
processDeletedBitstream(info);
}
else
{
} else {
processBitstream(info);
}
@@ -178,24 +173,18 @@ public final class CheckerCommand
/**
* Compares two checksums.
*
* @param checksumA
* the first checksum
* @param checksumB
* the second checksum
*
*
* @param checksumA the first checksum
* @param checksumB the second checksum
* @return a result code (constants defined in Util)
* @throws SQLException if database error
*/
protected ChecksumResult compareChecksums(String checksumA, String checksumB) throws SQLException {
ChecksumResult result = getChecksumResultByCode(ChecksumResultCode.CHECKSUM_NO_MATCH);
if ((checksumA == null) || (checksumB == null))
{
if ((checksumA == null) || (checksumB == null)) {
result = getChecksumResultByCode(ChecksumResultCode.CHECKSUM_PREV_NOT_FOUND);
}
else if (checksumA.equals(checksumB))
{
} else if (checksumA.equals(checksumB)) {
result = getChecksumResultByCode(ChecksumResultCode.CHECKSUM_MATCH);
}
@@ -207,9 +196,8 @@ public final class CheckerCommand
* bitstream should only be checked once afterwards it should be marked
* 'to_be_processed=false'. Note that to_be_processed must be manually
* updated in db to allow for future processing.
*
* @param info
* a deleted bitstream.
*
* @param info a deleted bitstream.
* @throws SQLException if database error
*/
protected void processDeletedBitstream(MostRecentChecksum info) throws SQLException {
@@ -225,10 +213,9 @@ public final class CheckerCommand
* Process bitstream whose ID was not found in most_recent_checksum or
* bitstream table. No updates can be done. The missing bitstream is output
* to the log file.
*
* @param info
* A not found BitStreamInfo
* TODO is this method required?
*
* @param info A not found BitStreamInfo
* TODO is this method required?
* @throws SQLException if database error
*/
protected void processNullInfoBitstream(MostRecentChecksum info) throws SQLException {
@@ -242,57 +229,50 @@ public final class CheckerCommand
* <p>
* Process general case bitstream.
* </p>
*
*
* <p>
* Note: bitstream will have timestamp indicating it was "checked", even if
* actual checksumming never took place.
* </p>
*
*
* TODO Why does bitstream have a timestamp indicating it's checked if
* checksumming doesn't occur?
*
* @param info
* BitstreamInfo to handle
* checksumming doesn't occur?
*
* @param info BitstreamInfo to handle
* @throws SQLException if database error
*/
protected void processBitstream(MostRecentChecksum info) throws SQLException {
info.setProcessStartDate(new Date());
try
{
try {
Map checksumMap = bitstreamStorageService.computeChecksum(context, info.getBitstream());
if(MapUtils.isNotEmpty(checksumMap)) {
if (MapUtils.isNotEmpty(checksumMap)) {
info.setBitstreamFound(true);
if(checksumMap.containsKey("checksum")) {
if (checksumMap.containsKey("checksum")) {
info.setCurrentChecksum(checksumMap.get("checksum").toString());
}
if(checksumMap.containsKey("checksum_algorithm")) {
if (checksumMap.containsKey("checksum_algorithm")) {
info.setChecksumAlgorithm(checksumMap.get("checksum_algorithm").toString());
}
}
// compare new checksum to previous checksum
info.setChecksumResult(compareChecksums(info.getExpectedChecksum(), info.getCurrentChecksum()));
}
catch (IOException e)
{
} catch (IOException e) {
// bitstream located, but file missing from asset store
info.setChecksumResult(getChecksumResultByCode(ChecksumResultCode.BITSTREAM_NOT_FOUND));
info.setToBeProcessed(false);
LOG.error("Error retrieving bitstream ID " + info.getBitstream().getID()
+ " from " + "asset store.", e);
}
catch (SQLException e)
{
+ " from " + "asset store.", e);
} catch (SQLException e) {
// ??this code only executes if an SQL
// exception occurs in *DSpace* code, probably
// indicating a general db problem?
info.setChecksumResult(getChecksumResultByCode(ChecksumResultCode.BITSTREAM_INFO_NOT_FOUND));
LOG.error("Error retrieving metadata for bitstream ID "
+ info.getBitstream().getID(), e);
} finally
{
+ info.getBitstream().getID(), e);
} finally {
info.setProcessEndDate(new Date());
// record new checksum and comparison result in db
@@ -307,85 +287,73 @@ public final class CheckerCommand
/**
* Get dispatcher being used by this run of the checker.
*
*
* @return the dispatcher being used by this run.
*/
public BitstreamDispatcher getDispatcher()
{
public BitstreamDispatcher getDispatcher() {
return dispatcher;
}
/**
* Set the dispatcher to be used by this run of the checker.
*
* @param dispatcher
* Dispatcher to use.
*
* @param dispatcher Dispatcher to use.
*/
public void setDispatcher(BitstreamDispatcher dispatcher)
{
public void setDispatcher(BitstreamDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
/**
* Get the collector that holds/logs the results for this process run.
*
*
* @return The ChecksumResultsCollector being used.
*/
public ChecksumResultsCollector getCollector()
{
public ChecksumResultsCollector getCollector() {
return collector;
}
/**
* Set the collector that holds/logs the results for this process run.
*
* @param collector
* the collector to be used for this run
*
* @param collector the collector to be used for this run
*/
public void setCollector(ChecksumResultsCollector collector)
{
public void setCollector(ChecksumResultsCollector collector) {
this.collector = collector;
}
/**
* Get time at which checker process began.
*
*
* @return start time
*/
public Date getProcessStartDate()
{
public Date getProcessStartDate() {
return processStartDate == null ? null : new Date(processStartDate.getTime());
}
/**
* Set time at which checker process began.
*
* @param startDate
* start time
*
* @param startDate start time
*/
public void setProcessStartDate(Date startDate)
{
public void setProcessStartDate(Date startDate) {
processStartDate = startDate == null ? null : new Date(startDate.getTime());
}
/**
* Determine if any errors are reported
*
*
* @return true if only errors reported
*/
public boolean isReportVerbose()
{
public boolean isReportVerbose() {
return reportVerbose;
}
/**
* Set report errors only
*
* @param reportVerbose
* true to report only errors in the logs.
*
* @param reportVerbose true to report only errors in the logs.
*/
public void setReportVerbose(boolean reportVerbose)
{
public void setReportVerbose(boolean reportVerbose) {
this.reportVerbose = reportVerbose;
}
}