KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > checker > ReporterDAO


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.checker;
35
36 import java.sql.Connection JavaDoc;
37 import java.sql.PreparedStatement JavaDoc;
38 import java.sql.ResultSet JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.util.Date JavaDoc;
41 import java.util.LinkedList JavaDoc;
42 import java.util.List JavaDoc;
43
44 import org.apache.log4j.Logger;
45 import org.dspace.storage.rdbms.DatabaseManager;
46
47 /**
48  * This class will report information on the checksum checker process.
49  *
50  * @author Jim Downing
51  * @author Grace Carpenter
52  * @author Nathan Sarr
53  *
54  *
55  */

56 public class ReporterDAO extends DAOSupport
57 {
58     /**
59      * Select the most recent bitstream information for a given date range with
60      * the specified status. This select is from the checksum history and
61      * checksum results tables.
62      */

63     public static final String JavaDoc 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     /**
73      *
74      * Find all bitstreams that were set to not be processed for the specified
75      * date range.
76      *
77      */

78     public static final String JavaDoc 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     /**
90      * Find all bitstreams that the checksum checker is unaware of
91      */

92     public static final String JavaDoc 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     /**
103      * Usual Log4J Logger.
104      */

105     private static final Logger LOG = Logger.getLogger(ReporterDAO.class);
106
107     /**
108      * Default constructor
109      */

110     public ReporterDAO()
111     {
112         ;
113     }
114
115     /**
116      * Select the most recent bitstream for a given date range with the
117      * specified status.
118      *
119      * @param startDate
120      * the start date range
121      * @param endDate
122      * the end date range.
123      * @param resultCode
124      * the result code
125      *
126      * @return a list of BitstreamHistoryInfo objects
127      */

128     public List JavaDoc getBitstreamResultTypeReport(Date JavaDoc startDate, Date JavaDoc endDate,
129             String JavaDoc resultCode)
130     {
131         List JavaDoc bitstreamHistory = new LinkedList JavaDoc();
132
133         Connection JavaDoc conn = null;
134         PreparedStatement JavaDoc prepStmt = null;
135         ResultSet JavaDoc rs = null;
136
137         try
138         {
139             // create the connection and execute the statement
140
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 JavaDoc(startDate.getTime()));
146             prepStmt.setDate(3, new java.sql.Date JavaDoc(endDate.getTime()));
147
148             rs = prepStmt.executeQuery();
149
150             // add the bitstream history objects
151
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 JavaDoc 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     /**
176      * Find all bitstreams that were set to not be processed for the specified
177      * date range.
178      *
179      * @param startDate
180      * the start of the date range
181      * @param endDate
182      * the end of the date range
183      * @return a list of BitstreamHistoryInfo objects
184      */

185     public List JavaDoc getNotProcessedBitstreamsReport(Date JavaDoc startDate, Date JavaDoc endDate)
186     {
187         List JavaDoc bitstreamHistory = new LinkedList JavaDoc();
188
189         Connection JavaDoc conn = null;
190         PreparedStatement JavaDoc prepStmt = null;
191         ResultSet JavaDoc rs = null;
192
193         try
194         {
195             // create the connection and execute the statement
196
conn = DatabaseManager.getConnection();
197
198             prepStmt = conn
199                     .prepareStatement(DATE_RANGE_NOT_PROCESSED_BITSTREAMS);
200
201             prepStmt.setDate(1, new java.sql.Date JavaDoc(startDate.getTime()));
202             prepStmt.setDate(2, new java.sql.Date JavaDoc(endDate.getTime()));
203
204             rs = prepStmt.executeQuery();
205
206             // add the bitstream history objects
207
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 JavaDoc 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     /**
232      * Find all bitstreams that the checksum checker is currently not aware of
233      *
234      * @return a List of DSpaceBitstreamInfo objects
235      */

236     public List JavaDoc getUnknownBitstreams()
237     {
238         List JavaDoc unknownBitstreams = new LinkedList JavaDoc();
239
240         Connection JavaDoc conn = null;
241         PreparedStatement JavaDoc prepStmt = null;
242         ResultSet JavaDoc rs = null;
243
244         try
245         {
246             // create the connection and execute the statement
247
conn = DatabaseManager.getConnection();
248
249             prepStmt = conn.prepareStatement(FIND_UNKNOWN_BITSTREAMS);
250
251             rs = prepStmt.executeQuery();
252
253             // add the bitstream history objects
254
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 JavaDoc 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