Class DatabaseProperties


  • @ThreadSafe
    public class DatabaseProperties
    extends java.lang.Object
    This is a wrapper around a set of properties that are stored in the database. This class is safe to be accessed from multiple threads in parallel.
    Author:
    Jeremy Long
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String KEV_LAST_CHECKED
      The key for the last check time for the Known Exploited Vulnerabilities.
      static java.lang.String KEV_VERSION
      The key for the version the Known Exploited Vulnerabilities.
      static java.lang.String LAST_CPE_UPDATE
      The key for the last time the CPE data was updated.
      static java.lang.String NVD_API_LAST_CHECKED
      The date the NVD API was last checked for an update.
      static java.lang.String NVD_API_LAST_MODIFIED
      The last modified request data for the NVD API.
      static java.lang.String NVD_CACHE_LAST_CHECKED
      The date the NVD cache was last checked for an update.
      static java.lang.String NVD_CACHE_LAST_MODIFIED
      The date the NVD cache data was last modified/updated.
      static java.lang.String VERSION
      The key for the database schema version.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.time.ZonedDateTime getIsoTimestamp​(java.util.Properties properties, java.lang.String key)
      Retrieves a zoned date time.
      java.util.Map<java.lang.String,​java.lang.String> getMetaData()
      Returns a map of the meta data from the database properties.
      java.util.Properties getProperties()
      Returns the collection of Database Properties as a properties collection.
      java.lang.String getProperty​(java.lang.String key)
      Returns the property value for the given key.
      java.lang.String getProperty​(java.lang.String key, java.lang.String defaultValue)
      Returns the property value for the given key.
      long getPropertyInSeconds​(java.lang.String key)
      Returns the database property value in seconds.
      java.time.ZonedDateTime getTimestamp​(java.lang.String key)
      Retrieves a zoned date time.
      static java.time.ZonedDateTime getTimestamp​(java.util.Properties properties, java.lang.String key)
      Retrieves a zoned date time.
      boolean isEmpty()
      Returns whether or not any properties are set.
      void save​(java.lang.String key, java.lang.String value)
      Saves the key value pair to the properties store.
      void save​(java.lang.String key, java.time.ZonedDateTime timestamp)
      Stores a timestamp.
      static void setTimestamp​(java.util.Properties properties, java.lang.String key, java.time.ZonedDateTime timestamp)
      Stores a timestamp in the properties file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NVD_API_LAST_MODIFIED

        public static final java.lang.String NVD_API_LAST_MODIFIED
        The last modified request data for the NVD API.
        See Also:
        Constant Field Values
      • NVD_API_LAST_CHECKED

        public static final java.lang.String NVD_API_LAST_CHECKED
        The date the NVD API was last checked for an update.
        See Also:
        Constant Field Values
      • NVD_CACHE_LAST_CHECKED

        public static final java.lang.String NVD_CACHE_LAST_CHECKED
        The date the NVD cache was last checked for an update.
        See Also:
        Constant Field Values
      • NVD_CACHE_LAST_MODIFIED

        public static final java.lang.String NVD_CACHE_LAST_MODIFIED
        The date the NVD cache data was last modified/updated.
        See Also:
        Constant Field Values
      • LAST_CPE_UPDATE

        public static final java.lang.String LAST_CPE_UPDATE
        The key for the last time the CPE data was updated.
        See Also:
        Constant Field Values
      • VERSION

        public static final java.lang.String VERSION
        The key for the database schema version.
        See Also:
        Constant Field Values
      • KEV_LAST_CHECKED

        public static final java.lang.String KEV_LAST_CHECKED
        The key for the last check time for the Known Exploited Vulnerabilities.
        See Also:
        Constant Field Values
      • KEV_VERSION

        public static final java.lang.String KEV_VERSION
        The key for the version the Known Exploited Vulnerabilities.
        See Also:
        Constant Field Values
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns whether or not any properties are set.
        Returns:
        whether or not any properties are set
      • save

        public void save​(java.lang.String key,
                         java.lang.String value)
        Saves the key value pair to the properties store.
        Parameters:
        key - the property key
        value - the property value
      • getProperty

        public java.lang.String getProperty​(java.lang.String key)
        Returns the property value for the given key. If the key is not contained in the underlying properties null is returned.
        Parameters:
        key - the property key
        Returns:
        the value of the property
      • getProperty

        public java.lang.String getProperty​(java.lang.String key,
                                            java.lang.String defaultValue)
        Returns the property value for the given key. If the key is not contained in the underlying properties the default value is returned.
        Parameters:
        key - the property key
        defaultValue - the default value
        Returns:
        the value of the property
      • getProperties

        public java.util.Properties getProperties()
        Returns the collection of Database Properties as a properties collection.
        Returns:
        the collection of Database Properties
      • getMetaData

        public java.util.Map<java.lang.String,​java.lang.String> getMetaData()
        Returns a map of the meta data from the database properties. This primarily contains timestamps of when the NVD CVE information was last updated.
        Returns:
        a map of the database meta data
      • getTimestamp

        public java.time.ZonedDateTime getTimestamp​(java.lang.String key)
        Retrieves a zoned date time.
        Parameters:
        key - the property key
        Returns:
        the zoned date time
      • save

        public void save​(java.lang.String key,
                         java.time.ZonedDateTime timestamp)
        Stores a timestamp.
        Parameters:
        key - the property key
        timestamp - the zoned date time
      • setTimestamp

        public static void setTimestamp​(java.util.Properties properties,
                                        java.lang.String key,
                                        java.time.ZonedDateTime timestamp)
        Stores a timestamp in the properties file.
        Parameters:
        properties - the properties to store the timestamp
        key - the property key
        timestamp - the zoned date time
      • getTimestamp

        public static java.time.ZonedDateTime getTimestamp​(java.util.Properties properties,
                                                           java.lang.String key)
        Retrieves a zoned date time.
        Parameters:
        properties - the properties file containing the date time
        key - the property key
        Returns:
        the zoned date time
      • getIsoTimestamp

        public static java.time.ZonedDateTime getIsoTimestamp​(java.util.Properties properties,
                                                              java.lang.String key)
        Retrieves a zoned date time.
        Parameters:
        properties - the properties file containing the date time
        key - the property key
        Returns:
        the zoned date time
      • getPropertyInSeconds

        public long getPropertyInSeconds​(java.lang.String key)
        Returns the database property value in seconds.
        Parameters:
        key - the key to the property
        Returns:
        the property value in seconds