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.text.SimpleDateFormat;
037: import java.util.Date;
038:
039: import org.apache.log4j.Logger;
040: import org.dspace.core.I18nUtil;
041:
042: /**
043: * <p>
044: * Collects results from a Checksum process and outputs them to a Log4j Logger.
045: * </p>
046: *
047: *
048: * @author Jim Downing
049: * @author Grace Carpenter
050: * @author Nathan Sarr
051: *
052: *
053: */
054: public class ResultsLogger implements ChecksumResultsCollector {
055: /**
056: * Usual Log4J logger.
057: */
058: private static final Logger LOG = Logger
059: .getLogger(ResultsLogger.class);
060:
061: /**
062: * Utility date format.
063: */
064: private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(
065: "MM/dd/yyyy hh:mm:ss");
066:
067: /**
068: * Date the current checking run started.
069: */
070: Date startDate = null;
071:
072: /**
073: * ChecksumResultDAO dependency variable.
074: */
075: private ChecksumResultDAO resultDAO;
076:
077: /**
078: * Blanked off, no-op constructor. Do not use.
079: */
080: private ResultsLogger() {
081: ;
082: }
083:
084: /**
085: * Main constructor.
086: *
087: * @param startDt
088: * Date the checking run started.
089: */
090: public ResultsLogger(Date startDt) {
091: this .resultDAO = new ChecksumResultDAO();
092:
093: LOG.info(msg("run-start-time") + ": "
094: + DATE_FORMAT.format(startDt));
095: }
096:
097: /**
098: * Get the i18N string.
099: *
100: * @param key
101: * to get the message.
102: * @return the message found.
103: */
104: private String msg(String key) {
105: return I18nUtil.getMessage("org.dspace.checker.ResultsLogger."
106: + key);
107: }
108:
109: /**
110: * Collect a result for logging.
111: *
112: * @param info
113: * the BitstreamInfo representing the result.
114: * @see org.dspace.checker.ChecksumResultsCollector#collect(org.dspace.checker.BitstreamInfo)
115: */
116: public void collect(BitstreamInfo info) {
117: LOG
118: .info("******************************************************");
119: LOG.info(msg("bitstream-id") + ": " + info.getBitstreamId());
120: LOG.info(msg("bitstream-info-found") + ": "
121: + info.getInfoFound());
122: LOG.info(msg("bitstream-marked-deleted") + ": "
123: + info.getDeleted());
124: LOG.info(msg("bitstream-found") + ": "
125: + info.getBitstreamFound());
126: LOG.info(msg("to-be-processed") + ": "
127: + info.getToBeProcessed());
128: LOG.info(msg("internal-id") + ": " + info.getInternalId());
129: LOG.info(msg("name") + ": " + info.getName());
130: LOG.info(msg("store-number") + ": " + info.getStoreNumber());
131: LOG.info(msg("size") + ": " + info.getSize());
132: LOG.info(msg("bitstream-format") + ": "
133: + info.getBitstreamFormatId());
134: LOG.info(msg("user-format-description") + ": "
135: + info.getUserFormatDescription());
136: LOG.info(msg("source") + ": " + info.getSource());
137: LOG.info(msg("checksum-algorithm") + ": "
138: + info.getChecksumAlgorithm());
139: LOG.info(msg("previous-checksum") + ": "
140: + info.getStoredChecksum());
141: LOG.info(msg("previous-checksum-date")
142: + ": "
143: + ((info.getProcessEndDate() != null) ? DATE_FORMAT
144: .format(info.getProcessEndDate()) : "unknown"));
145: LOG.info(msg("new-checksum") + ": "
146: + info.getCalculatedChecksum());
147: LOG.info(msg("checksum-comparison-result")
148: + ": "
149: + resultDAO.getChecksumCheckStr(info
150: .getChecksumCheckResult()));
151: LOG.info("\n\n");
152: }
153: }
|