Class SystemUtil
java.lang.Object
com.ssgllc.fish.service.util.registered.SystemUtil
Application-level facts and services: configuration values, text templates, caches, logging, and
database capability.
Prefer these over hardcoding anything environment-specific -
getBaseUrl(), getEnvironmentName() and getSystemTimezone() keep a
script correct in every environment it runs in. getApplicationProperty(String) is
deliberately restricted: it serves only the application's own namespaces and withholds anything
named like a secret.
-
Constructor Summary
ConstructorsConstructorDescriptionSystemUtil(org.springframework.core.env.Environment environment, com.ssgllc.fish.service.cache.EntityConfigCacheService entityConfigCacheService, com.ssgllc.fish.service.cache.CustomCacheService customCacheService, com.ssgllc.fish.config.ApplicationProperties applicationProperties, String springJpaDatabase) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidWritesmessageto the application log at DEBUG level (off in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request.static voidWritesmessageto the application log at ERROR level (always on), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request.static <T> TevaluateExpression(Object rootObject, String expression, String returnTypeName, boolean mapContext) Evaluate given expression in context of a root object and return result in given type.
Example:
evaluateExpression(entity, "firstName == null", "java.lang.Boolean", false)
Returns:
Boolean true or false
static <T> TevaluateExpressionSafe(Object rootObject, String expression, String returnTypeName, boolean mapContext, T exceptionReturnValue) Safely evaluates a given expression within the context of a specified root object and returns the result cast to the specified type.
If the evaluation fails due to an exception, a fallback value is returned instead.static ObjectexecuteScript(String templateName, Map<String, Object> config, List<Map<String, Object>> payload, Object body) Runs a named TextTemplate as a Groovy script and returns its result.static StringgetAppConfig(String name) Retrieves the application configuration value associated with the given name.static booleangetAppConfigBoolean(String name, boolean defaultVal) Retrieves the application configuration value associated with the given name as a boolean, or returns the specified default value if the configuration is not found or cannot be parsed as a boolean.static IntegergetAppConfigInteger(String name, Integer defaultVal) Retrieves the application configuration value associated with the given name as an integer, or returns the specified default value if the configuration is not found or cannot be parsed as an integer.static StringgetAppConfigString(String name, String defaultVal) Retrieves the application configuration value associated with the given name, or returns the specified default value if the configuration is not found.static StringReads a Spring environment property, restricted to the application's own namespaces and with secrets withheld.static StringThe application's configured base URL.static ObjectReturns a whole named cache, for iterating or inspecting it.static StringFilesystem folder holding the EC private keys used for signing.static StringThe application's configured environment name.static ObjectgetFromCache(String cacheName, String entryKey) Reads one entry from a named application cache.static StringIdentifies the node running this code, as"hostname ipAddress".static StringThe application's configured system time zone.static StringgetTextTemplate(String name) The text of a named TextTemplate, read from cache.static voidWritesmessageto the application log at INFO level (on in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request.static ObjectLogs a value at WARN and returns it unchanged, so it can be dropped into the middle of an expression or a chain without restructuring the code.static booleanWhether DEBUG logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil.static booleanWhether ERROR logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil.static booleanWhether INFO logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil.static booleanWhether TRACE logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil.static booleanWhether this deployment's database supports vector columns, which today means PostgreSQL.static booleanWhether WARN logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil.static voidWritesmessageto the application log at TRACE level (the finest level, off in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request.static voidWritesmessageto the application log at WARN level (always on), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request.
-
Constructor Details
-
SystemUtil
public SystemUtil(org.springframework.core.env.Environment environment, com.ssgllc.fish.service.cache.EntityConfigCacheService entityConfigCacheService, com.ssgllc.fish.service.cache.CustomCacheService customCacheService, com.ssgllc.fish.config.ApplicationProperties applicationProperties, @Value("${spring.jpa.database}") String springJpaDatabase)
-
-
Method Details
-
getApplicationProperty
Reads a Spring environment property, restricted to the application's own namespaces and with secrets withheld. Returns null - rather than throwing - for anything outside the allowed prefixes (APPLICATION_,application.,CASETIVITY_,casetivity.) and for any key whose name containspasswordorsecretin any case. So a script cannot read arbitrary Spring properties or exfiltrate credentials, and a null means either "not set" or "not readable" - it does not distinguish them.- Parameters:
key- the property name, which must start with an allowed prefix- Returns:
- the property value, or
nullif unset, out of namespace, or secret-named
Groovy example:
return systemUtil.getApplicationProperty("application.baseUrl")
Returns:
"https://iis.example.gov"
SpEL example:
#getApplicationProperty("application.environmentName")
Returns:
"prod"
-
getBaseUrl
The application's configured base URL. Use it to build a link that will work in whichever environment the script is running in, rather than hardcoding a host.- Returns:
- the base URL, e.g.
"https://iis.example.gov"
Groovy example:
def link = systemUtil.getBaseUrl() + "/#/AppCase/" + entity.id
Returns:
a deep link to the case, correct for this environment
SpEL example:
#getBaseUrl() + '/#/Order/' + #id
Returns:
"https://iis.example.gov/#/Order/3f2b1c8e"
-
getSystemTimezone
The application's configured system time zone. Date functions that need an explicit zone should take it from here rather than from the JVM default, which can differ between nodes.- Returns:
- the configured zone id, e.g.
"America/New_York"
Groovy example:
return systemUtil.getSystemTimezone()
Returns:
"America/New_York"
SpEL example:
#f().instant.of(#createdDate).inZone(#getSystemTimezone()).toIso()
Returns:
the creation timestamp rendered in the application's zone
-
getEcPrivateKeyFolder
Filesystem folder holding the EC private keys used for signing. Returns the configured path only - it does not read any key material.- Returns:
- the configured folder path
Groovy example:
return systemUtil.getEcPrivateKeyFolder()
Returns:
"/opt/casetivity/keys"
-
getEnvironmentName
The application's configured environment name. Use it to branch behaviour that must differ between environments - suppressing an outbound call outside prod, say - instead of keying on a hostname.- Returns:
- the environment name, e.g.
"prod"or"cert"
Groovy example:
return systemUtil.getEnvironmentName() == "prod"
Returns:
true only in production
SpEL example:
#getEnvironmentName() == 'prod'
Returns:
true in production
-
getNodeId
Identifies the node running this code, as"hostname ipAddress". Falls back to a random seven-character string when the local host cannot be resolved, so it is stable for the life of a JVM but not guaranteed to be meaningful across restarts. Useful for attributing a log line or a record to one node of a cluster.- Returns:
- the node identifier
Groovy example:
systemUtil.info("Import ran on " + systemUtil.getNodeId())
Returns:
nothing; the node id appears in the log line
SpEL example:
#getNodeId()
Returns:
"app-node-2 10.4.1.17"
-
getAppConfig
Retrieves the application configuration value associated with the given name.- Parameters:
name- The name of the configuration key to retrieve.- Returns:
- The configuration value as a string, or null if no value is associated with the key.
Groovy example:
return systemUtil.getAppConfig("MyConfig")
Returns:
"MyConfigValue"
SpEL example:
#getAppConfig("MyConfig")
Returns:
"MyConfigValue"
-
getAppConfigString
Retrieves the application configuration value associated with the given name, or returns the specified default value if the configuration is not found.- Parameters:
name- The name of the configuration key to retrieve.defaultVal- The default value to return if no configuration is found for the key.- Returns:
- The configuration value as a string, or the specified default value if no value is associated with the key.
Groovy example:
return systemUtil.getAppConfigString("HeaderDisplayValue", "My Header")
Returns:
"My Header"
SpEL example:
#getAppConfigString("HeaderDisplayValue", "My Header")
Returns:
"My Header"
-
getAppConfigBoolean
Retrieves the application configuration value associated with the given name as a boolean, or returns the specified default value if the configuration is not found or cannot be parsed as a boolean.- Parameters:
name- The name of the configuration key to retrieve.defaultVal- The default value to return if no configuration is found for the key or if the value cannot be parsed as a boolean.- Returns:
- The configuration value as a boolean, or the specified default value.
Groovy example:
return systemUtil.getAppConfigBoolean("IsNewFeatureEnabled", false)
Returns:
false
SpEL example:
#getAppConfigBoolean("IsNewFeatureEnabled", false)
Returns:
false
-
getAppConfigInteger
Retrieves the application configuration value associated with the given name as an integer, or returns the specified default value if the configuration is not found or cannot be parsed as an integer.- Parameters:
name- The name of the configuration key to retrieve.defaultVal- The default value to return if no configuration is found for the key or if the value cannot be parsed as an integer.- Returns:
- The configuration value as an integer, or the specified default value.
Groovy example:
return systemUtil.getAppConfigInteger("MaxBatchSize", 100)
Returns:
100
SpEL example:
#getAppConfigInteger("MaxBatchSize", 100)
Returns:
100
-
getTextTemplate
The text of a named TextTemplate, read from cache. Use it to keep a message body, a fragment of SQL or a word list in configuration rather than in a script. To execute a TextTemplate as a script instead of reading it, useexecuteScript(String, Map, List, Object).- Parameters:
name- the TextTemplate's name- Returns:
- the template text, or
nullif no template has that name
Groovy example:
def body = systemUtil.getTextTemplate("orderConfirmationEmail")
Returns:
the template's text
SpEL example:
#getTextTemplate('orderConfirmationEmail')
Returns:
the template's text
-
getFromCache
Reads one entry from a named application cache.- Parameters:
cacheName- the cache's nameentryKey- the entry's key- Returns:
- the cached value, or
nullif the cache or the entry is absent
Groovy example:
def rates = systemUtil.getFromCache("lookupCache", "taxRates")
Returns:
the cached value for that key
SpEL example:
#getFromCache('lookupCache', 'taxRates')
Returns:
the cached value
-
getCache
Returns a whole named cache, for iterating or inspecting it. PrefergetFromCache(String, String)when one key is wanted.- Parameters:
cacheName- the cache's name- Returns:
- the cache, or
nullif no cache has that name
Groovy example:
def cache = systemUtil.getCache("lookupCache")
Returns:
the cache itself
SpEL example:
#getCache('lookupCache')
Returns:
the cache itself
-
executeScript
public static Object executeScript(String templateName, Map<String, Object> config, List<Map<String, Object>> payload, Object body) Runs a named TextTemplate as a Groovy script and returns its result. This is how one script calls another: keep shared logic in a TextTemplate and invoke it here, rather than copying it between BPMN script tasks. To read a template's text without executing it, usegetTextTemplate(String).- Parameters:
templateName- the TextTemplate to executeconfig- configuration values bound into the scriptpayload- rows bound into the scriptbody- a single value bound into the script- Returns:
- whatever the script returns
Groovy example:
def result = systemUtil.executeScript("computeEligibility", ['strict': true], null, entity)
Returns:
whatever computeEligibility returns
-
evaluateExpression
public static <T> T evaluateExpression(Object rootObject, String expression, String returnTypeName, boolean mapContext) throws ClassNotFoundException Evaluate given expression in context of a root object and return result in given type.
Example:
evaluateExpression(entity, "firstName == null", "java.lang.Boolean", false)
Returns:
Boolean true or false
- Parameters:
rootObject- object in scope where given expression will be evaluatedexpression- expression to be evaluatedreturnTypeName- fully qualified name of return type from expression evaluationmapContext- true if map accessor should be used in evaluation context, false otherwise- Returns:
- result from expression evaluation
- Throws:
ClassNotFoundException
-
evaluateExpressionSafe
public static <T> T evaluateExpressionSafe(Object rootObject, String expression, String returnTypeName, boolean mapContext, T exceptionReturnValue) throws ClassNotFoundException Safely evaluates a given expression within the context of a specified root object and returns the result cast to the specified type.
If the evaluation fails due to an exception, a fallback value is returned instead.- Parameters:
rootObject- The object serving as the evaluation context for the expression.expression- The expression to evaluate.returnTypeName- The fully qualified name of the expected return type.mapContext- Indicates whether the evaluation context should treat the rootObject as a map.exceptionReturnValue- The value to return if an exception occurs during evaluation.- Returns:
- The result of the evaluated expression, or
exceptionReturnValueif an error occurs.
Groovy example:
return systemUtil.evaluateExpressionSafe(entity, "firstName == null", "java.lang.Boolean", false, false)
Returns:
true
SpEL example:
#evaluateExpressionSafe(entity, "status == 'ACTIVE'", "java.lang.Boolean", false, false)
Returns:
true
- Throws:
ClassNotFoundException
-
trace
Writesmessageto the application log at TRACE level (the finest level, off in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request. Guard an expensive message withisTraceEnabled().- Parameters:
message- the line to log
Groovy example:
systemUtil.trace("Processing order " + entity.id)
Returns:
nothing; the line is written to the log
-
debug
Writesmessageto the application log at DEBUG level (off in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request. Guard an expensive message withisDebugEnabled().- Parameters:
message- the line to log
Groovy example:
systemUtil.debug("Processing order " + entity.id)
Returns:
nothing; the line is written to the log
-
info
Writesmessageto the application log at INFO level (on in normal operation), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request. Guard an expensive message withisInfoEnabled().- Parameters:
message- the line to log
Groovy example:
systemUtil.info("Processing order " + entity.id)
Returns:
nothing; the line is written to the log
-
warn
Writesmessageto the application log at WARN level (always on), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request. Guard an expensive message withisWarnEnabled().- Parameters:
message- the line to log
Groovy example:
systemUtil.warn("Processing order " + entity.id)
Returns:
nothing; the line is written to the log
-
error
Writesmessageto the application log at ERROR level (always on), under the loggercom.ssgllc.fish.service.util.registered.SystemUtil- that is the logger to enable when looking for these lines, and set-debug-logging is the quickest way to do it for one request. Guard an expensive message withisErrorEnabled().- Parameters:
message- the line to log
Groovy example:
systemUtil.error("Processing order " + entity.id)
Returns:
nothing; the line is written to the log
-
isTraceEnabled
public static boolean isTraceEnabled()Whether TRACE logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil. Use it to skip building a message that would be discarded.- Returns:
- true if the level is enabled
Groovy example:
if (systemUtil.isTraceEnabled()) { systemUtil.trace(bpmUtil.serializeObject(['orderId': 42, 'status': 'OPEN'])) }
Returns:
true when the level is on, so the serialisation only happens then
-
isDebugEnabled
public static boolean isDebugEnabled()Whether DEBUG logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil. Use it to skip building a message that would be discarded.- Returns:
- true if the level is enabled
Groovy example:
if (systemUtil.isDebugEnabled()) { systemUtil.debug(bpmUtil.serializeObject(['orderId': 42, 'status': 'OPEN'])) }
Returns:
true when the level is on, so the serialisation only happens then
-
isInfoEnabled
public static boolean isInfoEnabled()Whether INFO logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil. Use it to skip building a message that would be discarded.- Returns:
- true if the level is enabled
Groovy example:
if (systemUtil.isInfoEnabled()) { systemUtil.info(bpmUtil.serializeObject(['orderId': 42, 'status': 'OPEN'])) }
Returns:
true when the level is on, so the serialisation only happens then
-
isWarnEnabled
public static boolean isWarnEnabled()Whether WARN logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil. Use it to skip building a message that would be discarded.- Returns:
- true if the level is enabled
Groovy example:
if (systemUtil.isWarnEnabled()) { systemUtil.warn(bpmUtil.serializeObject(['orderId': 42, 'status': 'OPEN'])) }
Returns:
true when the level is on, so the serialisation only happens then
-
isErrorEnabled
public static boolean isErrorEnabled()Whether ERROR logging is currently enabled forcom.ssgllc.fish.service.util.registered.SystemUtil. Use it to skip building a message that would be discarded.- Returns:
- true if the level is enabled
Groovy example:
if (systemUtil.isErrorEnabled()) { systemUtil.error(bpmUtil.serializeObject(['orderId': 42, 'status': 'OPEN'])) }
Returns:
true when the level is on, so the serialisation only happens then
-
inspect
Logs a value at WARN and returns it unchanged, so it can be dropped into the middle of an expression or a chain without restructuring the code. WARN rather than DEBUG so the line appears without reconfiguring logging - which also means these calls are worth removing once the question is answered. Throws ifobjectis null, since it logsobject.toString().- Parameters:
object- the value to log- Returns:
- the same value
Groovy example:
def total = systemUtil.inspect(orderItems).sum { it.quantity }
Returns:
the collection, having logged it on the way through
SpEL example:
#inspect(#lineItems).size()
Returns:
the size, having logged the collection
-
isVectorSupported
public static boolean isVectorSupported()Whether this deployment's database supports vector columns, which today means PostgreSQL. Guard embedding and semantic-search work with this so the same configuration can run against a non-PostgreSQL database without failing.- Returns:
- true when the configured database is PostgreSQL
Groovy example:
if (!systemUtil.isVectorSupported()) { return }
Returns:
exits early where embeddings cannot be stored
SpEL example:
#isVectorSupported()
Returns:
true on PostgreSQL
-