Project

General

Profile

« Previous | Next » 

Revision 2139

Refactored a number of methods to allow for more effective JUnit testing

View differences:

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