Project

General

Profile

« Previous | Next » 

Revision 4698

Added by daigle over 15 years ago

Renamed MetaCatUtil to MetacatUtil

View differences:

MetaCatServlet.java
78 78
import edu.ucsb.nceas.metacat.service.DatabaseService;
79 79
import edu.ucsb.nceas.metacat.service.PropertyService;
80 80
import edu.ucsb.nceas.metacat.service.ServiceException;
81
import edu.ucsb.nceas.metacat.service.ServiceService;
81 82
import edu.ucsb.nceas.metacat.service.SessionService;
82 83
import edu.ucsb.nceas.metacat.service.SkinPropertyService;
83 84
import edu.ucsb.nceas.metacat.service.XMLSchemaService;
84 85
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester;
85 86
import edu.ucsb.nceas.metacat.spatial.SpatialQuery;
86 87
import edu.ucsb.nceas.metacat.util.AuthUtil;
87
import edu.ucsb.nceas.metacat.util.MetaCatUtil;
88
import edu.ucsb.nceas.metacat.util.MetacatUtil;
88 89
import edu.ucsb.nceas.metacat.util.RequestUtil;
89 90
import edu.ucsb.nceas.metacat.util.SystemUtil;
90 91
import edu.ucsb.nceas.metacat.util.SessionData;
......
163 164
    public static final String NONAMESPACELOCATION = ":noNamespaceSchemaLocation";
164 165
    public static final String EML2KEYWORD = ":eml";
165 166
    public static final String XMLFORMAT = "xml";
166
    private static final String CONFIG_DIR = "WEB-INF";
167 167
    private static final String FALSE = "false";
168 168
    private static final String TRUE  = "true";
169 169
    
......
176 176
            super.init(config);
177 177
            
178 178
            ServletContext context = config.getServletContext();
179
             
179
            
180
            ServiceService serviceService = ServiceService.getInstance(context);
181
            logMetacat.debug("ServiceService singleton created " + serviceService);
182
            
180 183
            // Initialize the properties file
181
            String dirPath = context.getRealPath(CONFIG_DIR);
184
            String dirPath = ServiceService.getRealConfigDir();
182 185
            
183 186
            String LOG_CONFIG_NAME = dirPath + "/log4j.properties";
184 187
            PropertyConfigurator.configureAndWatch(LOG_CONFIG_NAME);
185 188
            
186
            PropertyService propertyService = PropertyService.getInstance(dirPath);
187
            logMetacat.debug("PropertyService singleton created " + propertyService);
189
            // Register preliminary services
190
            ServiceService.registerService("PropertyService", PropertyService.getInstance());
191
            ServiceService.registerService("SkinPropertyService", SkinPropertyService.getInstance());
192
            ServiceService.registerService("SessionService", SessionService.getInstance()); 
188 193
            
189
            SkinPropertyService skinPropertyService = SkinPropertyService.getInstance(context);
190
            logMetacat.debug("PropertyService singleton created " + skinPropertyService);
191
            
192
            SessionService sessionService = SessionService.getInstance();
193
            logMetacat.debug("SessionService singleton created " + sessionService);
194
            
195
            
196 194
    		// Check to see if the user has requested to bypass configuration 
197 195
            // (dev option) and check see if metacat has been configured.
198 196
    		// If both are false then stop the initialization
199
            if (!MetaCatUtil.bypassConfiguration() && !MetaCatUtil.isMetacatConfigured()) {
197
            if (!MetacatUtil.bypassConfiguration() && !MetacatUtil.isMetacatConfigured()) {
200 198
            	return;
201 199
            }  
202 200
            
......
207 205
        		"Service problem while intializing MetaCat Servlet: " + se.getMessage();
208 206
            logMetacat.error(errorMessage);
209 207
            throw new ServletException(errorMessage);
208
        } catch (UtilException ue) {
209
        	String errorMessage = 
210
        		"Utility problem while intializing MetaCat Servlet: " + ue.getMessage();
211
            logMetacat.error(errorMessage);
212
            throw new ServletException(errorMessage);
210 213
        } 
211 214
    }
