Project

General

Profile

« Previous | Next » 

Revision 4154

Added by daigle over 16 years ago

Add functionality to allow developer to bypass configuration utility

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
179 179
            SessionService sessionService = SessionService.getInstance();
180 180
            logMetacat.debug("SessionService singleton created " + sessionService);
181 181
            
182
            // Check if the servlet was configured, and if not stop the
183
            // initialization and skip to the configuration web form when
184
            // metacat is called
185
            if (!MetaCatUtil.isMetacatConfigured()) {
182
            
183
    		// Check to see if the user has requested to bypass configuration 
184
            // (dev option) and check see if metacat has been configured.
185
    		// If both are false then stop the initialization
186
            if (!MetaCatUtil.bypassConfiguration() && !MetaCatUtil.isMetacatConfigured()) {
186 187
            	return;
187 188
            }       
188 189
            
......
491 492
			SessionService.touchSession(httpSession.getId());
492 493
		}
493 494
		
494
		// Each time metacat is called, see if it has been configured,
495
		// and if not, then forward to the administration servlet
495
		// Each time metacat is called, check to see if metacat has been 
496
		// configured. If not then forward to the administration servlet
496 497
		if (!MetaCatUtil.isMetacatConfigured()) {
497 498
			RequestUtil.forwardRequest(request, response, "/admin?action=configure");
498 499
			return;
src/edu/ucsb/nceas/metacat/service/PropertyService.java
63 63
	private static final String MAIN_CONFIG_NAME = "metacat.properties";
64 64
	private static final String ORG_CONFIG_NAME = "org.properties";
65 65
	
66
	private static boolean bypassAlreadyChecked = false;
67
	
66 68
	private static String mainPropertiesFilePath = null;
67 69
	private static SortedProperties mainProperties = null;
68 70
	
......
256 258
	public static void persistProperties() throws GeneralPropertyException {
257 259
		mainProperties.store();
258 260
	}
259

  
261
	
260 262
	/**
261 263
	 * Get the main backup properties file. These are configurable properties that
262 264
	 * are stored outside the metacat install directories so the user does not
......
421 423
	}
422 424
	
423 425
	/**
426
	 * Reports whether the metacat configuration utility should be run.  
427
	 * Returns false if  
428
	 *   -- dev.runConfiguration=false and
429
	 *   -- backup properties file exists
430
	 * Note that dev.runConfiguration should only be set to false when
431
	 * reinstalling the same version of the application in developement.
432
	 * 
433
	 * @return a boolean that is false if dev.runConfiguration is false and 
434
	 * the backup properties file exists.  
435
	 */
436
	public static boolean bypassConfiguration() {
437
		boolean bypass = false;
438
		
439
		// We only want to go through the check once to see if we want to
440
		// bypass the configuration.  We don't want to run through all of
441
		// this every time  we hit metacat. 
442
		if (bypassAlreadyChecked) {
443
			return bypass;
444
		}
445
		
446
		try {
447
			// check how dev.runConfiguration is set in metacat.properties
448
			String strRunConfiguration = PropertyService.getProperty("dev.runConfiguration");
449
			bypass = !(Boolean.parseBoolean(strRunConfiguration));
450
			
451
			// if the deb.runConfiguration is true, return false here.
452
			if (!bypass) {
453
				bypassAlreadyChecked = true;
454
				return false;
455
			}
456

  
457
			// The system is bypassing the configuration utility. We need to
458
			// get the backup properties and replace existing properties with
459
			// backup values.  We do this for main and org properties.		
460
			SortedProperties mainBackupProperties = getMainBackupProperties();
461
			Vector<String> backupPropertyNames = 
462
				mainBackupProperties.getPropertyNames();
463
			for (String backupPropertyName : backupPropertyNames) {
464
				String value = mainBackupProperties.getProperty(backupPropertyName);
465
				setPropertyNoPersist(backupPropertyName, value);
466
			}
467
				
468
			SortedProperties orgBackupProperties = getOrgBackupProperties();
469
			Vector<String> orgBackupPropertyNames = 
470
				orgBackupProperties.getPropertyNames();
471
			for (String orgBackupPropertyName : orgBackupPropertyNames) {
472
				String value = orgBackupProperties.getProperty(orgBackupPropertyName);
473
				setPropertyNoPersist(orgBackupPropertyName, value);
474
			}
475
			
476
			setPropertyNoPersist("configutil.propertiesConfigured", "true");
477
			setPropertyNoPersist("configutil.ldapConfigured", "true");
478
			setPropertyNoPersist("configutil.skinsConfigured", "true");
479
			setPropertyNoPersist("configutil.databaseConfigured", "true");
480
				
481
			persistProperties();
482

  
483
		} catch (PropertyNotFoundException pnfe) {
484
			logMetacat.error("Could not find property: " + pnfe.getMessage());
485
		} catch (GeneralPropertyException gpe) {
486
			logMetacat.error("General property error: " + gpe.getMessage());
487
		}
488

  
489
		bypassAlreadyChecked = true;
490
		return bypass;
491
	}
492
	
493
	/**
424 494
	 * Take input from the user in an HTTP request about an property to be changed
425 495
	 * and update the metacat property file with that new value if it has
426 496
	 * changed from the value that was originally set.
src/edu/ucsb/nceas/metacat/service/SkinPropertyService.java
53 53
	
54 54
	private static SkinPropertyService skinService = null;
55 55
	
56
	private static boolean bypassAlreadyChecked = false;
57
	
56 58
	private static String SKIN_DIR = null;
57 59
	private static String BACKUP_DIR = null;
58 60
	
......
407 409
			SkinPropertyService.setPropertyNoPersist(skinName, propertyName, newValue);
408 410
		}
409 411
	}
412
	
413
	/**
414
	 * Reports whether the metacat configuration utility should be run.  
415
	 * Returns false if  
416
	 *   -- dev.runConfiguration=false and
417
	 *   -- backup properties file exists
418
	 * Note that dev.runConfiguration should only be set to false when
419
	 * reinstalling the same version of the application in developement.
420
	 * 
421
	 * @return a boolean that is false if dev.runConfiguration is false and 
422
	 * the backup properties file exists.  
423
	 */
424
	public static boolean bypassConfiguration() {
425
		boolean bypass = false;
426
		
427
		// We only want to go through the check once to see if we want to
428
		// bypass the configuration.  We don't want to run through all of
429
		// this every time  we hit metacat. 
430
		if (bypassAlreadyChecked) {
431
			return bypass;
432
		}
433
		
434
		try {		
435
			// check how dev.runConfiguration is set in metacat.properties
436
			String strRunConfiguration = PropertyService.getProperty("dev.runConfiguration");
437
			bypass = !(Boolean.parseBoolean(strRunConfiguration));
438
			
439
			// if the deb.runConfiguration is true, return false here.
440
			if (!bypass) {
441
				bypassAlreadyChecked = true;
442
				return false;
443
			}
410 444

  
445
			// the system is bypassing the configuration utility. We need to
446
			// get the backup properties and replace existing properties with
447
			// backup values.  We do this for main and org properties.
448
			for (String skinName : skinNames) {
449
				SortedProperties backupProperties = getBackupProperties(skinName);
450
				Vector<String> backupPropertyNames = 
451
					backupProperties.getPropertyNames();
452
				for (String backupPropertyName : backupPropertyNames) {
453
					String value = backupProperties.getProperty(backupPropertyName);
454
					backupProperties.setPropertyNoPersist(backupPropertyName, value);
455
				}
456
				backupProperties.store();
457
			}
458
		} catch (PropertyNotFoundException pnfe) {
459
			logMetacat.error("Could not find property: " + pnfe.getMessage());
460
		} catch (GeneralPropertyException gpe) {
461
			logMetacat.error("General property error: " + gpe.getMessage());
462
		}
463

  
464
		bypassAlreadyChecked = true;
465
		return bypass;
466
	}
467

  
411 468
}
src/edu/ucsb/nceas/metacat/util/MetaCatUtil.java
47 47
import edu.ucsb.nceas.metacat.DBSAXHandler;
48 48
import edu.ucsb.nceas.metacat.MetaCatServlet;
49 49
import edu.ucsb.nceas.metacat.service.PropertyService;
50
import edu.ucsb.nceas.metacat.service.SkinPropertyService;
50 51
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
52
import edu.ucsb.nceas.utilities.FileUtil;
51 53

  
52 54
/**
53 55
 * A suite of utility classes for the metadata catalog server
......
1000 1002

  
1001 1003
		return metacatConfigured;
1002 1004
	}
1005
		
1006
	/**
1007
	 * Reports whether the metacat configuration utility should be run.  
1008
	 * Returns false if  
1009
	 *   -- dev.runConfiguration=false and
1010
	 *   -- backup properties file exists
1011
	 * Note that dev.runConfiguration should only be set to false when
1012
	 * reinstalling the same version of the application in developement.
1013
	 * 
1014
	 * @return a boolean that is false if dev.runConfiguration is false and 
1015
	 * the backup properties file exists.  
1016
	 */
1017
	public static boolean bypassConfiguration() {
1018
		
1019
		// we use the bypassConfiguration() method in Property service
1020
		// to determine if bypass is necessary.  if it is, we call the 
1021
		// similar method in SkinPropertyService.  Both of these calls
1022
		// make sure backup properties get persisted to active properties.
1023
		boolean bypass = PropertyService.bypassConfiguration();
1024
		if (bypass) {
1025
			SkinPropertyService.bypassConfiguration();
1026
		}
1027
		
1028
		return bypass;
1029
	}
1030
		
1003 1031
}
src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
107 107
						.discoverServerPort(request));
108 108
				PropertyService.setPropertyNoPersist("server.httpSSLPort",
109 109
						SystemUtil.discoverServerSSLPort(request));
110
				// TODO MCD change this to handle deploy dir
110 111
				PropertyService.setPropertyNoPersist("application.tomcatDir",
111 112
						SystemUtil.discoverTomcatDir(request));
112 113

  

Also available in: Unified diff