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 |
2139
|
costa
|
|
41 |
|
|
private Connection conn;
|
42 |
2031
|
costa
|
private Harvester harvester; // The parent Harvester object
|
43 |
2022
|
costa
|
private int detailLogID;
|
44 |
2031
|
costa
|
private int harvestLogID;
|
45 |
|
|
private HarvestDocument harvestDocument; // The associated HarvestDocument
|
46 |
2022
|
costa
|
private String errorMessage;
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
2031
|
costa
|
* Creates a new instance of HarvestDetailLog and inserts the data into
|
51 |
|
|
* the HARVEST_DETAIL_LOG table.
|
52 |
|
|
*
|
53 |
|
|
* @param harvester the Harvester parent object
|
54 |
2139
|
costa
|
* @param conn the database connection
|
55 |
|
|
* @param detailLogID primary key in the HARVEST_LOG table
|
56 |
2031
|
costa
|
* @param harvestLogID foreign key value matching the HARVEST_LOG table
|
57 |
|
|
* @param harvestDocument HarvestDocument object that generated an error
|
58 |
|
|
* @param errorMessage text of the error message
|
59 |
2022
|
costa
|
*/
|
60 |
2031
|
costa
|
public HarvestDetailLog(Harvester harvester,
|
61 |
2139
|
costa
|
Connection conn,
|
62 |
|
|
int detailLogID,
|
63 |
2031
|
costa
|
int harvestLogID,
|
64 |
|
|
HarvestDocument harvestDocument,
|
65 |
|
|
String errorMessage
|
66 |
|
|
) {
|
67 |
|
|
this.harvester = harvester;
|
68 |
2139
|
costa
|
this.conn = conn;
|
69 |
|
|
this.detailLogID = detailLogID;
|
70 |
2031
|
costa
|
this.harvestLogID = harvestLogID;
|
71 |
|
|
this.harvestDocument = harvestDocument;
|
72 |
|
|
this.errorMessage = errorMessage;
|
73 |
2022
|
costa
|
}
|
74 |
2031
|
costa
|
|
75 |
2022
|
costa
|
|
76 |
|
|
/**
|
77 |
|
|
* Inserts a new entry into the HARVEST_DETAIL_LOG table, based on the
|
78 |
2031
|
costa
|
* contents of this HarvestDetailLog object.
|
79 |
2022
|
costa
|
*/
|
80 |
2031
|
costa
|
void dbInsertHarvestDetailLogEntry() {
|
81 |
2036
|
costa
|
String dequotedMessage;
|
82 |
2031
|
costa
|
String insertString;
|
83 |
|
|
Statement stmt;
|
84 |
2036
|
costa
|
|
85 |
|
|
dequotedMessage = harvester.dequoteText(errorMessage);
|
86 |
2031
|
costa
|
|
87 |
|
|
// Set the value of the HARVEST_LOG_ID to the current time in UTC seconds
|
88 |
|
|
insertString = "INSERT INTO HARVEST_DETAIL_LOG " +
|
89 |
|
|
"(DETAIL_LOG_ID, HARVEST_LOG_ID, SCOPE," +
|
90 |
|
|
" IDENTIFIER, REVISION," +
|
91 |
|
|
" DOCUMENT_URL, ERROR_MESSAGE, DOCUMENT_TYPE) " +
|
92 |
|
|
"values(" +
|
93 |
|
|
detailLogID + ", " +
|
94 |
|
|
harvestLogID + ", " +
|
95 |
|
|
"'" + harvestDocument.scope + "', " +
|
96 |
|
|
harvestDocument.identifier + ", " +
|
97 |
|
|
harvestDocument.revision + ", " +
|
98 |
|
|
"'" + harvestDocument.documentURL + "', " +
|
99 |
2036
|
costa
|
"'" + dequotedMessage + "'," +
|
100 |
2031
|
costa
|
"'" + harvestDocument.documentType + "'" +
|
101 |
|
|
")";
|
102 |
|
|
|
103 |
|
|
try {
|
104 |
2139
|
costa
|
stmt = conn.createStatement();
|
105 |
2031
|
costa
|
stmt.executeUpdate(insertString);
|
106 |
|
|
stmt.close();
|
107 |
|
|
}
|
108 |
|
|
catch(SQLException e) {
|
109 |
|
|
System.out.println("SQLException: " + e.getMessage());
|
110 |
|
|
}
|
111 |
2022
|
costa
|
}
|
112 |
2031
|
costa
|
|
113 |
|
|
|
114 |
|
|
/**
|
115 |
|
|
* Prints the contents of this HarvestLog object. Used in generating reports.
|
116 |
2086
|
costa
|
*
|
117 |
|
|
* @param out the PrintStream to write to
|
118 |
2031
|
costa
|
*/
|
119 |
2139
|
costa
|
public void printOutput(PrintStream out) {
|
120 |
2086
|
costa
|
out.println("* detailLogID: " + detailLogID);
|
121 |
|
|
out.println("* errorMessage: " + errorMessage);
|
122 |
|
|
harvestDocument.printOutput(out);
|
123 |
2031
|
costa
|
}
|
124 |
|
|
|
125 |
2022
|
costa
|
}
|