212 215

  
......
221 224
	public void initSecondHalf(ServletContext context) throws ServletException {
222 225
		Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
223 226

  
224
		try {
225
            DatabaseService databaseService = DatabaseService.getInstance();
226
            logMetacat.debug("DatabaseService singleton created " + databaseService);
227
		try {			
228
			ServiceService.registerService("DatabaseService", DatabaseService.getInstance());
227 229
			
228 230
			// initialize DBConnection pool
229 231
			DBConnectionPool connPool = DBConnectionPool.getInstance();
230 232
			logMetacat.debug("DBConnection pool initialized: " + connPool.toString());
231 233
			
232
			XMLSchemaService xmlService = XMLSchemaService.getInstance();
233
			logMetacat.debug("XMLService initialized: " + xmlService.toString());
234
			ServiceService.registerService("XMLSchemaService", XMLSchemaService.getInstance());
234 235

  
235 236
			// check if eml201 document were corrected or not. if not, correct
236 237
			// eml201 documents.
......
321 322
					+ gpe.getMessage();
322 323
			logMetacat.error(errorMessage);
323 324
			throw new ServletException(errorMessage);
324
		}
325
		} catch (ServiceException se) {
326
			String errorMessage = "Service problem while intializing MetaCat Servlet: "
327
				+ se.getMessage();
328
			logMetacat.error(errorMessage);
329
			throw new ServletException(errorMessage);
330
		} 
325 331
	}
326 332
    
