Project

General

Profile

« Previous | Next » 

Revision 5167

Added by daigle over 14 years ago

add method name to log statements

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
76 76
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
77 77
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
78 78
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
79
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
80 79
import edu.ucsb.nceas.metacat.cart.CartManager;
81 80
import edu.ucsb.nceas.metacat.database.DBConnection;
82 81
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
......
86 85
import edu.ucsb.nceas.metacat.properties.SkinPropertyService;
87 86
import edu.ucsb.nceas.metacat.replication.ForceReplicationHandler;
88 87
import edu.ucsb.nceas.metacat.replication.ReplicationService;
89
import edu.ucsb.nceas.metacat.scheduler.SchedulerService;
90 88
import edu.ucsb.nceas.metacat.service.ServiceService;
91 89
import edu.ucsb.nceas.metacat.service.SessionService;
92 90
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
......
94 92
import edu.ucsb.nceas.metacat.shared.BaseException;
95 93
import edu.ucsb.nceas.metacat.shared.HandlerException;
96 94
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
97
//import edu.ucsb.nceas.metacat.shared.AccessException;
98 95
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
99 96
import edu.ucsb.nceas.metacat.spatial.SpatialQuery;
100 97
import edu.ucsb.nceas.metacat.util.AuthUtil;
......
287 284

  
288 285
	private static final long serialVersionUID = 1L;
289 286
	private Timer timer = null;
290
    private static boolean sitemapScheduled;
291
    private static boolean firstHalfInitialized = false;
292
    private static boolean fullyInitialized = false;
287
    private static boolean _sitemapScheduled;
288
    private static boolean _firstHalfInitialized = false;
289
    private static boolean _fullyInitialized = false;
293 290
    
294 291
    // Constants -- these should be final in a servlet
295 292
    private static final String PROLOG = "<?xml version=\"1.0\"?>";
......
311 308
    public void init(ServletConfig config) throws ServletException {
312 309
    	Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
313 310
    	try {
314
    		if(firstHalfInitialized) {
311
    		if(_firstHalfInitialized) {
315 312
    			return;
316 313
    		}
317 314
    		
......
321 318
            context.setAttribute("APPLICATION_NAME", APPLICATION_NAME);
322 319
            
323 320
            ServiceService serviceService = ServiceService.getInstance(context);
324
            logMetacat.debug("ServiceService singleton created " + serviceService);
321
            logMetacat.debug("MetaCatServlet.init - ServiceService singleton created " + serviceService);
325 322
            
326 323
            // Initialize the properties file
327 324
            String dirPath = ServiceService.getRealConfigDir();
......
341 338
            	return;
342 339
            }  
343 340
            
344
            firstHalfInitialized = true;
341
            _firstHalfInitialized = true;
345 342
            
346 343
            initSecondHalf(context);
347 344
            
348 345
    	} catch (ServiceException se) {
349 346
        	String errorMessage = 
350 347
        		"Service problem while intializing MetaCat Servlet: " + se.getMessage();
351
            logMetacat.error(errorMessage);
348
            logMetacat.error("MetaCatServlet.init - " + errorMessage);
352 349
            throw new ServletException(errorMessage);
353 350
        } catch (MetacatUtilException mue) {
354 351
        	String errorMessage = "Metacat utility problem while intializing MetaCat Servlet: " 
355 352
        		+ mue.getMessage();
356
            logMetacat.error(errorMessage);
353
            logMetacat.error("MetaCatServlet.init - " + errorMessage);
357 354
            throw new ServletException(errorMessage);
358 355
        } 
359 356
    }
......
375 372
			
376 373
			// initialize DBConnection pool
377 374
			DBConnectionPool connPool = DBConnectionPool.getInstance();
378
			logMetacat.debug("DBConnection pool initialized: " + connPool.toString());
375
			logMetacat.debug("MetaCatServlet.initSecondHalf - DBConnection pool initialized: " + connPool.toString());
379 376
			
380 377
			ServiceService.registerService("XMLSchemaService", XMLSchemaService.getInstance());
381 378
//			ServiceService.registerService("SchedulerService", SchedulerService.getInstance());
......
383 380
			// check if eml201 document were corrected or not. if not, correct eml201 documents.
384 381
			// Before Metacat 1.8.1, metacat uses tag RELEASE_EML_2_0_1_UPDATE_6 as eml
385 382
			// schema, which accidentily points to wrong version of eml-resource.xsd.
386
			String correctedEML201Doc = PropertyService
387
					.getProperty("document.eml201DocumentCorrected");
383
			String correctedEML201Doc = PropertyService.getProperty("document.eml201DocumentCorrected");
388 384
			if (correctedEML201Doc != null && correctedEML201Doc.equals(FALSE)) {
389
				logMetacat.info("===Start to correct eml201 documents");
385
				logMetacat.info("MetaCatServlet.initSecondHalf - Start to correct eml201 documents");
390 386
				EML201DocumentCorrector correct = new EML201DocumentCorrector();
391 387
				boolean success = correct.run();
392 388
				if (success) {
393 389
					PropertyService.setProperty("document.eml201DocumentCorrected", TRUE);
394 390
				}
395
				logMetacat.info("====Finish to correct eml201 documents");
391
				logMetacat.info("MetaCatServlet.initSecondHalf - Finish to correct eml201 documents");
396 392
			}
397 393

  
398 394
			// Index the paths specified in the metacat.properties
......
437 433

  
438 434
				// End timer
439 435
				long after = System.currentTimeMillis();
440
				logMetacat.info(" ------ Spatial Harvester Time  " 
436
				logMetacat.info("MetaCatServlet.initSecondHalf - Spatial Harvester Time  " 
441 437
						+ (after - before) + "ms");
442 438

  
443 439
			} else {
444
				logMetacat.info(" \n **** Spatial cache is not set to regenerate on restart");
440
				logMetacat.info("MetaCatServlet.initSecondHalf - Spatial cache is not set to regenerate on restart");
445 441
			}
446 442
		
447 443
			// Set up the replication log file by setting the "replication.logfile.name" 
......
454 450
			}
455 451

  
456 452
			if (FileUtil.getFileStatus(replicationLogPath) < FileUtil.EXISTS_READ_WRITABLE) {
457
				logMetacat.error("Replication log file: " + replicationLogPath 
453
				logMetacat.error("MetaCatServlet.initSecondHalf - Replication log file: " + replicationLogPath 
458 454
						+ " does not exist read/writable.");
459 455
			}
460 456
			
461 457
			System.setProperty("replication.logfile.name", replicationLogPath);			
462 458
			PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
463 459
			
464
			sitemapScheduled = false;
460
			_sitemapScheduled = false;
465 461

  
466
			fullyInitialized = true;
462
			_fullyInitialized = true;
467 463
			
468
			logMetacat.warn("Metacat (" + MetacatVersion.getVersionID()
464
			logMetacat.warn("MetaCatServlet.initSecondHalf - Metacat (" + MetacatVersion.getVersionID()
469 465
					+ ") initialized.");
470 466
			
471 467
		} catch (SQLException e) {
472 468
			String errorMessage = "SQL problem while intializing MetaCat Servlet: "
473 469
					+ e.getMessage();
474
			logMetacat.error(errorMessage);
470
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
475 471
			throw new ServletException(errorMessage);
476 472
		} catch (IOException ie) {
477 473
			String errorMessage = "IO problem while intializing MetaCat Servlet: "
478 474
					+ ie.getMessage();
479
			logMetacat.error(errorMessage);
475
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
480 476
			throw new ServletException(errorMessage);
481 477
		} catch (GeneralPropertyException gpe) {
482 478
			String errorMessage = "Could not retrieve property while intializing MetaCat Servlet: "
483 479
					+ gpe.getMessage();
484
			logMetacat.error(errorMessage);
480
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
485 481
			throw new ServletException(errorMessage);
486 482
		} catch (ServiceException se) {
487 483
			String errorMessage = "Service problem while intializing MetaCat Servlet: "
488 484
				+ se.getMessage();
489
			logMetacat.error(errorMessage);
485
			logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
490 486
			throw new ServletException(errorMessage);
491 487
		} catch (UtilException ue) {
492 488
        	String errorMessage = "Utility problem while intializing MetaCat Servlet: " 
493 489
        		+ ue.getMessage();
494
            logMetacat.error(errorMessage);
490
            logMetacat.error("MetaCatServlet.initSecondHalf - " + errorMessage);
495 491
            throw new ServletException(errorMessage);
496 492
        } 
497 493
	}
