Class PropertiesWrapper

java.lang.Object
edu.ucsb.nceas.metacat.properties.PropertiesWrapper

public class PropertiesWrapper extends Object
A Class that provides a wrapper around standard java.util.Properties to provide backwards compatibility with metacat's original properties implementation
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Properties
     
    protected static final List<String>
    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 Type
    Method
    Description
    protected void
    implementation of abstract method in edu.ucsb.nceas.metacat.shared.BaseService, delegated to by PropertyService, which extends BaseService
    protected 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.
    protected Map<String,String>
    Get a Map of all properties that start with the groupName prefix.
    protected String
    getProperty(String propertyName)
    Get a property value.
    protected Vector<String>
    Get a set of all property names.
    protected Vector<String>
    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 file
    protected 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.
    Provides a string representation of all the properties seen by the application at runtime, in the format: key1=property1 key2=property2 key3=property3 ...etc.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • defaultProperties

      protected Properties defaultProperties
    • WRITEABLE_DEFAULTS

      protected static final List<String> 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

      public String 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. If a problem is encountered when retrieving any of the properties, the output for that key will be in the form: (keyname)=EXCEPTION getting this property: (exception message)
      Overrides:
      toString in class Object
      Returns:
      string representation of all the properties seen by the application at runtime
    • getInstance

      protected static PropertiesWrapper getInstance() throws edu.ucsb.nceas.utilities.GeneralPropertyException
      get the current instance of the PropertiesWrapper. To set specific property file locations . use the getNewInstance(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, call getinstance() 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 passed propertyName key is not in the properties at all
    • getPropertyNames

      protected Vector<String> getPropertyNames()
      Get a set of all property names.
      Returns:
      Vector of property names
    • getPropertyNamesByGroup

      protected Vector<String> getPropertyNamesByGroup(String groupName)
      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 passed groupName 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 requested
      newValue - 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 requested
      newValue - 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.GeneralPropertyException
      Save 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.GeneralPropertyException
      implementation 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

      protected Path getDefaultPropertiesFilePath()
      Get the path to the read-only, default properties in metacat.properties.
    • getSitePropertiesFilePath

      protected Path getSitePropertiesFilePath()
      Get the path to the metacat-site.properties file, which holds configurable properties used to override the defaults in metacat.properties.
    • getMainMetadataFilePath

      protected Path 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.GeneralPropertyException
      The 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()