Project

General

Profile

« Previous | Next » 

Revision 4795

Added by daigle over 15 years ago

Allow for backup properties to be written to context based subdirectory of the external configuration directory. This allow multiple instances of metacat to be run side by side.

View differences:

lib/metacat.properties
31 31
application.knbSiteURL=http://knb.ecoinformatics.org
32 32
application.backupDir=
33 33
application.windowsBackupBaseDir=C:\\Program Files
34
application.linuxBackupBaseDir=/var/metacat
34
application.linuxBackupBaseDir=/var
35 35
application.datafilepath=/var/metacat/data
36 36
application.inlinedatafilepath=/var/metacat/inline-data
37 37
application.documentfilepath=/var/metacat/documents
src/edu/ucsb/nceas/metacat/service/ServiceService.java
27 27
package edu.ucsb.nceas.metacat.service;
28 28

  
29 29
import java.util.Hashtable;
30

  
31 30
import javax.servlet.ServletContext;
32

  
33 31
import org.apache.log4j.Logger;
34 32

  
33
import edu.ucsb.nceas.metacat.util.SystemUtil;
34

  
35 35
public class ServiceService {
36 36
	
37 37
	private static ServiceService serviceService = null;
......
42 42
	private static final String SKIN_DIR = "/style/skins";
43 43
	private static String REAL_SKIN_DIR = "";
44 44
	
45
	private static String REAL_APPLICATION_CONTEXT = null;
46
	
45 47
	private static Logger logMetacat = Logger.getLogger(ServiceService.class);
46 48
	private static Hashtable<String, BaseService> serviceList = new Hashtable<String, BaseService>();
47 49
	
......
51 53
	private ServiceService(ServletContext servletContext) {
52 54
		REAL_CONFIG_DIR = servletContext.getRealPath(CONFIG_DIR);
53 55
		REAL_SKIN_DIR = servletContext.getRealPath(SKIN_DIR);
56
		
57
		REAL_APPLICATION_CONTEXT = SystemUtil.discoverApplicationContext(servletContext);
54 58
	}
55 59
	
56 60
	/**
......
125 129
		return REAL_SKIN_DIR;
126 130
	}
127 131
	
132
	/**
133
	 * Get the servlet context name
134
	 * @return a string holding the context name
135
	 */
136
	public static String getRealApplicationContext() throws ServiceException {
137
		if (REAL_APPLICATION_CONTEXT == null) {
138
			throw new ServiceException("Application context name is null");
139
		}
140
		return REAL_APPLICATION_CONTEXT;
141
	}
142
	
128 143
}
src/edu/ucsb/nceas/metacat/service/PropertyService.java
64 64
	
65 65
	private static boolean bypassAlreadyChecked = false;
66 66
	
67
	private static String recommendedExternalDir = null;
68
	
67 69
	private static String mainPropertiesFilePath = null;
68 70
	private static SortedProperties mainProperties = null;
69 71
	
......
90 92
	 * @param servletContext the context we will use to get relative paths
91 93
	 */
92 94
	private PropertyService() throws ServiceException {
93
		try {
94
			initialize();
95
		} catch (GeneralPropertyException gpe) {
96
			throw new ServiceException("Properties problem while initializing " + 
97
					"PropertyService: " + gpe.getMessage());
98
		} catch (IOException ioe) {
99
			throw new ServiceException("I/O Problem while initializing " + 
100
					"PropertyService: " + ioe.getMessage());
101
		}
95
		initialize();		
102 96
	}
103 97
	
104 98
	/**
......
137 131
	}
138 132
	
139 133
	protected void doRefresh() throws ServiceException {
140
		try {
141
			initialize();
142
		} catch (IOException ioe) {
143
			throw new ServiceException("Could not refresh SkinPropertyService due to"
144
					+ " I/O error: " + ioe.getMessage());
145
		} catch (GeneralPropertyException gpe) {
146
			throw new ServiceException("Could not refresh SkinPropertyService due to"
147
					+ " property error: " + gpe.getMessage());
148
		}
134
		initialize();
149 135
	}
150 136
	
151 137
	/**
......
153 139
	 * 
154 140
	 * @param servletContext the context we will use to get relative paths
155 141
	 */