......
505 501
    	ServiceService.stopAllServices();
506 502
    	
507 503
        // Close all db connection
508
        logMetacat.warn("Destroying MetacatServlet");
504
        logMetacat.warn("MetaCatServlet.destroy - Destroying MetacatServlet");
509 505
        timer.cancel();
510 506
        IndexingQueue.getInstance().setMetacatRunning(false);
511 507
        DBConnectionPool.release();
......
539 535
        }
540 536
        catch (MetacatUtilException ue) {
541 537
        	pathsForIndexing = null;
542
            logMetacat.error("Could not find index paths.  Setting " 
538
            logMetacat.error("MetaCatServlet.checkIndexPaths - not find index paths.  Setting " 
543 539
            		+ "pathsForIndexing to null: " + ue.getMessage());
544 540
        }
545 541
        
546 542
        if (pathsForIndexing != null && !pathsForIndexing.isEmpty()) {
547 543
            
548
            logMetacat.debug("Indexing paths specified in metacat.properties....");
544
            logMetacat.debug("MetaCatServlet.checkIndexPaths - Indexing paths specified in metacat.properties....");
549 545
            
550 546
            DBConnection conn = null;
551 547
            int serialNumber = -1;
......
554 550
            ResultSet rs = null;
555 551
            
556 552
            for (String pathIndex : pathsForIndexing) {
557
                logMetacat.debug("Checking if '" + pathIndex  + "' is indexed.... ");
553
                logMetacat.debug("MetaCatServlet.checkIndexPaths - Checking if '" + pathIndex  + "' is indexed.... ");
558 554
                
559 555
                try {
560 556
                    //check out DBConnection
......
570 566
                    rs = pstmt.getResultSet();
571 567
                    
572 568
                    if (!rs.next()) {
573
                        logMetacat.debug(".....not indexed yet.");
569
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - not indexed yet.");
574 570
                        rs.close();
575 571
                        pstmt.close();
576 572
                        conn.increaseUsageCount(1);
577 573
                        
578
                        logMetacat.debug("Inserting following path in xml_path_index: "
574
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - Inserting following path in xml_path_index: "
579 575
                                + pathIndex);
580 576
                        if(pathIndex.indexOf("@")<0){
581 577
                            pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, "
......
595 591
                        rs = pstmt.getResultSet();
596 592
                        
597 593
                        int count = 0;
598
                        logMetacat.debug("Executed the select statement for: "
594
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - Executed the select statement for: "
599 595
                                + pathIndex);
600 596
                        
601 597
                        try {
......
627 623
                                }
628 624
                            }
629 625
                        } catch (Exception e) {
630
                            logMetacat.error("Exception:" + e.getMessage());
626
                            logMetacat.error("MetaCatServlet.checkIndexPaths - Exception:" + e.getMessage());
631 627
                            e.printStackTrace();
632 628
                        }
633 629
                        
......
635 631
                        pstmt.close();
636 632
                        conn.increaseUsageCount(1);
637 633
                        
638
                        logMetacat.info("Indexed " + count + " records from xml_nodes for '"
634
                        logMetacat.info("MetaCatServlet.checkIndexPaths - Indexed " + count + " records from xml_nodes for '"
639 635
                                + pathIndex + "'");
640 636
                        
641 637
                    } else {
642
                        logMetacat.debug(".....already indexed.");
638
                        logMetacat.debug("MetaCatServlet.checkIndexPaths - already indexed.");
643 639
                    }
644 640
                    
645 641
                    rs.close();
......
647 643
                    conn.increaseUsageCount(1);
648 644
                    
649 645
                } catch (Exception e) {
650
                    logMetacat.error("Error in MetaCatServlet.checkIndexPaths: "
646
                    logMetacat.error("MetaCatServlet.checkIndexPaths - Error in MetaCatServlet.checkIndexPaths: "
651 647
                            + e.getMessage());
652 648
                }finally {
653 649
                    //check in DBonnection
......
657 653
                
658 654
            }
659 655
            
660
            logMetacat.debug("Path Indexing Completed");
656
            logMetacat.debug("MetaCatServlet.checkIndexPaths - Path Indexing Completed");
661 657
        }
662 658
    }
663 659
    
664 660
    /**
665 661
	 * Control servlet response depending on the action parameter specified
666 662
	 */
663
	@SuppressWarnings("unchecked")
667 664
	private void handleGetOrPost(HttpServletRequest request,
668 665
			HttpServletResponse response) throws ServletException, IOException {
669 666
		Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
......
691 688
		// if we get here, metacat is configured.  If we have not completed the 
692 689
		// second half of the initialization, do so now.  This allows us to initially
693 690
		// configure metacat without a restart.
694
		if (!fullyInitialized) {
691
		if (!_fullyInitialized) {
695 692
			initSecondHalf(request.getSession().getServletContext());
696 693
		}
697 694
		
......
707 704

  
708 705
		// Debug message to print out the method which have a busy DBConnection
709 706
		try {
707
			@SuppressWarnings("unused")
710 708
			DBConnectionPool pool = DBConnectionPool.getInstance();
711
			pool.printMethodNameHavingBusyDBConnection();
709
//			pool.printMethodNameHavingBusyDBConnection();
712 710
		} catch (SQLException e) {
713
			logMetacat.error("Error in MetacatServlet.handleGetOrPost: " + e.getMessage());
711
			logMetacat.error("MetaCatServlet.handleGetOrPost - Error in MetacatServlet.handleGetOrPost: " + e.getMessage());
714 712
			e.printStackTrace();
715 713
		}
716 714

  
......
738 736
					String docidToRead = path[1];
739 737
					String docs[] = new String[1];
740 738
					docs[0] = docidToRead;
741
					logMetacat.debug("READING DOCID FROM PATHINFO: " + docs[0]);
739
					logMetacat.debug("MetaCatServlet.handleGetOrPost - READING DOCID FROM PATHINFO: " + docs[0]);
742 740
					params.put("docid", docs);
743 741
					String skin = null;
744 742
					if (path.length > 2) {
......
794 792
			}
795 793

  
796 794
			String action = (params.get("action"))[0];
797
			logMetacat.info("Action is: " + action);
795
			logMetacat.info("MetaCatServlet.handleGetOrPost - Action is: " + action);
798 796

  
799 797
			// This block handles session management for the servlet
800 798
			// by looking up the current session information for all actions
......
859 857
					sessionId = sessionData.getId();
860 858
				}
861 859

  
862
				logMetacat.info("The user is : " + userName);
860
				logMetacat.info("MetaCatServlet.handleGetOrPost - The user is : " + userName);
863 861
			}
864 862
			// Now that we know the session is valid, we can delegate the
865 863
			// request to a particular action handler
......
881 879
			} else if (action.trim().equals("spatial_query")) {
882 880

  
883 881
				logMetacat
884
						.debug("******************* SPATIAL QUERY ********************");
882
						.debug("MetaCatServlet.handleGetOrPost - ******************* SPATIAL QUERY ********************");
885 883
				ServletOutputStream streamOut = response.getOutputStream();
886 884
				PrintWriter out = new PrintWriter(streamOut);
887 885
				handleSpatialQuery(out, params, response, userName, groupNames, sessionId);
......
889 887

  
890 888
			} else if (action.trim().equals("dataquery")) {
891 889

  
892
				logMetacat.debug("******************* DATA QUERY ********************");
890
				logMetacat.debug("MetaCatServlet.handleGetOrPost - ******************* DATA QUERY ********************");
893 891
				handleDataquery(params, response, sessionId);
894 892
			} else if (action.trim().equals("editcart")) {
895
				logMetacat.debug("******************* EDIT CART ********************");
893
				logMetacat.debug("MetaCatServlet.handleGetOrPost - ******************* EDIT CART ********************");
896 894
				handleEditCart(params, response, sessionId);
897 895
			} else if (action.equals("export")) {
898 896

  
......
1110 1108

  
1111 1109
		} catch (PropertyNotFoundException pnfe) {
1112 1110
			String errorString = "Critical property not found: " + pnfe.getMessage();
1113
			logMetacat.error(errorString);
1111
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1114 1112
			throw new ServletException(errorString);
1115 1113
		} catch (MetacatUtilException ue) {
1116 1114
			String errorString = "Utility error: " + ue.getMessage();
1117
			logMetacat.error(errorString);
1115
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1118 1116
			throw new ServletException(errorString);
1119 1117
		} catch (ServiceException ue) {
1120 1118
			String errorString = "Service error: " + ue.getMessage();
1121
			logMetacat.error(errorString);
1119
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1122 1120
			throw new ServletException(errorString);
1123 1121
		} catch (HandlerException he) {
1124 1122
			String errorString = "Handler error: " + he.getMessage();
1125
			logMetacat.error(errorString);
1123
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1126 1124
			throw new ServletException(errorString);
1127 1125
		} catch (ErrorSendingErrorException esee) {
1128 1126
			String errorString = "Error sending error message: " + esee.getMessage();
1129
			logMetacat.error(errorString);
1127
			logMetacat.error("MetaCatServlet.handleGetOrPost - " + errorString);
1130 1128
			throw new ServletException(errorString);
1131 1129
		} catch (ErrorHandledException ehe) {
1132 1130
			// Nothing to do here.  We assume if we get here, the error has been 
......
1284 1282
        } catch (java.lang.NullPointerException e) {
1285 1283
            // should be "default" but keep this for backwards compatibility
1286 1284
			// with knp site
1287
            logMetacat.warn("No SKIN specified for metacat actions=spatial_query... defaulting to 'knp' skin !\n");
1285
            logMetacat.warn("MetaCatServlet.handleSpatialQuery - No SKIN specified for metacat actions=spatial_query... defaulting to 'knp' skin !\n");
1288 1286
            qformatArray[0] = "knp";
1289 1287
        }
1290 1288
        params.put("qformat", qformatArray);
......
1339 1337
        }
