DS-2863 Stop checksum checker from crashing

This commit is contained in:
Peter Dietz
2015-11-05 13:29:15 -05:00
parent 903a43c61b
commit 905445c864
6 changed files with 58 additions and 38 deletions

View File

@@ -8,6 +8,7 @@
package org.dspace.checker;
import org.dspace.core.Context;
import org.dspace.content.Bitstream;
import javax.persistence.*;
import java.util.Date;
@@ -35,8 +36,9 @@ public class ChecksumHistory
@SequenceGenerator(name="checksum_history_check_id_seq", sequenceName="checksum_history_check_id_seq", allocationSize = 1)
private long id;
@Column(name = "bitstream_id")
private UUID bitstreamId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "bitstream_id")
private Bitstream bitstream;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "process_start_date", nullable = false)
@@ -72,13 +74,13 @@ public class ChecksumHistory
/**
* @return Returns the bitstreamId.
*/
public UUID getBitstreamId()
public Bitstream getBitstream()
{
return bitstreamId;
return bitstream;
}
public void setBitstreamId(UUID bitstreamId) {
this.bitstreamId = bitstreamId;
public void setBitstream(Bitstream bitstream) {
this.bitstream = bitstream;
}
/**

View File

@@ -61,7 +61,7 @@ public class ChecksumHistoryServiceImpl implements ChecksumHistoryService {
@Override
public void addHistory(Context context, MostRecentChecksum mostRecentChecksum) throws SQLException {
ChecksumHistory checksumHistory = checksumHistoryDAO.create(context, new ChecksumHistory());
checksumHistory.setBitstreamId(mostRecentChecksum.getBitstream().getID());
checksumHistory.setBitstream(mostRecentChecksum.getBitstream());
checksumHistory.setProcessStartDate(mostRecentChecksum.getProcessStartDate());
checksumHistory.setProcessEndDate(mostRecentChecksum.getProcessEndDate());
checksumHistory.setChecksumExpected(mostRecentChecksum.getExpectedChecksum());

View File

@@ -7,10 +7,12 @@
*/
package org.dspace.checker;
import org.apache.log4j.Logger;
import org.dspace.content.Bitstream;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.Date;
/**
@@ -22,6 +24,7 @@ import java.util.Date;
@Table(name="most_recent_checksum")
public class MostRecentChecksum implements Serializable
{
private static final Logger log = Logger.getLogger(MostRecentChecksum.class);
@Id
@OneToOne
@@ -68,7 +71,32 @@ public class MostRecentChecksum implements Serializable
*/
protected MostRecentChecksum()
{
}
public MostRecentChecksum(Bitstream bitstream) {
try {
setToBeProcessed(!bitstream.isDeleted());
if (bitstream.getChecksum() == null) {
setCurrentChecksum("");
setExpectedChecksum("");
} else {
setCurrentChecksum(bitstream.getChecksum());
setExpectedChecksum(bitstream.getChecksum());
}
setProcessStartDate(new Date());
setProcessEndDate(new Date());
if (bitstream.getChecksumAlgorithm() == null) {
bitstream.setChecksumAlgorithm("MD5");
} else {
bitstream.setChecksumAlgorithm(bitstream.getChecksumAlgorithm());
}
setMatchedPrevChecksum(true);
} catch (SQLException e) {
log.error(e);
//log
}
}
public Bitstream getBitstream() {

View File

@@ -7,6 +7,7 @@
*/
package org.dspace.checker;
import org.apache.log4j.Logger;
import org.dspace.checker.dao.MostRecentChecksumDAO;
import org.dspace.checker.service.ChecksumResultService;
import org.dspace.checker.service.MostRecentChecksumService;
@@ -28,6 +29,8 @@ import java.util.List;
*/
public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
{
private static final Logger log = Logger.getLogger(MostRecentChecksumServiceImpl.class);
@Autowired(required = true)
protected MostRecentChecksumDAO mostRecentChecksumDAO;
@@ -40,7 +43,7 @@ public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
@Override
public MostRecentChecksum getNonPersistedObject()
{
return new MostRecentChecksum();
return new MostRecentChecksum(new Bitstream());
}
@Override
@@ -107,27 +110,9 @@ public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
List<Bitstream> unknownBitstreams = bitstreamService.findBitstreamsWithNoRecentChecksum(context);
for (Bitstream bitstream : unknownBitstreams)
{
MostRecentChecksum mostRecentChecksum = mostRecentChecksumDAO.create(context, new MostRecentChecksum());
mostRecentChecksum.setBitstream(bitstream);
//Only process if our bitstream isn't deleted
mostRecentChecksum.setToBeProcessed(!bitstream.isDeleted());
if(bitstream.getChecksum() == null)
{
mostRecentChecksum.setCurrentChecksum("");
mostRecentChecksum.setExpectedChecksum("");
}else{
mostRecentChecksum.setCurrentChecksum(bitstream.getChecksum());
mostRecentChecksum.setExpectedChecksum(bitstream.getChecksum());
}
mostRecentChecksum.setProcessStartDate(new Date());
mostRecentChecksum.setProcessEndDate(new Date());
if(bitstream.getChecksumAlgorithm() == null)
{
bitstream.setChecksumAlgorithm("MD5");
}else{
bitstream.setChecksumAlgorithm(bitstream.getChecksumAlgorithm());
}
mostRecentChecksum.setMatchedPrevChecksum(true);
log.info(bitstream + " " + bitstream.getID().toString() + " " + bitstream.getName());
MostRecentChecksum mostRecentChecksum = mostRecentChecksumDAO.create(context, new MostRecentChecksum(bitstream));
ChecksumResult checksumResult;
if(bitstream.isDeleted())
{

View File

@@ -48,8 +48,8 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
criteria.add(
Restrictions.and(
Restrictions.eq("toBeProcessed", false),
Restrictions.le("lastProcessStartDate", startDate),
Restrictions.gt("lastProcessStartDate", endDate)
Restrictions.le("processStartDate", startDate),
Restrictions.gt("processStartDate", endDate)
)
);
criteria.addOrder(Order.asc("bitstream.id"));
@@ -79,8 +79,8 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
criteria.add(
Restrictions.and(
Restrictions.eq("result.resultCode", resultCode),
Restrictions.le("lastProcessStartDate", startDate),
Restrictions.gt("lastProcessStartDate", endDate)
Restrictions.le("processStartDate", startDate),
Restrictions.gt("processStartDate", endDate)
)
);
criteria.addOrder(Order.asc("bitstream.id"));
@@ -105,7 +105,7 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
// + "bitstream_id " + "ASC LIMIT 1";
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
criteria.add(Restrictions.eq("toBeProcessed", true));
criteria.addOrder(Order.asc("lastProcessEndDate")).addOrder(Order.asc("bitstream.id"));
criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id"));
criteria.setMaxResults(1);
return uniqueResult(criteria);
}
@@ -122,9 +122,9 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
criteria.add(
Restrictions.and(
Restrictions.eq("toBeProcessed", true),
Restrictions.lt("lastProcessStartDate", lessThanDate)
Restrictions.lt("processStartDate", lessThanDate)
));
criteria.addOrder(Order.asc("lastProcessEndDate")).addOrder(Order.asc("bitstream.id"));
criteria.addOrder(Order.asc("processEndDate")).addOrder(Order.asc("bitstream.id"));
criteria.setMaxResults(1);
return uniqueResult(criteria);
}

View File

@@ -18,6 +18,7 @@ import org.dspace.core.AbstractHibernateDSODAO;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Subqueries;
@@ -65,8 +66,12 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
// + "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id "
// + "where not exists( select 'x' from most_recent_checksum "
// + "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )"
Criteria criteria = createCriteria(context, Bitstream.class)
.add(Subqueries.propertyNotIn("id", DetachedCriteria.forClass(MostRecentChecksum.class)));
DetachedCriteria d = DetachedCriteria.forClass(MostRecentChecksum.class, "mrc");
d.setProjection(Projections.projectionList().add(Projections.property("mrc.bitstream")));
Criteria criteria = createCriteria(context, Bitstream.class, "b")
.add(Subqueries.propertyNotIn("b.id", d));
@SuppressWarnings("unchecked")
List<Bitstream> result = (List<Bitstream>) criteria.list();