156
	private void initialize()
157
			throws IOException, GeneralPropertyException, ServiceException {
142
	private void initialize() throws ServiceException {
158 143
		
159 144
		logMetacat.debug("Initializing PropertyService");
160 145
		
......
164 149
		} else {
165 150
			configDir = ServiceService.getRealConfigDir();
166 151
		}
152
		
153
		try {
154
			// mainProperties will hold the primary configuration values for
155
			// metacat.
156
			mainPropertiesFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME;
157
			mainProperties = new SortedProperties(mainPropertiesFilePath);
158
			mainProperties.load();
167 159

  
168
		// mainProperties will hold the primary configuration values for metacat.
169
		mainPropertiesFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME;
170
		mainProperties = new SortedProperties(mainPropertiesFilePath);
171
		mainProperties.load();
172

  
173
		try {
174
			// mainMetaData holds configuration information about main properties.
175
			// This is primarily used to display input fields on the configuration
176
			// page. The information is retrieved from an xml metadata file
177
			propertiesMetaDataFilePath = configDir + FileUtil.getFS() + MAIN_CONFIG_NAME + ".metadata.xml";
160
			// mainMetaData holds configuration information about main
161
			// properties. This is primarily used to display input fields on 
162
			// the configuration page. The information is retrieved from an 
163
			// xml metadata file
164
			propertiesMetaDataFilePath = 
165
				configDir + FileUtil.getFS() + MAIN_CONFIG_NAME + ".metadata.xml";
178 166
			mainMetaData = new PropertiesMetaData(propertiesMetaDataFilePath);
179 167

  
180
			// authMetaData holds configuration information about organization level 
181
			// properties.  This is primarily used to display input fields on 
182
			// the auth configuration page. The information is retrieved 
168
			// authMetaData holds configuration information about organization
169
			// level
170
			// properties. This is primarily used to display input fields on
171
			// the auth configuration page. The information is retrieved
183 172
			// from an xml metadata file dedicated just to auth properties.
184
			authMetaDataFilePath = configDir + FileUtil.getFS() + AUTH_CONFIG_NAME + ".metadata.xml";
173
			authMetaDataFilePath = 
174
				configDir + FileUtil.getFS() + AUTH_CONFIG_NAME + ".metadata.xml";
185 175
			authMetaData = new PropertiesMetaData(authMetaDataFilePath);
186
		} catch (TransformerException te) {
187
			throw new GeneralPropertyException(te.getMessage());
188
		}
189
		
190
		String backupBasePath = getProperty("application.backupDir");
191
		
192
		// If the backupBasePath does not exist in metacat.properties, see if we can discover it.
193
		if (backupBasePath == null || backupBasePath.equals("")) {
194
			backupBasePath = SystemUtil.discoverExternalBaseDir();
195
		}
196 176

  
197
		// if backupBasePath is still null, no reason to initialize the backup properties. The
198
		// system will need to prompt the user for the backup properties and reinitialize 
199
		// PropertyService.
200
		if (backupBasePath != null && !backupBasePath.equals("")) {
201
			setProperty("application.backupDir", backupBasePath);
177
			String recommendedExternalDir = SystemUtil.discoverExternalDir();
178
			setRecommendedExternalDir(recommendedExternalDir);
202 179
			
203
			String backupDirPath = backupBasePath + FileUtil.getFS() + ".metacat";
180
			String backupPath = getProperty("application.backupDir");
181
			
182
			if ((backupPath == null || backupPath.equals("")) && recommendedExternalDir != null) {
183
				String realApplicationContext = 
184
					ServiceService.getRealApplicationContext();
185
				backupPath = 
186
					recommendedExternalDir + FileUtil.getFS() + "." + realApplicationContext;
187
			}
204 188

  
205
			// The mainBackupProperties hold properties that were backed up the
206
			// last time the application was configured. On disk, the file will
207
			// look like a smaller version of metacat.properties. It is stored
208
			// in the data storage directory outside the application
209
			// directories.
210
			mainBackupPropertiesFilePath = 
211
				backupDirPath + FileUtil.getFS() + MAIN_CONFIG_NAME + ".backup";
212
			mainBackupProperties = new SortedProperties(mainBackupPropertiesFilePath);
213
			mainBackupProperties.load();
189
			// if backupPath is still null, no reason to initialize the
190
			// backup properties. The system will need to prompt the user for 
191
			// the backup properties and reinitialize PropertyService.
192
			if (backupPath != null && !backupPath.equals("")) {
193
				
194
				setProperty("application.backupDir", backupPath);
214 195

  
215
			// The authBackupProperties hold properties that were backed up the
216
			// last time the auth was configured. On disk, the file will
217
			// look like a smaller version of metacat.properties. It is stored
218
			// in the data storage directory outside the application
219
			// directories.
220
			authBackupPropertiesFilePath = 
221
				backupDirPath + FileUtil.getFS() + AUTH_CONFIG_NAME + ".backup";
222
			authBackupProperties = new SortedProperties(authBackupPropertiesFilePath);
223
			authBackupProperties.load();
224
		}
196
				// The mainBackupProperties hold properties that were backed up
197
				// the last time the application was configured. On disk, the 
198
				// file will look like a smaller version of metacat.properties. 
199
				// It is stored in the data storage directory outside the 
200
				// application directories.
201
				mainBackupPropertiesFilePath =
202
					backupPath + FileUtil.getFS() + MAIN_CONFIG_NAME + ".backup";
203
				mainBackupProperties = new SortedProperties(mainBackupPropertiesFilePath);
204
				mainBackupProperties.load();
205

  
206
				// The authBackupProperties hold properties that were backed up
207
				// the last time the auth was configured. On disk, the file 
208
				// will look like a smaller version of metacat.properties. It 
209
				// is stored in the data storage directory outside the 
210
				// application directories.
211
				authBackupPropertiesFilePath = 
212
					backupPath + FileUtil.getFS() + AUTH_CONFIG_NAME + ".backup";
213
				authBackupProperties = new SortedProperties(authBackupPropertiesFilePath);
214
				authBackupProperties.load();
215
			}
216
		} catch (TransformerException te) {
217
			throw new ServiceException("Transform problem while loading properties: "
218
					+ te.getMessage());
219
		} catch (IOException ioe) {
220
			throw new ServiceException("I/O problem while loading properties: "
221
					+ ioe.getMessage());
222
		} catch (GeneralPropertyException gpe) {
223
			throw new ServiceException("General properties problem while loading properties: "
224
					+ gpe.getMessage());
225
		} catch (UtilException ue) {
226
			throw new ServiceException("Utilities problem while loading properties: "
227
					+ ue.getMessage());
228
		} 
225 229
	}
