Project

General

Profile

« Previous | Next » 

Revision 2385

Formatting improvements.

View differences:

src/edu/ucsb/nceas/metacat/harvesterClient/HarvesterRegistration.java
98 98

  
99 99
    // Check validity of the Harvest List URL field    
100 100
    if (documentListURL.equals("")) {
101
      out.println(
102
              "A value must be specified in the Harvest List URL field"
103
                 );
101
      out.println("A value must be specified in the Harvest List URL field");
104 102
      validValues = false;
105 103
    }
106 104

  
......
159 157
    Date dnh;                          // Date of next harvest
160 158
    Date now;                          // Today's date
161 159
    String query;
162
		Statement stmt;
160
    Statement stmt;
163 161
    long timeNextHarvest;
164 162
    SimpleDateFormat writeFormat = new SimpleDateFormat("dd-MMM-yyyy");
165 163
    
......
179 177
    dnh = new Date(timeNextHarvest);
180 178
    dateNextHarvest = writeFormat.format(dnh);
181 179
	
182
		try {
183
			stmt = conn.createStatement();							
184
			query = "insert into HARVEST_SITE_SCHEDULE " +
185
      "(SITE_SCHEDULE_ID, CONTACT_EMAIL, DOCUMENTLISTURL, LDAPDN, LDAPPWD, " +
186
      "UNIT, UPDATEFREQUENCY, DATENEXTHARVEST) " +
187
      "values(" + siteScheduleID + "," +
188
                  quoteString(contactEmail) + "," +
189
                  quoteString(documentListURL) + "," +
190
                  quoteString(ldapDN) + "," +
191
                  quoteString(ldapPwd) + "," +
192
                  quoteString(unit) + "," +
193
                  updateFrequency + "," +
194
                  quoteString(dateNextHarvest) + ")";
180
    try {
181
      stmt = conn.createStatement();
182
      query = "insert into HARVEST_SITE_SCHEDULE " +
183
        "(SITE_SCHEDULE_ID, CONTACT_EMAIL, DOCUMENTLISTURL, LDAPDN, LDAPPWD, " +
184
        "UNIT, UPDATEFREQUENCY, DATENEXTHARVEST) " +
185
        "values(" + siteScheduleID + "," +
186
        quoteString(contactEmail) + "," +
187
        quoteString(documentListURL) + "," +
188
        quoteString(ldapDN) + "," +
189
        quoteString(ldapPwd) + "," +
190
        quoteString(unit) + "," +
191
        updateFrequency + "," +
192
        quoteString(dateNextHarvest) + ")";
195 193
                  
196 194
      System.out.println(query);
197 195
      stmt.executeUpdate(query);
198
			stmt.close();
196
      stmt.close();
199 197
      reportResults(out, ldapDN, contactEmail, documentListURL, updateFrequency,
200 198
                    unit, dateNextHarvest);
201
		}
199
    }
202 200
    catch(SQLException e) {
203
			System.out.println("SQLException: " + e.getMessage());
204
		}
205
   }
201
      System.out.println("SQLException: " + e.getMessage());
202
	}
203
  }
206 204
   
