Class PropertiesWrapper
java.lang.Object
edu.ucsb.nceas.metacat.properties.PropertiesWrapper
A Class that provides a wrapper around standard java.util.Properties to provide backwards
compatibility with metacat's original properties implementation
-
Field Summary
Modifier and TypeFieldDescriptionprotected Properties
TODO: Eliminate the need for this list! It is here for legacy reasons; See GitHub Issue #1638: https://github.com/NCEAS/metacat/issues/1638 Whenever setPropertyNoPersist() is called, the code checks to see if the passed propertyName parameter is listed in 'writeableDefaults'. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
implementation of abstract method in edu.ucsb.nceas.metacat.shared.BaseService, delegated to by PropertyService, which extends BaseServiceprotected Path
Get the path to the read-only, default properties in metacat.properties.protected static PropertiesWrapper
get the current instance of the PropertiesWrapper.protected edu.ucsb.nceas.utilities.PropertiesMetaData
Get the main properties metadata.protected Path
Get the path to the main Metadata file, which holds configuration information about main properties.protected static PropertiesWrapper
getNewInstance
(Path defaultPropertiesFilePath, Path sitePropertiesFilePath) get an instance of the PropertiesWrapper.getPropertiesByGroup
(String groupName) Get a Map of all properties that start with the groupName prefix.protected 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.protected Path
Get the path to the metacat-site.properties file, which holds configurable properties used to override the defaults in metacat.properties.protected void
Save the properties to the metacat-site.properties file.protected void
setProperty
(String propertyName, String newValue) Utility method to set a property value both in memory and to the properties fileprotected void
setPropertyNoPersist
(String propertyName, String newValue) Utility method to set a property value in memory.protected void
The properties on the dataONE Setting class aren't synchronized with changes to the Metacat properties files.toString()
Provides a string representation of all the properties seen by the application at runtime, in the format: key1=property1 key2=property2 key3=property3 ...etc.
-
Field Details
-
defaultProperties
-
WRITEABLE_DEFAULTS
TODO: Eliminate the need for this list! It is here for legacy reasons; See GitHub Issue #1638: https://github.com/NCEAS/metacat/issues/1638 Whenever setPropertyNoPersist() is called, the code checks to see if the passed propertyName parameter is listed in 'writeableDefaults'. If so, the property is added directly to 'defaultProperties' instead of to 'mainProperties'. It will therefore end up being written to the 'metacat.properties' file instead of the 'metacat-site.properties' file. This breaks the design intent of the Properties setup, and has been done as a temporary workaround preceding incremental improvements. DO NOT ADD ANY MORE KEYS TO THIS LIST! - IT WILL BE DELETED when the code is refactored to to handle upgrades across deployments for k8s and legacy installations. Basically, the metacat.properties file should never need to be writeable. If you find yourself wanting to write to it, there must be a better solution.
-
-
Method Details
-
toString
Provides a string representation of all the properties seen by the application at runtime, in the format:- key1=property1
- key2=property2
- key3=property3
-
getInstance
protected static PropertiesWrapper getInstance() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionget the current instance of the PropertiesWrapper. To set specific property file locations . use thegetNewInstance(Path, Path)
method.- Returns:
- singleton instance of PropertiesWrapper
- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- when things go wrong
-
getNewInstance
protected static PropertiesWrapper getNewInstance(Path defaultPropertiesFilePath, Path sitePropertiesFilePath) throws edu.ucsb.nceas.utilities.GeneralPropertyException get an instance of the PropertiesWrapper. WARNING: all calls to this method will re-initialize PropertiesWrapper with the newly-passed values of defaultPropertiesFilePath and sitePropertiesFilePath. If you just want to get an instance without affecting its internals, callgetinstance()
instead.- Parameters:
defaultPropertiesFilePath
- (Can be null) Full path to the default properties file (e.g. /var/lib/tomcat/webapps/WEB-INF/metacat.properties)sitePropertiesFilePath
- (Can be null) Full path to the site properties file (e.g. /var/metacat/config/metacat-site.properties)- Returns:
- singleton instance of PropertiesWrapper
- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- when things go wrong
-
getProperty
protected 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
protected 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
protected 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's a problem setting or storing the property
-
setPropertyNoPersist
protected 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 the property wasn't found, or there's a problem responding to a change in the property "application.sitePropertiesDir"
-
persistProperties
protected void persistProperties() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionSave the properties to the metacat-site.properties file.- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if an I/O Exception is encountered
-
getMainMetaData
protected 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
-
doRefresh
protected void doRefresh() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionimplementation of abstract method in edu.ucsb.nceas.metacat.shared.BaseService, delegated to by PropertyService, which extends BaseService- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there is a problem with initialization
-
getDefaultPropertiesFilePath
Get the path to the read-only, default properties in metacat.properties. -
getSitePropertiesFilePath
Get the path to the metacat-site.properties file, which holds configurable properties used to override the defaults in metacat.properties. -
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 -
syncToSettings
protected void syncToSettings() throws edu.ucsb.nceas.utilities.GeneralPropertyExceptionThe properties on the dataONE Setting class aren'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. NOTE that secrets passed as environment variables are accessible only by code that calls PropertyService.getProperty(). Calling syncToSettings() does NOT make them accessible via org.dataone.configuration.Settings. (See inline code comment for suggestions on how to implement, if this becomes necessary in future)- Throws:
edu.ucsb.nceas.utilities.GeneralPropertyException
- if there's a problem calling Settings.augmentConfiguration()
-