Source Code Cross Referenced for SimpleReporterImpl.java in  » Content-Management-System » dspace » org » dspace » checker » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » dspace » org.dspace.checker 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
003:         * Institute of Technology.  All rights reserved.
004:         *
005:         * Redistribution and use in source and binary forms, with or without
006:         * modification, are permitted provided that the following conditions are
007:         * met:
008:         *
009:         * - Redistributions of source code must retain the above copyright
010:         * notice, this list of conditions and the following disclaimer.
011:         *
012:         * - Redistributions in binary form must reproduce the above copyright
013:         * notice, this list of conditions and the following disclaimer in the
014:         * documentation and/or other materials provided with the distribution.
015:         *
016:         * - Neither the name of the Hewlett-Packard Company nor the name of the
017:         * Massachusetts Institute of Technology nor the names of their
018:         * contributors may be used to endorse or promote products derived from
019:         * this software without specific prior written permission.
020:         *
021:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022:         * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
024:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
025:         * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
028:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
030:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
031:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
032:         * DAMAGE.
033:         */
034:        package org.dspace.checker;
035:
036:        import java.io.IOException;
037:        import java.io.OutputStreamWriter;
038:        import java.text.DateFormat;
039:        import java.util.Date;
040:        import java.util.Iterator;
041:        import java.util.List;
042:
043:        import org.apache.log4j.Logger;
044:        import org.dspace.core.I18nUtil;
045:
046:        /**
047:         * 
048:         * Simple Reporter implementation.
049:         * 
050:         * @author Jim Downing
051:         * @author Grace Carpenter
052:         * @author Nathan Sarr
053:         * 
054:         * @todo estimate string buffer sizes.
055:         */
056:        public class SimpleReporterImpl implements  SimpleReporter {
057:            /** log4j logger. */
058:            private static Logger LOG = Logger
059:                    .getLogger(SimpleReporterImpl.class);
060:
061:            /** Utility date format which includes hours minutes and seconds. */
062:            private static final DateFormat DATE_FORMAT_MAX = DateFormat
063:                    .getDateInstance(DateFormat.MEDIUM);
064:
065:            /** Utility date format which only includes Month/day/year. */
066:            private static final DateFormat DATE_FORMAT_MIN = DateFormat
067:                    .getDateInstance(DateFormat.SHORT);
068:
069:            /** The reporter access object to be used. */
070:            private ReporterDAO reporter = null;
071:
072:            private String msg(String key) {
073:                return I18nUtil
074:                        .getMessage("org.dspace.checker.SimpleReporterImpl."
075:                                + key);
076:            }
077:
078:            /**
079:             * Main Constructor.
080:             * 
081:             * @param reporter
082:             *            reporter to select the information
083:             */
084:            public SimpleReporterImpl() {
085:                this .reporter = new ReporterDAO();
086:            }
087:
088:            /**
089:             * Sends the Deleteted bitstream report to an administrator. for the
090:             * specified date range.
091:             * 
092:             * @param startDate
093:             *            the start date for the range
094:             * @param endDate
095:             *            the end date for the range
096:             * @param osw
097:             *            the output stream writer to write to.
098:             * 
099:             * @return number of bitstreams found
100:             * 
101:             * @throws IOException
102:             *             if io error occurs
103:             */
104:            public int getDeletedBitstreamReport(Date startDate, Date endDate,
105:                    OutputStreamWriter osw) throws IOException {
106:                // get all the bitstreams marked deleted for today
107:                List history = reporter.getBitstreamResultTypeReport(startDate,
108:                        endDate, ChecksumCheckResults.BITSTREAM_MARKED_DELETED);
109:
110:                osw.write("\n");
111:                osw.write(msg("deleted-bitstream-intro"));
112:                osw.write(DATE_FORMAT_MIN.format(startDate));
113:                osw.write(" ");
114:                osw.write(msg("date-range-to"));
115:                osw.write(" ");
116:                osw.write(DATE_FORMAT_MIN.format(endDate));
117:                osw.write("\n\n\n");
118:
119:                if (history.size() == 0) {
120:                    osw.write("\n\n");
121:                    osw.write(msg("no-bitstreams-to-delete"));
122:                    osw.write("\n");
123:                } else {
124:                    printHistoryRecords(history, osw);
125:                }
126:
127:                return history.size();
128:            }
129:
130:            /**
131:             * Send the checksum changed report for the specified date range.
132:             * 
133:             * @param startDate
134:             *            the start date for the range
135:             * @param endDate
136:             *            the end date for the range
137:             * @param osw
138:             *            the output stream writer to write to.
139:             * 
140:             * @return number of bitstreams found
141:             * 
142:             * @throws IOException
143:             *             if io error occurs
144:             */
145:            public int getChangedChecksumReport(Date startDate, Date endDate,
146:                    OutputStreamWriter osw) throws IOException {
147:                // get all the bitstreams marked deleted for today
148:                List history = reporter.getBitstreamResultTypeReport(startDate,
149:                        endDate, ChecksumCheckResults.CHECKSUM_NO_MATCH);
150:
151:                osw.write("\n");
152:                osw.write(msg("checksum-did-not-match"));
153:                osw.write(" ");
154:                osw.write("\n");
155:                osw.write(DATE_FORMAT_MIN.format(startDate));
156:                osw.write(" ");
157:                osw.write(msg("date-range-to"));
158:                osw.write(" ");
159:                osw.write(DATE_FORMAT_MIN.format(endDate));
160:                osw.write("\n\n\n");
161:
162:                if (history.size() == 0) {
163:                    osw.write("\n\n");
164:                    osw.write(msg("no-changed-bitstreams"));
165:                    osw.write("\n");
166:                } else {
167:                    printHistoryRecords(history, osw);
168:                }
169:
170:                return history.size();
171:            }
172:
173:            /**
174:             * Send the bitstream not found report for the specified date range.
175:             * 
176:             * @param startDate
177:             *            the start date for the range.
178:             * @param endDate
179:             *            the end date for the range.
180:             * @param osw
181:             *            the output stream writer to write to.
182:             * 
183:             * @return number of bitstreams found
184:             * 
185:             * @throws IOException
186:             *             if io error occurs
187:             */
188:            public int getBitstreamNotFoundReport(Date startDate, Date endDate,
189:                    OutputStreamWriter osw) throws IOException {
190:                // get all the bitstreams marked deleted for today
191:                List history = reporter.getBitstreamResultTypeReport(startDate,
192:                        endDate, ChecksumCheckResults.BITSTREAM_NOT_FOUND);
193:
194:                osw.write("\n");
195:                osw.write(msg("bitstream-not-found-report"));
196:                osw.write(DATE_FORMAT_MIN.format(startDate));
197:                osw.write(" ");
198:                osw.write(msg("date-range-to"));
199:                osw.write(" ");
200:                osw.write(DATE_FORMAT_MIN.format(endDate));
201:                osw.write("\n\n\n");
202:
203:                if (history.size() == 0) {
204:                    osw.write("\n\n");
205:                    osw.write(msg("no-bitstreams-changed"));
206:                    osw.write("\n");
207:                } else {
208:                    printHistoryRecords(history, osw);
209:                }
210:
211:                return history.size();
212:            }
213:
214:            /**
215:             * Send the bitstreams that were set to not be processed report for the
216:             * specified date range.
217:             * 
218:             * @param startDate
219:             *            the start date for the range
220:             * @param endDate
221:             *            the end date for the range
222:             * @param osw
223:             *            the output stream writer to write to.
224:             * 
225:             * @return number of bitstreams found
226:             * 
227:             * @throws IOException
228:             *             if io error occurs
229:             */
230:            public int getNotToBeProcessedReport(Date startDate, Date endDate,
231:                    OutputStreamWriter osw) throws IOException {
232:                // get all the bitstreams marked deleted for today
233:                List history = reporter.getNotProcessedBitstreamsReport(
234:                        startDate, endDate);
235:
236:                osw.write("\n");
237:                osw.write(msg("bitstream-will-no-longer-be-processed"));
238:                osw.write(" ");
239:                osw.write(DATE_FORMAT_MIN.format(startDate));
240:                osw.write(" ");
241:                osw.write(msg("date-range-to"));
242:                osw.write(" ");
243:                osw.write(DATE_FORMAT_MIN.format(endDate));
244:                osw.write("\n\n\n");
245:
246:                if (history.size() == 0) {
247:                    osw.write("\n\n");
248:                    osw.write(msg("no-bitstreams-to-no-longer-be-processed"));
249:                    osw.write("\n");
250:                } else {
251:                    printHistoryRecords(history, osw);
252:                }
253:
254:                return history.size();
255:            }
256:
257:            /**
258:             * Get any bitstreams that are not checked by the checksum checker.
259:             * 
260:             * @param osw
261:             *            the OutputStreamWriter to write to
262:             * 
263:             * @return the number of unchecked bitstreams
264:             * 
265:             * @throws IOException
266:             *             if io error occurs
267:             */
268:            public int getUncheckedBitstreamsReport(OutputStreamWriter osw)
269:                    throws IOException {
270:                // get all the bitstreams marked deleted for today
271:                List bitstreams = reporter.getUnknownBitstreams();
272:
273:                osw.write("\n");
274:                osw.write(msg("unchecked-bitstream-report"));
275:                osw.write(DATE_FORMAT_MIN.format(new Date()));
276:                osw.write("\n\n\n");
277:
278:                if (bitstreams.size() == 0) {
279:                    osw.write("\n\n");
280:                    osw.write(msg("no-unchecked-bitstreams"));
281:                    osw.write("\n");
282:                } else {
283:                    osw.write(msg("howto-add-unchecked-bitstreams"));
284:                    osw.write("\n\n\n");
285:                    this .printDSpaceInfoRecords(bitstreams, osw);
286:                }
287:
288:                return bitstreams.size();
289:            }
290:
291:            /**
292:             * Create a list of the found history records.
293:             * 
294:             * @param history
295:             *            the list of history records to be iterated over.
296:             * @param osw
297:             *            the output stream writer to write to.
298:             * 
299:             * @throws IOException
300:             *             if io error occurs
301:             */
302:            private void printHistoryRecords(List history,
303:                    OutputStreamWriter osw) throws IOException {
304:                Iterator iter = history.iterator();
305:                while (iter.hasNext()) {
306:                    ChecksumHistory historyInfo = (ChecksumHistory) iter.next();
307:                    StringBuffer buf = new StringBuffer(1000);
308:                    buf
309:                            .append("------------------------------------------------ \n");
310:                    buf.append(msg("bitstream-id")).append(" = ").append(
311:                            historyInfo.getBitstreamId()).append("\n");
312:                    buf.append(msg("process-start-date")).append(" = ").append(
313:                            DATE_FORMAT_MAX.format(historyInfo
314:                                    .getProcessStartDate())).append("\n");
315:                    buf.append(msg("process-end-date")).append(" = ").append(
316:                            DATE_FORMAT_MAX.format(historyInfo
317:                                    .getProcessEndDate())).append("\n");
318:                    buf.append(msg("checksum-expected")).append(" = ").append(
319:                            historyInfo.getChecksumExpected()).append("\n");
320:                    buf.append(msg("checksum-calculated")).append(" = ")
321:                            .append(historyInfo.getChecksumCalculated())
322:                            .append("\n");
323:                    buf.append(msg("result")).append(" = ").append(
324:                            historyInfo.getResult()).append("\n");
325:                    buf
326:                            .append("----------------------------------------------- \n\n");
327:                    osw.write(buf.toString());
328:                }
329:            }
330:
331:            /**
332:             * Create a list of the found history records.
333:             * 
334:             * @param bitstreams
335:             *            the list of history records to be iterated over.
336:             * @param osw
337:             *            the output stream to write to.
338:             * 
339:             * @throws IOException
340:             *             if io error occurs
341:             */
342:            private void printDSpaceInfoRecords(List bitstreams,
343:                    OutputStreamWriter osw) throws IOException {
344:                Iterator iter = bitstreams.iterator();
345:
346:                while (iter.hasNext()) {
347:                    DSpaceBitstreamInfo info = (DSpaceBitstreamInfo) iter
348:                            .next();
349:                    StringBuffer buf = new StringBuffer(1000);
350:                    buf
351:                            .append("------------------------------------------------ \n");
352:                    buf.append(msg("format-id")).append(" =  ").append(
353:                            info.getBitstreamFormatId()).append("\n");
354:                    buf.append(msg("deleted")).append(" = ").append(
355:                            info.getDeleted()).append("\n");
356:                    buf.append(msg("bitstream-id")).append(" = ").append(
357:                            info.getBitstreamId()).append("\n");
358:                    buf.append(msg("checksum-algorithm")).append(" = ").append(
359:                            info.getChecksumAlgorithm()).append("\n");
360:                    buf.append(msg("internal-id")).append(" = ").append(
361:                            info.getInternalId()).append("\n");
362:                    buf.append(msg("name")).append(" = ")
363:                            .append(info.getName()).append("\n");
364:                    buf.append(msg("size")).append(" = ")
365:                            .append(info.getSize()).append("\n");
366:                    buf.append(msg("source")).append(" = ").append(
367:                            info.getSource()).append("\n");
368:                    buf.append(msg("checksum")).append(" = ").append(
369:                            info.getStoredChecksum()).append("\n");
370:                    buf.append(msg("store-number")).append(" = ").append(
371:                            info.getStoreNumber()).append("\n");
372:                    buf.append(msg("description")).append(" = ").append(
373:                            info.getUserFormatDescription()).append("\n");
374:                    buf
375:                            .append("----------------------------------------------- \n\n");
376:                    osw.write(buf.toString());
377:                }
378:            }
379:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.