1340 1338
        
1341 1339
        String un = (params.get("username"))[0];
1342
        logMetacat.info("user " + un + " is trying to login");
1340
        logMetacat.info("MetaCatServlet.handleLoginAction - user " + un + " is trying to login");
1343 1341
        String pw = (params.get("password"))[0];
1344 1342
        
1345 1343
        String qformat = "xml";
......
1350 1348
        try {
1351 1349
            sess = new AuthSession();
1352 1350
        } catch (Exception e) {
1353
        	String errorMsg = "MetacatServlet.handleLoginAction()- Problem in MetacatServlet.handleLoginAction() authenicating session: "
1351
        	String errorMsg = "MetacatServlet.handleLoginAction - Problem in MetacatServlet.handleLoginAction() authenicating session: "
1354 1352
                + e.getMessage();
1355 1353
            logMetacat.error(errorMsg);
1356 1354
            out.println(errorMsg);
......
1363 1361
            HttpSession session = sess.getSessions();
1364 1362
            String id = session.getId();
1365 1363
            
1366
            logMetacat.debug("Store session id " + id
1364
            logMetacat.debug("MetaCatServlet.handleLoginAction - Store session id " + id
1367 1365
                    + " which has username" + session.getAttribute("username")
1368 1366
                    + " into hash in login method");
1369 1367
            try {
......
1373 1371
						(String) session.getAttribute("password"), 
1374 1372
						(String) session.getAttribute("name"));
1375 1373
			} catch (ServiceException se) {
1376
				String errorMsg = "MetacatServlet.handleLoginAction()- service problem registering session: "
1374
				String errorMsg = "MetacatServlet.handleLoginAction - service problem registering session: "
1377 1375
						+ se.getMessage();
1378
				logMetacat.error(errorMsg);
1376
				logMetacat.error("MetaCatServlet.handleLoginAction - " + errorMsg);
1379 1377
				out.println(errorMsg);
1380 1378
				return;
1381 1379
			} 			
......
1393 1391
                        "-//NCEAS//login//EN", "-//W3C//HTML//EN", qformat,
1394 1392
                        out, null, null);
1395 1393
            } catch (Exception e) {               
1396
                logMetacat.error("Error in MetaCatServlet.handleLoginAction: "
1394
                logMetacat.error("MetaCatServlet.handleLoginAction - General error"
1397 1395
                        + e.getMessage());
1398 1396
            }
1399 1397
        }
......
1412 1410
        
1413 1411
        // close the connection
1414 1412
        HttpSession sess = request.getSession(false);
1415
        logMetacat.info("After get session in logout request");
1413
        logMetacat.info("MetaCatServlet.handleLogoutAction - After get session in logout request");
1416 1414
        if (sess != null) {
1417
            logMetacat.info("The session id " + sess.getId()
1415
            logMetacat.info("MetaCatServlet.handleLogoutAction - The session id " + sess.getId()
1418 1416
            + " will be invalidate in logout action");
1419
            logMetacat.info("The session contains user "
1417
            logMetacat.info("MetaCatServlet.handleLogoutAction - The session contains user "
1420 1418
                    + sess.getAttribute("username")
1421 1419
                    + " will be invalidate in logout action");
1422 1420
            sess.invalidate();
......
1443 1441
                        out, null, null);
1444 1442
            } catch (Exception e) {
1445 1443
                logMetacat.error(
1446
                        "Error in MetaCatServlet.handleLogoutAction"
1444
                        "MetaCatServlet.handleLogoutAction - General error: "
1447 1445
                        + e.getMessage());
1448 1446
            }
1449 1447
        }
......
1464 1462
    private void handleSQuery(PrintWriter out, Hashtable<String, String[]> params,
1465 1463
            HttpServletResponse response, String user, String[] groups,
1466 1464
            String sessionid) throws PropertyNotFoundException {
1467
        double startTime = System.currentTimeMillis() / 1000;
1465
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1466
        long squeryWarnLimit = Long.parseLong(PropertyService.getProperty("database.squeryTimeWarnLimit"));
1467
    	
1468
        long startTime = System.currentTimeMillis();
1468 1469
        DBQuery queryobj = new DBQuery();
1469 1470
        queryobj.findDocuments(response, out, params, user, groups, sessionid);
1470
        double outPutTime = System.currentTimeMillis() / 1000;
1471
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1472
        logMetacat.warn("Total search time for action 'squery': "
1473
                + (outPutTime - startTime));
1474
        MetacatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1475
                "-------------------------------------------------------------------------------Total search time for "
1476
                + (outPutTime - startTime));
1477
        MetacatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1471
        long outPutTime = System.currentTimeMillis();
1472
        long runTime = outPutTime - startTime;
1473

  
1474
        if (runTime > squeryWarnLimit) {
1475
        	logMetacat.warn("MetaCatServlet.handleSQuery - Long running squery.  Total time: " + runTime + 
1476
        			" ms, squery: " + ((String[])params.get("query"))[0]);
1477
        }
1478
        logMetacat.debug("MetaCatServlet.handleSQuery - squery: " + ((String[])params.get("query"))[0] + 
1479
        		" ran in " + runTime + " ms");
1478 1480
    }
1479 1481
    