207 205

  
208 206
  /**
......
221 219
    String query = "DELETE FROM HARVEST_SITE_SCHEDULE WHERE " +
222 220
                   "SITE_SCHEDULE_ID=" + siteScheduleID;
223 221
    int nRecords = 0;
224
		Statement stmt;
222
	Statement stmt;
225 223
     
226
		try {
227
			stmt = conn.createStatement();
224
	try {
225
      stmt = conn.createStatement();
228 226
      System.out.println(query);
229 227
      nRecords = stmt.executeUpdate(query);
230 228
      stmt.close();
......
237 235
        out.println("A problem was encountered removing registration for user " 
238 236
                    + ldapDN);
239 237
      }
240
		}
238
    }
241 239
    catch(SQLException e) {
242
			System.out.println("SQLException: " + e.getMessage());
243
		}
244
   }
240
      System.out.println("SQLException: " + e.getMessage());
241
    }
242
  }
245 243
   
246 244

  
247 245
  /**
......
275 273
    Date dlh;                          // Date of last harvest
276 274
    Date dnh;                          // Date of next harvest
277 275
    Date now = new Date();             // Today's date
278
//    SimpleDateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
276
//  SimpleDateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
279 277
    SimpleDateFormat readFormat = new SimpleDateFormat("yyyy-MM-dd");
280 278
    SimpleDateFormat writeFormat = new SimpleDateFormat("dd-MMM-yyyy");
281
		Statement stmt;
279
    Statement stmt;
282 280
    long timeLastHarvest;
283 281
    long timeNextHarvest;
284 282
    long timeNow = now.getTime();
......
314 312
    dnh = new Date(timeNextHarvest);
315 313
    dateNextHarvest = writeFormat.format(dnh);
316 314
	
317
		try {
318
			stmt = conn.createStatement();							
319
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET CONTACT_EMAIL=" +
315
    try {
316
      stmt = conn.createStatement();
317
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET CONTACT_EMAIL=" +
320 318
                         quoteString(contactEmail) +
321 319
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
322
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET DOCUMENTLISTURL=" +
320
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET DOCUMENTLISTURL=" +
323 321
                         quoteString(documentListURL) +
324 322
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
325
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET LDAPPWD=" +
323
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET LDAPPWD=" +
326 324
                         quoteString(ldapPwd) +
327 325
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
328
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET UNIT=" +
326
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET UNIT=" +
329 327
                         quoteString(unit) +
330 328
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
331
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET UPDATEFREQUENCY=" +
329
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET UPDATEFREQUENCY=" +
332 330
                         updateFrequency +
333 331
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
334
			stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET DATENEXTHARVEST=" +
332
      stmt.executeUpdate("UPDATE HARVEST_SITE_SCHEDULE SET DATENEXTHARVEST=" +
335 333
                         quoteString(dateNextHarvest) +
336 334
                         " WHERE SITE_SCHEDULE_ID = " + siteScheduleID);
337
			stmt.close();
335
      stmt.close();
338 336
      reportResults(out, ldapDN, contactEmail, documentListURL, updateFrequency,
339 337
                    unit, dateNextHarvest);
340
		}
338
    }
341 339
    catch(SQLException e) {
342
			System.out.println("SQLException: " + e.getMessage());
343
		}
344
     
340
      System.out.println("SQLException: " + e.getMessage());
341
    }
342
 
345 343
  }
346 344
   
347 345

  
......
365 363
    String ldapPwd;
366 364
    String query;
367 365
    int siteScheduleID;
368
		Statement stmt;
366
    Statement stmt;
369 367
    String unit = "days";
370 368
    int updateFrequency = 1;
371 369

  
......
389 387
      query = "SELECT * FROM HARVEST_SITE_SCHEDULE WHERE SITE_SCHEDULE_ID=" +
390 388
              siteScheduleID;
391 389
      
392
		  try {
393
			  stmt = conn.createStatement();							
394
			  ResultSet rs = stmt.executeQuery(query);
395
	
396
			  while (rs.next()) {
390
      try {
391
        stmt = conn.createStatement();
392
        ResultSet rs = stmt.executeQuery(query);
393
        
394
        while (rs.next()) {
397 395
          contactEmail = rs.getString("CONTACT_EMAIL");
398 396
          documentListURL = rs.getString("DOCUMENTLISTURL");
399 397
          updateFrequency = rs.getInt("UPDATEFREQUENCY");
400 398
          unit = rs.getString("UNIT");
401 399
        }
402

  
403
			  stmt.close();	
404
		  }
400
        
401
        stmt.close();
402
      }
405 403
      catch (SQLException ex) {
406
			  System.out.println("SQLException: " + ex.getMessage());
407
		  }
404
        System.out.println("SQLException: " + ex.getMessage());
405
      }
408 406
    }
409 407

  
410 408
    res.setContentType("text/html");
......
635 633
    String dateLastHarvest = "";
636 634
    String query = "SELECT DATELASTHARVEST FROM HARVEST_SITE_SCHEDULE " +
637 635
                   "WHERE SITE_SCHEDULE_ID=" + siteScheduleID;
638
		Statement stmt;
636
	Statement stmt;
639 637
    
640
		try {
641
			stmt = conn.createStatement();							
642
			ResultSet rs = stmt.executeQuery(query);
638
	try {
639
      stmt = conn.createStatement();
640
      ResultSet rs = stmt.executeQuery(query);
643 641
	
644
			while (rs.next()) {
642
      while (rs.next()) {
645 643
        dateLastHarvest = rs.getString("DATELASTHARVEST");
646 644
        if (rs.wasNull()) {
647 645
          dateLastHarvest = "";  // Convert null value to empty string
648 646
        }
649
			}
650

  
651
			stmt.close();	
652
		}
647
      }
648
      
649
      stmt.close();
650
    }
653 651
    catch (SQLException ex) {
654
			System.out.println("SQLException: " + ex.getMessage());
655
		}
652
      System.out.println("SQLException: " + ex.getMessage());
653
    }
656 654
    
657 655
    return dateLastHarvest;
658 656
  }
......
669 667
  private int getMaxValue(Connection conn, String tableName, String fieldName) {
670 668
    int maxValue = 0;
671 669
    int fieldValue;
672
		String query = "SELECT " + fieldName + " FROM " + tableName;
673
		Statement stmt;
670
    String query = "SELECT " + fieldName + " FROM " + tableName;
671
    Statement stmt;
674 672
    
675
		try {
676
			stmt = conn.createStatement();							
677
			ResultSet rs = stmt.executeQuery(query);
678
	
679
			while (rs.next()) {
680
				fieldValue = rs.getInt(fieldName);
673
    try {
674
      stmt = conn.createStatement();
675
      ResultSet rs = stmt.executeQuery(query);
676
      
677
      while (rs.next()) {
678
        fieldValue = rs.getInt(fieldName);
681 679
        maxValue = Math.max(maxValue, fieldValue);
682
			}
683
	
684
			stmt.close();	
685
		} 
680
      }
681
      
682
      stmt.close();
683
    } 
686 684
    catch (SQLException ex) {
687
			System.out.println("SQLException: " + ex.getMessage());
688
		}
685
      System.out.println("SQLException: " + ex.getMessage());
686
    }
689 687
    
690 688
    return maxValue;
691 689
  }
......
703 701
    String ldapDNValue;                       // value of LDAPDN field
704 702
    String query = "SELECT * FROM HARVEST_SITE_SCHEDULE";
705 703
    int siteScheduleID = 0;
706
		Statement stmt;
704
    Statement stmt;
707 705
    
708
		try {
709
			stmt = conn.createStatement();							
710
			ResultSet rs = stmt.executeQuery(query);
711
	
712
			while (rs.next()) {
706
    
707
    try {
708
      stmt = conn.createStatement();
709
      ResultSet rs = stmt.executeQuery(query);
710
      
711
      while (rs.next()) {
713 712
        ldapDNValue = rs.getString("LDAPDN");
714 713
        
715 714
        if (ldapDNValue.equalsIgnoreCase(ldapDN)) {
716
				  siteScheduleID = rs.getInt("SITE_SCHEDULE_ID");
715
          siteScheduleID = rs.getInt("SITE_SCHEDULE_ID");
717 716
        }
718
			}
719

  
720
			stmt.close();	
721
		}
717
      }
718
      
719
      stmt.close();
720
    }
722 721
    catch (SQLException ex) {
723
			System.out.println("SQLException: " + ex.getMessage());
724
		}
722
      System.out.println("SQLException: " + ex.getMessage());
723
    }
725 724
    
726 725
    return siteScheduleID;
727 726
  }

Also available in: Unified diff