Revision 2139
Added by Duane Costa over 20 years ago
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestDetailLog.java | ||
---|---|---|
37 | 37 |
* @author costa |
38 | 38 |
*/ |
39 | 39 |
public class HarvestDetailLog { |
40 |
|
|
40 |
|
|
41 |
private Connection conn; |
|
41 | 42 |
private Harvester harvester; // The parent Harvester object |
42 | 43 |
private int detailLogID; |
43 | 44 |
private int harvestLogID; |
... | ... | |
50 | 51 |
* the HARVEST_DETAIL_LOG table. |
51 | 52 |
* |
52 | 53 |
* @param harvester the Harvester parent object |
54 |
* @param conn the database connection |
|
55 |
* @param detailLogID primary key in the HARVEST_LOG table |
|
53 | 56 |
* @param harvestLogID foreign key value matching the HARVEST_LOG table |
54 | 57 |
* @param harvestDocument HarvestDocument object that generated an error |
55 | 58 |
* @param errorMessage text of the error message |
56 | 59 |
*/ |
57 | 60 |
public HarvestDetailLog(Harvester harvester, |
61 |
Connection conn, |
|
62 |
int detailLogID, |
|
58 | 63 |
int harvestLogID, |
59 | 64 |
HarvestDocument harvestDocument, |
60 | 65 |
String errorMessage |
61 | 66 |
) { |
62 | 67 |
this.harvester = harvester; |
63 |
this.detailLogID = harvester.getDetailLogID(); // Primary key for record |
|
68 |
this.conn = conn; |
|
69 |
this.detailLogID = detailLogID; |
|
64 | 70 |
this.harvestLogID = harvestLogID; |
65 | 71 |
this.harvestDocument = harvestDocument; |
66 | 72 |
this.errorMessage = errorMessage; |
... | ... | |
95 | 101 |
")"; |
96 | 102 |
|
97 | 103 |
try { |
98 |
stmt = harvester.conn.createStatement();
|
|
104 |
stmt = conn.createStatement(); |
|
99 | 105 |
stmt.executeUpdate(insertString); |
100 | 106 |
stmt.close(); |
101 | 107 |
} |
... | ... | |
110 | 116 |
* |
111 | 117 |
* @param out the PrintStream to write to |
112 | 118 |
*/ |
113 |
void printOutput(PrintStream out) { |
|
119 |
public void printOutput(PrintStream out) {
|
|
114 | 120 |
out.println("* detailLogID: " + detailLogID); |
115 | 121 |
out.println("* errorMessage: " + errorMessage); |
116 | 122 |
harvestDocument.printOutput(out); |
src/edu/ucsb/nceas/metacat/harvesterClient/Harvester.java | ||
---|---|---|
59 | 59 |
private static final String marker = |
60 | 60 |
"*****************************************************************************"; |
61 | 61 |
|
62 |
static Properties properties; |
|
62 |
public static Properties properties;
|
|
63 | 63 |
|
64 | 64 |
|
65 | 65 |
/* |
... | ... | |
77 | 77 |
/** |
78 | 78 |
* Loads Harvester properties from a configuration file. |
79 | 79 |
*/ |
80 |
private static void loadProperties() { |
|
81 |
File configfile = new File("../../lib/harvester", "harvester.properties"); |
|
80 |
public static void loadProperties(File configfile) { |
|
82 | 81 |
properties = new Properties(); |
83 | 82 |
|
84 | 83 |
try { |
... | ... | |
100 | 99 |
* @throws ParserConfigurationException |
101 | 100 |
*/ |
102 | 101 |
public static void main(String[] args) { |
102 |
File configfile = new File("../../lib/harvester", "harvester.properties"); |
|
103 | 103 |
Integer delayDefault = new Integer(0); // Default number of hours delay |
104 | 104 |
int delay = delayDefault.intValue(); // Delay in hours before first harvest |
105 | 105 |
Integer d; // Used for determining delay |
... | ... | |
118 | 118 |
|
119 | 119 |
System.out.println(marker); |
120 | 120 |
System.out.println("Starting Harvester"); |
121 |
Harvester.loadProperties(); |
|
122 |
//properties.list(System.out); |
|
121 |
Harvester.loadProperties(configfile); |
|
123 | 122 |
|
124 | 123 |
// Parse the delay property. Use default if necessary. |
125 | 124 |
try { |
... | ... | |
216 | 215 |
*/ |
217 | 216 |
|
218 | 217 |
/** Database connection */ |
219 |
Connection conn;
|
|
218 |
private Connection conn = null;
|
|
220 | 219 |
|
221 | 220 |
/** Used during development to determine whether to connect to metacat |
222 | 221 |
* Sometimes it's useful to test parts of the code without actually |
... | ... | |
283 | 282 |
String errorMessage |
284 | 283 |
) { |
285 | 284 |
HarvestLog harvestLog; |
285 |
int harvestLogID = getHarvestLogID(); |
|
286 |
int detailLogID; |
|
286 | 287 |
|
287 | 288 |
/* If there is no associated harvest document, call the basic constructor; |
288 | 289 |
* else call the extended constructor. |
289 | 290 |
*/ |
290 | 291 |
if (harvestDocument == null) { |
291 |
harvestLog = new HarvestLog(this, harvestStartTime, status, message, |
|
292 |
harvestOperationCode, siteScheduleID); |
|
292 |
harvestLog = new HarvestLog(this, conn, harvestLogID, harvestStartTime, |
|
293 |
status, message, harvestOperationCode, |
|
294 |
siteScheduleID); |
|
293 | 295 |
} |
294 | 296 |
else { |
295 |
harvestLog = new HarvestLog(this, harvestStartTime, status, message, |
|
297 |
detailLogID = getDetailLogID(); |
|
298 |
harvestLog = new HarvestLog(this, conn, harvestLogID, detailLogID, |
|
299 |
harvestStartTime, status, message, |
|
296 | 300 |
harvestOperationCode, siteScheduleID, |
297 | 301 |
harvestDocument, errorMessage); |
298 | 302 |
} |
299 | 303 |
|
300 | 304 |
harvestLogList.add(harvestLog); |
301 | 305 |
} |
306 |
|
|
307 |
|
|
308 |
public void closeConnection() { |
|
309 |
try { |
|
310 |
// Close the database connection |
|
311 |
System.out.println("Closing the database connection."); |
|
312 |
conn.close(); |
|
313 |
} |
|
314 |
catch (SQLException e) { |
|
315 |
System.out.println("Database access failed " + e); |
|
316 |
} |
|
317 |
} |
|
302 | 318 |
|
303 | 319 |
|
304 | 320 |
/** |
... | ... | |
322 | 338 |
* @param text the original string |
323 | 339 |
* @return a string containing the normalized text |
324 | 340 |
*/ |
325 |
String dequoteText(String text) { |
|
341 |
public String dequoteText(String text) {
|
|
326 | 342 |
char c; |
327 | 343 |
StringBuffer stringBuffer = new StringBuffer(); |
328 | 344 |
|
... | ... | |
343 | 359 |
|
344 | 360 |
return stringBuffer.toString(); |
345 | 361 |
} |
362 |
|
|
363 |
/** |
|
364 |
* Returns a connection to the database. Opens the connection if a connection |
|
365 |
* has not already been made previously. |
|
366 |
* |
|
367 |
* @return conn the database Connection object |
|
368 |
*/ |
|
369 |
public Connection getConnection() { |
|
370 |
String database; |
|
371 |
String dbDriver = ""; |
|
372 |
String defaultDB; |
|
373 |
String password; |
|
374 |
Properties properties = Harvester.properties; |
|
375 |
String user; |
|
376 |
SQLWarning warn; |
|
377 |
|
|
378 |
if (conn == null) { |
|
379 |
database = properties.getProperty("database"); |
|
380 |
|
|
381 |
if (database.equalsIgnoreCase("oracle")) { |
|
382 |
dbDriver = "oracle.jdbc.driver.OracleDriver"; |
|
383 |
} |
|
384 |
else if (database.equalsIgnoreCase("postgresql")) { |
|
385 |
dbDriver = "org.postgresql.Driver"; |
|
386 |
} |
|
387 |
else if (database.equalsIgnoreCase("sqlserver")) { |
|
388 |
dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; |
|
389 |
} |
|
346 | 390 |
|
391 |
defaultDB = properties.getProperty("defaultDB"); |
|
392 |
password = properties.getProperty("password"); |
|
393 |
user = properties.getProperty("user"); |
|
347 | 394 |
|
395 |
// Load the jdbc driver |
|
396 |
try { |
|
397 |
Class.forName(dbDriver); |
|
398 |
} |
|
399 |
catch (ClassNotFoundException e) { |
|
400 |
System.out.println("Can't load driver " + e); |
|
401 |
System.exit(1); |
|
402 |
} |
|
403 |
|
|
404 |
// Make the database connection |
|
405 |
try { |
|
406 |
System.out.println("Getting connection to Harvester tables"); |
|
407 |
conn = DriverManager.getConnection(defaultDB, user, password); |
|
408 |
|
|
409 |
// If a SQLWarning object is available, print its warning(s). |
|
410 |
// There may be multiple warnings chained. |
|
411 |
warn = conn.getWarnings(); |
|
412 |
|
|
413 |
if (warn != null) { |
|
414 |
while (warn != null) { |
|
415 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
416 |
System.out.println("Message: " + warn.getMessage()); |
|
417 |
System.out.println("Vendor: " + warn.getErrorCode()); |
|
418 |
System.out.println(""); |
|
419 |
warn = warn.getNextWarning(); |
|
420 |
} |
|
421 |
} |
|
422 |
} |
|
423 |
catch (SQLException e) { |
|
424 |
System.out.println("Database access failed " + e); |
|
425 |
System.exit(1); |
|
426 |
} |
|
427 |
} |
|
428 |
|
|
429 |
return conn; |
|
430 |
} |
|
431 |
|
|
432 |
|
|
348 | 433 |
/** |
349 | 434 |
* Gets the current value of the detailLogID for storage as a primary key in |
350 | 435 |
* the DETAIL_LOG_ID field of the HARVEST_DETAIL_LOG table. |
351 | 436 |
* |
352 | 437 |
* @return the current value of the detailLogID |
353 | 438 |
*/ |
354 |
int getDetailLogID() { |
|
439 |
public int getDetailLogID() {
|
|
355 | 440 |
int currentValue = detailLogID; |
356 | 441 |
|
357 | 442 |
detailLogID++; |
... | ... | |
365 | 450 |
* |
366 | 451 |
* @return the current value of the detailLogID |
367 | 452 |
*/ |
368 |
int getHarvestLogID() { |
|
453 |
public int getHarvestLogID() {
|
|
369 | 454 |
int currentValue = harvestLogID; |
370 | 455 |
|
371 | 456 |
harvestLogID++; |
... | ... | |
381 | 466 |
* @return the maximum integer stored in the fieldName field of tableName |
382 | 467 |
*/ |
383 | 468 |
private int getMaxValue(String tableName, String fieldName) { |
384 |
int maxValue = 100;
|
|
469 |
int maxValue = 0; |
|
385 | 470 |
int fieldValue; |
386 | 471 |
String query = "SELECT " + fieldName + " FROM " + tableName; |
387 | 472 |
Statement stmt; |
... | ... | |
465 | 550 |
* Initializes the detailLogID and harvestLogID values to their current |
466 | 551 |
* maximums + 1. |
467 | 552 |
*/ |
468 |
private void initLogIDs() {
|
|
553 |
public void initLogIDs() {
|
|
469 | 554 |
detailLogID = getMaxValue("HARVEST_DETAIL_LOG", "DETAIL_LOG_ID") + 1; |
470 | 555 |
harvestLogID = getMaxValue("HARVEST_LOG", "HARVEST_LOG_ID") + 1; |
471 | 556 |
} |
... | ... | |
737 | 822 |
System.out.println("There was a problem sending email to " + to); |
738 | 823 |
System.out.println("IOException: " + e.getMessage()); |
739 | 824 |
} |
825 |
} |
|
740 | 826 |
} |
741 |
} |
|
827 |
|
|
828 |
|
|
829 |
/** |
|
830 |
* Sets the harvest start time for this harvest run. |
|
831 |
* |
|
832 |
* @param date |
|
833 |
*/ |
|
834 |
public void setHarvestStartTime(Date date) { |
|
835 |
harvestStartTime = date; |
|
836 |
} |
|
742 | 837 |
|
743 | 838 |
|
744 | 839 |
/** |
... | ... | |
755 | 850 |
addLogEntry(0, "Shutting Down Harvester", "HarvesterShutdown", 0, null, ""); |
756 | 851 |
pruneHarvestLog(); |
757 | 852 |
pruneHarvestDetailLog(); |
758 |
|
|
759 |
try { |
|
760 |
// Close the database connection |
|
761 |
conn.close(); |
|
762 |
} |
|
763 |
catch (SQLException e) { |
|
764 |
System.out.println("Database access failed " + e); |
|
765 |
} |
|
766 |
|
|
853 |
closeConnection(); |
|
767 | 854 |
// Print log to standard output and then email the Harvester administrator |
768 | 855 |
printHarvestLog(System.out, maxCodeLevel, siteScheduleID); |
769 | 856 |
reportToAdministrator(maxCodeLevel); // Send a copy to harvester admin |
... | ... | |
779 | 866 |
*/ |
780 | 867 |
private void startup(int nHarvests, int maxHarvests) { |
781 | 868 |
Boolean ctm; |
782 |
String database; |
|
783 |
String dbDriver = ""; |
|
784 |
String defaultDB; |
|
785 | 869 |
Integer lp; |
786 | 870 |
String metacatURL; |
787 |
Date now; |
|
788 |
String password; |
|
789 |
Properties properties; |
|
790 |
//String response; |
|
791 |
String sessionId; |
|
792 |
String user; |
|
793 |
String userName = System.getProperty("user.name"); |
|
794 |
SQLWarning warn; |
|
871 |
Date now = new Date(); |
|
872 |
Properties properties = Harvester.properties; |
|
795 | 873 |
|
796 |
// Log startup operation
|
|
874 |
timestamp = now.toString();
|
|
797 | 875 |
System.out.println(Harvester.marker); |
798 |
now = new Date(); |
|
799 |
timestamp = now.toString(); |
|
800 | 876 |
System.out.println(timestamp + ": Starting Next Harvest (" + |
801 | 877 |
nHarvests + "/" + maxHarvests + ")"); |
802 |
Harvester.loadProperties(); |
|
803 |
properties = Harvester.properties; |
|
804 | 878 |
ctm = Boolean.valueOf(properties.getProperty("connectToMetacat", "true")); |
805 | 879 |
connectToMetacat = ctm.booleanValue(); |
806 |
database = properties.getProperty("database"); |
|
807 |
|
|
808 |
if (database.equalsIgnoreCase("oracle")) { |
|
809 |
dbDriver = "oracle.jdbc.driver.OracleDriver"; |
|
810 |
} |
|
811 |
else if (database.equalsIgnoreCase("postgresql")) { |
|
812 |
dbDriver = "org.postgresql.Driver"; |
|
813 |
} |
|
814 |
else if (database.equalsIgnoreCase("sqlserver")) { |
|
815 |
dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; |
|
816 |
} |
|
817 |
|
|
818 | 880 |
harvesterAdministrator = properties.getProperty("harvesterAdministrator"); |
881 |
smtpServer = properties.getProperty("smtpServer", "localhost"); |
|
819 | 882 |
|
820 | 883 |
try { |
821 | 884 |
lp = Integer.valueOf(properties.getProperty("logPeriod", "90")); |
... | ... | |
828 | 891 |
logPeriod = 90; |
829 | 892 |
} |
830 | 893 |
|
831 |
defaultDB = properties.getProperty("defaultDB"); |
|
832 |
metacatURL = properties.getProperty("metacatURL"); |
|
833 |
password = properties.getProperty("password"); |
|
834 |
smtpServer = properties.getProperty("smtpServer", "localhost"); |
|
835 |
user = properties.getProperty("user"); |
|
836 |
|
|
837 |
// Load the jdbc driver |
|
838 |
try { |
|
839 |
Class.forName(dbDriver); |
|
840 |
} |
|
841 |
catch (ClassNotFoundException e) { |
|
842 |
System.out.println("Can't load driver " + e); |
|
843 |
System.exit(1); |
|
844 |
} |
|
845 |
|
|
846 |
// Make the database connection |
|
847 |
try { |
|
848 |
System.out.println("Getting connection to Harvester tables"); |
|
849 |
conn = DriverManager.getConnection(defaultDB, user, password); |
|
850 |
|
|
851 |
// If a SQLWarning object is available, print its warning(s). |
|
852 |
// There may be multiple warnings chained. |
|
853 |
warn = conn.getWarnings(); |
|
854 |
|
|
855 |
if (warn != null) { |
|
856 |
while (warn != null) { |
|
857 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
858 |
System.out.println("Message: " + warn.getMessage()); |
|
859 |
System.out.println("Vendor: " + warn.getErrorCode()); |
|
860 |
System.out.println(""); |
|
861 |
warn = warn.getNextWarning(); |
|
862 |
} |
|
863 |
} |
|
864 |
} |
|
865 |
catch (SQLException e) { |
|
866 |
System.out.println("Database access failed " + e); |
|
867 |
System.exit(1); |
|
868 |
} |
|
869 |
|
|
894 |
conn = getConnection(); |
|
870 | 895 |
initLogIDs(); |
871 |
harvestStartTime = new Date(); |
|
896 |
setHarvestStartTime(now); |
|
897 |
// Log startup operation |
|
872 | 898 |
addLogEntry(0, "Starting Up Harvester", "HarvesterStartup", 0, null, ""); |
873 | 899 |
|
874 | 900 |
if (connectToMetacat()) { |
875 | 901 |
try { |
902 |
metacatURL = properties.getProperty("metacatURL"); |
|
876 | 903 |
System.out.println("Connecting to Metacat: " + metacatURL); |
877 | 904 |
metacat = MetacatFactory.createMetacatConnection(metacatURL); |
878 | 905 |
} |
... | ... | |
885 | 912 |
} |
886 | 913 |
} |
887 | 914 |
|
888 |
|
|
889 | 915 |
} |
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestDocument.java | ||
---|---|---|
31 | 31 |
import java.io.StringReader; |
32 | 32 |
import java.net.MalformedURLException; |
33 | 33 |
import java.net.URL; |
34 |
import java.sql.Connection; |
|
34 | 35 |
import java.sql.ResultSet; |
35 | 36 |
import java.sql.SQLException; |
36 | 37 |
import java.sql.Statement; |
... | ... | |
74 | 75 |
* @param documentType the value of the <documentType> element |
75 | 76 |
* @param documentURL the value of the <documentURL> element |
76 | 77 |
*/ |
77 |
public HarvestDocument( |
|
78 |
public HarvestDocument (
|
|
78 | 79 |
Harvester harvester, |
79 | 80 |
HarvestSiteSchedule harvestSiteSchedule, |
80 | 81 |
String scope, |
... | ... | |
101 | 102 |
* |
102 | 103 |
* @return A StringReader containing the document string. |
103 | 104 |
*/ |
104 |
private StringReader getSiteDocument() {
|
|
105 |
public StringReader getSiteDocument() {
|
|
105 | 106 |
String documentString; |
106 | 107 |
InputStream inputStream; |
107 | 108 |
InputStreamReader inputStreamReader; |
... | ... | |
223 | 224 |
* Metacat. Returns -1 if Metacat does not currently hold the |
224 | 225 |
* document. |
225 | 226 |
*/ |
226 |
private int metacatHighestRevision() { |
|
227 |
public int metacatHighestRevision() { |
|
228 |
Connection conn = harvester.getConnection(); |
|
227 | 229 |
int highestRevision = -1; |
228 | 230 |
String query = "SELECT REV FROM XML_DOCUMENTS WHERE DOCID = " + |
229 | 231 |
"'" + docid + "'"; |
230 | 232 |
Statement stmt; |
231 | 233 |
|
232 | 234 |
try { |
233 |
stmt = harvester.conn.createStatement();
|
|
235 |
stmt = conn.createStatement(); |
|
234 | 236 |
ResultSet rs = stmt.executeQuery(query); |
235 | 237 |
|
236 | 238 |
while (rs.next()) { |
... | ... | |
252 | 254 |
* |
253 | 255 |
* @param out the PrintStream to write to |
254 | 256 |
*/ |
255 |
void printOutput(PrintStream out) { |
|
257 |
public void printOutput(PrintStream out) {
|
|
256 | 258 |
out.println("* scope: " + scope); |
257 | 259 |
out.println("* identifier: " + identifier); |
258 | 260 |
out.println("* revision: " + revision); |
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestLog.java | ||
---|---|---|
42 | 42 |
* @author costa |
43 | 43 |
*/ |
44 | 44 |
public class HarvestLog { |
45 |
|
|
45 |
|
|
46 |
private Connection conn; |
|
46 | 47 |
private Harvester harvester; // The parent Harvester object |
47 | 48 |
private int harvestLogID; |
48 | 49 |
private Date harvestDate; |
... | ... | |
64 | 65 |
* (For that type of log entry, use the alternate constructor below.) |
65 | 66 |
* |
66 | 67 |
* @param harvester the parent Harvester object |
68 |
* @param conn the database connection |
|
69 |
* @param harvestLogID the primary key in the HARVEST_LOG table |
|
67 | 70 |
* @param harvestDate the date of this harvest |
68 | 71 |
* @param status the status of the harvest operation |
69 | 72 |
* @param message the message text of the harvest operation |
... | ... | |
73 | 76 |
* involve a particular harvest site. |
74 | 77 |
*/ |
75 | 78 |
public HarvestLog(Harvester harvester, |
79 |
Connection conn, |
|
80 |
int harvestLogID, |
|
76 | 81 |
Date harvestDate, |
77 | 82 |
int status, |
78 | 83 |
String message, |
... | ... | |
83 | 88 |
timestamp = now.toString(); |
84 | 89 |
|
85 | 90 |
this.harvester = harvester; |
86 |
this.harvestLogID = harvester.getHarvestLogID(); |
|
91 |
this.conn = conn; |
|
92 |
this.harvestLogID = harvestLogID; |
|
87 | 93 |
this.harvestDate = harvestDate; |
88 | 94 |
this.status = status; |
89 | 95 |
this.message = message; |
... | ... | |
103 | 109 |
* HarvestDetailLog object and inserts it to the HARVEST_DETAIL_LOG table. |
104 | 110 |
* |
105 | 111 |
* @param harvester the parent Harvester object |
112 |
* @param conn the database connection |
|
113 |
* @param harvestLogID the primary key in the HARVEST_LOG table |
|
114 |
* @param detailLogID the primary key in the HARVEST_DETAIL_LOG table |
|
106 | 115 |
* @param harvestDate the date of this harvest |
107 | 116 |
* @param status the status of the harvest operation |
108 | 117 |
* @param message the message text of the harvest operation |
... | ... | |
114 | 123 |
* @param errorMessage the error message generated by this operation |
115 | 124 |
*/ |
116 | 125 |
public HarvestLog(Harvester harvester, |
126 |
Connection conn, |
|
127 |
int harvestLogID, |
|
128 |
int detailLogID, |
|
117 | 129 |
Date harvestDate, |
118 | 130 |
int status, |
119 | 131 |
String message, |
... | ... | |
126 | 138 |
timestamp = now.toString(); |
127 | 139 |
|
128 | 140 |
this.harvester = harvester; |
129 |
this.harvestLogID = harvester.getHarvestLogID(); |
|
141 |
this.conn = conn; |
|
142 |
this.harvestLogID = harvestLogID; |
|
130 | 143 |
this.harvestDate = harvestDate; |
131 | 144 |
this.status = status; |
132 | 145 |
this.message = message; |
133 | 146 |
this.harvestOperationCode = harvestOperationCode; |
134 | 147 |
this.siteScheduleID = siteScheduleID; |
135 |
this.harvestDetailLog = new HarvestDetailLog(harvester, harvestLogID, |
|
136 |
harvestDocument, errorMessage); |
|
148 |
this.harvestDetailLog = new HarvestDetailLog(harvester, conn, detailLogID, |
|
149 |
harvestLogID, harvestDocument, |
|
150 |
errorMessage); |
|
137 | 151 |
harvestOperationCodeLevel = |
138 | 152 |
getHarvestOperationCodeLevel(harvestOperationCode); |
139 | 153 |
explanation = getExplanation(harvestOperationCode); |
140 | 154 |
dbInsertHarvestLogEntry(); // Insert to the HARVEST_LOG table |
141 |
harvestDetailLog.dbInsertHarvestDetailLogEntry(); // and HARVEST_DETAIL_LOG
|
|
155 |
harvestDetailLog.dbInsertHarvestDetailLogEntry(); // HARVEST_DETAIL_LOG |
|
142 | 156 |
} |
143 | 157 |
|
144 | 158 |
|
... | ... | |
165 | 179 |
")"; |
166 | 180 |
|
167 | 181 |
try { |
168 |
stmt = harvester.conn.createStatement();
|
|
182 |
stmt = conn.createStatement(); |
|
169 | 183 |
stmt.executeUpdate(insertString); |
170 | 184 |
stmt.close(); |
171 | 185 |
} |
... | ... | |
182 | 196 |
* "info", or "debug" |
183 | 197 |
* @return codeLevelValue the corresponding code level value |
184 | 198 |
*/ |
185 |
int getCodeLevelValue(String codeLevel) { |
|
199 |
public int getCodeLevelValue(String codeLevel) {
|
|
186 | 200 |
int codeLevelValue = 0; |
187 | 201 |
|
188 | 202 |
if (codeLevel.equalsIgnoreCase("error")) { |
... | ... | |
213 | 227 |
* @param harvestOperationCode string value of the harvest operation code |
214 | 228 |
* @return the explanation for this harvest operation, a String |
215 | 229 |
*/ |
216 |
String getExplanation(String harvestOperationCode) { |
|
230 |
public String getExplanation(String harvestOperationCode) {
|
|
217 | 231 |
String explanation; |
218 | 232 |
String fieldName = "EXPLANATION"; |
219 | 233 |
|
... | ... | |
270 | 284 |
* @return the code level value, a String, one of the following: |
271 | 285 |
* "error", "warning", "notice", "info", or "debug" |
272 | 286 |
*/ |
273 |
String getHarvestOperationCodeLevel(String harvestOperationCode) { |
|
287 |
public String getHarvestOperationCodeLevel(String harvestOperationCode) {
|
|
274 | 288 |
String harvestOperationCodeLevel; |
275 | 289 |
String fieldName = "HARVEST_OPERATION_CODE_LEVEL"; |
276 | 290 |
|
... | ... | |
316 | 330 |
* (level 1), then anything lower ("warning", "notice", etc.) |
317 | 331 |
* will not generate any output. |
318 | 332 |
*/ |
319 |
void printOutput(PrintStream out, String maxLevel) { |
|
333 |
public void printOutput(PrintStream out, String maxLevel) {
|
|
320 | 334 |
int codeLevelValue = getCodeLevelValue(harvestOperationCodeLevel); |
321 | 335 |
int maxLevelValue = getCodeLevelValue(maxLevel); |
322 | 336 |
|
... | ... | |
331 | 345 |
out.println("* harvestOperationCode: " + harvestOperationCode); |
332 | 346 |
out.println("* description: " + explanation); |
333 | 347 |
|
334 |
if (harvestOperationCode.equals("GetDocListSuccess") ||
|
|
335 |
harvestOperationCode.equals("GetDocListError")) {
|
|
348 |
if (harvestOperationCode.equals("GetHarvestListSuccess") ||
|
|
349 |
harvestOperationCode.equals("GetHarvestListError")) {
|
|
336 | 350 |
if (siteScheduleID != 0) { |
337 | 351 |
harvester.printHarvestSiteSchedule(out, siteScheduleID); |
338 | 352 |
} |
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestSiteSchedule.java | ||
---|---|---|
63 | 63 |
* |
64 | 64 |
* @author costa |
65 | 65 |
*/ |
66 |
class HarvestSiteSchedule { |
|
66 |
public class HarvestSiteSchedule {
|
|
67 | 67 |
|
68 | 68 |
private String contactEmail; |
69 | 69 |
private String dateLastHarvest; |
... | ... | |
77 | 77 |
private String ldapDN; |
78 | 78 |
private String ldapPwd; |
79 | 79 |
final private long millisecondsPerDay = (1000 * 60 * 60 * 24); |
80 |
private String schemaLocation = |
|
81 |
"eml://ecoinformatics.org/harvestList ../../lib/harvester/harvestList.xsd"; |
|
80 | 82 |
int siteScheduleID; |
81 | 83 |
private String unit; |
82 | 84 |
private int updateFrequency; |
... | ... | |
150 | 152 |
Statement stmt; |
151 | 153 |
long timeNextHarvest; |
152 | 154 |
|
153 |
conn = harvester.conn;
|
|
155 |
conn = harvester.getConnection();
|
|
154 | 156 |
now = new Date(); |
155 | 157 |
currentTime = now.getTime(); |
156 | 158 |
timeNextHarvest = currentTime + delta; |
... | ... | |
182 | 184 |
* |
183 | 185 |
* @retrun true if due for harvest, otherwise false |
184 | 186 |
*/ |
185 |
private boolean dueForHarvest() {
|
|
187 |
public boolean dueForHarvest() {
|
|
186 | 188 |
boolean dueForHarvest = false; |
187 | 189 |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); |
188 | 190 |
Date now = new Date(); |
... | ... | |
208 | 210 |
|
209 | 211 |
return dueForHarvest; |
210 | 212 |
} |
213 |
|
|
211 | 214 |
|
215 |
/** |
|
216 |
* Accessor method for the schemaLocation field. |
|
217 |
* |
|
218 |
* @return schemaLocation the schema location string |
|
219 |
*/ |
|
220 |
public String getSchemaLocation() { |
|
221 |
return schemaLocation; |
|
222 |
} |
|
212 | 223 |
|
224 |
|
|
213 | 225 |
/** |
214 | 226 |
* Harvests each document in the site document list. |
215 | 227 |
* |
... | ... | |
223 | 235 |
|
224 | 236 |
if (dueForHarvest()) { |
225 | 237 |
try { |
226 |
success = parseDocumentList();
|
|
238 |
success = parseHarvestList();
|
|
227 | 239 |
|
228 | 240 |
/* If the document list was validated, then proceed with harvesting |
229 | 241 |
* the documents |
... | ... | |
255 | 267 |
/** |
256 | 268 |
* Login to Metacat using the ldapDN and ldapPwd |
257 | 269 |
*/ |
258 |
private void metacatLogin() {
|
|
270 |
public void metacatLogin() {
|
|
259 | 271 |
Metacat metacat = harvester.metacat; |
272 |
String response; |
|
260 | 273 |
|
261 | 274 |
if (harvester.connectToMetacat()) { |
262 | 275 |
try { |
263 | 276 |
System.out.println("Logging in to Metacat: " + ldapDN); |
264 |
metacat.login(ldapDN, ldapPwd); |
|
277 |
response = metacat.login(ldapDN, ldapPwd);
|
|
265 | 278 |
//System.out.println("Metacat login response: " + response); |
266 |
//sessionId = metacat.getSessionId(); |
|
267 |
//System.out.println("Session ID: " + sessionId); |
|
268 | 279 |
} |
269 | 280 |
catch (MetacatInaccessibleException e) { |
270 | 281 |
System.out.println("Metacat login failed." + e.getMessage()); |
... | ... | |
299 | 310 |
|
300 | 311 |
|
301 | 312 |
/** |
302 |
* Parse the site document list to find out which documents to harvest. |
|
313 |
* Parses the site harvest list XML file to find out which documents to |
|
314 |
* harvest. |
|
303 | 315 |
* |
304 | 316 |
* @return true if successful, otherwise false |
305 | 317 |
*/ |
306 |
private boolean parseDocumentList()
|
|
318 |
public boolean parseHarvestList()
|
|
307 | 319 |
throws ParserConfigurationException { |
308 | 320 |
DocumentListHandler documentListHandler = new DocumentListHandler(); |
309 | 321 |
InputStream inputStream; |
310 | 322 |
InputStreamReader inputStreamReader; |
311 |
String schemaLocation = |
|
312 |
"eml://ecoinformatics.org/harvestList ../../lib/harvester/harvestList.xsd"; |
|
323 |
String schemaLocation = getSchemaLocation(); |
|
313 | 324 |
boolean success = false; |
314 | 325 |
URL url; |
315 | 326 |
|
... | ... | |
318 | 329 |
inputStream = url.openStream(); |
319 | 330 |
harvester.addLogEntry(0, |
320 | 331 |
"Retrieved: " + documentListURL, |
321 |
"GetDocListSuccess",
|
|
332 |
"GetHarvestListSuccess",
|
|
322 | 333 |
siteScheduleID, |
323 | 334 |
null, |
324 | 335 |
""); |
... | ... | |
326 | 337 |
documentListHandler.runParser(inputStreamReader, schemaLocation); |
327 | 338 |
harvester.addLogEntry(0, |
328 | 339 |
"Validated: " + documentListURL, |
329 |
"ValidateDocListSuccess",
|
|
340 |
"ValidateHarvestListSuccess",
|
|
330 | 341 |
siteScheduleID, |
331 | 342 |
null, |
332 | 343 |
""); |
... | ... | |
334 | 345 |
} |
335 | 346 |
catch (MalformedURLException e){ |
336 | 347 |
harvester.addLogEntry(1, "MalformedURLException: " + e.getMessage(), |
337 |
"GetDocListError", siteScheduleID, null, "");
|
|
348 |
"GetHarvestListError", siteScheduleID, null, "");
|
|
338 | 349 |
} |
339 | 350 |
catch (FileNotFoundException e) { |
340 | 351 |
harvester.addLogEntry(1, "FileNotFoundException: " + e.getMessage(), |
341 |
"GetDocListError", siteScheduleID, null, "");
|
|
352 |
"GetHarvestListError", siteScheduleID, null, "");
|
|
342 | 353 |
} |
343 | 354 |
catch (SAXException e) { |
344 | 355 |
harvester.addLogEntry(1, "SAXException: " + e.getMessage(), |
345 |
"ValidateDocListError", siteScheduleID, null, "");
|
|
356 |
"ValidateHarvestListError", siteScheduleID, null, "");
|
|
346 | 357 |
} |
347 | 358 |
catch (ClassNotFoundException e) { |
348 | 359 |
harvester.addLogEntry(1, "ClassNotFoundException: " + e.getMessage(), |
349 |
"ValidateDocListError", siteScheduleID, null, "");
|
|
360 |
"ValidateHarvestListError", siteScheduleID, null, "");
|
|
350 | 361 |
} |
351 | 362 |
catch (IOException e) { |
352 | 363 |
harvester.addLogEntry(1, "IOException: " + e.getMessage(), |
353 |
"GetDocListError", siteScheduleID, null, "");
|
|
364 |
"GetHarvestListError", siteScheduleID, null, "");
|
|
354 | 365 |
} |
355 | 366 |
|
356 | 367 |
return success; |
... | ... | |
362 | 373 |
* |
363 | 374 |
* @param out the PrintStream to write to |
364 | 375 |
*/ |
365 |
void printOutput(PrintStream out) { |
|
376 |
public void printOutput(PrintStream out) {
|
|
366 | 377 |
out.println("* siteScheduleID: " + siteScheduleID); |
367 | 378 |
out.println("* documentListURL: " + documentListURL); |
368 | 379 |
out.println("* ldapDN: " + ldapDN); |
... | ... | |
408 | 419 |
|
409 | 420 |
|
410 | 421 |
/** |
422 |
* Accessor method for setting the value of the schemaLocation field. |
|
423 |
* |
|
424 |
* @param schemaLocation the new value of the schemaLocation field |
|
425 |
*/ |
|
426 |
public void setSchemaLocation(String schemaLocation) { |
|
427 |
this.schemaLocation = schemaLocation; |
|
428 |
} |
|
429 |
|
|
430 |
|
|
431 |
/** |
|
411 | 432 |
* This inner class extends DefaultHandler. It parses the document list, |
412 | 433 |
* creating a new HarvestDocument object every time it finds a </Document> |
413 | 434 |
* end tag. |
Also available in: Unified diff
Refactored a number of methods to allow for more effective JUnit testing