Merge pull request #822 from KevinVdV/DS-2396

[DS-2396] Checksum checker and bitstream.user_format_description
This commit is contained in:
Tim Donohue
2015-01-14 15:39:19 -06:00
7 changed files with 53 additions and 31 deletions

View File

@@ -8,6 +8,7 @@
package org.dspace.app.checker;
import java.io.FileNotFoundException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -32,6 +33,7 @@ import org.dspace.checker.ListDispatcher;
import org.dspace.checker.ResultsLogger;
import org.dspace.checker.ResultsPruner;
import org.dspace.checker.SimpleDispatcher;
import org.dspace.core.Context;
import org.dspace.core.Utils;
/**
@@ -78,8 +80,7 @@ public final class ChecksumChecker
* <dd>Don't prune results before running checker</dd>
* </dl>
*/
public static void main(String[] args)
{
public static void main(String[] args) throws SQLException {
// set up command line parser
CommandLineParser parser = new PosixParser();
CommandLine line = null;
@@ -230,7 +231,13 @@ public final class ChecksumChecker
checker.setProcessStartDate(processStart);
checker.setDispatcher(dispatcher);
checker.setCollector(logger);
checker.process();
Context context = new Context();
try {
checker.process(context);
} finally {
context.commit();
context.complete();
}
System.exit(0);
}

View File

@@ -17,7 +17,9 @@ import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.dspace.content.Bitstream;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager;
/**
@@ -43,9 +45,9 @@ public final class BitstreamInfoDAO extends DAOSupport
/** Query that gets bitstream information for a specified ID. */
private static final String FIND_BY_BITSTREAM_ID = "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, "
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
+ "bitstream.user_format_description, bitstream.internal_id, "
+ "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, "
+ "bitstream.name, most_recent_checksum.last_process_end_date,"
+ "bitstream.internal_id, "
+ "bitstream.checksum_algorithm, bitstream.checksum, "
+ "most_recent_checksum.last_process_end_date,"
+ "most_recent_checksum.to_be_processed "
+ "from bitstream left outer join bitstreamformatregistry on "
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id, "
@@ -226,7 +228,7 @@ public final class BitstreamInfoDAO extends DAOSupport
* @return the bitstream information needed for checksum validation. Returns
* null if bitstream info isn't found.
*/
public BitstreamInfo findByBitstreamId(int id)
public BitstreamInfo findByBitstreamId(Context context, int id)
{
Connection conn = null;
BitstreamInfo info = null;
@@ -246,14 +248,14 @@ public final class BitstreamInfoDAO extends DAOSupport
// if the bitstream is found return it
if (rs.next())
{
Bitstream bitstream = Bitstream.find(context, rs.getInt("bitstream_id"));
info = new BitstreamInfo(rs.getBoolean("deleted"), rs
.getInt("store_number"), rs.getLong("size_bytes"), rs
.getString("short_description"), rs
.getInt("bitstream_id"), rs
.getString("user_format_description"), rs
.getString("internal_id"), rs.getString("source"), rs
.getInt("bitstream_id"), bitstream.getUserFormatDescription(), rs
.getString("internal_id"), bitstream.getSource(), rs
.getString("checksum_algorithm"), rs
.getString("checksum"), rs.getString("name"), rs
.getString("checksum"), bitstream.getName(), rs
.getTimestamp("last_process_end_date"), rs
.getBoolean("to_be_processed"), new Date());
}

View File

@@ -16,6 +16,7 @@ import java.sql.SQLException;
import java.util.Date;
import org.apache.log4j.Logger;
import org.dspace.core.Context;
import org.dspace.core.Utils;
/**
@@ -93,7 +94,7 @@ public final class CheckerCommand
* setBitstreamDispatcher before calling this method
* </p>
*/
public void process()
public void process(Context context)
{
LOG.debug("Begin Checker Processing");
@@ -116,7 +117,7 @@ public final class CheckerCommand
while (id != BitstreamDispatcher.SENTINEL)
{
LOG.debug("Processing bitstream id = " + id);
BitstreamInfo info = checkBitstream(id);
BitstreamInfo info = checkBitstream(context, id);
if (reportVerbose
|| !ChecksumCheckResults.CHECKSUM_MATCH.equals(info.getChecksumCheckResult()))
@@ -136,10 +137,10 @@ public final class CheckerCommand
*
* @return the information about the bitstream and its checksum data
*/
private BitstreamInfo checkBitstream(final int id)
private BitstreamInfo checkBitstream(Context context, final int id)
{
// get bitstream info from bitstream table
BitstreamInfo info = bitstreamInfoDAO.findByBitstreamId(id);
BitstreamInfo info = bitstreamInfoDAO.findByBitstreamId(context, id);
// requested id was not found in bitstream
// or most_recent_checksum table

View File

@@ -10,6 +10,7 @@ package org.dspace.checker;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.mail.MessagingException;
@@ -22,6 +23,7 @@ import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.log4j.Logger;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.core.Email;
/**
@@ -178,9 +180,11 @@ public class DailyReportEmailer
File report = null;
FileWriter writer = null;
Context context = null;
try
{
context = new Context();
// the number of bitstreams in report
int numBitstreams = 0;
@@ -221,7 +225,7 @@ public class DailyReportEmailer
tomorrow, writer);
writer
.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
numBitstreams += reporter.getUncheckedBitstreamsReport(writer);
numBitstreams += reporter.getUncheckedBitstreamsReport(context, writer);
writer
.write("\n--------------------------------- End Report ---------------------------\n\n");
writer.flush();
@@ -279,7 +283,7 @@ public class DailyReportEmailer
writer
.write("\n--------------------------------- Begin Reporting ------------------------\n\n");
numBitstreams += reporter
.getUncheckedBitstreamsReport(writer);
.getUncheckedBitstreamsReport(context, writer);
writer.flush();
writer.close();
emailer.sendReport(report, numBitstreams);
@@ -293,9 +297,14 @@ public class DailyReportEmailer
catch (IOException e)
{
log.fatal(e);
}
finally
} catch (SQLException e) {
log.fatal(e);
} finally
{
if(context != null && context.isValid())
{
context.abort();
}
if (writer != null)
{
try

View File

@@ -16,7 +16,9 @@ import java.util.LinkedList;
import java.util.List;
import org.apache.log4j.Logger;
import org.dspace.content.Bitstream;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager;
/**
@@ -77,9 +79,8 @@ public class ReporterDAO extends DAOSupport
*/
public static final String FIND_UNKNOWN_BITSTREAMS = "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, "
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
+ "bitstream.user_format_description, bitstream.internal_id, "
+ "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, "
+ "bitstream.name, bitstream.description "
+ "bitstream.internal_id, "
+ "bitstream.checksum_algorithm, bitstream.checksum "
+ "from bitstream left outer join bitstreamformatregistry on "
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
+ "where not exists( select 'x' from most_recent_checksum "
@@ -224,7 +225,7 @@ public class ReporterDAO extends DAOSupport
*
* @return a List of DSpaceBitstreamInfo objects
*/
public List<DSpaceBitstreamInfo> getUnknownBitstreams()
public List<DSpaceBitstreamInfo> getUnknownBitstreams(Context context)
{
List<DSpaceBitstreamInfo> unknownBitstreams = new LinkedList<DSpaceBitstreamInfo>();
@@ -244,16 +245,15 @@ public class ReporterDAO extends DAOSupport
// add the bitstream history objects
while (rs.next())
{
Bitstream bitstream = Bitstream.find(context, rs.getInt("bitstream_id"));
unknownBitstreams.add(new DSpaceBitstreamInfo(rs
.getBoolean("deleted"), rs.getInt("store_number"), rs
.getInt("size_bytes"), rs
.getString("short_description"), rs
.getInt("bitstream_id"), rs
.getString("user_format_description"), rs
.getString("internal_id"), rs.getString("source"), rs
.getInt("bitstream_id"), bitstream.getFormatDescription(), rs
.getString("internal_id"), bitstream.getSource(), rs
.getString("checksum_algorithm"), rs
.getString("checksum"), rs.getString("name"), rs
.getString("description")));
.getString("checksum"), bitstream.getName(), bitstream.getDescription()));
}
}
catch (SQLException e)

View File

@@ -7,6 +7,8 @@
*/
package org.dspace.checker;
import org.dspace.core.Context;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Date;
@@ -110,6 +112,6 @@ public interface SimpleReporter
* if io error occurs
*
*/
public int getUncheckedBitstreamsReport(OutputStreamWriter osw)
public int getUncheckedBitstreamsReport(Context context, OutputStreamWriter osw)
throws IOException;
}

View File

@@ -14,6 +14,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.dspace.core.Context;
import org.dspace.core.I18nUtil;
/**
@@ -240,11 +241,11 @@ public class SimpleReporterImpl implements SimpleReporter
* @throws IOException
* if io error occurs
*/
public int getUncheckedBitstreamsReport(OutputStreamWriter osw)
public int getUncheckedBitstreamsReport(Context context, OutputStreamWriter osw)
throws IOException
{
// get all the bitstreams marked deleted for today
List<DSpaceBitstreamInfo> bitstreams = reporter.getUnknownBitstreams();
List<DSpaceBitstreamInfo> bitstreams = reporter.getUnknownBitstreams(context);
osw.write("\n");
osw.write(msg("unchecked-bitstream-report"));