226 230

  
227 231
	/**
......
562 566
			PropertyService.setPropertyNoPersist(propertyName, newValue.trim());
563 567
		}
564 568
	}
569
	
570
	/**
571
	 * Sets the recommended external directory.  This is populated during initialization 
572
	 * time using the SystemUtil.discoverExternalDir() method.  This directory will be used to
573
	 * suggest external user directories when the user configures metacat for the first time.
574
	 * 
575
	 */
576
	public static void setRecommendedExternalDir(String extBaseDir) {
577
		recommendedExternalDir = extBaseDir;
578
	}
579
	
580
	/**
581
	 * Returns the recommended external base directory.  This is populated during initialization 
582
	 * time using the SystemUtil.discoverExternalBaseDir() method.  This directory will be used to
583
	 * suggest external user directories when the user configures metacat for the first time.
584
	 * 
585
	 * @return a String holding the recommended external directory
586
	 */
587
	public static String getRecommendedExternalDir() {
588
		return recommendedExternalDir;
589
	}
565 590

  
566 591
}
src/edu/ucsb/nceas/metacat/service/SkinPropertyService.java
127 127

  
128 128
		logMetacat.debug("Initializing SkinService");
129 129

  
130
		BACKUP_DIR = PropertyService.getProperty("application.backupDir")
131
				+ FileUtil.getFS() + ".metacat";
130
		BACKUP_DIR = PropertyService.getProperty("application.backupDir");
132 131

  
133 132
		skinNames = SkinUtil.getSkinNames();
