Class PropertyService
java.lang.Object
edu.ucsb.nceas.metacat.shared.BaseService
edu.ucsb.nceas.metacat.properties.PropertyService
A suite of utility classes for the metadata configuration utility
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static String
The directory holding properties and other configuration filesstatic final String
static final String
static final String
static final String
Fields inherited from class edu.ucsb.nceas.metacat.shared.BaseService
_serviceName
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Reports whether properties are fully configured, by checking the value of the property "configutil.propertiesConfigured", which is set from the Admin flow.static void
(for dev use only) Bypasses the properties configuration utility by using the backup properties to overwrite the main properties.static void
checkAndSetProperty
(javax.servlet.http.HttpServletRequest request, String propertyName) Deprecated.static boolean
doBypass()
Determine if the system is able to bypass configuration.void
static edu.ucsb.nceas.utilities.SortedProperties
Get the auth backup properties file.static edu.ucsb.nceas.utilities.PropertiesMetaData
Get the auth properties metadata.static Path
Get the path to the directory where the backup properties are stored, and as a side effect, update the properties file to save this path as "application.backupDir"static PropertyService
Get the single instance of PropertyService, only after it has been previously instantiated with a call to one of the other getInstance() methods passing either a reference to the servlet context or the config file pathstatic PropertyService
getInstance
(String testConfigFileDir) Get the single instance of PropertyService for test purposes.static PropertyService
getInstance
(javax.servlet.ServletContext context) Get the single instance of PropertyService.static PropertyService
getInstanceForTesting
(Path testDefaultPropertiesFilePath, Path testSitePropertiesFilePath) Get the single instance of PropertyService for test purposes.static edu.ucsb.nceas.utilities.SortedProperties
Get the main backup properties file.static edu.ucsb.nceas.utilities.PropertiesMetaData
Get the main properties metadata.static Path
Get the path to the main Metadata file, which holds configuration information about main properties.getPropertiesByGroup
(String groupName) Get a Map of all properties that start with the groupName prefix.static String
getProperty
(String propertyName) Get a property value.Get a set of all property names.getPropertyNamesByGroup
(String groupName) Get a Set of all property names that start with the groupName prefix.static String
Returns the recommended external base directory.static void
Writes out configurable properties to a backup file outside the metacat install directory, so they are not lost if metacat installation is overwritten during an upgrade.static void
Writes out configurable properties to a backup file outside the metacat install directory, so they are not lost if metacat installation is overwritten during an upgrade.static void
Save the properties to a properties file on disk.boolean
static void
setProperty
(String propertyName, String newValue) Utility method to set a property value both in memory and to the properties filestatic void
setPropertyNoPersist
(String propertyName, String newValue) Utility method to set a property value in memory.static void
setRecommendedExternalDir
(String extBaseDir) Sets the recommended external directory.void
stop()
static void
The properties on the dataONE Setting class isn't synchronized with changes to the Metacat properties files.Methods inherited from class edu.ucsb.nceas.metacat.shared.BaseService
refresh
-
Field Details
-
CONFIGURED
- See Also:
-
UNCONFIGURED
- See Also:
-
BYPASSED
- See Also:
-
SITE_PROPERTIES_FILENAME
- See Also:
-
SITE_PROPERTIES_DIR_PATH_KEY
- See Also:
-
CONFIG_FILE_DIR
The directory holding properties and other configuration files
-
-
Method Details
-
getInstance
public static PropertyService getInstance(javax.servlet.ServletContext context) throws ServiceException Get the single instance of PropertyService.- Parameters:
context
- a reference to the ServletContext- Returns:
- the single instance of PropertyService
- Throws:
ServiceException
- if initialization of new instance fails
-
getInstance
Get the single instance of PropertyService for test purposes. In this case, we allow the configuration directory to be passed in.- Parameters:
testConfigFileDir
- the test configuration directory we need to look in- Returns:
- the single instance of PropertyService
- Throws:
ServiceException
- if initialization of new instance fails
-
getInstanceForTesting
public static PropertyService getInstanceForTesting(Path testDefaultPropertiesFilePath, Path testSitePropertiesFilePath) throws ServiceException Get the single instance of PropertyService for test purposes. In this case, we allow passing in the paths (relative to the working directory) to both the default properties file (e.g. lib/metacat.properties) and the site-specific (or in this case, the test-specific) properties file (eg test/test.properties) to be overlaid on top of those defaults.- Parameters:
testDefaultPropertiesFilePath
- the path to the default properties file (relative to the working directory)testSitePropertiesFilePath
- the path to the site-specific properties overlay file (relative to the working directory)- Returns:
- the single instance of PropertyService
- Throws:
ServiceException
- if initialization of new instance fails
-
getInstance
Get the single instance of PropertyService, only after it has been previously instantiated with a call to one of the other getInstance() methods passing either a reference to the servlet context or the config file path- Returns:
- the single instance of PropertyService
- Throws:
ServiceException
- if there was an attempt to call getInstance() without parameters, before a PropertyService instance has first been created with either a servlet context or config file path.
-
getProperty
public static String getProperty(String propertyName) throws edu.ucsb.nceas.utilities.PropertyNotFoundException Get a property value. 1. First check if the property has been overridden by an environment variable (override mappings are defined in the properties files as: "application.envSecretKeys") 2. if no environment variable override is found, then return the regular value from the properties files, if it has been set. Otherwise, throw a PropertyNotFoundException- Parameters:
propertyName
- the name of the property requested- Returns:
- the String value for the property, even if blank. Will never return null
- Throws:
edu.ucsb.nceas.utilities.PropertyNotFoundException
- if the passedpropertyName
key is not in the properties at all
-
getPropertyNames
Get a set of all property names.- Returns:
- Vector of property names
-
getPropertyNamesByGroup
Get a Set of all property names that start with the groupName prefix.- Parameters:
groupName
- the prefix of the keys to search for.- Returns:
- enumeration of property names
-
getPropertiesByGroup
public static Map<String,String> getPropertiesByGroup(String groupName) throws edu.ucsb.nceas.utilities.PropertyNotFoundException Get a Map of all properties that start with the groupName prefix.- Parameters:
groupName
- the prefix of the keys to search for.- Returns:
- Map of property names
- Throws:
edu.ucsb.nceas.utilities.PropertyNotFoundException
- if the passedgroupName
key is not in the properties at all
-
setProperty
public static void setProperty(String propertyName, String newValue) throws edu.ucsb.nceas.utilities.GeneralPropertyException Utility method to set a property value both in memory and to the properties file- Parameters:
propertyName
- the name of the property requestednewValue
- the new value for the property- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the required properties
-
setPropertyNoPersist
public static void setPropertyNoPersist(String propertyName, String newValue) throws edu.ucsb.nceas.utilities.GeneralPropertyException Utility method to set a property value in memory. This will NOT cause the property to be written to disk. Use this method to set multiple properties in a row without causing excessive I/O. You must call persistProperties() once you're done setting properties to have them written to disk.- Parameters:
propertyName
- the name of the property requestednewValue
- the new value for the property- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the required properties
-
persistProperties
public static void persistProperties() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionSave the properties to a properties file on disk.- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the properties
-
getMainBackupProperties
public static edu.ucsb.nceas.utilities.SortedProperties getMainBackupProperties()Get the main backup properties file. These are configurable properties that are stored outside the metacat install directories so the user does not need to re-enter all the configuration information every time they do an upgrade.- Returns:
- a SortedProperties object with the backup properties
-
getAuthBackupProperties
public static edu.ucsb.nceas.utilities.SortedProperties getAuthBackupProperties()Get the auth backup properties file. These are configurable properties that are stored outside the metacat install directories so the user does not need to re-enter all the configuration information every time they do an upgrade.- Returns:
- a SortedProperties object with the backup properties
-
getMainMetaData
public static edu.ucsb.nceas.utilities.PropertiesMetaData getMainMetaData()Get the main properties metadata. This is retrieved from an xml file that describes the attributes of configurable properties.- Returns:
- a PropertiesMetaData object with the main properties metadata
-
getAuthMetaData
public static edu.ucsb.nceas.utilities.PropertiesMetaData getAuthMetaData()Get the auth properties metadata. This is retrieved from an xml file that describes the attributes of configurable properties.- Returns:
- a PropertiesMetaData object with the organization properties metadata
-
persistMainBackupProperties
public static void persistMainBackupProperties() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionWrites out configurable properties to a backup file outside the metacat install directory, so they are not lost if metacat installation is overwritten during an upgrade. These backup properties are used by the admin page to populate defaults when the configuration is edited. (They are also used to overwrite the main properties if bypassConfiguration() is called)- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the required properties
-
persistAuthBackupProperties
public static void persistAuthBackupProperties() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionWrites out configurable properties to a backup file outside the metacat install directory, so they are not lost if metacat installation is overwritten during an upgrade. These backup properties are used by the admin page to populate defaults when the configuration is edited. (They are also used to overwrite the main properties if bypassConfiguration() is called)- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the required properties
-
arePropertiesConfigured
public static boolean arePropertiesConfigured() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionReports whether properties are fully configured, by checking the value of the property "configutil.propertiesConfigured", which is set from the Admin flow.- Returns:
- a boolean that is true if properties are configured and false otherwise
- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems getting the "configutil.propertiesConfigured" property- See Also:
-
doBypass
public static boolean doBypass() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionDetermine if the system is able to bypass configuration. If so, the system will look for backup or "site-specific" configuration files at startup time and use those to configure metacat. The bypass options should only be set by developers. Production code should never bypass configuration.- Returns:
- true if dev.runConfiguration is set to true in metacat.properties AND we have not already checked for bypass; false otherwise.
- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are problems manipulating the required properties
-
bypassConfiguration
public static void bypassConfiguration()(for dev use only) Bypasses the properties configuration utility by using the backup properties to overwrite the main properties. -
checkAndSetProperty
@Deprecated public static void checkAndSetProperty(javax.servlet.http.HttpServletRequest request, String propertyName) throws edu.ucsb.nceas.utilities.GeneralPropertyException Deprecated.Take input from the user in an HTTP request about a property to be changed and update the metacat property file with that new value if it has changed from the value that was originally set.- Parameters:
request
- that was generated by the userpropertyName
- the name of the property to be checked and set- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
-
getRecommendedExternalDir
Returns the recommended external base directory. This is populated during initialization time using the SystemUtil.discoverExternalBaseDir() method. This directory will be used to suggest external user directories when the user configures metacat for the first time.- Returns:
- a String holding the recommended external directory
-
setRecommendedExternalDir
Sets the recommended external directory. This is populated during initialization time using the SystemUtil.discoverExternalDir() method. This directory will be used to suggest external user directories when the user configures metacat for the first time. -
syncToSettings
public static void syncToSettings() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionThe properties on the dataONE Setting class isn't synchronized with changes to the Metacat properties files. This method synchronizes (reloads) the properties' changes to the Settings class, and should be called whenever the property files are modified.- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there's a problem calling Settings.augmentConfiguration()
-
getMainMetadataFilePath
Get the path to the main Metadata file, which holds configuration information about main properties. This is primarily used to display input fields on the configuration page. The information is retrieved from an xml metadata file -
getBackupDirPath
Get the path to the directory where the backup properties are stored, and as a side effect, update the properties file to save this path as "application.backupDir"- Returns:
- java.nio.Path representation of the directory path
- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there are issues retrieving or persisting the value
-
refreshable
public boolean refreshable()- Specified by:
refreshable
in classBaseService
-
doRefresh
- Specified by:
doRefresh
in classBaseService
- Throws:
ServiceException
-
stop
- Specified by:
stop
in classBaseService
- Throws:
ServiceException
-