1480 1482
    /**
......
1488 1490
    private void handleQuery(PrintWriter out, Hashtable<String, String[]> params,
1489 1491
            HttpServletResponse response, String user, String[] groups,
1490 1492
            String sessionid) throws PropertyNotFoundException {
1493
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1494
        long queryWarnLimit = Long.parseLong(PropertyService.getProperty("database.queryTimeWarnLimit"));
1495
    	
1491 1496
        //create the query and run it
1492 1497
        String xmlquery = DBQuery.createSQuery(params);
1493 1498
        String[] queryArray = new String[1];
1494 1499
        queryArray[0] = xmlquery;
1495 1500
        params.put("query", queryArray);
1496
        double startTime = System.currentTimeMillis() / 1000;
1501
        long startTime = System.currentTimeMillis();
1497 1502
        DBQuery queryobj = new DBQuery();
1498 1503
        queryobj.findDocuments(response, out, params, user, groups, sessionid);
1499
        double outPutTime = System.currentTimeMillis() / 1000;
1500
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1501
        logMetacat.warn("Total search time for action 'query': "
1502
                + (outPutTime - startTime));
1503
        MetacatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1504
                "-------------------------------------------------------------------------------Total search time is "
1505
                + (outPutTime - startTime));
1506
        MetacatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1507
        
1508
        //handleSQuery(out, params, response,user, groups, sessionid);
1504
        long outPutTime = System.currentTimeMillis();
1505
        long runTime = outPutTime -startTime;
1506

  
1507
        if (runTime > queryWarnLimit) {
1508
        	logMetacat.warn("MetaCatServlet.handleQuery - Long running squery.  Total time: " + runTime + 
1509
        			" ms, squery: " + ((String[])params.get("query"))[0]);
1510
        }
1511
        logMetacat.debug("MetaCatServlet.handleQuery - query: " + ((String[])params.get("query"))[0] + 
1512
        		" ran in " + runTime + " ms");
1509 1513
    }
1510 1514
    
1511 1515
    // END OF SQUERY & QUERY SECTION
......
1588 1592
                    zOut.close();
1589 1593
                }
1590 1594
            } catch (IOException ioe) {
1591
                logMetacat.error("Problem with the servlet output "
1592
                        + "in MetacatServlet.handleExportAction: "
1595
                logMetacat.error("MetaCatServlet.handleExportAction - Problem with the servlet output: "
1593 1596
                        + ioe.getMessage());
1594 1597
            }
1595 1598
            
1596
            logMetacat.error(
1597
                    "Error in MetacatServlet.handleExportAction: "
1599
            logMetacat.error("MetaCatServlet.handleExportAction - General error: "
1598 1600
                    + e.getMessage());
1599 1601
            e.printStackTrace(System.out);
1600 1602
            
......
1697 1699
                    out.close();
1698 1700
                }
1699 1701
            } catch (IOException ioe) {
1700
                logMetacat.error("Problem with the servlet output "
1701
                        + "in MetacatServlet.handleExportAction: "
1702
                logMetacat.error("MetaCatServlet.handleReadInlineDataAction - Problem with the servlet output: "
1702 1703
                        + ioe.getMessage());
1703 1704
            }
1704
            logMetacat.error(
1705
                    "Error in MetacatServlet.handleReadInlineDataAction: "
1705
            logMetacat.error("MetaCatServlet.handleReadInlineDataAction - General error: "
1706 1706
                    + e.getMessage());
1707 1707
        }
1708 1708
    }
......
1812 1812
            // the docid which didn't be found
1813 1813
            String notFoundDocId = notFoundE.getUnfoundDocId();
1814 1814
            String notFoundRevision = notFoundE.getUnfoundRevision();
1815
            logMetacat.warn("Missed id: " + notFoundDocId);
1816
            logMetacat.warn("Missed rev: " + notFoundRevision);
1815
            logMetacat.warn("MetaCatServlet.handleReadAction - Missed id: " + notFoundDocId);
1816
            logMetacat.warn("MetaCatServlet.handleReadAction - Missed rev: " + notFoundRevision);
1817 1817
            try {
1818 1818
                // read docid from remote server
1819 1819
                readFromRemoteMetaCat(response, notFoundDocId,
......
1828 1828
                }
1829 1829
                
1830 1830
            } catch (Exception exc) {
1831
                logMetacat.error(
1832
                        "Erorr in MetacatServlet.hanldReadAction: "
1831
                logMetacat.error("MetaCatServlet.handleReadAction - General error: "
1833 1832
                        + exc.getMessage());
1834 1833
                try {
1835 1834
                    if (out != null) {
......
1861 1860
                        zout.close();
1862 1861
                    }
1863 1862
                } catch (IOException ie) {
1864
                    logMetacat.error("Problem with the servlet output "
1865
                            + "in MetacatServlet.handleReadAction: "
1863
                    logMetacat.error("MetaCatServlet.handleReadAction - Problem with the servlet output: "
1866 1864
                            + ie.getMessage());
1867 1865
                }
1868 1866
            }
......
1896 1894
                    zout.close();
1897 1895
                }
1898 1896
                
1899
            } catch (IOException ioe) {
1900
                logMetacat.error("Problem with the servlet output "
1901
                        + "in MetacatServlet.handleReadAction: "
1902
                        + ioe.getMessage());
1903
                ioe.printStackTrace(System.out);
1897
            } catch (Exception e2) {
1898
                logMetacat.error("MetaCatServlet.handleReadAction - Problem with the servlet output: "
1899
                        + e2.getMessage());
1900
                e2.printStackTrace(System.out);
1904 1901
                
1905 1902
            }
1906 1903
            
1907
            logMetacat.error(
1908
                    "Error in MetacatServlet.handleReadAction: "
1904
            logMetacat.error("MetaCatServlet.handleReadAction - General error: "
1909 1905
                    + e.getMessage());
1910 1906
            //e.printStackTrace(System.out);
1911 1907
        }
......
1962 1958
                    ContentTypeProvider provider = new ContentTypeProvider(
1963 1959
                            docid);
1964 1960
                    contentType = provider.getContentType();
1965
                    logMetacat.info("Final contenttype is: "
1961
                    logMetacat.info("MetaCatServlet.readFromMetacat - Final contenttype is: "
1966 1962
                            + contentType);
1967 1963
                }
1968 1964
                
......
2041 2037
					} catch (Exception e) {
2042 2038
						// any exceptions in reading the xml from disc, and we go back to the
2043 2039
						// old way of creating the xml directly.
2044
						logMetacat.error("could not read from document file " + docid 
2040
						logMetacat.error("MetaCatServlet.readFromMetacat - could not read from document file " + docid 
2045 2041
								+ ": " + e.getMessage());
2046 2042
						PrintWriter out = new PrintWriter(streamOut);
2047 2043
						doc.toXmlFromDb(out, user, groups, withInlineData);
......
2291 2287
            out.println("<error>");
2292 2288
            out.println("Docid not specified");
2293 2289
            out.println("</error>");
2294
            logMetacat.error("Docid not specified");
2290
            logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - Docid not specified");
2295 2291
            return;
2296 2292
        }
2297 2293
        
......
2301 2297
				out.println("<error>");
2302 2298
				out.println("User '" + user + "' not allowed to insert and update");
2303 2299
				out.println("</error>");
2304
				logMetacat.error("User '" + user + "' not allowed to insert and update");
2300
				logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - User '" + user + "' not allowed to insert and update");
2305 2301
				return;
2306 2302
			}
2307 2303
		} catch (MetacatUtilException ue) {
2308
			logMetacat.error("Could not determine if user could insert or update: "
2304
			logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - Could not determine if user could insert or update: "
2309 2305
					+ ue.getMessage());
2310 2306
		}
2311 2307
        
2312 2308
        try {
2313 2309
            // Get the document indicated
2314
            logMetacat.debug("params: " + params.toString());
2310
            logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - params: " + params.toString());
2315 2311
            
2316 2312
            String[] doctext = params.get("doctext");
2317 2313
            String pub = null;
......
2338 2334
                return;
2339 2335
            }
2340 2336
            
2341
            logMetacat.debug("======the xml document in metacat servlet (before parsing):\n"+doctext[0]);
2337
            logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - the xml document in metacat servlet (before parsing):\n" + doctext[0]);
2342 2338
            StringReader xml = new StringReader(doctext[0]);
2343 2339
            boolean validate = false;
2344 2340
            DocumentImplWrapper documentWrapper = null;
......
2362 2358
                            // set eml2 base	 validation parser
2363 2359
                            String rule = DocumentImpl.EML200;
2364 2360
                            // using emlparser to check id validation
2365
                            EMLParser parser = new EMLParser(doctext[0]);
2361
                            @SuppressWarnings("unused")
2362
							EMLParser parser = new EMLParser(doctext[0]);
2366 2363
                            documentWrapper = new DocumentImplWrapper(rule, true);
2367 2364
                        } else if (namespace.compareTo(
2368 2365
                                DocumentImpl.EML2_1_0NAMESPACE) == 0) {
2369 2366
                            // set eml2 base validation parser
2370 2367
                            String rule = DocumentImpl.EML210;
2371 2368
                            // using emlparser to check id validation
2372
                            EMLParser parser = new EMLParser(doctext[0]);
2369
                            @SuppressWarnings("unused")
2370
							EMLParser parser = new EMLParser(doctext[0]);
2373 2371
                            documentWrapper = new DocumentImplWrapper(rule, true);
2374 2372
                        } else {
2375 2373
                            // set schema base validation parser
......
2401 2399
                    // write the document to the database and disk
2402 2400
                    try {
2403 2401
                        String accNumber = docid[0];
2404
                        logMetacat.debug("" + doAction + " "
2402
                        logMetacat.debug("MetaCatServlet.handleInsertOrUpdateAction - " + doAction + " "
2405 2403
                                + accNumber + "...");
2406 2404
                        if (accNumber.equals("")) {
2407 2405
                            accNumber = null;
......
2414 2412
                                user, accNumber, action[0]);
2415 2413
                    } catch (NullPointerException npe) {
2416 2414
                      // MCD this seems a bit dubious, since many things can throw npe
2417
                      logMetacat.warn("writing with null acnumber");
2415
                      logMetacat.warn("MetaCatServlet.handleInsertOrUpdateAction - writing with null acnumber");
2418 2416
                        newdocid = documentWrapper.write(dbConn, xml, pub, dtd,
2419 2417
                                doAction, null, user, groups);
2420 2418
                        EventLog.getInstance().log(request.getRemoteAddr(),
......
2438 2436
                output += "<error>";
2439 2437
                output += npe.getMessage();
2440 2438
                output += "</error>";
2441
                logMetacat.warn("Error in writing eml document to the database" + npe.getMessage());
2439
                logMetacat.warn("MetaCatServlet.handleInsertOrUpdateAction - Error in writing eml document to the database" + npe.getMessage());
2442 2440
                npe.printStackTrace();
2443 2441
            }
2444 2442
        } catch (Exception e) {
......
2447 2445
            output += "<error>";
2448 2446
            output += e.getMessage();
2449 2447
            output += "</error>";
2450
            logMetacat.warn("Error in writing eml document to the database" + e.getMessage());
2448
            logMetacat.warn("MetaCatServlet.handleInsertOrUpdateAction - Error in writing eml document to the database" + e.getMessage());
2451 2449
            e.printStackTrace();
2452 2450
        }
2453 2451
        
......
2463 2461
                        out, null, null);
2464 2462
            } catch (Exception e) {
2465 2463
                
2466
                logMetacat.error(
2467
                        "Error in MetaCatServlet.handleLoginAction: "
2464
                logMetacat.error("MetaCatServlet.handleInsertOrUpdateAction - General error: "
2468 2465
                        + e.getMessage());
2469 2466
            }
2470 2467
        }
......
2529 2526
            }
2530 2527
        }
2531 2528
        
2532
        logMetacat.info("Validation for dtd is " + validate);
2529
        logMetacat.info("MetaCatServlet.needDTDValidation - Validation for dtd is " + validate);
2533 2530
        return validate;
2534 2531
    }
2535 2532
    
......
2551 2548
            out.println("<error>");
2552 2549
            out.println("Docid not specified.");
2553 2550
            out.println("</error>");
2554
            logMetacat.error("Docid not specified for the document to be deleted.");
2551
            logMetacat.error("MetaCatServlet.handleDeleteAction - Docid not specified for the document to be deleted.");
2555 2552
        } else {
2556 2553
            
2557 2554
            // delete the document from the database
......
2567 2564
                    out.println("<success>");
2568 2565
                    out.println("Document deleted.");
2569 2566
                    out.println("</success>");
2570
                    logMetacat.info("Document deleted.");
2567
                    logMetacat.info("MetaCatServlet.handleDeleteAction - Document deleted.");
2571 2568
                    
2572 2569
                    // Delete from spatial cache if runningSpatialOption
2573 2570
                    if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") ) {
......
2583 2580
                    //out.println("Error deleting document!!!");
2584 2581
                    out.println(ane.getMessage());
2585 2582
                    out.println("</error>");
2586
                    logMetacat.error("Document could not be deleted: "
2583
                    logMetacat.error("MetaCatServlet.handleDeleteAction - Document could not be deleted: "
2587 2584
                            + ane.getMessage());
2588 2585
                }
2589 2586
            } catch (Exception e) {
......
2592 2589
                out.println("<error>");
2593 2590
                out.println(e.getMessage());
2594 2591
                out.println("</error>");
2595
                logMetacat.error("Document could not be deleted: "
2592
                logMetacat.error("MetaCatServlet.handleDeleteAction - Document could not be deleted: "
2596 2593
                        + e.getMessage());
2597 2594
            }
2598 2595
        }
......
2714 2711
        		String actualDocId = LSIDUtil.getDocId(docid, false);
2715 2712
        		docid = actualDocId;
2716 2713
        	} catch (ParseLSIDException ple) {
2717
        		logMetacat.error("MetaCatServlet.handleGetAccessControlAction - " +
2714
        		logMetacat.error("MetaCatServlet.handleGetAccessControlAction - MetaCatServlet.handleGetAccessControlAction - " +
2718 2715
        				"could not parse lsid: " + docid + " : " + ple.getMessage());        		
2719 2716
        	}
2720 2717
        }
......
2957 2954
                    endDate = new Timestamp((format.parse(end)).getTime());
2958 2955
                }
2959 2956
            } catch (ParseException e) {
2960
                logMetacat.error("Failed to created Timestamp from input.");
2957
                logMetacat.error("MetaCatServlet.handleGetLogAction - Failed to created Timestamp from input.");
2961 2958
            }
2962 2959
            
2963 2960
            // Request the report by passing the filter parameters
......
2965 2962
                    docid, event, startDate, endDate));
2966 2963
            out.close();
2967 2964
        } catch (IOException e) {
2968
			logMetacat.error("Could not open http response for writing: "
2965
			logMetacat.error("MetaCatServlet.handleGetLogAction - Could not open http response for writing: "
2969 2966
					+ e.getMessage());
2970 2967
		} catch (MetacatUtilException ue) {
2971
			logMetacat.error("Could not determine if user is administrator: "
2968
			logMetacat.error("MetaCatServlet.handleGetLogAction - Could not determine if user is administrator: "
2972 2969
					+ ue.getMessage());
2973 2970
		}
2974 2971
    }
......
3034 3031
            out.println("</success>");
3035 3032
            out.close();
3036 3033
        } catch (IOException e) {
3037
            logMetacat.error(
3038
                    "Could not open http response for writing: "
3034
            logMetacat.error("MetaCatServlet.handleBuildIndexAction - Could not open http response for writing: "
3039 3035
                    + e.getMessage());
3040 3036
        } catch (MetacatUtilException ue) {
3041
			logMetacat.error("Could not determine if user is administrator: "
3037
			logMetacat.error("MetaCatServlet.handleBuildIndexAction - Could not determine if user is administrator: "
3042 3038
					+ ue.getMessage());
3043 3039
		}
3044 3040
    }
......
3084 3080
        	sizeLimit = 
3085 3081
        		(new Integer(PropertyService.getProperty("replication.datafilesizelimit"))).intValue();
3086 3082
        } catch (PropertyNotFoundException pnfe) {
3087
        	logMetacat.error("Could not determine data file size limit.  Using 1000. " 
3083
        	logMetacat.error("MetaCatServlet.handleMultipartForm - Could not determine data file size limit.  Using 1000. " 
3088 3084
        			+ pnfe.getMessage());
3089 3085
        }
3090
        logMetacat.debug("The size limit of uploaded data files is: " + sizeLimit);
3086
        logMetacat.debug("MetaCatServlet.handleMultipartForm - The size limit of uploaded data files is: " + sizeLimit);
3091 3087
        
3092 3088
        try {
3093 3089
            MultipartParser mp = new MultipartParser(request,
......
3118 3114
                    fileList.put("filename", fileName);
3119 3115
                    fileList.put("name", fileTempLocation);
3120 3116
                } else {
3121
                    logMetacat.info("Upload name '" + name + "' was empty.");
3117
                    logMetacat.info("MetaCatServlet.handleMultipartForm - Upload name '" + name + "' was empty.");
3122 3118
                }
3123 3119
            }
3124 3120
        } catch (IOException ioe) {
3125 3121
            try {
3126 3122
                out = response.getWriter();
3127 3123
            } catch (IOException ioe2) {
3128
                logMetacat.fatal("Fatal Error: couldn't get response output stream.");
3124
                logMetacat.fatal("MetaCatServlet.handleMultipartForm - Fatal Error: couldn't get response output stream.");
3129 3125
            }
3130 3126
            out.println("<?xml version=\"1.0\"?>");
3131 3127
            out.println("<error>");
......
3165 3161
        try {
3166 3162
            out = response.getWriter();
3167 3163
        } catch (IOException ioe2) {
3168
            logMetacat.error("Fatal Error: couldn't get response "
3164
            logMetacat.error("MetaCatServlet.handleMultipartForm - Fatal Error: couldn't get response "
3169 3165
                    + "output stream.");
3170 3166
        }
3171 3167
        
......
3181 3177
            }
3182 3178
        } else if(action.equals("insertmultipart")) {
3183 3179
          if (username != null && !username.equals("public")) {
3184
            logMetacat.debug("!!!!!!!!!!handling multipart insert");
3180
            logMetacat.debug("MetaCatServlet.handleMultipartForm - handling multipart insert");
3185 3181
              handleInsertMultipartAction(request, response,
3186 3182
                            out, params, fileList, username, groupnames);
3187 3183
          } else {
......
3239 3235
      // Make sure we have a docid and datafile
3240 3236
      if (docid != null && fileList.containsKey("datafile")) 
3241 3237
      {
3242
        logMetacat.info("Uploading data docid: " + docid);
3238
        logMetacat.info("MetaCatServlet.handleInsertMultipartAction - Uploading data docid: " + docid);
3243 3239
        // Get a reference to the file part of the form
3244 3240
        //FilePart filePart = (FilePart) fileList.get("datafile");
3245 3241
        String fileName = fileList.get("filename");
3246
        logMetacat.debug("Uploading filename: " + fileName);
3242
        logMetacat.debug("MetaCatServlet.handleInsertMultipartAction - Uploading filename: " + fileName);
3247 3243
        // Check if the right file existed in the uploaded data
3248 3244
        if (fileName != null) 
3249 3245
        {
......
3270 3266
              {
3271 3267
                newFile = new File(newFileName);
3272 3268
                fileExists = newFile.exists();
3273
                logMetacat.info("new file status is: " + fileExists);
3269
                logMetacat.info("MetaCatServlet.handleInsertMultipartAction - new file status is: " + fileExists);
3274 3270
                if(fileExists)
3275 3271
                {
3276 3272
                  newFile.delete();
......
3287 3283
                    } 
3288 3284
                    catch (IOException ioe) 
3289 3285
                    {
3290
                        logMetacat.error("IO Exception copying file: " +
3286
                        logMetacat.error("MetaCatServlet.handleInsertMultipartAction - IO Exception copying file: " +
3291 3287
                                ioe.getMessage());
3292 3288
                    }
3293 3289
                    size = newFile.length();
3294 3290
                    if (size == 0) 
3295 3291
                    {
3296
                        throw new IOException("Uploaded file is 0 bytes!");
3292
                        throw new IOException("MetaCatServlet.handleInsertMultipartAction - Uploaded file is 0 bytes!");
3297 3293
                    }
3298 3294
                }
3299
                logMetacat.info("Uploading the following to Metacat:" +
3295
                logMetacat.info("MetaCatServlet.handleInsertMultipartAction - Uploading the following to Metacat:" +
3300 3296
                        fileName + ", " + docid + ", " +
3301 3297
                        username + ", " + groupnames);
3302 3298
                FileReader fr = new FileReader(newFile);
......
3336 3332
          }
3337 3333
          catch(Exception e)
3338 3334
          {
3339
              logMetacat.error("error uploading text file via multipart: " + e.getMessage());
3335
              logMetacat.error("MetaCatServlet.handleInsertMultipartAction - error uploading text file via multipart: " + e.getMessage());
3340 3336
              e.printStackTrace();
3341 3337
          }
3342 3338
        }
......
3375 3371
        
3376 3372
        // Make sure we have a docid and datafile
3377 3373
        if (docid != null && fileList.containsKey("datafile")) {
3378
            logMetacat.info("Uploading data docid: " + docid);
3374
            logMetacat.info("MetaCatServlet.handleUploadAction - Uploading data docid: " + docid);
3379 3375
            // Get a reference to the file part of the form
3380 3376
            //FilePart filePart = (FilePart) fileList.get("datafile");
3381 3377
            String fileName = fileList.get("filename");
3382
            logMetacat.info("Uploading filename: " + fileName);
3378
            logMetacat.info("MetaCatServlet.handleUploadAction - Uploading filename: " + fileName);
3383 3379
            // Check if the right file existed in the uploaded data
3384 3380
            if (fileName != null) {
3385 3381
                
......
3402 3398
                        try {
3403 3399
                            newFile = new File(newFileName);
3404 3400
                            fileExists = newFile.exists();
3405
                            logMetacat.info("new file status is: " + fileExists);
3401
                            logMetacat.info("MetaCatServlet.handleUploadAction - new file status is: " + fileExists);
3406 3402
                            if ( fileExists == false ) {
3407 3403
                                // copy file to desired output location
3408 3404
                                try {
......
3416 3412
                                    throw new IOException("Uploaded file is 0 bytes!");
3417 3413
                                }
3418 3414
                            }
3419
                            logMetacat.info("Uploading the following to Metacat:" +
3415
                            logMetacat.info("MetaCatServlet.handleUploadAction - Uploading the following to Metacat:" +
3420 3416
                                    fileName + ", " + docid + ", " +
3421 3417
                                    username + ", " + groupnames);
3422 3418
                            //register the file in the database (which generates
......
3432 3428
                            if ( fileExists == false ) {
3433 3429
                                newFile.delete();
3434 3430
                            }
3435
                            logMetacat.info("in Exception: fileExists is " + fileExists);
3436
                            logMetacat.error("Upload Error: " + ee.getMessage());
3431
                            logMetacat.info("MetaCatServlet.handleUploadAction - in Exception: fileExists is " + fileExists);
3432
                            logMetacat.error("MetaCatServlet.handleUploadAction - Upload Error: " + ee.getMessage());
3437 3433
                            throw ee;
3438 3434
                        }
3439 3435
                        
......
3448 3444
                        // not get force replication info from another metacat
3449 3445
                        ForceReplicationHandler frh = new ForceReplicationHandler(
3450 3446
                                docid, "insert", false, null);
3451
                        logMetacat.debug("ForceReplicationHandler created: " + frh.toString());
3447
                        logMetacat.debug("MetaCatServlet.handleUploadAction - ForceReplicationHandler created: " + frh.toString());
3452 3448
                        
3453 3449
                        // set content type and other response header fields
3454 3450
                        // first
......
3494 3490
                        out, null, null);
3495 3491
            } catch (Exception e) {
3496 3492
                
3497
                logMetacat.error(
3498
                        "Error in MetaCatServlet.handleLoginAction: "
3493
                logMetacat.error("MetaCatServlet.handleUploadAction - General error: "
3499 3494
                        + e.getMessage());
3500 3495
            }
3501 3496
        }
......
3589 3584
            		String actualDocId = LSIDUtil.getDocId(docid, false);
3590 3585
            		docid = actualDocId;
3591 3586
            	} catch (ParseLSIDException ple) {
3592
            		logMetacat.error("MetaCatServlet.handleGetAccessControlAction - " +
3587
            		logMetacat.error("MetaCatServlet.handleSetAccessAction - " +
3593 3588
            				"could not parse lsid: " + docid + " : " + ple.getMessage());        		
3594 3589
            	}
3595 3590
            }
......
3716 3711
                        + accessionNumber);
3717 3712
            }
3718 3713
        } catch (Exception e) {
3719
            logMetacat.error(
3720
                    "Exception in MetacatServlet.getPublicIdForDoc: "
3714
            logMetacat.error("MetaCatServlet.getFieldValueForDoc - General error: "
3721 3715
                    + e.getMessage());
3722 3716
            throw e;
3723 3717
        } finally {
......
3761 3755
                docList.add(docid + "." + rev);
3762 3756
            }
3763 3757
        } catch (SQLException e) {
3764
            logMetacat.error(
3765
                    "Exception in MetacatServlet.getDocumentList: "
3758
            logMetacat.error("MetaCatServlet.getDocumentList - General exception: "
3766 3759
                    + e.getMessage());
3767 3760
            throw e;
3768 3761
        } finally {
......
3771 3764
                pstmt.close();
3772 3765
                
3773 3766
            } catch (SQLException se) {
3774
                logMetacat.error(
3775
                        "Exception in MetacatServlet.getDocumentList: "
3767
                logMetacat.error("MetaCatServlet.getDocumentList - General exception: "
3776 3768
                        + se.getMessage());
3777 3769
                throw se;
3778 3770
            } finally {
......
3854 3846
     */
