1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 University of New Mexico and the
|
4
|
* Regents of the University of California
|
5
|
*
|
6
|
* '$Author: jones $'
|
7
|
* '$Date: 2004-04-01 16:41:58 -0800 (Thu, 01 Apr 2004) $'
|
8
|
* '$Revision: 2094 $'
|
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
|
*/
|
24
|
|
25
|
package edu.ucsb.nceas.metacat.harvesterClient;
|
26
|
|
27
|
import java.io.PrintStream;
|
28
|
import java.sql.Connection;
|
29
|
import java.sql.SQLException;
|
30
|
import java.sql.Statement;
|
31
|
|
32
|
/**
|
33
|
* HarvestDetailLog manages data and operations corresponding to the
|
34
|
* HARVEST_DETAIL_LOG table. It records errors encountered while attempting
|
35
|
* to harvest a particular EML document.
|
36
|
*
|
37
|
* @author costa
|
38
|
*/
|
39
|
public class HarvestDetailLog {
|
40
|
|
41
|
private Harvester harvester; // The parent Harvester object
|
42
|
private int detailLogID;
|
43
|
private int harvestLogID;
|
44
|
private HarvestDocument harvestDocument; // The associated HarvestDocument
|
45
|
private String errorMessage;
|
46
|
|
47
|
|
48
|
/**
|
49
|
* 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
|
*/
|
57
|
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
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* Inserts a new entry into the HARVEST_DETAIL_LOG table, based on the
|
72
|
* contents of this HarvestDetailLog object.
|
73
|
*/
|
74
|
void dbInsertHarvestDetailLogEntry() {
|
75
|
String dequotedMessage;
|
76
|
String insertString;
|
77
|
Statement stmt;
|
78
|
|
79
|
dequotedMessage = harvester.dequoteText(errorMessage);
|
80
|
|
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
|
"'" + dequotedMessage + "'," +
|
94
|
"'" + harvestDocument.documentType + "'" +
|
95
|
")";
|
96
|
|
97
|
try {
|
98
|
stmt = harvester.conn.createStatement();
|
99
|
stmt.executeUpdate(insertString);
|
100
|
stmt.close();
|
101
|
}
|
102
|
catch(SQLException e) {
|
103
|
System.out.println("SQLException: " + e.getMessage());
|
104
|
}
|
105
|
}
|
106
|
|
107
|
|
108
|
/**
|
109
|
* Prints the contents of this HarvestLog object. Used in generating reports.
|
110
|
*
|
111
|
* @param out the PrintStream to write to
|
112
|
*/
|
113
|
void printOutput(PrintStream out) {
|
114
|
out.println("* detailLogID: " + detailLogID);
|
115
|
out.println("* errorMessage: " + errorMessage);
|
116
|
harvestDocument.printOutput(out);
|
117
|
}
|
118
|
|
119
|
}
|