1 34 package org.dspace.checker; 35 36 import java.sql.Connection ; 37 import java.sql.PreparedStatement ; 38 import java.sql.ResultSet ; 39 import java.sql.SQLException ; 40 import java.util.Date ; 41 import java.util.LinkedList ; 42 import java.util.List ; 43 44 import org.apache.log4j.Logger; 45 import org.dspace.storage.rdbms.DatabaseManager; 46 47 56 public class ReporterDAO extends DAOSupport 57 { 58 63 public static final String DATE_RANGE_BITSTREAMS = "select bitstream_id, last_process_start_date, last_process_end_date, " 64 + "expected_checksum, current_checksum, result_description " 65 + "from most_recent_checksum, checksum_results " 66 + "where most_recent_checksum.result = checksum_results.result_code " 67 + "and most_recent_checksum.result= ? " 68 + "and most_recent_checksum.last_process_start_date >= ? " 69 + "and most_recent_checksum.last_process_start_date < ? " 70 + "order by bitstream_id;"; 71 72 78 public static final String DATE_RANGE_NOT_PROCESSED_BITSTREAMS = "select most_recent_checksum.bitstream_id, " 79 + "most_recent_checksum.last_process_start_date, most_recent_checksum.last_process_end_date, " 80 + "most_recent_checksum.expected_checksum, most_recent_checksum.current_checksum, " 81 + "result_description " 82 + "from checksum_results, most_recent_checksum " 83 + "where most_recent_checksum.to_be_processed = false " 84 + "and most_recent_checksum.result = checksum_results.result_code " 85 + "and most_recent_checksum.last_process_start_date >= ? " 86 + "and most_recent_checksum.last_process_start_date < ? " 87 + "order by most_recent_checksum.bitstream_id;"; 88 89 92 public static final String FIND_UNKNOWN_BITSTREAMS = "select bitstream.deleted, bitstream.store_number, bitstream.size_bytes, " 93 + "bitstreamformatregistry.short_description, bitstream.bitstream_id, " 94 + "bitstream.user_format_description, bitstream.internal_id, " 95 + "bitstream.source, bitstream.checksum_algorithm, bitstream.checksum, " 96 + "bitstream.name, bitstream.description " 97 + "from bitstream left outer join bitstreamformatregistry on " 98 + "bitstream.bitstream_format_id = bitstreamformatregistry.bitstream_format_id " 99 + "where not exists( select 'x' from most_recent_checksum " 100 + "where most_recent_checksum.bitstream_id = bitstream.bitstream_id );"; 101 102 105 private static final Logger LOG = Logger.getLogger(ReporterDAO.class); 106 107 110 public ReporterDAO() 111 { 112 ; 113 } 114 115 128 public List getBitstreamResultTypeReport(Date startDate, Date endDate, 129 String resultCode) 130 { 131 List bitstreamHistory = new LinkedList (); 132 133 Connection conn = null; 134 PreparedStatement prepStmt = null; 135 ResultSet rs = null; 136 137 try 138 { 139 conn = DatabaseManager.getConnection(); 141 142 prepStmt = conn.prepareStatement(DATE_RANGE_BITSTREAMS); 143 144 prepStmt.setString(1, resultCode); 145 prepStmt.setDate(2, new java.sql.Date (startDate.getTime())); 146 prepStmt.setDate(3, new java.sql.Date (endDate.getTime())); 147 148 rs = prepStmt.executeQuery(); 149 150 while (rs.next()) 152 { 153 bitstreamHistory.add(new ChecksumHistory(rs 154 .getInt("bitstream_id"), rs 155 .getTimestamp("last_process_start_date"), rs 156 .getTimestamp("last_process_end_date"), rs 157 .getString("expected_checksum"), rs 158 .getString("current_checksum"), rs 159 .getString("result_description"))); 160 } 161 } 162 catch (SQLException e) 163 { 164 LOG.warn("Bitstream history could not be found for specified type " 165 + e.getMessage(), e); 166 } 167 finally 168 { 169 cleanup(prepStmt, conn, rs); 170 } 171 172 return bitstreamHistory; 173 } 174 175 185 public List getNotProcessedBitstreamsReport(Date startDate, Date endDate) 186 { 187 List bitstreamHistory = new LinkedList (); 188 189 Connection conn = null; 190 PreparedStatement prepStmt = null; 191 ResultSet rs = null; 192 193 try 194 { 195 conn = DatabaseManager.getConnection(); 197 198 prepStmt = conn 199 .prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS); 200 201 prepStmt.setDate(1, new java.sql.Date (startDate.getTime())); 202 prepStmt.setDate(2, new java.sql.Date (endDate.getTime())); 203 204 rs = prepStmt.executeQuery(); 205 206 while (rs.next()) 208 { 209 bitstreamHistory.add(new ChecksumHistory(rs 210 .getInt("bitstream_id"), rs 211 .getTimestamp("last_process_start_date"), rs 212 .getTimestamp("last_process_end_date"), rs 213 .getString("expected_checksum"), rs 214 .getString("current_checksum"), rs 215 .getString("result_description"))); 216 } 217 } 218 catch (SQLException e) 219 { 220 LOG.warn("Bitstream history could not be found for specified type " 221 + e.getMessage(), e); 222 } 223 finally 224 { 225 cleanup(prepStmt, conn, rs); 226 } 227 228 return bitstreamHistory; 229 } 230 231 236 public List getUnknownBitstreams() 237 { 238 List unknownBitstreams = new LinkedList (); 239 240 Connection conn = null; 241 PreparedStatement prepStmt = null; 242 ResultSet rs = null; 243 244 try 245 { 246 conn = DatabaseManager.getConnection(); 248 249 prepStmt = conn.prepareStatement(FIND_UNKNOWN_BITSTREAMS); 250 251 rs = prepStmt.executeQuery(); 252 253 while (rs.next()) 255 { 256 unknownBitstreams.add(new DSpaceBitstreamInfo(rs 257 .getBoolean("deleted"), rs.getInt("store_number"), rs 258 .getInt("size_bytes"), rs 259 .getString("short_description"), rs 260 .getInt("bitstream_id"), rs 261 .getString("user_format_description"), rs 262 .getString("internal_id"), rs.getString("source"), rs 263 .getString("checksum_algorithm"), rs 264 .getString("checksum"), rs.getString("name"), rs 265 .getString("description"))); 266 } 267 } 268 catch (SQLException e) 269 { 270 LOG.warn("Bitstream history could not be found for specified type " 271 + e.getMessage(), e); 272 } 273 finally 274 { 275 cleanup(prepStmt, conn, rs); 276 } 277 278 return unknownBitstreams; 279 } 280 } 281
| Popular Tags
|