mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Merge pull request #822 from KevinVdV/DS-2396
[DS-2396] Checksum checker and bitstream.user_format_description
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.app.checker;
|
package org.dspace.app.checker;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -32,6 +33,7 @@ import org.dspace.checker.ListDispatcher;
|
|||||||
import org.dspace.checker.ResultsLogger;
|
import org.dspace.checker.ResultsLogger;
|
||||||
import org.dspace.checker.ResultsPruner;
|
import org.dspace.checker.ResultsPruner;
|
||||||
import org.dspace.checker.SimpleDispatcher;
|
import org.dspace.checker.SimpleDispatcher;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.Utils;
|
import org.dspace.core.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,8 +80,7 @@ public final class ChecksumChecker
|
|||||||
* <dd>Don't prune results before running checker</dd>
|
* <dd>Don't prune results before running checker</dd>
|
||||||
* </dl>
|
* </dl>
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args) throws SQLException {
|
||||||
{
|
|
||||||
// set up command line parser
|
// set up command line parser
|
||||||
CommandLineParser parser = new PosixParser();
|
CommandLineParser parser = new PosixParser();
|
||||||
CommandLine line = null;
|
CommandLine line = null;
|
||||||
@@ -230,7 +231,13 @@ public final class ChecksumChecker
|
|||||||
checker.setProcessStartDate(processStart);
|
checker.setProcessStartDate(processStart);
|
||||||
checker.setDispatcher(dispatcher);
|
checker.setDispatcher(dispatcher);
|
||||||
checker.setCollector(logger);
|
checker.setCollector(logger);
|
||||||
checker.process();
|
Context context = new Context();
|
||||||
|
try {
|
||||||
|
checker.process(context);
|
||||||
|
} finally {
|
||||||
|
context.commit();
|
||||||
|
context.complete();
|
||||||
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,9 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
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. */
|
/** 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, "
|
private static final String FIND_BY_BITSTREAM_ID = "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, "
|
||||||
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
|
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
|
||||||
+ "bitstream.user_format_description, bitstream.internal_id, "
|
+ "bitstream.internal_id, "
|
||||||
+ "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, "
|
+ "bitstream.checksum_algorithm, bitstream.checksum, "
|
||||||
+ "bitstream.name, most_recent_checksum.last_process_end_date,"
|
+ "most_recent_checksum.last_process_end_date,"
|
||||||
+ "most_recent_checksum.to_be_processed "
|
+ "most_recent_checksum.to_be_processed "
|
||||||
+ "from bitstream left outer join bitstreamformatregistry on "
|
+ "from bitstream left outer join bitstreamformatregistry on "
|
||||||
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id, "
|
+ "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
|
* @return the bitstream information needed for checksum validation. Returns
|
||||||
* null if bitstream info isn't found.
|
* null if bitstream info isn't found.
|
||||||
*/
|
*/
|
||||||
public BitstreamInfo findByBitstreamId(int id)
|
public BitstreamInfo findByBitstreamId(Context context, int id)
|
||||||
{
|
{
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
BitstreamInfo info = null;
|
BitstreamInfo info = null;
|
||||||
@@ -246,14 +248,14 @@ public final class BitstreamInfoDAO extends DAOSupport
|
|||||||
// if the bitstream is found return it
|
// if the bitstream is found return it
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
|
Bitstream bitstream = Bitstream.find(context, rs.getInt("bitstream_id"));
|
||||||
info = new BitstreamInfo(rs.getBoolean("deleted"), rs
|
info = new BitstreamInfo(rs.getBoolean("deleted"), rs
|
||||||
.getInt("store_number"), rs.getLong("size_bytes"), rs
|
.getInt("store_number"), rs.getLong("size_bytes"), rs
|
||||||
.getString("short_description"), rs
|
.getString("short_description"), rs
|
||||||
.getInt("bitstream_id"), rs
|
.getInt("bitstream_id"), bitstream.getUserFormatDescription(), rs
|
||||||
.getString("user_format_description"), rs
|
.getString("internal_id"), bitstream.getSource(), rs
|
||||||
.getString("internal_id"), rs.getString("source"), rs
|
|
||||||
.getString("checksum_algorithm"), rs
|
.getString("checksum_algorithm"), rs
|
||||||
.getString("checksum"), rs.getString("name"), rs
|
.getString("checksum"), bitstream.getName(), rs
|
||||||
.getTimestamp("last_process_end_date"), rs
|
.getTimestamp("last_process_end_date"), rs
|
||||||
.getBoolean("to_be_processed"), new Date());
|
.getBoolean("to_be_processed"), new Date());
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.Utils;
|
import org.dspace.core.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,7 +94,7 @@ public final class CheckerCommand
|
|||||||
* setBitstreamDispatcher before calling this method
|
* setBitstreamDispatcher before calling this method
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void process()
|
public void process(Context context)
|
||||||
{
|
{
|
||||||
LOG.debug("Begin Checker Processing");
|
LOG.debug("Begin Checker Processing");
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ public final class CheckerCommand
|
|||||||
while (id != BitstreamDispatcher.SENTINEL)
|
while (id != BitstreamDispatcher.SENTINEL)
|
||||||
{
|
{
|
||||||
LOG.debug("Processing bitstream id = " + id);
|
LOG.debug("Processing bitstream id = " + id);
|
||||||
BitstreamInfo info = checkBitstream(id);
|
BitstreamInfo info = checkBitstream(context, id);
|
||||||
|
|
||||||
if (reportVerbose
|
if (reportVerbose
|
||||||
|| !ChecksumCheckResults.CHECKSUM_MATCH.equals(info.getChecksumCheckResult()))
|
|| !ChecksumCheckResults.CHECKSUM_MATCH.equals(info.getChecksumCheckResult()))
|
||||||
@@ -136,10 +137,10 @@ public final class CheckerCommand
|
|||||||
*
|
*
|
||||||
* @return the information about the bitstream and its checksum data
|
* @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
|
// get bitstream info from bitstream table
|
||||||
BitstreamInfo info = bitstreamInfoDAO.findByBitstreamId(id);
|
BitstreamInfo info = bitstreamInfoDAO.findByBitstreamId(context, id);
|
||||||
|
|
||||||
// requested id was not found in bitstream
|
// requested id was not found in bitstream
|
||||||
// or most_recent_checksum table
|
// or most_recent_checksum table
|
||||||
|
@@ -10,6 +10,7 @@ package org.dspace.checker;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
@@ -22,6 +23,7 @@ import org.apache.commons.cli.ParseException;
|
|||||||
import org.apache.commons.cli.PosixParser;
|
import org.apache.commons.cli.PosixParser;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.Email;
|
import org.dspace.core.Email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,9 +180,11 @@ public class DailyReportEmailer
|
|||||||
|
|
||||||
File report = null;
|
File report = null;
|
||||||
FileWriter writer = null;
|
FileWriter writer = null;
|
||||||
|
Context context = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
context = new Context();
|
||||||
// the number of bitstreams in report
|
// the number of bitstreams in report
|
||||||
int numBitstreams = 0;
|
int numBitstreams = 0;
|
||||||
|
|
||||||
@@ -221,7 +225,7 @@ public class DailyReportEmailer
|
|||||||
tomorrow, writer);
|
tomorrow, writer);
|
||||||
writer
|
writer
|
||||||
.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
|
.write("\n--------------------------------- Report Spacer ---------------------------\n\n");
|
||||||
numBitstreams += reporter.getUncheckedBitstreamsReport(writer);
|
numBitstreams += reporter.getUncheckedBitstreamsReport(context, writer);
|
||||||
writer
|
writer
|
||||||
.write("\n--------------------------------- End Report ---------------------------\n\n");
|
.write("\n--------------------------------- End Report ---------------------------\n\n");
|
||||||
writer.flush();
|
writer.flush();
|
||||||
@@ -279,7 +283,7 @@ public class DailyReportEmailer
|
|||||||
writer
|
writer
|
||||||
.write("\n--------------------------------- Begin Reporting ------------------------\n\n");
|
.write("\n--------------------------------- Begin Reporting ------------------------\n\n");
|
||||||
numBitstreams += reporter
|
numBitstreams += reporter
|
||||||
.getUncheckedBitstreamsReport(writer);
|
.getUncheckedBitstreamsReport(context, writer);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
emailer.sendReport(report, numBitstreams);
|
emailer.sendReport(report, numBitstreams);
|
||||||
@@ -293,9 +297,14 @@ public class DailyReportEmailer
|
|||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
log.fatal(e);
|
log.fatal(e);
|
||||||
}
|
} catch (SQLException e) {
|
||||||
finally
|
log.fatal(e);
|
||||||
|
} finally
|
||||||
{
|
{
|
||||||
|
if(context != null && context.isValid())
|
||||||
|
{
|
||||||
|
context.abort();
|
||||||
|
}
|
||||||
if (writer != null)
|
if (writer != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@@ -16,7 +16,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.content.Bitstream;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
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, "
|
public static final String FIND_UNKNOWN_BITSTREAMS = "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, "
|
||||||
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
|
+ "bitstreamformatregistry.short_description, bitstream.bitstream_id, "
|
||||||
+ "bitstream.user_format_description, bitstream.internal_id, "
|
+ "bitstream.internal_id, "
|
||||||
+ "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, "
|
+ "bitstream.checksum_algorithm, bitstream.checksum "
|
||||||
+ "bitstream.name, bitstream.description "
|
|
||||||
+ "from bitstream left outer join bitstreamformatregistry on "
|
+ "from bitstream left outer join bitstreamformatregistry on "
|
||||||
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
|
+ "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
|
||||||
+ "where not exists( select 'x' from most_recent_checksum "
|
+ "where not exists( select 'x' from most_recent_checksum "
|
||||||
@@ -224,7 +225,7 @@ public class ReporterDAO extends DAOSupport
|
|||||||
*
|
*
|
||||||
* @return a List of DSpaceBitstreamInfo objects
|
* @return a List of DSpaceBitstreamInfo objects
|
||||||
*/
|
*/
|
||||||
public List<DSpaceBitstreamInfo> getUnknownBitstreams()
|
public List<DSpaceBitstreamInfo> getUnknownBitstreams(Context context)
|
||||||
{
|
{
|
||||||
List<DSpaceBitstreamInfo> unknownBitstreams = new LinkedList<DSpaceBitstreamInfo>();
|
List<DSpaceBitstreamInfo> unknownBitstreams = new LinkedList<DSpaceBitstreamInfo>();
|
||||||
|
|
||||||
@@ -244,16 +245,15 @@ public class ReporterDAO extends DAOSupport
|
|||||||
// add the bitstream history objects
|
// add the bitstream history objects
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
Bitstream bitstream = Bitstream.find(context, rs.getInt("bitstream_id"));
|
||||||
unknownBitstreams.add(new DSpaceBitstreamInfo(rs
|
unknownBitstreams.add(new DSpaceBitstreamInfo(rs
|
||||||
.getBoolean("deleted"), rs.getInt("store_number"), rs
|
.getBoolean("deleted"), rs.getInt("store_number"), rs
|
||||||
.getInt("size_bytes"), rs
|
.getInt("size_bytes"), rs
|
||||||
.getString("short_description"), rs
|
.getString("short_description"), rs
|
||||||
.getInt("bitstream_id"), rs
|
.getInt("bitstream_id"), bitstream.getFormatDescription(), rs
|
||||||
.getString("user_format_description"), rs
|
.getString("internal_id"), bitstream.getSource(), rs
|
||||||
.getString("internal_id"), rs.getString("source"), rs
|
|
||||||
.getString("checksum_algorithm"), rs
|
.getString("checksum_algorithm"), rs
|
||||||
.getString("checksum"), rs.getString("name"), rs
|
.getString("checksum"), bitstream.getName(), bitstream.getDescription()));
|
||||||
.getString("description")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.checker;
|
package org.dspace.checker;
|
||||||
|
|
||||||
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -110,6 +112,6 @@ public interface SimpleReporter
|
|||||||
* if io error occurs
|
* if io error occurs
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public int getUncheckedBitstreamsReport(OutputStreamWriter osw)
|
public int getUncheckedBitstreamsReport(Context context, OutputStreamWriter osw)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ import java.util.Date;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.core.I18nUtil;
|
import org.dspace.core.I18nUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,11 +241,11 @@ public class SimpleReporterImpl implements SimpleReporter
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if io error occurs
|
* if io error occurs
|
||||||
*/
|
*/
|
||||||
public int getUncheckedBitstreamsReport(OutputStreamWriter osw)
|
public int getUncheckedBitstreamsReport(Context context, OutputStreamWriter osw)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// get all the bitstreams marked deleted for today
|
// get all the bitstreams marked deleted for today
|
||||||
List<DSpaceBitstreamInfo> bitstreams = reporter.getUnknownBitstreams();
|
List<DSpaceBitstreamInfo> bitstreams = reporter.getUnknownBitstreams(context);
|
||||||
|
|
||||||
osw.write("\n");
|
osw.write("\n");
|
||||||
osw.write(msg("unchecked-bitstream-report"));
|
osw.write(msg("unchecked-bitstream-report"));
|
||||||
|
Reference in New Issue
Block a user