Package de.ubs.xdm.utils.modification
Class ScriptContext
java.lang.Object
de.ubs.xdm.utils.modification.ScriptContext
- Direct Known Subclasses:
ModificationContext
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionObject[]buildObjectArray(Object... arr) Utility function that accepts several objects and returns a java array as result that can be used in the mapping functions.callRestEndpoint(String url) calls the named URL with GET and returns the response body.callRestEndpoint(String url, String method, String requestLoad) calls the named URL with method and returns the response body.callRestEndpoint(String url, String method, String requestLoad, Object headersMap) calls the named URL with method and returns the response body.calls the named URL with method and returns the response body.callRestEndpoint(String url, String method, String requestLoad, Map<String, String> headersMap, String proxyUrl) calls the named URL with method and returns the response body.callRestEndpoint(String url, String method, String requestLoad, Map<String, String> headersMap, String proxyUrl, boolean trustAll) calls the named URL with method and returns the response body.nl.flotsam.xeger.XegercreateXeger(String pattern) Creates a reverse Regex object.generateValueByRegexPattern(String pattern) Allows the user to specify a regular expression pattern with which this function will generate a random value matching this regular expression.static FilegetLibraryFileName(String filename) protected StringgetTaskRuntimeProperty(String value) Retrieves a runtime property set to the task execution (e.g. runtime parameter by a script call on run-task.sh or via XDM WebPortal)getTaskRuntimeProperty(String value, String defaultValue) Retrieves a runtime property set to the task execution (e.g. runtime parameter by a script call on run-task.sh or via XDM WebPortal)getXmlAsString(Clob clob) Returns an object from the data array that has datatype XML in the database as plain stringgetXmlXPath(String xmlContent, String path, String type) getXmlXPathValue(String xmlContent, String path) Retrieves a value from an XML column specified by an XPath expressiongetXmlXPathValue(Clob clob, String path) Retrieves a value from an XML column specified by an XPath expressionprotected abstract voidloadLibrary(InputStream jslibReader, String filename) phoneNumber(String pattern) does the same as generateValueByRegexPattern(pattern)phoneticEncryption(String input, String secret) Performs the phonetic encryption method.voidPrints a message to the console in INFO level.voidPrints a message to the console.removeXmlPathTag(String xmlContent, String path) removes the tag specified by the XPath.voidThis method imports an external javascript library from the {inst.dir}/global_jslib directory into the code of the current modification method.setXmlXPathValue(String xmlContent, String path, String newValue) Changes the value at the position specified by the path and returns the new XML content with the changes applied.Shifts a date by an amount of time units generated from the input parameters.static DateshiftDateSt(Date input, int amount, String unit) INTERNAL USEString[]Splits the given string containing space separators and returns an array of trimmed substrings.wrapStringIntoClob(String xmlContent) Repacks a string into an CLOB object that will be used in XDM internal processing.
-
Field Details
-
xegersMap
-
-
Constructor Details
-
ScriptContext
public ScriptContext()
-
-
Method Details
-
shiftDateSt
INTERNAL USE- Parameters:
input- a date to be shiftedamount- The maximum amount of units the day should be shiftedunit- one of DAYS, MONTHS, YEARS as string value- Returns:
- Resulting Date
-
print
Prints a message to the console in INFO level. Name of modification method and table will be added to the log message- Parameters:
message- the message to be printed
-
print
Prints a message to the console. Name of modification method and table will be added to the log message- Parameters:
level- one of SEVERE, WARNING, INFO, FINE, FINERmessage- the message to be printed
-
getLogContext
-
require
This method imports an external javascript library from the {inst.dir}/global_jslib directory into the code of the current modification method. If there is a need to use a common or global javascript file or library in code of the current method then simply import it withctx.require(filename).- Parameters:
filename- the global javascript library to be imported.
-
getLibraryFileName
-
loadLibrary
- Throws:
IOException
-
phoneticEncryption
Performs the phonetic encryption method. This method takes a character variable as string, encrypts this with a triple-AES algorithm using the given secret and then represents the resulting bytes as a human readable string with alternating vocals and consonants. This method will always return the same output for identical input parameter and secret.- Parameters:
input- the string to encryptsecret- the secret to use- Returns:
- the encrypted string
-
buildObjectArray
Utility function that accepts several objects and returns a java array as result that can be used in the mapping functions.- Parameters:
arr- - List of objects.- Returns:
- Object[]
-
shiftDate
Shifts a date by an amount of time units generated from the input parameters. The method guarantees that the returned date is always the same, when the same input values are used.- Parameters:
input- The date value from the source tableamount- The maximum amount of units the day should be shiftedunit- one of DAYS, MONTHS, YEARS as string value- Returns:
- java.util.Date
-
splitTrim
Splits the given string containing space separators and returns an array of trimmed substrings.- Parameters:
str- the string to be split- Returns:
- an array of splits
-
phoneNumber
does the same as generateValueByRegexPattern(pattern)- Parameters:
pattern- the pattern to be used- Returns:
- a generated number
-
generateValueByRegexPattern
Allows the user to specify a regular expression pattern with which this function will generate a random value matching this regular expression. The regular expressions should be built according the rules defined in the Java Pattern class.- Parameters:
pattern- Regular expression- Returns:
- Object
-
createXeger
Creates a reverse Regex object. This can generate String matching a certain regular expression.- Parameters:
pattern- the regular expression all generated values should match- Returns:
- An object that can be used as described here: https://github.com/bluezio/xeger
-
getXmlAsString
Returns an object from the data array that has datatype XML in the database as plain string- Parameters:
clob- the original value from the object array- Returns:
- the content asstring
-
getXmlXPathValue
Retrieves a value from an XML column specified by an XPath expression- Parameters:
clob- the original value from the datapath- a Xpath- Returns:
- The Object resulting from the xpath evaluation
-
getXmlXPathValue
Retrieves a value from an XML column specified by an XPath expression- Parameters:
xmlContent- the xml as stringpath- a Xpath- Returns:
- The Object resulting from the xpath evaluation
-
getXmlXPath
-
setXmlXPathValue
Changes the value at the position specified by the path and returns the new XML content with the changes applied.- Parameters:
xmlContent- The XML as stringpath- a xpath expression to identify the valuenewValue- The value to be set- Returns:
- String The resulting XML as string
-
removeXmlPathTag
removes the tag specified by the XPath. Returns the newly generated XML as a string.- Parameters:
xmlContent- the XML as stringpath- an xpath- Returns:
- String resulting content after removal
-
wrapStringIntoClob
Repacks a string into an CLOB object that will be used in XDM internal processing. If you want to pass an XML object back to data you need to wrap it with this method.- Parameters:
xmlContent- The XML content as string- Returns:
- The XMl content as CLOB object
-
getTaskRuntimeProperty
Retrieves a runtime property set to the task execution (e.g. runtime parameter by a script call on run-task.sh or via XDM WebPortal)- Parameters:
value- the name of the runtime property- Returns:
- the value of the runtime property or null if missing
-
getTaskRuntimeProperty
Retrieves a runtime property set to the task execution (e.g. runtime parameter by a script call on run-task.sh or via XDM WebPortal)- Parameters:
value- the name of the runtime propertydefaultValue- the value to be returned if missing- Returns:
- the value of the runtime property or defaultValue if missing
-
callRestEndpoint
calls the named URL with GET and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be called- Returns:
- The response body as string
-
callRestEndpoint
calls the named URL with method and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be calledmethod- The HTTP Method to be used ("GET", "POST" ...)requestLoad- The content of the POST request- Returns:
- The response body as string
-
callRestEndpoint
calls the named URL with method and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be calledmethod- The HTTP Method to be used ("GET", "POST" ...)requestLoad- The content of the POST requestheadersMap- convenience type to call with java script array ( { "Authorization": "Basic abc", ...} )- Returns:
- The response body as string
-
callRestEndpoint
public String callRestEndpoint(String url, String method, String requestLoad, Map<String, String> headersMap) calls the named URL with method and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be calledmethod- The HTTP Method to be used ("GET", "POST" ...)requestLoad- The content of the POST requestheadersMap- The header as java.util.Map- Returns:
- The response of the call as string
-
callRestEndpoint
public String callRestEndpoint(String url, String method, String requestLoad, Map<String, String> headersMap, String proxyUrl) calls the named URL with method and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be calledmethod- The HTTP Method to be used ("GET", "POST" ...)requestLoad- The content of the POST requestheadersMap- The header as java.util.MapproxyUrl- a HTTP(S) proxy to use to perform the call- Returns:
- The response of the call as string
-
callRestEndpoint
public String callRestEndpoint(String url, String method, String requestLoad, Map<String, String> headersMap, String proxyUrl, boolean trustAll) calls the named URL with method and returns the response body. Throws exception if call is unsuccessful- Parameters:
url- the URL of the endpoint to be calledmethod- The HTTP Method to be used ("GET", "POST" ...)requestLoad- The content of the POST requestheadersMap- The header as java.util.MapproxyUrl- a HTTP(S) proxy to use to perform the calltrustAll- skips the certificate check for HTTPS connections- Returns:
- The response of the call as string
-