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.sql.Connection;
10
import java.sql.SQLException;
11
import java.sql.Statement;
12

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

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

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

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

    
88

    
89
  /**
90
   * Prints the contents of this HarvestLog object. Used in generating reports.
91
   */
92
  void printOutput() {
93
    System.out.println("* detailLogID:          " + detailLogID);
94
    System.out.println("* errorMessage:         " + errorMessage);
95
    harvestDocument.printOutput();
96
  }
97

    
98
}
(1-1/7)