327 333
    /**
......
358 364
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
359 365
        
360 366
        try {
361
        	MetaCatUtil.pathsForIndexing
362
                = MetaCatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
367
        	MetacatUtil.pathsForIndexing
368
                = MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
363 369
        
364
        	MetaCatUtil.pathsForIndexing = 
365
        		MetaCatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
370
        	MetacatUtil.pathsForIndexing = 
371
        		MetacatUtil.getOptionList(PropertyService.getProperty("xml.indexPaths"));
366 372
        }
367 373
        catch (PropertyNotFoundException pnfe) {
368
        	MetaCatUtil.pathsForIndexing = null;
374
        	MetacatUtil.pathsForIndexing = null;
369 375
            logMetacat.error("Could not find index paths.  Setting " 
370
            		+ "MetaCatUtil.pathsForIndexing to null: " + pnfe.getMessage());
376
            		+ "MetacatUtil.pathsForIndexing to null: " + pnfe.getMessage());
371 377
        }
372 378
        
373
        if (MetaCatUtil.pathsForIndexing != null) {
379
        if (MetacatUtil.pathsForIndexing != null) {
374 380
            
375 381
            logMetacat.debug("Indexing paths specified in metacat.properties....");
376 382
            
......
380 386
            PreparedStatement pstmt1 = null;
381 387
            ResultSet rs = null;
382 388
            
383
            for (int i = 0; i < MetaCatUtil.pathsForIndexing.size(); i++) {
389
            for (int i = 0; i < MetacatUtil.pathsForIndexing.size(); i++) {
384 390
                logMetacat.debug("Checking if '"
385
                        + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
391
                        + (String) MetacatUtil.pathsForIndexing.elementAt(i)
386 392
                        + "' is indexed.... ");
387 393
                
388 394
                try {
......
393 399
                    
394 400
                    pstmt = conn.prepareStatement(
395 401
                            "SELECT * FROM xml_path_index " + "WHERE path = ?");
396
                    pstmt.setString(1, (String) MetaCatUtil.pathsForIndexing
402
                    pstmt.setString(1, (String) MetacatUtil.pathsForIndexing
397 403
                            .elementAt(i));
398 404
                    
399 405
                    pstmt.execute();
......
407 413
                        
408 414
                        logMetacat.debug(
409 415
                                "Inserting following path in xml_path_index: "
410
                                + (String)MetaCatUtil.pathsForIndexing
416
                                + (String)MetacatUtil.pathsForIndexing
411 417
                                .elementAt(i));
412
                        if(((String)MetaCatUtil.pathsForIndexing.elementAt(i)).indexOf("@")<0){
418
                        if(((String)MetacatUtil.pathsForIndexing.elementAt(i)).indexOf("@")<0){
413 419
                            pstmt = conn.prepareStatement("SELECT DISTINCT n.docid, "
414 420
                                    + "n.nodedata, n.nodedatanumerical, n.parentnodeid"
415 421
                                    + " FROM xml_nodes n, xml_index i WHERE"
......
422 428
                                    + " i.path = ? and n.nodeid=i.nodeid and"
423 429
                                    + " n.nodetype LIKE 'ATTRIBUTE' order by n.parentnodeid");
424 430
                        }
425
                        pstmt.setString(1, (String) MetaCatUtil.
431
                        pstmt.setString(1, (String) MetacatUtil.
426 432
                                pathsForIndexing.elementAt(i));
427 433
                        pstmt.execute();
428 434
                        rs = pstmt.getResultSet();
......
430 436
                        int count = 0;
431 437
                        logMetacat.debug(
432 438
                                "Executed the select statement for: "
433
                                + (String) MetaCatUtil.pathsForIndexing
439
                                + (String) MetacatUtil.pathsForIndexing
434 440
                                .elementAt(i));
435 441
                        
436 442
                        try {
......
449 455
                                            + " VALUES (?, ?, ?, ?, ?)");
450 456
                                    
451 457
                                    pstmt1.setString(1, docid);
452
                                    pstmt1.setString(2, (String) MetaCatUtil.
458
                                    pstmt1.setString(2, (String) MetacatUtil.
453 459
                                            pathsForIndexing.elementAt(i));
454 460
                                    pstmt1.setString(3, nodedata);
455 461
                                    pstmt1.setFloat(4, nodedatanumerical);
......
473 479
                        
474 480
                        logMetacat.info("Indexed " + count
475 481
                                + " records from xml_nodes for '"
476
                                + (String) MetaCatUtil.pathsForIndexing.elementAt(i)
482
                                + (String) MetacatUtil.pathsForIndexing.elementAt(i)
477 483
                                + "'");
478 484
                        
479 485
                    } else {
......
514 520
		
515 521
		// Each time metacat is called, check to see if metacat has been 
516 522
		// configured. If not then forward to the administration servlet
517
		if (!MetaCatUtil.isMetacatConfigured()) {
523
		if (!MetacatUtil.isMetacatConfigured()) {
518 524
			RequestUtil.forwardRequest(request, response, "/admin?action=configure");
519 525
			return;
520 526
		}
521 527

  
522 528
		// if we get here, metacat is configured.  If we have not completed the 
523
		// second half of the intialization, do so now.  This allows us to initially
529
		// second half of the initialization, do so now.  This allows us to initially
524 530
		// configure metacat without a restart.
525
		// TODO MCD eventually put in more intelligent reinitialization code so we
526
		// can change (some) properties without restarting metacat.
527 531
		if (!fullyInitialized) {
528 532
			initSecondHalf(request.getSession().getServletContext());
529 533
		}
......
846 850
					 * out.println(" Ref: " + u.getRef()); String pquery =
847 851
					 * u.getQuery(); out.println(" Query: " + pquery);
848 852
					 * out.println(" Params: "); if (pquery != null) { Hashtable
849
					 * qparams = MetaCatUtil.parseQuery(u.getQuery()); for
853
					 * qparams = MetacatUtil.parseQuery(u.getQuery()); for
850 854
					 * (Enumeration en = qparams.keys(); en .hasMoreElements();) {
851 855
					 * String pname = (String) en.nextElement(); String pvalue =
852 856
					 * (String) qparams.get(pname); out.println(" " + pname + ": " +
......
864 868
					// TODO MCD this interface is for testing.  It should go through a 
865 869
					// ServiceService class and only work for an admin user.  Move to the
866 870
					// MetacatAdminServlet
867
					XMLSchemaService.getInstance().refresh();
871
					ServiceService.refreshService("XMLSchemaService");
868 872
					return;
869 873
				}else {
870 874
					PrintWriter out = response.getWriter();
......
891 895
			String errorString = "Utility error: " + ue.getMessage();
892 896
			logMetacat.error(errorString);
893 897
			throw new ServletException(errorString);
898
		} catch (ServiceException ue) {
899
			String errorString = "Service error: " + ue.getMessage();
900
			logMetacat.error(errorString);
901
			throw new ServletException(errorString);
894 902
		}
895 903
	}
896 904
    
......
1221 1229
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1222 1230
        logMetacat.warn("Total search time for action 'squery': "
1223 1231
                + (outPutTime - startTime));
1224
        MetaCatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1232
        MetacatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1225 1233
                "-------------------------------------------------------------------------------Total search time for "
1226 1234
                + (outPutTime - startTime));
1227
        MetaCatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1235
        MetacatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1228 1236
    }
1229 1237
    
1230 1238
    /**
......
1250 1258
        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1251 1259
        logMetacat.warn("Total search time for action 'query': "
1252 1260
                + (outPutTime - startTime));
1253
        MetaCatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1261
        MetacatUtil.writeDebugToFile("---------------------------------------------------------------------------------"+
1254 1262
                "-------------------------------------------------------------------------------Total search time is "
1255 1263
                + (outPutTime - startTime));
1256
        MetaCatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1264
        MetacatUtil.writeDebugToDelimiteredFile(" "+ (outPutTime - startTime), true);
1257 1265
        
1258 1266
        //handleSQuery(out, params, response,user, groups, sessionid);
1259 1267
    }
......
1383 1391
                throw new Exception("You didn't specify requested inlinedataid"); }
1384 1392
            
1385 1393
            // check for permission
1386
            docId = MetaCatUtil
1394
            docId = MetacatUtil
1387 1395
                    .getDocIdWithoutRevFromInlineDataID(inlineDataId);
1388 1396
            PermissionController controller = new PermissionController(docId);
1389 1397
            // check top level read permission
......
1398 1406
                    Hashtable<String,String> unReadableInlineDataList =
1399 1407
                            PermissionController.getUnReadableInlineDataIdList(docId,
1400 1408
                            user, groups, false);
1401
                    String inlineDataIdWithoutRev = MetaCatUtil.getInlineDataIdWithoutRev(inlineDataId);
1409
                    String inlineDataIdWithoutRev = MetacatUtil.getInlineDataIdWithoutRev(inlineDataId);
1402 1410
                    if (unReadableInlineDataList.containsValue(inlineDataIdWithoutRev)) {
1403 1411
                        throw new Exception("User " + user
1404 1412
                                + " doesn't have permission " + " to read inlinedata "
......
1457 1465
        }
1458 1466
    }
1459 1467
    
1460
//    /*
1461
//     * Get the nodeid from xml_nodes for the inlinedataid
1462
//     */
1463
//    private long getInlineDataNodeId(String inLineDataId, String docId)
1464
//    throws SQLException {
1465
//        Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
1466
//        long nodeId = 0;
1467
//        String INLINE = "inline";
1468
//        boolean hasRow;
1469
//        PreparedStatement pStmt = null;
1470
//        DBConnection conn = null;
1471
//        int serialNumber = -1;
1472
//        String sql = "SELECT nodeid FROM xml_nodes WHERE docid=? AND nodedata=? "
1473
//                + "AND nodetype='TEXT' AND parentnodeid IN "
1474
//                + "(SELECT nodeid FROM xml_nodes WHERE docid=? AND "
1475
//                + "nodetype='ELEMENT' AND nodename='" + INLINE + "')";
1476
//        
1477
//        try {
1478
//            //check out DBConnection
1479
//            conn = DBConnectionPool
1480
//                    .getDBConnection("AccessControlList.isAllowFirst");
1481
//            serialNumber = conn.getCheckOutSerialNumber();
1482
//            
1483
//            pStmt = conn.prepareStatement(sql);
1484
//            //bind value
1485
//            pStmt.setString(1, docId);//docid
1486
//            pStmt.setString(2, inLineDataId);//inlinedataid
1487
//            pStmt.setString(3, docId);
1488
//            // excute query
1489
//            pStmt.execute();
1490
//            ResultSet rs = pStmt.getResultSet();
1491
//            hasRow = rs.next();
1492
//            // get result
1493
//            if (hasRow) {
1494
//                nodeId = rs.getLong(1);
1495
//            }//if
1496
//            
1497
//        } catch (SQLException e) {
1498
//            throw e;
1499
//        } finally {
1500
//            try {
1501
//                pStmt.close();
1502
//            } finally {
1503
//                DBConnectionPool.returnDBConnection(conn, serialNumber);
1504
//            }
1505
//        }
1506
//        logMetacat.debug("The nodeid for inlinedataid " + inLineDataId
1507
//                + " is: " + nodeId);
1508
//        return nodeId;
1509
//    }
1510
    