134 133

  
src/edu/ucsb/nceas/metacat/util/SystemUtil.java
36 36

  
37 37
import edu.ucsb.nceas.metacat.MetaCatVersion;
38 38
import edu.ucsb.nceas.metacat.service.PropertyService;
39
import edu.ucsb.nceas.metacat.service.ServiceException;
40
import edu.ucsb.nceas.metacat.service.ServiceService;
39 41
import edu.ucsb.nceas.utilities.FileUtil;
40 42
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
41 43

  
......
282 284
	 * has been populated in metacat.properties. You should always use
283 285
	 * getApplicationContext() instead of this method if possible.
284 286
	 * 
285
	 * @param request
286
	 *            the http servlet request we will use to find the context
287
	 * @param servletContext
288
	 *            the servlet context we will use to find the application context
287 289
	 * 
288 290
	 * @return a string holding the context
289 291
	 */
290
	public static String discoverApplicationContext(HttpServletRequest request) {
291
		String contextPath = request.getContextPath();
292
	public static String discoverApplicationContext(ServletContext servletContext) {
293
		String applicationContext = "";
294
		String realPath = servletContext.getRealPath("/");
292 295

  
293
		if (contextPath.charAt(0) == '/') {
294
			contextPath = contextPath.substring(1);
296
		if (realPath.charAt(realPath.length() - 1) == '/') {
297
			realPath = realPath.substring(0, realPath.length() - 1);
295 298
		}
296
		logMetacat.debug("contextPath: " + contextPath);
299
		
300
		int lastSlashIndex = realPath.lastIndexOf('/');
301
		if (lastSlashIndex != -1) {
302
			applicationContext = realPath.substring(lastSlashIndex + 1);
303
		}
304
				
305
		logMetacat.debug("application context: " + applicationContext);
297 306

  
298
		return contextPath;
307
		return applicationContext;
299 308
	}
300 309
	
301 310
	/**
......
307 316
	 * the directory:
308 317
	 * 
309 318
	 * -- 1) Look for a saved backup location file in the user home dir - Is there a file named 
310
	 *       <user_home>/.metacat/backup-location for the user that started tomcat? if so, does 
311
	 *       it contain a single line which is a readable directory?  This directory was the backup 
312
	 *       directory used during a previous install.  Return that directory.
313
	 * -- 2) Look for an existing hidden (.metacat) directory in a default system directory.  Get 
319
	 *       <user_home>/metacat/.<application_context>/backup-location for the user that started 
320
	 *       tomcat? if so, does it contain a single line which is a readable directory?  This 
321
	 *       directory was the backup directory used during a previous install.  Return that directory.
322
	 * -- 2) Otherwise, look for an existing hidden (.<application_context>) directory in a default system directory.  Get 
314 323
	 *       the default base directory for the OS.  (See application.windowsBackupBaseDir and 
315 324
	 *       application.linuxBackupBaseDir in metacat.properties.)  If a directory called 
316
	 *       <base_dir>/metacat/.metacat exists, return <base_dir>/metacat.
317
	 * -- 3) Look for an existing hidden (.metacat) directory in the user directory. If a directory 
318
	 *       called <user_dir>/.metacat exists for the user that started tomcat, return <user_dir>.
319
	 * -- 4) Is the <base_dir> writable by the user that started tomcat?  If so, return <base_dir>
320
	 * -- 5) Does the <user_home> exist?  If so, return <user_home>
321
	 * -- 6) Otherwise, return null
325
	 *       <base_dir>/metacat/.<application_context> exists, return <base_dir>/metacat.
326
	 * -- 3) Otherwise, look for an existing hidden (.metacat) directory in the user directory. If a directory 
327
	 *       called <user_dir>/metacat/.<application_context> exists for the user that started tomcat, 
328
	 *       return <user_dir>/metacat.
329
	 * -- 4) Otherwise, look for an existing metacat directory in a default system directory.  Get 
330
	 *       the default base directory for the OS.  (See application.windowsBackupBaseDir and 
331
	 *       application.linuxBackupBaseDir in metacat.properties.)  If a directory called 
332
	 *       <base_dir>/metacat exists, return <base_dir>/metacat.
333
	 * -- 5) Otherwise, look for an existing metacat directory in the user directory. If a directory 
334
	 *       called <user_dir>/metacat/ exists for the user that started tomcat, return <user_dir>/metacat.
335
	 * -- 6) Otherwise, is the <base_dir> writable by the user that started tomcat?  If so, return 
336
	 *       <base_dir>/metacat
337
	 * -- 7) Does the <user_home> exist?  If so, return <user_home>/metacat
338
	 * -- 8) Otherwise, return null
322 339
	 *    
323 340
	 * @return a string holding the backup directory path
324 341
	 */
325
	public static String discoverExternalBaseDir() throws PropertyNotFoundException {
326
		String userHomeDir = getUserHomeDir();
327
		String defaultBaseDir = "";
342
	public static String discoverExternalDir() throws UtilException {
343
		String applicationContext = null; 
328 344
		
329 345
		try {
330
			// Check if there is a file at <user_home>/.metacat/backup-location.  If so, it
346
			applicationContext = ServiceService.getRealApplicationContext();
347
			// Check if there is a file at <user_home>/<application_context>/backup-location.  If so, it
331 348
			// should contain one line that is a file that points to a writable directory. 
332 349
			// If that is true, use that value as the external dir.
333
			String storedBackupFileLoc = getUserHomeDir() + FileUtil.getFS() + ".metacat"
350
			String storedBackupFileLoc = getUserHomeDir() + FileUtil.getFS() + "." + applicationContext
334 351
					+ FileUtil.getFS() + "backup-location";
335 352
			if (FileUtil.getFileStatus(storedBackupFileLoc) >= FileUtil.EXISTS_READABLE) {
336 353
				String storedBackupDirLoc = FileUtil.readFileToString(storedBackupFileLoc);
......
339 356
					return storedBackupDirLoc;
340 357
				}
341 358
			}
359
			
360
			// Set the default location using the os
361
			String systemDir = "";
362
			if (getOsClass() == WIN_OS) {
363
				systemDir = PropertyService.getProperty("application.windowsBackupBaseDir");
364
			} else {
365
				systemDir = PropertyService.getProperty("application.linuxBackupBaseDir");
366
			}	
367
			String systemMetacatDir = systemDir + FileUtil.getFS() + "metacat";
368
			String systemBackupDir = systemMetacatDir + FileUtil.getFS() + "."
369
					+ applicationContext;
370

  
371
			String userHomeDir = getUserHomeDir();
372
			String userHomeMetacatDir = userHomeDir + FileUtil.getFS() + "metacat";
373
			String userHomeBackupDir = userHomeMetacatDir + FileUtil.getFS() + "." + applicationContext;
374

  
375
			// If <system_dir>/metacat/.<application_context> exists writable, 
376
			// return <system_dir>/metacat
377
			if ((FileUtil.getFileStatus(systemBackupDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
378
				return systemMetacatDir;
379
			}
380

  
381
			// Otherwise if <user_dir>/metacat/.<application_context> exists writable, return
382
			// <user_dir>/metacat
383
			if ((FileUtil.getFileStatus(userHomeBackupDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
384
				return userHomeMetacatDir;
385
			}
386

  
387
			// Otherwise if <system_dir>/metacat exists writable, create 
388
			// <system_dir>/metacat/.<application_context> and return <system_dir>/metacat
389
			if ((FileUtil.getFileStatus(systemMetacatDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
390
				// go ahead and create the backup hidden dir
391
				FileUtil.createDirectory(systemBackupDir);
392
				return systemMetacatDir;
393
			}
394

  
395
			// Otherwise if <user_dir>/metacat exists writable, create 
396
			// <user_dir>/metacat/.<application_context> and return <user_dir>/metacat
397
			if ((FileUtil.getFileStatus(userHomeMetacatDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
398
				// go ahead and create the backup hidden dir
399
				FileUtil.createDirectory(userHomeBackupDir);
400
				return userHomeMetacatDir;
401
			}
402
			
403
			// Otherwise if <system_dir> exists, create 
404
			// <system_dir>/metacat/.<application_context> and return <system_dir>/metacat
405
			if ((FileUtil.getFileStatus(systemDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
406
				// go ahead and create the backup hidden dir
407
				FileUtil.createDirectory(systemBackupDir);
408
				return systemMetacatDir;
409
			}
410

  
411
			// Otherwise if <user_dir> exists, return <user_dir> create 
412
			// <user_dir>/metacat/.<application_context> and return <user_dir>/metacat
413
			if ((FileUtil.getFileStatus(userHomeDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
414
				// go ahead and create the backup hidden dir
415
				FileUtil.createDirectory(userHomeBackupDir);
416
				return userHomeMetacatDir;
417
			}
418

  
342 419
		} catch (IOException ioe) {
343
			logMetacat.warn("Could not read stored backup location: " + ioe.getMessage());
420
			logMetacat.warn("I/O proplem finding backup location: " + ioe.getMessage());
421
		} catch (ServiceException se) {
422
			logMetacat.warn("Could not get real application context: " + se.getMessage());
423
		} catch (PropertyNotFoundException pnfe) {
424
			logMetacat.warn("Could not get default backup base dir property: "
425
					+ pnfe.getMessage());
344 426
		}
345
		
346
		// Set the default location using the os
347
		if (getOsClass() == WIN_OS) {
348
			defaultBaseDir = PropertyService.getProperty("application.windowsBackupBaseDir");
349
		} else {
350
			defaultBaseDir = PropertyService.getProperty("application.linuxBackupBaseDir");
351
		}
352
		
353
		String defaultBackupDir = defaultBaseDir + FileUtil.getFS() + "metacat";
354
		String defaultBackupHiddenDir = defaultBackupDir + FileUtil.getFS() + ".metacat";
355
		String userHomeBackupHiddenDir = userHomeDir + FileUtil.getFS() + ".metacat";
356
		
357
		// If <base_dir>/metacat/.metacat exists, return <base_dir>
358
		if ((FileUtil.getFileStatus(defaultBackupHiddenDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
359
			return defaultBaseDir;
360
		}
361
		
362
		// Otherwise if <user_dir>/.metacat exists, return <user_dir>
363
		if ((FileUtil.getFileStatus(userHomeBackupHiddenDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
364
			return userHomeDir;
365
		}
366
		
367
		// Otherwise if <base_dir>/metacat exists, return <base_dir>
368
		if ((FileUtil.getFileStatus(defaultBaseDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
369
			return defaultBaseDir;
370
		}
371
		
372
		// Otherwise if <user_dir> exists, return <user_dir>
373
		if ((FileUtil.getFileStatus(userHomeDir) >= FileUtil.EXISTS_READ_WRITABLE)) {
374
			return userHomeDir;
375
		}
376 427
	
377 428
		// Otherwise, return userHomeDir
378 429
		return null;
......
380 431
	
381 432
	/**
382 433
	 * Store the location of the backup file location into a file at 
383
	 * <user_home>/.metacat/backup-location
434
	 * <user_home>/<application_dir>/backup-location
384 435
	 * 
385 436
	 * @param externalDir the backup file location.
386 437
	 */
387 438
	public static void storeExternalDirLocation(String externalDir) {
388 439
		if (getUserHomeDir() != null) {
389
			String storedBackupLocDir = getUserHomeDir() + FileUtil.getFS() + ".metacat";
390
			String storedBackupLocFile = storedBackupLocDir + FileUtil.getFS() + "backup-location";
440
			String applicationContext = null;
441
			String storedBackupLocDir = null;
442
			String storedBackupLocFile = null;
391 443
			try {
444
				applicationContext = ServiceService.getRealApplicationContext();
445
				storedBackupLocDir = getUserHomeDir() + FileUtil.getFS() + "."
446
						+ applicationContext;
447
				storedBackupLocFile = storedBackupLocDir + FileUtil.getFS()
448
						+ "backup-location";
449
			
392 450
				FileUtil.createDirectory(storedBackupLocDir);
393 451
				FileUtil.writeFile(storedBackupLocFile, externalDir);
394 452
			} catch (IOException ioe) {
395 453
				logMetacat.error("I/O error while trying to write stored backup directory: "
396
								+ storedBackupLocFile + " : " + ioe.getMessage());
454
							+ storedBackupLocFile + " : " + ioe.getMessage());
455
			} catch (ServiceException se) {
456
				logMetacat.error("Could not get real application directory while trying to write "
457
							+ "stored backup directory: "+ storedBackupLocFile + " : " + se.getMessage());
397 458
			}
398 459
		} else {
399 460
			logMetacat.warn("Could not write out stored backup directory." 
src/edu/ucsb/nceas/metacat/util/MetacatUtil.java
42 42

  
43 43
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
44 44
import edu.ucsb.nceas.metacat.DBSAXHandler;
45
import edu.ucsb.nceas.metacat.MetaCatServlet;
46 45
import edu.ucsb.nceas.metacat.NodeRecord;
47 46
import edu.ucsb.nceas.metacat.service.PropertyService;
48 47
import edu.ucsb.nceas.metacat.service.ServiceException;
......
60 59

  
61 60
    public static AbstractDatabase dbAdapter;
62 61

  
63
    public static Vector pathsForIndexing;
62
    public static Vector<String> pathsForIndexing;
64 63
    
65
    private static boolean debug = true;
66
    
67 64
    private static boolean debugErrorDisplayed = false;
68 65
    
69 66
    private static Logger logMetacat = Logger.getLogger(MetacatUtil.class);
......
946 943
	 * @return false if the application.backupDir property does not point to a
947 944
	 *         writable directory.
948 945
	 */
949
	public static boolean isBackupDirConfigured() throws PropertyNotFoundException {
946
	public static boolean isBackupDirConfigured() throws UtilException, PropertyNotFoundException {
950 947
		String backupDir = PropertyService.getProperty("application.backupDir");
951
		if (backupDir == null) {
948
		if (backupDir == null || backupDir.equals("")) {
952 949
			return false;
953 950
		}		
954 951
		if (FileUtil.getFileStatus(backupDir) < FileUtil.EXISTS_READ_WRITABLE) {
955 952
			return false;
956
		}
957
		
953
		}	
958 954
		return true;
959 955
	}
960 956
		
......
978 974

  
979 975
			// Get the most likely backup files.  If these cannot be found, we 
980 976
			// cannot do the configuration bypass.
981
			String backupDir = SystemUtil.discoverExternalBaseDir();
982
			if (backupDir == null) {
977
			String ExternalBaseDir = SystemUtil.discoverExternalDir();
978
			if (ExternalBaseDir == null) {
983 979
				logMetacat.error("bypassConfiguration: Could not find backup directory.");
984 980
				// could not find backup files ... force the configuration
985 981
				return false;
986 982
			}
987
			PropertyService.setProperty("application.backupDir", backupDir);
983
			String realContext = ServiceService.getRealApplicationContext();
984
			PropertyService.setRecommendedExternalDir(ExternalBaseDir);
985
			PropertyService.setProperty("application.backupDir", 
986
					ExternalBaseDir + FileUtil.getFS() + "." + realContext);
988 987

  
989 988
			// Refresh the property service and skin property service.  This will pick up 
990 989
			// the backup directory and populate backup properties in caches.
src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
38 38
import edu.ucsb.nceas.metacat.DBVersion;
39 39
import edu.ucsb.nceas.metacat.MetaCatVersion;
40 40
import edu.ucsb.nceas.metacat.service.PropertyService;
41
import edu.ucsb.nceas.metacat.service.ServiceException;
42
import edu.ucsb.nceas.metacat.service.ServiceService;
41 43
import edu.ucsb.nceas.metacat.util.RequestUtil;
42 44
import edu.ucsb.nceas.metacat.util.SystemUtil;
43 45

  
......
97 99
				PropertiesMetaData metadata = PropertyService.getMainMetaData();
98 100
				request.setAttribute("metadata", metadata);
99 101

  
100
				String externalDir = PropertyService.getProperty("application.backupDir");
102
				String externalDir = PropertyService.getRecommendedExternalDir();
101 103
				
102 104
				if (externalDir == null) {
103
					throw new AdminException("Could not initialize property configuration"
104
									+ "page since application.backupDir was null");
105
					throw new AdminException("Could not initialize property configuration "
106
									+ "page recommended application backup directory was null");
105 107
				}
106 108
				
107 109
				// Attempt to discover the following properties.  These will show
108 110
				// up in the configuration fields if nothing else is provided.
109 111
				PropertyService.setPropertyNoPersist("application.context",
110
						SystemUtil.discoverApplicationContext(request));
112
						ServiceService.getRealApplicationContext());
111 113
				PropertyService.setPropertyNoPersist("server.name", SystemUtil
112 114
						.discoverServerName(request));
113 115
				PropertyService.setPropertyNoPersist("server.httpPort", SystemUtil
......
162 164
			} catch (IOException ioe) {
163 165
				throw new AdminException("IO problem while initializing "
164 166
						+ "system properties page:" + ioe.getMessage());
167
			} catch (ServiceException se) {
168
				throw new AdminException("Service problem while initializing "
169
						+ "system properties page:" + se.getMessage());
165 170
			} catch (ServletException se) {
166 171
				throw new AdminException("problem forwarding request while " 
167 172
						+ "initializing system properties page: " + se.getMessage());
src/edu/ucsb/nceas/metacat/admin/BackupAdmin.java
40 40
import edu.ucsb.nceas.metacat.service.ServiceService;
41 41
import edu.ucsb.nceas.metacat.util.RequestUtil;
42 42
import edu.ucsb.nceas.metacat.util.SystemUtil;
43
import edu.ucsb.nceas.metacat.util.UtilException;
43 44
import edu.ucsb.nceas.utilities.FileUtil;
44
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
45 45
import edu.ucsb.nceas.utilities.GeneralPropertyException;
46 46

  
47 47
/**
......
98 98
			// the web form for configuring metacat
99 99
			
100 100
			try {
101
				String backupBaseDir = SystemUtil.discoverExternalBaseDir();
101
				String backupBaseDir = SystemUtil.discoverExternalDir();
102 102
				logMetacat.debug("Backup dir discovered as: " + backupBaseDir);
103 103
				String backupDirStatus = getBackupDirStatus(backupBaseDir);
104 104
				logMetacat.debug("Status of discovered backup dir: " + backupDirStatus);
......
119 119
			} catch (ServletException se) {
120 120
				throw new AdminException("Problem forwarding request while "
121 121
						+ "initializing backup configuration page: " + se.getMessage());
122
			} catch (PropertyNotFoundException pnfe) {
122
			} catch (UtilException ue) {
123 123
				throw new AdminException("Problem discovering backup directory while "
124
						+ "initializing backup configuration page: " + pnfe.getMessage());
124
						+ "initializing backup configuration page: " + ue.getMessage());
125 125
			}
126 126
		} else {
127 127
			// The configuration form is being submitted and needs to be
......
130 130
			Vector<String> processingErrors = new Vector<String>();
131 131
			Vector<String> validationErrors = new Vector<String>();
132 132
			
133
			String backupDir = request.getParameter("backup-dir");
134
			String hiddenBackupDir = backupDir + FileUtil.getFS() + ".metacat";
135

  
136 133
			// Validate that the options provided are legitimate.
137 134
			validationErrors.addAll(validateOptions(request));
138

  
135
			String backupDir = null;
136
			String realApplicationContext = null;
137
			String hiddenBackupDir = null;
138
			
139 139
			if (validationErrors.size() == 0) {
140 140
				try {
141
					backupDir = request.getParameter("backup-dir");
142
					realApplicationContext = ServiceService.getRealApplicationContext();
143
					hiddenBackupDir = 
144
						backupDir + FileUtil.getFS() + "." + realApplicationContext;
145
					
141 146
					FileUtil.createDirectory(hiddenBackupDir);
142 147
					
143 148
					PropertyService.setProperty("application.backupDir", backupDir);
144 149
					ServiceService.refreshService("PropertyService");
150
					PropertyService.setRecommendedExternalDir(backupDir);
151
					
145 152
					ServiceService.refreshService("SkinPropertyService");
146 153
					SystemUtil.storeExternalDirLocation(backupDir);
147 154
				} catch (IOException ue) {

Also available in: Unified diff