3855 3847
    private void scheduleSitemapGeneration(HttpServletRequest request) {
3856 3848
    	Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
3857
    	if (!sitemapScheduled) {
3849
    	if (!_sitemapScheduled) {
3858 3850
        	String directoryName = null;
3859 3851
        	String skin = null;
3860 3852
        	long sitemapInterval = 0;
......
3865 3857
				sitemapInterval = 
3866 3858
					Integer.parseInt(PropertyService.getProperty("sitemap.interval"));
3867 3859
			} catch (PropertyNotFoundException pnfe) {
3868
				logMetacat.error("Could not run site map generation because property " 
3860
				logMetacat.error("MetaCatServlet.scheduleSitemapGeneration - Could not run site map generation because property " 
3869 3861
						+ "could not be found: " + pnfe.getMessage());
3870 3862
			}
3871 3863
			
......
3875 3867
            Sitemap smap = new Sitemap(directory, urlRoot, skin);
3876 3868
            long firstDelay = 60*1000;   // 60 seconds delay
3877 3869
            timer.schedule(smap, firstDelay, sitemapInterval);
3878
            sitemapScheduled = true;
3870
            _sitemapScheduled = true;
3879 3871
        }
3880 3872
    }
3881 3873
    
......
3885 3877
     * @return true if fully intialized, false otherwise
3886 3878
     */
3887 3879
    public static boolean isFullyInitialized() {
3888
    	return fullyInitialized;
3880
    	return _fullyInitialized;
3889 3881
    }
3890 3882
}
src/edu/ucsb/nceas/metacat/DBUtil.java
29 29

  
30 30
package edu.ucsb.nceas.metacat;
31 31

  
32
import java.sql.Connection;
33 32
import java.sql.SQLException;
34 33
import java.sql.PreparedStatement;
35 34
import java.sql.ResultSet;
......
38 37
import java.io.InputStream;
39 38
import java.io.IOException;
40 39
import java.net.URL;
41
import java.net.URLConnection;
42 40
import java.net.MalformedURLException;
43 41

  
44 42
import java.util.Enumeration;
45 43
import java.util.Vector;
46
import java.util.Stack;
47 44

  
48 45
import org.apache.log4j.Logger;
49 46

  
......
55 52
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
56 53

  
57 54
/**
58
 * A suite of utility classes for quering DB
55
 * A suite of utility classes for querying DB
59 56
 */
