Project

General

Profile

1 2094 jones
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 University of New Mexico and the
4
 *                  Regents of the University of California
5 2022 costa
 *
6 2094 jones
 *   '$Author$'
7
 *     '$Date$'
8
 * '$Revision$'
9
 *
10
 * This program is free software; you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation; either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 2022 costa
 */
24
25
package edu.ucsb.nceas.metacat.harvesterClient;
26
27 2086 costa
import java.io.PrintStream;
28 2031 costa
import java.sql.Connection;
29
import java.sql.SQLException;
30
import java.sql.Statement;
31
32 2022 costa
/**
33
 * HarvestDetailLog manages data and operations corresponding to the
34
 * HARVEST_DETAIL_LOG table. It records errors encountered while attempting
35 2031 costa
 * to harvest a particular EML document.
36 2022 costa
 *
37
 * @author  costa
38
 */
39
public class HarvestDetailLog {
40
41 2031 costa
  private Harvester harvester;              // The parent Harvester object
42 2022 costa
  private int detailLogID;
43 2031 costa
  private int harvestLogID;
44
  private HarvestDocument harvestDocument;  // The associated HarvestDocument
45 2022 costa
  private String errorMessage;
46
47
48
  /**
49 2031 costa
   * Creates a new instance of HarvestDetailLog and inserts the data into
50
   * the HARVEST_DETAIL_LOG table.
51
   *
52
   * @param  harvester       the Harvester parent object
53
   * @param  harvestLogID    foreign key value matching the HARVEST_LOG table
54
   * @param  harvestDocument HarvestDocument object that generated an error
55
   * @param  errorMessage    text of the error message
56 2022 costa
   */
57 2031 costa
  public HarvestDetailLog(Harvester       harvester,
58
                          int             harvestLogID,
59
                          HarvestDocument harvestDocument,
60
                          String          errorMessage
61
                         ) {
62
    this.harvester = harvester;
63
    this.detailLogID = harvester.getDetailLogID();  // Primary key for record
64
    this.harvestLogID = harvestLogID;
65
    this.harvestDocument = harvestDocument;
66
    this.errorMessage = errorMessage;
67 2022 costa
  }
68 2031 costa
69 2022 costa
70
  /**
71
   * Inserts a new entry into the HARVEST_DETAIL_LOG table, based on the
72 2031 costa
   * contents of this HarvestDetailLog object.
73 2022 costa
   */
74 2031 costa
  void dbInsertHarvestDetailLogEntry() {
75 2036 costa
    String dequotedMessage;
76 2031 costa
    String insertString;
77
		Statement stmt;
78 2036 costa
79
    dequotedMessage = harvester.dequoteText(errorMessage);
80 2031 costa
81
    // Set the value of the HARVEST_LOG_ID to the current time in UTC seconds
82
    insertString = "INSERT INTO HARVEST_DETAIL_LOG " +
83
                   "(DETAIL_LOG_ID, HARVEST_LOG_ID, SCOPE," +
84
                   " IDENTIFIER, REVISION," +
85
                   " DOCUMENT_URL, ERROR_MESSAGE, DOCUMENT_TYPE) " +
86
                   "values(" +
87
                   detailLogID + ", " +
88
                   harvestLogID + ", " +
89
                   "'" + harvestDocument.scope + "', " +
90
                   harvestDocument.identifier + ", " +
91
                   harvestDocument.revision + ", " +
92
                   "'" + harvestDocument.documentURL + "', " +
93 2036 costa
                   "'" + dequotedMessage + "'," +
94 2031 costa
                   "'" + harvestDocument.documentType + "'" +
95
                   ")";
96
97
		try {
98 2036 costa
			stmt = harvester.conn.createStatement();
99 2031 costa
			stmt.executeUpdate(insertString);
100
			stmt.close();
101
		}
102
    catch(SQLException e) {
103
			System.out.println("SQLException: " + e.getMessage());
104
		}
105 2022 costa
  }
106 2031 costa
107
108
  /**
109
   * Prints the contents of this HarvestLog object. Used in generating reports.
110 2086 costa
   *
111
   * @param out   the PrintStream to write to
112 2031 costa
   */
113 2086 costa
  void printOutput(PrintStream out) {
114
    out.println("* detailLogID:          " + detailLogID);
115
    out.println("* errorMessage:         " + errorMessage);
116
    harvestDocument.printOutput(out);
117 2031 costa
  }
118
119 2022 costa
}