- java.lang.Object
-
- com.erudika.para.core.utils.Config
-
- Direct Known Subclasses:
ParaConfig
public abstract class Config extends Object
This class loads configuration settings from a file and sets defaults.- Author:
- Alex Bogdanovski [alex@erudika.com]
-
-
Field Summary
Fields Modifier and Type Field Description static String_APPID"appid".static String_CREATORID"creatorid".static String_EMAIL"email".static String_EMAIL_TOKEN"etoken".static String_GROUPS"groups".static String_ID"id".static String_IDENTIFIER"identifier".static String_KEY"key".static String_NAME"name".static String_PARENTID"parentid".static String_PASSWORD"password".static String_PROPERTIES"properties".static String_RESET_TOKEN"token".static String_TAGS"tags".static String_TIMESTAMP"timestamp".static String_TYPE"type".static String_UPDATED"updated".static String_VERSION"version".static StringAMAZON_PREFIXAmazon prefix - defaults to 'az:'.static intDEFAULT_LIMIT10000.static StringFB_PREFIXFacebook prefix - defaults to 'fb:'.static StringGITHUB_PREFIXGitHub prefix - defaults to 'gh:'.static StringGPLUS_PREFIXGoogle prefix - defaults to 'gp:'.static StringLDAP_PREFIXLDAP prefix - defaults to 'ldap:'.static StringLINKEDIN_PREFIXLinkedIn prefix - defaults to 'in:'.static StringMATTERMOST_PREFIXMattermost prefix - defaults to 'mm:'.static StringMICROSOFT_PREFIXMicrosoft prefix - defaults to 'ms:'.static StringOAUTH2_PREFIXOAuth2 generic prefix - defaults to 'oa2:'.static StringOAUTH2_SECOND_PREFIXOAuth2 second generic prefix - defaults to 'oa2second:'.static StringOAUTH2_THIRD_PREFIXOAuth2 third generic prefix - defaults to 'oa2third:'.static StringPARA"para".static StringSAML_PREFIXSAML prefix - defaults to 'saml:'.static StringSLACK_PREFIXSlack prefix - defaults to 'sl:'.static StringTWITTER_PREFIXTwitter prefix - defaults to 'tw:'.
-
Constructor Summary
Constructors Constructor Description Config()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description com.typesafe.config.ConfiggetConfig()Returns the Config object.StringgetConfigFilePath()The name of the configuration file, usually 'app-application.conf'.Map<String,Object>getConfigMap()abstract StringgetConfigRootPrefix()The root prefix of the configuration property names, e.g.ObjectgetConfigValue(String key, String defaultValue)Returns the unwrapped value of a configuration parameter or its default value.Map<String,String>getSortedConfigKeys()Constructs a sorted set of configuration keys.Stringrender(boolean asJson)Stringrender(boolean asJson, String hoconHeader, String hoconFooter)Renders the current configuration as a String, taking into account system properties and ENV precedence ordering.StringrenderConfigDocumentation(String format, boolean groupByCategory)Renders all configuration options along with their documentation and default values.voidstore()Stores all available configuration to a file, overwriting the existing one.
-
-
-
Field Detail
-
PARA
public static final String PARA
"para".- See Also:
- Constant Field Values
-
_TYPE
public static final String _TYPE
"type".- See Also:
- Constant Field Values
-
_APPID
public static final String _APPID
"appid".- See Also:
- Constant Field Values
-
_CREATORID
public static final String _CREATORID
"creatorid".- See Also:
- Constant Field Values
-
_ID
public static final String _ID
"id".- See Also:
- Constant Field Values
-
_IDENTIFIER
public static final String _IDENTIFIER
"identifier".- See Also:
- Constant Field Values
-
_KEY
public static final String _KEY
"key".- See Also:
- Constant Field Values
-
_NAME
public static final String _NAME
"name".- See Also:
- Constant Field Values
-
_PARENTID
public static final String _PARENTID
"parentid".- See Also:
- Constant Field Values
-
_PASSWORD
public static final String _PASSWORD
"password".- See Also:
- Constant Field Values
-
_RESET_TOKEN
public static final String _RESET_TOKEN
"token".- See Also:
- Constant Field Values
-
_EMAIL_TOKEN
public static final String _EMAIL_TOKEN
"etoken".- See Also:
- Constant Field Values
-
_TIMESTAMP
public static final String _TIMESTAMP
"timestamp".- See Also:
- Constant Field Values
-
_UPDATED
public static final String _UPDATED
"updated".- See Also:
- Constant Field Values
-
_TAGS
public static final String _TAGS
"tags".- See Also:
- Constant Field Values
-
_EMAIL
public static final String _EMAIL
"email".- See Also:
- Constant Field Values
-
_GROUPS
public static final String _GROUPS
"groups".- See Also:
- Constant Field Values
-
_VERSION
public static final String _VERSION
"version".- See Also:
- Constant Field Values
-
_PROPERTIES
public static final String _PROPERTIES
"properties".- See Also:
- Constant Field Values
-
DEFAULT_LIMIT
public static final int DEFAULT_LIMIT
10000.- See Also:
- Constant Field Values
-
FB_PREFIX
public static final String FB_PREFIX
Facebook prefix - defaults to 'fb:'.- See Also:
- Constant Field Values
-
GPLUS_PREFIX
public static final String GPLUS_PREFIX
Google prefix - defaults to 'gp:'.- See Also:
- Constant Field Values
-
LINKEDIN_PREFIX
public static final String LINKEDIN_PREFIX
LinkedIn prefix - defaults to 'in:'.- See Also:
- Constant Field Values
-
TWITTER_PREFIX
public static final String TWITTER_PREFIX
Twitter prefix - defaults to 'tw:'.- See Also:
- Constant Field Values
-
GITHUB_PREFIX
public static final String GITHUB_PREFIX
GitHub prefix - defaults to 'gh:'.- See Also:
- Constant Field Values
-
MICROSOFT_PREFIX
public static final String MICROSOFT_PREFIX
Microsoft prefix - defaults to 'ms:'.- See Also:
- Constant Field Values
-
SLACK_PREFIX
public static final String SLACK_PREFIX
Slack prefix - defaults to 'sl:'.- See Also:
- Constant Field Values
-
MATTERMOST_PREFIX
public static final String MATTERMOST_PREFIX
Mattermost prefix - defaults to 'mm:'.- See Also:
- Constant Field Values
-
AMAZON_PREFIX
public static final String AMAZON_PREFIX
Amazon prefix - defaults to 'az:'.- See Also:
- Constant Field Values
-
OAUTH2_PREFIX
public static final String OAUTH2_PREFIX
OAuth2 generic prefix - defaults to 'oa2:'.- See Also:
- Constant Field Values
-
OAUTH2_SECOND_PREFIX
public static final String OAUTH2_SECOND_PREFIX
OAuth2 second generic prefix - defaults to 'oa2second:'.- See Also:
- Constant Field Values
-
OAUTH2_THIRD_PREFIX
public static final String OAUTH2_THIRD_PREFIX
OAuth2 third generic prefix - defaults to 'oa2third:'.- See Also:
- Constant Field Values
-
LDAP_PREFIX
public static final String LDAP_PREFIX
LDAP prefix - defaults to 'ldap:'.- See Also:
- Constant Field Values
-
SAML_PREFIX
public static final String SAML_PREFIX
SAML prefix - defaults to 'saml:'.- See Also:
- Constant Field Values
-
-
Method Detail
-
getConfigFilePath
public String getConfigFilePath()
The name of the configuration file, usually 'app-application.conf'.- Returns:
- prefix-application.conf or the value of @{code config.file} system property.
-
getConfigRootPrefix
public abstract String getConfigRootPrefix()
The root prefix of the configuration property names, e.g. "para".- Returns:
- the root prefix for all config property keys.
-
getConfigValue
public Object getConfigValue(String key, String defaultValue)
Returns the unwrapped value of a configuration parameter or its default value.- Parameters:
key- the param keydefaultValue- the default value- Returns:
- object a raw unwrapped value
-
getConfig
public com.typesafe.config.Config getConfig()
Returns the Config object.- Returns:
- the config object
-
getSortedConfigKeys
public Map<String,String> getSortedConfigKeys()
Constructs a sorted set of configuration keys. Heavily relies on theDocumentedannotation for sort order.- Returns:
- a set of map of config keys, without the root prefix (path), to config categories.
-
store
public void store()
Stores all available configuration to a file, overwriting the existing one. In case of HOCON, the commented lines are collected from existing file and appended at the end.
-
render
public String render(boolean asJson)
- Parameters:
asJson- if true, a JSON object will be rendered, otherwise the HOCON format is used- Returns:
- config as string
- See Also:
render(boolean, java.lang.String, java.lang.String)
-
render
public String render(boolean asJson, String hoconHeader, String hoconFooter)
Renders the current configuration as a String, taking into account system properties and ENV precedence ordering.- Parameters:
asJson- if true, a JSON object will be rendered, otherwise the HOCON format is usedhoconHeader- file headerhoconFooter- file footer- Returns:
- config as string
-
renderConfigDocumentation
public String renderConfigDocumentation(String format, boolean groupByCategory)
Renders all configuration options along with their documentation and default values.- Parameters:
format- one of "hocon", "json" or "markdown"groupByCategory- if true, will group properties by category- Returns:
- a HOCON, JSON or MD string
-
-