mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
DS-2863 Stop checksum checker from crashing
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.checker;
|
package org.dspace.checker;
|
||||||
|
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
import org.dspace.content.Bitstream;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.Date;
|
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)
|
@SequenceGenerator(name="checksum_history_check_id_seq", sequenceName="checksum_history_check_id_seq", allocationSize = 1)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name = "bitstream_id")
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
private UUID bitstreamId;
|
@JoinColumn(name = "bitstream_id")
|
||||||
|
private Bitstream bitstream;
|
||||||
|
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@Column(name = "process_start_date", nullable = false)
|
@Column(name = "process_start_date", nullable = false)
|
||||||
@@ -72,13 +74,13 @@ public class ChecksumHistory
|
|||||||
/**
|
/**
|
||||||
* @return Returns the bitstreamId.
|
* @return Returns the bitstreamId.
|
||||||
*/
|
*/
|
||||||
public UUID getBitstreamId()
|
public Bitstream getBitstream()
|
||||||
{
|
{
|
||||||
return bitstreamId;
|
return bitstream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBitstreamId(UUID bitstreamId) {
|
public void setBitstream(Bitstream bitstream) {
|
||||||
this.bitstreamId = bitstreamId;
|
this.bitstream = bitstream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -61,7 +61,7 @@ public class ChecksumHistoryServiceImpl implements ChecksumHistoryService {
|
|||||||
@Override
|
@Override
|
||||||
public void addHistory(Context context, MostRecentChecksum mostRecentChecksum) throws SQLException {
|
public void addHistory(Context context, MostRecentChecksum mostRecentChecksum) throws SQLException {
|
||||||
ChecksumHistory checksumHistory = checksumHistoryDAO.create(context, new ChecksumHistory());
|
ChecksumHistory checksumHistory = checksumHistoryDAO.create(context, new ChecksumHistory());
|
||||||
checksumHistory.setBitstreamId(mostRecentChecksum.getBitstream().getID());
|
checksumHistory.setBitstream(mostRecentChecksum.getBitstream());
|
||||||
checksumHistory.setProcessStartDate(mostRecentChecksum.getProcessStartDate());
|
checksumHistory.setProcessStartDate(mostRecentChecksum.getProcessStartDate());
|
||||||
checksumHistory.setProcessEndDate(mostRecentChecksum.getProcessEndDate());
|
checksumHistory.setProcessEndDate(mostRecentChecksum.getProcessEndDate());
|
||||||
checksumHistory.setChecksumExpected(mostRecentChecksum.getExpectedChecksum());
|
checksumHistory.setChecksumExpected(mostRecentChecksum.getExpectedChecksum());
|
||||||
|
@@ -7,10 +7,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.checker;
|
package org.dspace.checker;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.content.Bitstream;
|
import org.dspace.content.Bitstream;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +24,7 @@ import java.util.Date;
|
|||||||
@Table(name="most_recent_checksum")
|
@Table(name="most_recent_checksum")
|
||||||
public class MostRecentChecksum implements Serializable
|
public class MostRecentChecksum implements Serializable
|
||||||
{
|
{
|
||||||
|
private static final Logger log = Logger.getLogger(MostRecentChecksum.class);
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@@ -68,7 +71,32 @@ public class MostRecentChecksum implements Serializable
|
|||||||
*/
|
*/
|
||||||
protected MostRecentChecksum()
|
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() {
|
public Bitstream getBitstream() {
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.checker;
|
package org.dspace.checker;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.checker.dao.MostRecentChecksumDAO;
|
import org.dspace.checker.dao.MostRecentChecksumDAO;
|
||||||
import org.dspace.checker.service.ChecksumResultService;
|
import org.dspace.checker.service.ChecksumResultService;
|
||||||
import org.dspace.checker.service.MostRecentChecksumService;
|
import org.dspace.checker.service.MostRecentChecksumService;
|
||||||
@@ -28,6 +29,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
|
public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
|
||||||
{
|
{
|
||||||
|
private static final Logger log = Logger.getLogger(MostRecentChecksumServiceImpl.class);
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
protected MostRecentChecksumDAO mostRecentChecksumDAO;
|
protected MostRecentChecksumDAO mostRecentChecksumDAO;
|
||||||
|
|
||||||
@@ -40,7 +43,7 @@ public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
|
|||||||
@Override
|
@Override
|
||||||
public MostRecentChecksum getNonPersistedObject()
|
public MostRecentChecksum getNonPersistedObject()
|
||||||
{
|
{
|
||||||
return new MostRecentChecksum();
|
return new MostRecentChecksum(new Bitstream());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,27 +110,9 @@ public class MostRecentChecksumServiceImpl implements MostRecentChecksumService
|
|||||||
List<Bitstream> unknownBitstreams = bitstreamService.findBitstreamsWithNoRecentChecksum(context);
|
List<Bitstream> unknownBitstreams = bitstreamService.findBitstreamsWithNoRecentChecksum(context);
|
||||||
for (Bitstream bitstream : unknownBitstreams)
|
for (Bitstream bitstream : unknownBitstreams)
|
||||||
{
|
{
|
||||||
MostRecentChecksum mostRecentChecksum = mostRecentChecksumDAO.create(context, new MostRecentChecksum());
|
log.info(bitstream + " " + bitstream.getID().toString() + " " + bitstream.getName());
|
||||||
mostRecentChecksum.setBitstream(bitstream);
|
MostRecentChecksum mostRecentChecksum = mostRecentChecksumDAO.create(context, new MostRecentChecksum(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);
|
|
||||||
ChecksumResult checksumResult;
|
ChecksumResult checksumResult;
|
||||||
if(bitstream.isDeleted())
|
if(bitstream.isDeleted())
|
||||||
{
|
{
|
||||||
|
@@ -48,8 +48,8 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
criteria.add(
|
criteria.add(
|
||||||
Restrictions.and(
|
Restrictions.and(
|
||||||
Restrictions.eq("toBeProcessed", false),
|
Restrictions.eq("toBeProcessed", false),
|
||||||
Restrictions.le("lastProcessStartDate", startDate),
|
Restrictions.le("processStartDate", startDate),
|
||||||
Restrictions.gt("lastProcessStartDate", endDate)
|
Restrictions.gt("processStartDate", endDate)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
criteria.addOrder(Order.asc("bitstream.id"));
|
criteria.addOrder(Order.asc("bitstream.id"));
|
||||||
@@ -79,8 +79,8 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
criteria.add(
|
criteria.add(
|
||||||
Restrictions.and(
|
Restrictions.and(
|
||||||
Restrictions.eq("result.resultCode", resultCode),
|
Restrictions.eq("result.resultCode", resultCode),
|
||||||
Restrictions.le("lastProcessStartDate", startDate),
|
Restrictions.le("processStartDate", startDate),
|
||||||
Restrictions.gt("lastProcessStartDate", endDate)
|
Restrictions.gt("processStartDate", endDate)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
criteria.addOrder(Order.asc("bitstream.id"));
|
criteria.addOrder(Order.asc("bitstream.id"));
|
||||||
@@ -105,7 +105,7 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
// + "bitstream_id " + "ASC LIMIT 1";
|
// + "bitstream_id " + "ASC LIMIT 1";
|
||||||
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
Criteria criteria = createCriteria(context, MostRecentChecksum.class);
|
||||||
criteria.add(Restrictions.eq("toBeProcessed", true));
|
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);
|
criteria.setMaxResults(1);
|
||||||
return uniqueResult(criteria);
|
return uniqueResult(criteria);
|
||||||
}
|
}
|
||||||
@@ -122,9 +122,9 @@ public class MostRecentChecksumDAOImpl extends AbstractHibernateDAO<MostRecentCh
|
|||||||
criteria.add(
|
criteria.add(
|
||||||
Restrictions.and(
|
Restrictions.and(
|
||||||
Restrictions.eq("toBeProcessed", true),
|
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);
|
criteria.setMaxResults(1);
|
||||||
return uniqueResult(criteria);
|
return uniqueResult(criteria);
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ import org.dspace.core.AbstractHibernateDSODAO;
|
|||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.criterion.DetachedCriteria;
|
import org.hibernate.criterion.DetachedCriteria;
|
||||||
|
import org.hibernate.criterion.Projections;
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.criterion.Subqueries;
|
import org.hibernate.criterion.Subqueries;
|
||||||
|
|
||||||
@@ -65,8 +66,12 @@ public class BitstreamDAOImpl extends AbstractHibernateDSODAO<Bitstream> impleme
|
|||||||
// + "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 "
|
||||||
// + "where most_recent_checksum.bitstream_id = bitstream.bitstream_id )"
|
// + "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")
|
@SuppressWarnings("unchecked")
|
||||||
List<Bitstream> result = (List<Bitstream>) criteria.list();
|
List<Bitstream> result = (List<Bitstream>) criteria.list();
|
||||||
|
Reference in New Issue
Block a user