60 57
public class DBUtil {
61 58

  
......
75 72
     if (args.length < 1)
76 73
     {
77 74
        System.err.println("Wrong number of arguments!!!");
78
        System.err.println(
79
        "USAGE: java DBUtil <-dt | -ds [doctype] | -dl user>");
75
        System.err.println("USAGE: java DBUtil <-dt | -ds [doctype] | -dl user>");
80 76
        return;
81 77
     } else {
82 78
        try {
......
126 122
  public String readDoctypes()
127 123
        throws SQLException  {
128 124

  
129
    Vector doctypeList = new Vector();
125
    Vector<String> doctypeList = new Vector<String>();
130 126
    DBConnection dbConn = null;
131 127
    int serialNumber = -1;
132 128
    PreparedStatement pstmt = null;
......
150 146
      pstmt.close();
151 147

  
152 148
    } catch (SQLException e) {
153
      throw new SQLException("DBUtil.readDoctypes(). " + e.getMessage());
149
      throw new SQLException("DBUtil.readDoctypes - SQL error: " + e.getMessage());
154 150
    }
155 151
    finally
156 152
    {
......
200 196
        	systemID = SystemUtil.getContextURL() + systemID;
201 197
        }
202 198
      } else {
203
        throw new SQLException("Non-registered doctype: " + doctype);
199
        throw new SQLException("DBUtil.readDTDSchema - Non-registered doctype: " + doctype);
204 200
      }
205 201
      pstmt.close();
206 202

  
207 203
    } catch (SQLException e) {
208
      throw new SQLException("DBUtil.readDTD(). " + e.getMessage());
204
      throw new SQLException("DBUtil.readDTDSchema - " + e.getMessage());
209 205
    }
210 206
    finally
211 207
    {
......
238 234
	    in.close();
239 235
	    
240 236
    } catch (MalformedURLException e) {
241
      throw new MalformedURLException
242
      ("DBUtil.readDTD(). " + e.getMessage());
237
    	throw new MalformedURLException("DBUtil.readDTDSchema - Malformed URL Error: " + e.getMessage());
243 238
    } catch (IOException e) {
244
      throw new IOException
245
      ("DBUtil.readDTD(). " + e.getMessage());
239
    	throw new IOException("DBUtil.readDTDSchema - I/O error: " + e.getMessage());
246 240
    } catch (SecurityException e) {
247
      throw new IOException
248
      ("DBUtil.readDTD(). " + e.getMessage());
241
    	throw new IOException("DBUtil.readDTDSchema - Security error: " + e.getMessage());
249 242
    }
250 243
    
251 244
   return cbuff.toString();
252 245
  }
