Project

General

Profile

« Previous | Next » 

Revision 2105

Implement sending email reports to harvest administrator and site administrator

View differences:

HarvestLog.java
50 50
  private String message;
51 51
  private String harvestOperationCode;
52 52
  private int siteScheduleID;
53
  private String explanation;
54
  private String harvestOperationCodeLevel;
53 55
  private String timestamp;
54 56
  private HarvestDetailLog harvestDetailLog;  // Associated detail log, if any
55 57
    
......
86 88
    this.harvestOperationCode = harvestOperationCode;
87 89
    this.siteScheduleID = siteScheduleID;
88 90
    
91
    harvestOperationCodeLevel = 
92
            dbGetHarvestOperationCodeLevel(harvestOperationCode);
93
    explanation = dbGetExplanation(harvestOperationCode);
89 94
    dbInsertHarvestLogEntry();   // Insert this entry to the HARVEST_LOG table
90 95
  }
91 96
    
......
103 108
   * @param  siteScheduleID  the siteScheduleID for which this operation was
104 109
   *                         performed. 0 indicates that the operation did not
105 110
   *                         involve a particular harvest site.
111
   * @param  harvestDocument the HarvestDocument involved in this operation
112
   * @param  errorMessage    the error message generated by this operation
106 113
   */
107 114
  public HarvestLog(Harvester  harvester,
108 115
                    Date       harvestDate,
......
125 132
    this.siteScheduleID = siteScheduleID;
126 133
    this.harvestDetailLog = new HarvestDetailLog(harvester, harvestLogID, 
127 134
                                                 harvestDocument, errorMessage);
128
    
135
    harvestOperationCodeLevel = 
136
            dbGetHarvestOperationCodeLevel(harvestOperationCode);
137
    explanation = dbGetExplanation(harvestOperationCode);
129 138
    dbInsertHarvestLogEntry();               // Insert to the HARVEST_LOG table
130 139
    harvestDetailLog.dbInsertHarvestDetailLogEntry(); // and HARVEST_DETAIL_LOG
131 140
  }
......
279 288
    
280 289
    return returnString;
281 290
  }
291
  
282 292

  
293
  /**
294
   * Maps each code level to an integer value.
295
   * 
296
   * @param codeLevel        the code level: "error", "warning", "notice",
297
   *                         "info", or "debug"
298
   * @return codeLevelValue  the corresponding code level value
299
   */
300
  int getCodeLevelValue(String codeLevel) {
301
    int codeLevelValue = 0;
302
    
303
    if (codeLevel.equalsIgnoreCase("error")) {
304
      codeLevelValue = 1;
305
    }
306
    else if (codeLevel.equalsIgnoreCase("warning")) {
307
      codeLevelValue = 2;
308
    }
309
    else if (codeLevel.equalsIgnoreCase("notice")) {
310
      codeLevelValue = 3;
311
    }
312
    else if (codeLevel.equalsIgnoreCase("info")) {
313
      codeLevelValue = 4;
314
    }
315
    else if (codeLevel.equalsIgnoreCase("debug")) {
316
      codeLevelValue = 5;
317
    }
318
    
319
    return codeLevelValue;
320
  }
321
  
283 322

  
284 323
  /**
324
   * Access function for the siteScheduleID field.
325
   * 
326
   * @return  siteScheduleID, an int. If 0, indicates that this log entry does
327
   *          not pertain to a particular site.
328
   */
329
  int getSiteScheduleID() {
330
    return siteScheduleID;
331
  }
332
  
333

  
334
  /**
335
   * Determines whether this log entry had an error status.
336
   * 
337
   * @return  isError  true if this log entry had an error status, else false 
338
   */
339
  boolean isErrorEntry () {
340
    boolean isError;
341
    
342
    isError = (status != 0);
343
    
344
    return isError;
345
  }
346

  
347

  
348
  /**
285 349
   * Prints the contents of this HarvestLog object. Used in generating reports.
286 350
   * 
287
   * @param out   the PrintStream to write to
351
   * @param out        the PrintStream to write to
352
   * @param maxLevel  the maximum code level to output. If this log entry has a
353
   *                  higher code level than the maxLevel, no output
354
   *                  is issued. For example, if the maxLevel is "error"
355
   *                  (level 1), then anything lower ("warning", "notice", etc.)
356
   *                  will not generate any output.
288 357
   */
289
  void printOutput(PrintStream out) {
290
    out.println("");
291
    out.println(marker);
292
    out.println("*");
293
    out.println("* harvestLogID:         " + harvestLogID);
294
    out.println("* harvestDate:          " + harvestDate);
295
    out.println("* status:               " + status);
296
    out.println("* message:              " + message);
297
    out.println("* harvestOperationCode: " + harvestOperationCode);
358
  void printOutput(PrintStream out, String maxLevel) {
359
    int codeLevelValue = getCodeLevelValue(harvestOperationCodeLevel);
360
    int maxLevelValue = getCodeLevelValue(maxLevel);
361
    
362
    if (codeLevelValue <= maxLevelValue) {    
363
      out.println("");
364
      out.println(marker);
365
      out.println("*");
366
      out.println("* harvestLogID:         " + harvestLogID);
367
      out.println("* harvestDate:          " + harvestDate);
368
      out.println("* status:               " + status);
369
      out.println("* message:              " + message);
370
      out.println("* harvestOperationCode: " + harvestOperationCode);
371
      out.println("* description:          " + explanation);
298 372

  
299
    if (harvestOperationCode.equals("GetDocListSuccess") ||
373
      if (harvestOperationCode.equals("GetDocListSuccess") ||
300 374
        harvestOperationCode.equals("GetDocListError")) {
301
      if (siteScheduleID != 0) {
302
        harvester.printHarvestSiteSchedule(out, siteScheduleID);
375
        if (siteScheduleID != 0) {
376
          harvester.printHarvestSiteSchedule(out, siteScheduleID);
377
        }
303 378
      }
304
    }
305 379
    
306
    if (harvestDetailLog != null) {
307
      harvestDetailLog.printOutput(out);
380
      if (harvestDetailLog != null) {
381
        harvestDetailLog.printOutput(out);
382
      }
383

  
384
      out.println("*");
385
      out.println(marker);
308 386
    }
309

  
310
    out.println("*");
311
    out.println(marker);
312 387
  }
313 388

  
314 389
}

Also available in: Unified diff