1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 University of New Mexico and the
|
4
|
* Regents of the University of California
|
5
|
*
|
6
|
* '$Author: costa $'
|
7
|
* '$Date: 2004-04-28 10:54:02 -0700 (Wed, 28 Apr 2004) $'
|
8
|
* '$Revision: 2139 $'
|
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 Connection conn;
|
42
|
private Harvester harvester; // The parent Harvester object
|
43
|
private int detailLogID;
|
44
|
private int harvestLogID;
|
45
|
private HarvestDocument harvestDocument; // The associated HarvestDocument
|
46
|
private String errorMessage;
|
47
|
|
48
|
|
49
|
/**
|
50
|
* 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
|
* @param conn the database connection
|
55
|
* @param detailLogID primary key in the HARVEST_LOG table
|
56
|
* @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
|
*/
|
60
|
public HarvestDetailLog(Harvester harvester,
|
61
|
Connection conn,
|
62
|
int detailLogID,
|
63
|
int harvestLogID,
|
64
|
HarvestDocument harvestDocument,
|
65
|
String errorMessage
|
66
|
) {
|
67
|
this.harvester = harvester;
|
68
|
this.conn = conn;
|
69
|
this.detailLogID = detailLogID;
|
70
|
this.harvestLogID = harvestLogID;
|
71
|
this.harvestDocument = harvestDocument;
|
72
|
this.errorMessage = errorMessage;
|
73
|
}
|
74
|
|
75
|
|
76
|
/**
|
77
|
* Inserts a new entry into the HARVEST_DETAIL_LOG table, based on the
|
78
|
* contents of this HarvestDetailLog object.
|
79
|
*/
|
80
|
void dbInsertHarvestDetailLogEntry() {
|
81
|
String dequotedMessage;
|
82
|
String insertString;
|
83
|
Statement stmt;
|
84
|
|
85
|
dequotedMessage = harvester.dequoteText(errorMessage);
|
86
|
|
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
|
"'" + dequotedMessage + "'," +
|
100
|
"'" + harvestDocument.documentType + "'" +
|
101
|
")";
|
102
|
|
103
|
try {
|
104
|
stmt = conn.createStatement();
|
105
|
stmt.executeUpdate(insertString);
|
106
|
stmt.close();
|
107
|
}
|
108
|
catch(SQLException e) {
|
109
|
System.out.println("SQLException: " + e.getMessage());
|
110
|
}
|
111
|
}
|
112
|
|
113
|
|
114
|
/**
|
115
|
* Prints the contents of this HarvestLog object. Used in generating reports.
|
116
|
*
|
117
|
* @param out the PrintStream to write to
|
118
|
*/
|
119
|
public void printOutput(PrintStream out) {
|
120
|
out.println("* detailLogID: " + detailLogID);
|
121
|
out.println("* errorMessage: " + errorMessage);
|
122
|
harvestDocument.printOutput(out);
|
123
|
}
|
124
|
|
125
|
}
|