1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that implements utility methods for a metadata catalog
|
4
|
* Copyright: 2000 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Matt Jones, Jivka Bojilova
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2009-08-04 14:32:58 -0700 (Tue, 04 Aug 2009) $'
|
10
|
* '$Revision: 5015 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat.util;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
|
31
|
import edu.ucsb.nceas.dbadapter.AbstractDatabase;
|
32
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
33
|
import edu.ucsb.nceas.metacat.properties.SkinPropertyService;
|
34
|
import edu.ucsb.nceas.metacat.service.ServiceService;
|
35
|
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
|
36
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
37
|
import edu.ucsb.nceas.utilities.GeneralPropertyException;
|
38
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
39
|
import edu.ucsb.nceas.utilities.FileUtil;
|
40
|
|
41
|
/**
|
42
|
* A suite of utility classes for the metadata catalog server
|
43
|
*/
|
44
|
public class ConfigurationUtil
|
45
|
{
|
46
|
|
47
|
public static AbstractDatabase dbAdapter;
|
48
|
|
49
|
private static Logger logMetacat = Logger.getLogger(ConfigurationUtil.class);
|
50
|
|
51
|
/**
|
52
|
* Reports whether metacat is fully configured.
|
53
|
*
|
54
|
* @return a boolean that is true if all sections are configured and
|
55
|
* false otherwise
|
56
|
*/
|
57
|
public static boolean isMetacatConfigured() {
|
58
|
boolean metacatConfigured = false;
|
59
|
try {
|
60
|
metacatConfigured = PropertyService.arePropertiesConfigured()
|
61
|
&& AuthUtil.isAuthConfigured()
|
62
|
&& SkinUtil.areSkinsConfigured()
|
63
|
&& DatabaseUtil.isDatabaseConfigured()
|
64
|
&& GeoserverUtil.isGeoserverConfigured()
|
65
|
&& isBackupDirConfigured()
|
66
|
&& DataONEConfigUtil.isDataOneConfigured();
|
67
|
} catch (MetacatUtilException ue) {
|
68
|
logMetacat.error("Could not determine if metacat is configured due to utility exception: "
|
69
|
+ ue.getMessage());
|
70
|
} catch (GeneralPropertyException gpe) {
|
71
|
logMetacat.error("Could not determine if metacat is configured due to property exception: "
|
72
|
+ gpe.getMessage());
|
73
|
}
|
74
|
|
75
|
return metacatConfigured;
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* Check if the application.backupDir property is populated in
|
80
|
* metacat.properties and that it points to a writable directory.
|
81
|
*
|
82
|
* @return false if the application.backupDir property does not point to a
|
83
|
* writable directory.
|
84
|
*/
|
85
|
public static boolean isBackupDirConfigured() throws MetacatUtilException, PropertyNotFoundException {
|
86
|
String backupDir = PropertyService.getProperty("application.backupDir");
|
87
|
if (backupDir == null || backupDir.equals("")) {
|
88
|
return false;
|
89
|
}
|
90
|
if (FileUtil.getFileStatus(backupDir) < FileUtil.EXISTS_READ_WRITABLE) {
|
91
|
return false;
|
92
|
}
|
93
|
return true;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Reports whether the metacat configuration utility should be run. Returns
|
98
|
* false if
|
99
|
* -- dev.runConfiguration=false and
|
100
|
* -- backup properties file exists
|
101
|
* Note that dev.runConfiguration should only be set to false when reinstalling the
|
102
|
* same version of the application in development.
|
103
|
*
|
104
|
* @return a boolean that is false if dev.runConfiguration is false and the
|
105
|
* backup properties file exists.
|
106
|
*/
|
107
|
public static boolean bypassConfiguration() throws MetacatUtilException, ServiceException {
|
108
|
try {
|
109
|
// If the system is not configured to do bypass, return false.
|
110
|
if (!PropertyService.doBypass()) {
|
111
|
return false;
|
112
|
}
|
113
|
|
114
|
// Get the most likely backup files. If these cannot be found, we
|
115
|
// cannot do the configuration bypass.
|
116
|
String ExternalBaseDir = SystemUtil.discoverExternalDir();
|
117
|
if (ExternalBaseDir == null) {
|
118
|
logMetacat.error("bypassConfiguration: Could not find backup directory.");
|
119
|
// could not find backup files ... force the configuration
|
120
|
return false;
|
121
|
}
|
122
|
String realContext = ServiceService.getRealApplicationContext();
|
123
|
PropertyService.setRecommendedExternalDir(ExternalBaseDir);
|
124
|
PropertyService.setProperty("application.backupDir",
|
125
|
ExternalBaseDir + FileUtil.getFS() + "." + realContext);
|
126
|
|
127
|
// Refresh the property service and skin property service. This will pick up
|
128
|
// the backup directory and populate backup properties in caches.
|
129
|
ServiceService.refreshService("PropertyService");
|
130
|
ServiceService.refreshService("SkinPropertyService");
|
131
|
|
132
|
// Call bypassConfiguration to make sure backup properties get persisted
|
133
|
// to active properties for both main and skin properties.
|
134
|
PropertyService.bypassConfiguration();
|
135
|
SkinPropertyService.bypassConfiguration();
|
136
|
|
137
|
return true;
|
138
|
} catch (GeneralPropertyException gpe) {
|
139
|
throw new MetacatUtilException("Property error while discovering backup directory: "
|
140
|
+ gpe.getMessage());
|
141
|
} catch (MetacatUtilException mue) {
|
142
|
throw new MetacatUtilException("Utility error while discovering backup directory: "
|
143
|
+ mue.getMessage());
|
144
|
}
|
145
|
|
146
|
}
|
147
|
|
148
|
}
|