Class ScriptContext

java.lang.Object
de.ubs.xdm.utils.modification.ScriptContext
Direct Known Subclasses:
ModificationContext

public abstract class ScriptContext extends Object
  • Field Details

    • xegersMap

      public Map<String,nl.flotsam.xeger.Xeger> xegersMap
  • Constructor Details

    • ScriptContext

      public ScriptContext()
  • Method Details

    • shiftDateSt

      public static Date shiftDateSt(Date input, int amount, String unit)
      INTERNAL USE
      Parameters:
      input - a date to be shifted
      amount - The maximum amount of units the day should be shifted
      unit - one of DAYS, MONTHS, YEARS as string value
      Returns:
      Resulting Date
    • print

      public void print(String message)
      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

      public void print(String level, String message)
      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, FINER
      message - the message to be printed
    • getLogContext

      protected String getLogContext()
    • require

      public void require(String filename)
      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 with ctx.require(filename).
      Parameters:
      filename - the global javascript library to be imported.
    • getLibraryFileName

      @NotNull public static File getLibraryFileName(String filename)
    • loadLibrary

      protected abstract void loadLibrary(InputStream jslibReader, String filename) throws IOException
      Throws:
      IOException
    • phoneticEncryption

      public String phoneticEncryption(String input, String secret)
      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 encrypt
      secret - the secret to use
      Returns:
      the encrypted string
    • buildObjectArray

      public Object[] buildObjectArray(Object... arr)
      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

      public Date shiftDate(Date input, int amount, String unit)
      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 table
      amount - The maximum amount of units the day should be shifted
      unit - one of DAYS, MONTHS, YEARS as string value
      Returns:
      java.util.Date
    • splitTrim

      public String[] splitTrim(String str)
      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

      public Object phoneNumber(String pattern)
      does the same as generateValueByRegexPattern(pattern)
      Parameters:
      pattern - the pattern to be used
      Returns:
      a generated number
    • generateValueByRegexPattern

      public 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. The regular expressions should be built according the rules defined in the Java Pattern class.
      Parameters:
      pattern - Regular expression
      Returns:
      Object
    • createXeger

      public nl.flotsam.xeger.Xeger createXeger(String pattern)
      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

      public String getXmlAsString(Clob clob)
      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

      public Object getXmlXPathValue(Clob clob, String path)
      Retrieves a value from an XML column specified by an XPath expression
      Parameters:
      clob - the original value from the data
      path - a Xpath
      Returns:
      The Object resulting from the xpath evaluation
    • getXmlXPathValue

      public Object getXmlXPathValue(String xmlContent, String path)
      Retrieves a value from an XML column specified by an XPath expression
      Parameters:
      xmlContent - the xml as string
      path - a Xpath
      Returns:
      The Object resulting from the xpath evaluation
    • getXmlXPath

      public Object getXmlXPath(String xmlContent, String path, String type)
    • setXmlXPathValue

      public String 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.
      Parameters:
      xmlContent - The XML as string
      path - a xpath expression to identify the value
      newValue - The value to be set
      Returns:
      String The resulting XML as string
    • removeXmlPathTag

      public String removeXmlPathTag(String xmlContent, String path)
      removes the tag specified by the XPath. Returns the newly generated XML as a string.
      Parameters:
      xmlContent - the XML as string
      path - an xpath
      Returns:
      String resulting content after removal
    • wrapStringIntoClob

      public Clob wrapStringIntoClob(String xmlContent)
      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

      public String getTaskRuntimeProperty(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)
      Parameters:
      value - the name of the runtime property
      Returns:
      the value of the runtime property or null if missing
    • getTaskRuntimeProperty

      public String 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)
      Parameters:
      value - the name of the runtime property
      defaultValue - the value to be returned if missing
      Returns:
      the value of the runtime property or defaultValue if missing
    • callRestEndpoint

      public String callRestEndpoint(String url)
      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

      public String callRestEndpoint(String url, String method, String requestLoad)
      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 called
      method - The HTTP Method to be used ("GET", "POST" ...)
      requestLoad - The content of the POST request
      Returns:
      The response body as string
    • callRestEndpoint

      public String callRestEndpoint(String url, String method, String requestLoad, Object 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 called
      method - The HTTP Method to be used ("GET", "POST" ...)
      requestLoad - The content of the POST request
      headersMap - 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 called
      method - The HTTP Method to be used ("GET", "POST" ...)
      requestLoad - The content of the POST request
      headersMap - 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 called
      method - The HTTP Method to be used ("GET", "POST" ...)
      requestLoad - The content of the POST request
      headersMap - The header as java.util.Map
      proxyUrl - 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 called
      method - The HTTP Method to be used ("GET", "POST" ...)
      requestLoad - The content of the POST request
      headersMap - The header as java.util.Map
      proxyUrl - a HTTP(S) proxy to use to perform the call
      trustAll - skips the certificate check for HTTPS connections
      Returns:
      The response of the call as string