1511 1468
    /**
1512 1469
     * Handle the "read" request of metadata/data files from Metacat or any
1513 1470
     * files from Internet; transformed metadata XML document into HTML
......
1566 1523
                try {
1567 1524
                    
1568 1525
                    URL murl = new URL(docs[i]);
1569
                    Hashtable<String,String> murlQueryStr = MetaCatUtil.parseQuery(
1526
                    Hashtable<String,String> murlQueryStr = MetacatUtil.parseQuery(
1570 1527
                            murl.getQuery());
1571 1528
                    // case docid="http://.../?docid=aaa"
1572 1529
                    // or docid="metacat://.../?docid=bbb"
......
2369 2326
                    // Delete from spatial cache if runningSpatialOption
2370 2327
                    if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") ) {
2371 2328
                        SpatialHarvester sh = new SpatialHarvester();
2372
                        sh.addToDeleteQue( MetaCatUtil.getSmartDocId( docid[0] ) );
2329
                        sh.addToDeleteQue( MetacatUtil.getSmartDocId( docid[0] ) );
2373 2330
                        sh.destroy();
2374 2331
                    }
2375 2332
                    
......
2893 2850
                    String fileTempLocation;
2894 2851
                    
2895 2852
                    // the filePart will be clobbered on the next loop, save to disk
2896
                    fileTempLocation = MetaCatUtil.writeTempFile(filePart, fileName);
2853
                    fileTempLocation = MetacatUtil.writeTempFile(filePart, fileName);
2897 2854
                    fileList.put(name, fileTempLocation);
2898 2855
                    fileList.put("filename", fileName);
2899 2856
                    fileList.put("name", fileTempLocation);
......
3064 3021
                    // copy file to desired output location
3065 3022
                    try 
3066 3023
                    {
3067
                        MetaCatUtil.copyFile(tempFileName, newFileName);
3024
                        MetacatUtil.copyFile(tempFileName, newFileName);
3068 3025
                    } 
3069 3026
                    catch (IOException ioe) 
3070 3027
                    {
......
3187 3144
                            if ( fileExists == false ) {
3188 3145
                                // copy file to desired output location
3189 3146
                                try {
3190
                                    MetaCatUtil.copyFile(tempFileName, newFileName);
3147
                                    MetacatUtil.copyFile(tempFileName, newFileName);
3191 3148
                                } catch (IOException ioe) {
3192 3149
                                    logMetacat.error("IO Exception copying file: " +
3193 3150
                                            ioe.getMessage());
......
3344 3301
        Vector<String> packageSet = null;
3345 3302
        try {
3346 3303
        	packageSet = 
3347
        		MetaCatUtil.getOptionList(PropertyService.getProperty("xml.packagedoctypeset"));
3304
        		MetacatUtil.getOptionList(PropertyService.getProperty("xml.packagedoctypeset"));
3348 3305
        } catch (PropertyNotFoundException pnfe) {
3349 3306
        	logMetacat.error("Could not find package doctype set.  Setting to null: " 
3350 3307
        			+ pnfe.getMessage());
......
3464 3421
        int serialNumber = -1;
3465 3422
        
3466 3423
        // get rid of revision if access number has
3467
        docId = MetaCatUtil.getDocIdFromString(accessionNumber);
3424
        docId = MetacatUtil.getDocIdFromString(accessionNumber);
3468 3425
        try {
3469 3426
            //check out DBConnection
3470 3427
            conn = DBConnectionPool

Also available in: Unified diff