Project

General

Profile

1
/*
2
 * HarvestDetailLog.java
3
 *
4
 * Created on January 14, 2004, 4:59 PM
5
 */
6

    
7
package edu.ucsb.nceas.metacat.harvesterClient;
8

    
9
import java.io.PrintStream;
10
import java.sql.Connection;
11
import java.sql.SQLException;
12
import java.sql.Statement;
13

    
14
/**
15
 * HarvestDetailLog manages data and operations corresponding to the
16
 * HARVEST_DETAIL_LOG table. It records errors encountered while attempting
17
 * to harvest a particular EML document.
18
 * 
19
 * @author  costa
20
 */
21
public class HarvestDetailLog {
22
    
23
  private Harvester harvester;              // The parent Harvester object
24
  private int detailLogID;
25
  private int harvestLogID;
26
  private HarvestDocument harvestDocument;  // The associated HarvestDocument
27
  private String errorMessage;
28
    
29

    
30
  /** 
31
   * Creates a new instance of HarvestDetailLog and inserts the data into
32
   * the HARVEST_DETAIL_LOG table.
33
   *
34
   * @param  harvester       the Harvester parent object
35
   * @param  harvestLogID    foreign key value matching the HARVEST_LOG table
36
   * @param  harvestDocument HarvestDocument object that generated an error
37
   * @param  errorMessage    text of the error message
38
   */
39
  public HarvestDetailLog(Harvester       harvester,
40
                          int             harvestLogID,
41
                          HarvestDocument harvestDocument,
42
                          String          errorMessage
43
                         ) {
44
    this.harvester = harvester;
45
    this.detailLogID = harvester.getDetailLogID();  // Primary key for record
46
    this.harvestLogID = harvestLogID;
47
    this.harvestDocument = harvestDocument;
48
    this.errorMessage = errorMessage;
49
  }
50
    
51

    
52
  /**
53
   * Inserts a new entry into the HARVEST_DETAIL_LOG table, based on the 
54
   * contents of this HarvestDetailLog object.
55
   */
56
  void dbInsertHarvestDetailLogEntry() {
57
    String dequotedMessage;
58
    String insertString;
59
		Statement stmt;
60
    
61
    dequotedMessage = harvester.dequoteText(errorMessage);
62

    
63
    // Set the value of the HARVEST_LOG_ID to the current time in UTC seconds
64
    insertString = "INSERT INTO HARVEST_DETAIL_LOG " +
65
                   "(DETAIL_LOG_ID, HARVEST_LOG_ID, SCOPE," + 
66
                   " IDENTIFIER, REVISION," +
67
                   " DOCUMENT_URL, ERROR_MESSAGE, DOCUMENT_TYPE) " +
68
                   "values(" +
69
                   detailLogID + ", " +
70
                   harvestLogID + ", " +
71
                   "'" + harvestDocument.scope + "', " +
72
                   harvestDocument.identifier + ", " +
73
                   harvestDocument.revision + ", " +
74
                   "'" + harvestDocument.documentURL + "', " +
75
                   "'" + dequotedMessage + "'," +
76
                   "'" + harvestDocument.documentType + "'" +
77
                   ")";
78
                   
79
		try {
80
			stmt = harvester.conn.createStatement();
81
			stmt.executeUpdate(insertString);
82
			stmt.close();
83
		}
84
    catch(SQLException e) {
85
			System.out.println("SQLException: " + e.getMessage());
86
		}
87
  }
88

    
89

    
90
  /**
91
   * Prints the contents of this HarvestLog object. Used in generating reports.
92
   * 
93
   * @param out   the PrintStream to write to
94
   */
95
  void printOutput(PrintStream out) {
96
    out.println("* detailLogID:          " + detailLogID);
97
    out.println("* errorMessage:         " + errorMessage);
98
    harvestDocument.printOutput(out);
99
  }
100

    
101
}
(1-1/9)