253 246

  
254
  /**
255
   * format the DataGuide ResultSet to XML
256
   */
257
  private String formatToXML(Vector resultset) {
258
  
259
    String currPath = null;
260
    String currElement = null;
261
    String prevElement = null;
262
    StringBuffer result = new StringBuffer();
263
    Enumeration rs = resultset.elements(); 
264
    Stack st = new Stack();
265
    int i = 0;
247
//  /**
248
//   * format the DataGuide ResultSet to XML
249
//   */
250
//  private String formatToXML(Vector resultset) {
251
//  
252
//    String currPath = null;
253
//    String currElement = null;
254
//    String prevElement = null;
255
//    StringBuffer result = new StringBuffer();
256
//    Enumeration<String> rs = resultset.elements(); 
257
//    Stack st = new Stack();
258
//    int i = 0;
259
//
260
//    result.append("<?xml version=\"1.0\"?>\n");
261
//    result.append("<resultset>\n"); 
262
//    
263
//    while (rs.hasMoreElements()) {
264
//        currPath = (String)rs.nextElement();
265
//        while ( !In(prevElement, currPath) ) {
266
//            currElement = (String)st.pop();
267
//            result.append(pad(" ",i--) + "</" + currElement + ">\n");
268
//            if ( st.empty() ) 
269
//                prevElement = null;
270
//            else    
271
//                prevElement = (String)st.peek();
272
//        }    
273
//        currElement = getElementFromPath(currPath);
274
//        st.push(currElement);
275
//        result.append(pad(" ",++i) + "<" + currElement + ">\n");
276
//        prevElement = currElement;
277
//    }
278
//    while ( !st.empty() ) {
279
//        prevElement = (String)st.pop();
280
//        result.append(pad(" ",i--) + "</" + prevElement + ">\n");
281
//    }    
282
//    result.append("</resultset>\n"); 
283
//
284
//    return result.toString();
285
//  }
266 286

  
267
    result.append("<?xml version=\"1.0\"?>\n");
268
    result.append("<resultset>\n"); 
269
    
270
    while (rs.hasMoreElements()) {
271
        currPath = (String)rs.nextElement();
272
        while ( !In(prevElement, currPath) ) {
273
            currElement = (String)st.pop();
274
            result.append(pad(" ",i--) + "</" + currElement + ">\n");
275
            if ( st.empty() ) 
276
                prevElement = null;
277
            else    
278
                prevElement = (String)st.peek();
279
        }    
280
        currElement = getElementFromPath(currPath);
281
        st.push(currElement);
282
        result.append(pad(" ",++i) + "<" + currElement + ">\n");
283
        prevElement = currElement;
284
    }
285
    while ( !st.empty() ) {
286
        prevElement = (String)st.pop();
287
        result.append(pad(" ",i--) + "</" + prevElement + ">\n");
288
    }    
289
    result.append("</resultset>\n"); 
287
//  /**
288
//   * check if element is in path like /elem1/elem2/elemn3
289
//   */
290
//  private boolean In(String element, String path) {
291
//    
292
//    if ( element == null ) return true;
293
//    return ( path.indexOf(element) != -1 );
294
//  }
295
//
296
//  /**
297
//   * get last element from path like /elem1/elem2/elemn3
298
//   */
299
//  private String getElementFromPath(String path) {
300
//    
301
//    return ( path.substring(path.lastIndexOf("/")+1) );
302
//  }
303
//
304
//  /**
305
//   * repeates the str n-times
306
//   */
307
//  private String pad(String str, int n) {
308
//    
309
//    String result = "";
310
//    for ( int i = 0; i < n; i++ )
311
//        result = result.concat(str);
312
//        
313
//    return result;    
314
//  }
290 315

  
291
    return result.toString();
292
  }
293

  
294 316
  /**
295
   * check if element is in path like /elem1/elem2/elemn3
296
   */
297
  private boolean In(String element, String path) {
298
    
299
    if ( element == null ) return true;
300
    return ( path.indexOf(element) != -1 );
301
  }
302

  
303
  /**
304
   * get last element from path like /elem1/elem2/elemn3
305
   */
306
  private String getElementFromPath(String path) {
307
    
308
    return ( path.substring(path.lastIndexOf("/")+1) );
309
  }
310

  
311
  /**
312
   * repeates the str n-times
313
   */
314
  private String pad(String str, int n) {
315
    
316
    String result = "";
317
    for ( int i = 0; i < n; i++ )
318
        result = result.concat(str);
319
        
320
    return result;    
321
  }
322

  
323
  /**
324 317
   * format the ResultSet to XML
325 318
   */
326
  private String formatToXML(Vector resultset, String tag) {
319
  private String formatToXML(Vector<String> resultset, String tag) {
327 320
  
328 321
    String val = null;
329 322
    StringBuffer result = new StringBuffer();
330
    Enumeration rs = resultset.elements(); 
323
    Enumeration<String> rs = resultset.elements(); 
331 324

  
332 325
    result.append("<?xml version=\"1.0\"?>\n");
333 326
    result.append("<resultset>\n"); 
334 327
    while (rs.hasMoreElements()) {
335
        val = (String)rs.nextElement();
328
        val = rs.nextElement();
336 329
        result.append("   <" + tag + ">" + val + "</" + tag + ">\n");
337 330
    }
338 331
    result.append("</resultset>\n"); 
......
341 334
  }
342 335

  
343 336
  /**
344
   * get the lastest Accession Number from a particular scope
337
   * get the latest Accession Number from a particular scope
345 338
   */
346 339
  public String getMaxDocid(String scope)
347 340
        throws SQLException  {
......
351 344
    try {
352 345
    	PropertyService.getProperty("document.accNumSeparator");
353 346
    } catch (PropertyNotFoundException pnfe) {
354
    	logMetacat.error("could not get property 'accNumSeparator'.  setting to '.': " 
355
    			+ pnfe.getMessage());  	
347
    	logMetacat.error("DBUtil.getMaxDocid - could not get property " + 
348
    			"'accNumSeparator'.  setting to '.': " + pnfe.getMessage());  	
356 349
    }
357 350
    PreparedStatement pstmt = null;
358 351
    DBConnection dbConn = null;
......
427 420
  public boolean idExists(String docid)
428 421
    throws SQLException
429 422
  {
430
    Vector v = getAllDocids(null);
423
    Vector<String> v = getAllDocids(null);
431 424
    for(int i=0; i<v.size(); i++)
432 425
    {
433 426
      String id = (String)v.elementAt(i);
......
442 435
  /**
443 436
   * return all docids with a given doctype
444 437
   */
445
  public Vector getAllDocidsByType(String doctype, boolean includeRevs) throws SQLException {
438
  public Vector<String> getAllDocidsByType(String doctype, boolean includeRevs) throws SQLException {
446 439
		Vector<String> resultVector = new Vector<String>();
447
		String accnum = null;
448 440
		String sep = ".";
449 441
	    try {
450 442
	    	PropertyService.getProperty("document.accNumSeparator");
451 443
	    } catch (PropertyNotFoundException pnfe) {
452
	    	logMetacat.error("could not get property 'accNumSeparator'.  setting to '.': " 
453
	    			+ pnfe.getMessage());  	
444
	    	logMetacat.error("DBUtil.getAllDocidsByType - could not get property " + 
445
	    			"'accNumSeparator'.  setting to '.': " + pnfe.getMessage());  	
454 446
	    }
455 447
		PreparedStatement pstmt = null;
456 448
		DBConnection dbConn = null;
......
510 502
	}
511 503
  
512 504
  /**
513
   * get the lastest Accession Number from a particular scope
505
   * get the latest Accession Number from a particular scope
514 506
   */
515 507
  public Vector<String> getAllDocids(String scope)
516 508
        throws SQLException  {
517 509
    Vector<String> resultVector = new Vector<String>();
518
    String accnum = null;
510
//    String accnum = null;
519 511
    String sep = ".";
520 512
    try {
521 513
    	PropertyService.getProperty("document.accNumSeparator");
......
559 551
      pstmt.execute();
560 552
      ResultSet rs = pstmt.getResultSet();
561 553
      
562
      long max = 0;
554
//      long max = 0;
563 555
      String id = null;
564 556
      String rev = null;
565 557
      while(rs.next()){
......
574 566
      pstmt.close();
575 567

  
576 568
    } catch (SQLException e) {
577
      throw new SQLException("DBUtil.getAllDocids(). " + e.getMessage());
569
      throw new SQLException("DBUtil.getAllDocids - SQL error:  " + e.getMessage());
578 570
    }
579 571
    finally
580 572
    {
......
592 584
  }
593 585
  
594 586
  /**
595
   * To a given docid, found a dataset docid which conatains the the given doicd
587
   * To a given docid, found a dataset docid which contains the the given docid
596 588
   * This will be done by searching xml_relation table
597 589
   * If couldn't find, null will be return
598 590
   * @param givenDocId, the docid which we want to find
......
616 608
      dbConn=DBConnectionPool.
617 609
                  getDBConnection("DBUtil.findDataSetDocIdForGivenDocument");
618 610
      serialNumber=dbConn.getCheckOutSerialNumber();
619
      // Sql command to chose a docid from xm_relation table
611
      // SQL command to chose a docid from xm_relation table
620 612
      sqlCommand = "select docid from xml_relation where object like ? or " 
621 613
                                                    + "subject like ?";
622 614
      // Prepared statement
......
624 616
      // Bind variable
625 617
      pStmt.setString(1, givenDocId);
626 618
      pStmt.setString(2, givenDocId);
627
      // Excute prepared statement
619
      // Execute prepared statement
628 620
      pStmt.execute();
629 621
      // Get result set
630 622
      resultSet = pStmt.getResultSet();
......
645 637
    }//try
646 638
    catch ( SQLException e)
647 639
    {
648
      // Print out excepition
649
      logMetacat.error("Error in DBUil.findDataSEtDocIdForGivenDocument"
650
                                +e.getMessage());
640
      // Print out exception
641
      logMetacat.error("DBUtil.findDataSetDocIdForGivenDocument - " +
642
    		  "SQL error: " + e.getMessage());
651 643
      // return null
652 644
      return dataSetDocId;
653 645
     
......
663 655
      }//try
664 656
      catch ( SQLException e)
665 657
      {
666
        // Print out excepition
667
    	  logMetacat.error("Error in DBUil.findDataSetDocIdForGivenDoc"
668
                                + e.getMessage());
658
        // Print out exception
659
    	  logMetacat.error("DBUtil.findDataSetDocIdForGivenDocument - " +
660
    			  "error closing db resources: "  + e.getMessage());
669 661
     
670 662
      }//catch
671 663
      finally
......
692 684
    PreparedStatement pstmt = null;
693 685
    // String to store a docid without rev
694 686
    String docIdWithoutRevision = null;
695
    // SQL comand
687
    // SQL command
696 688
    String sqlCommand = null;
697
    // Resulst set
689
    // Result set
698 690
    ResultSet rs = null;
699 691
    // String to store the revision
700 692
    String revision = null;
......
703 695
    
704 696
    // Get docid without rev
705 697
    docIdWithoutRevision = DocumentUtil.getDocIdFromString(givenDocId);
706
    // SQL comand is:
698
    // SQL command is:
707 699
    sqlCommand = "select rev, doctype from xml_documents where docid like ?";
708 700
    
709 701
    try
......
715 707
      
716 708
      // Prepare the sql command
717 709
      pstmt = dbConn.prepareStatement(sqlCommand);
718
      // Bin vairable
710
      // Bin variable
719 711
      pstmt.setString(1, docIdWithoutRevision);
720
      // Excute the prepared statement
712
      // Execute the prepared statement
721 713
      pstmt.execute();
722 714
      // Get result set
723 715
      rs = pstmt.getResultSet();
......
731 723
      {
732 724
        // No record, throw a exception
733 725
        throw new 
734
              SQLException("There is not record for given docid:"+givenDocId);
726
              SQLException("DBUtil.getCurrentRevisionAndDocTypeForGivenDocument - " + 
727
            		  "There is no record for given docid: " + givenDocId);
735 728
      }//else
736 729
        
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff