Interface WorkflowUtilityFunctions


public interface WorkflowUtilityFunctions
Utility functions to be used in expressions in turiya workflows.

Example: ${util.env()}

Example: ${util.randomUUID()}

Example: ${util.randomInt(10)}

  • Method Details

    • env

      String env()
      Returns current environment (qa, prod)
      Returns:
      current environment
    • isProd

      boolean isProd()
      Returns true if current environment is prod, false otherwise.
      Returns:
      true if running in prod environment, false otherwise.
    • randomUUID

      String randomUUID()
      generates a random UUID.
      Returns:
      A randomly generated UUID
    • randomInt

      int randomInt(int bound)
      generates a pseudorandom number between 0 (inclusive) and the specified bound (exclusive).
      Parameters:
      bound - the upper bound (exclusive). Must be positive.
      Returns:
      a randomly (pseudorandom) generated integer.
    • merge

      void merge(String dest, String source)
      merges two map like values represented by the variable names specified. values in source are added onto dest. source remains unchanged.
      Parameters:
      dest - name of the destination process variable
      source - name of the source process variable
    • setInParentScope

      void setInParentScope(String variableName)
      propagates the value of the given variable to the immediate parent scope.
      Parameters:
      variableName - name of the variable to propagate to the parent scope.
    • get

      Object get(String variableName)
      returns the value of the given variable if it exists or null if it doesn't. useful when the variable may or may not exist.
      Parameters:
      variableName - name of the variable.
    • get

      Object get(String variableName, Object defaultValue)
      returns the value of the given variable if it exists or defaultValue if it doesn't. useful when the variable may or may not exist.
      Parameters:
      variableName - name of the variable.
    • set

      void set(String dest, String name, Object value)
      sets a property in a map like value represented by 'dest'.
      Parameters:
      dest - process variable representing a map.
      name - name of the new (or existing) map entry to add/overwrite.
      value - value of the new entry.
    • remove

      void remove(String dest, String... keys)
      removes one or more entries in a map like value represented by 'dest'.
      Parameters:
      dest - process variable representing a map.
      keys - keys in map whose entries will be removed.
    • setVariableLocalTransient

      void setVariableLocalTransient(String name, Object value)
      sets a transient local variable value in current scope. the variable is not persisted in database and is a good fit for use-and-throw variables.
      Parameters:
      name - name of the new variable
      value - value of the new variable
    • appendValueToList

      void appendValueToList(String variableName, String listName)
      appends a variable value to a list represented by 'listName'. list will be created if it doesn't exist.
      Parameters:
      variableName - name of variable holding the value to be added to the list.
      listName - name of the variable for the destination list
    • appendLocalValueToList

      void appendLocalValueToList(String variableName, String listName)
      appends a local variable value to a list represented by 'listName'. list will be created if it doesn't exist.
      Parameters:
      variableName - name of variable holding the value to be added to the list.
      listName - name of the variable for the destination list
    • appendValuesToList

      void appendValuesToList(String src, String dest)
      appends values from 'src' list to 'dest' list. 'dest' list will be created if it doesn't exist.
      Parameters:
      src - name of variable representing the source list.
      dest - name of variable representing the destination list.

      Note: value of src variable has to be a list. If it's not, it will just be added as a single entry to the destination.

    • appendLocalValuesToList

      void appendLocalValuesToList(String src, String dest)
      appends values from 'src' local list to 'dest' list. 'dest' list will be created if it doesn't exist.
      Parameters:
      src - name of variable representing the source list.
      dest - name of variable representing the destination list.

      Note: value of src variable has to be a list. If it's not, it will just be added as a single entry to the destination.

    • addToList

      void addToList(String listName, Object... values)
      adds value(s) to 'listName' list. 'listName' list will be created if it doesn't exist.
      Parameters:
      listName - name of variable representing the destination list.
      values - the values(s) to add.
    • toSet

      void toSet(String src, String dest)
      creates a new 'dest' set from 'src' list.
      Parameters:
      src - name of variable representing the source list.
      dest - name of variable representing the destination set.

      Note: value of src variable has to be a list. If it's not, it will just be added as a single entry to the destination.

    • toDate

      LocalDate toDate(String date)
      converts a string of pattern yyyy-MM-dd to a date object.
      Parameters:
      date - the date string (Ex: 2022-02-24)
      Returns:
      an immutable object representing the provided date. can be used to perform date related operations.

      See also LocalDate

    • toDate

      LocalDate toDate(String date, String pattern)
      converts a string of the given pattern to a date object.
      Parameters:
      date - the date string (Ex: 2022-02-24)
      pattern - the pattern of the provided date. See DateTimeFormatter for pattern specification.
      Returns:
      an immutable object representing the provided date. can be used to perform date related operations.

      See also LocalDate See also DateTimeFormatter

    • toDateTime

      OffsetDateTime toDateTime(String dateTime)
      converts a string of pattern yyyy-MM-dd'T'HH:mm:ss.SSS to a dateTime object.
      Parameters:
      dateTime - the date-time string (Ex: 2022-02-24T09:15:07+05:30)
      Returns:
      an immutable object representing the provided date-time. can be used to perform date related operations.

      See also OffsetDateTime

    • toDateTime

      OffsetDateTime toDateTime(String dateTime, String pattern)
      converts a string of given pattern to a dateTime object.
      Parameters:
      dateTime - the date-time string (Ex: 2022-02-24T09:15:07+05:30)
      pattern - the pattern of the provided date-time. See DateTimeFormatter for pattern specification.
      Returns:
      an immutable object representing the provided date-time. can be used to perform date related operations.

      See also OffsetDateTime See also DateTimeFormatter

    • periodDiff

      Period periodDiff(LocalDate start, LocalDate end)
      calculates the period between two date objects. can be used to calculate the interval between two dates in various supported units.
      Parameters:
      start - the start date
      end - the end date
      Returns:
      the period between the provided dates

      See also Period

    • dateDiff

      Duration dateDiff(LocalDate start, LocalDate end)
      calculates the duration between two date objects. can be used to calculate the interval between two dates in various supported units.
      Parameters:
      start - the start date
      end - the end date
      Returns:
      the duration between the provided dates

      See also Duration

    • dateTimeDiff

      Duration dateTimeDiff(Temporal start, Temporal end)
      calculates the duration between two date-time objects. can be used to calculate the interval between two date-times in various supported units.
      Parameters:
      start - the start date
      end - the end date
      Returns:
      the duration between the provided dates

      See also Duration

    • userRoles

      Set<String> userRoles()
      gets the roles assigned to the user in current synchronous transaction context
      Returns:
      user's roles
      Throws:
      IllegalStateException - when invoked in an asynchronous transaction
    • userClaim

      @Nullable Object userClaim(String claim)
      gets the value of the specified user claim
      Parameters:
      claim - the name of the claim
      Returns:
      the claim value
      Throws:
      IllegalStateException - when invoked in an asynchronous transaction
    • allowedChildBusinessKeys

      Set<String> allowedChildBusinessKeys()
      gets the allowedChildBusinessKeys claim from user's token
      Returns:
      user's allowedChildBusinessKeys claim
      Throws:
      IllegalStateException - when invoked in an asynchronous transaction
    • toLong

      long toLong(String number)
      Converts a numeric string to a long number.
      Parameters:
      number - the number to convert
      Returns:
      the converted number
    • formatNumber

      String formatNumber(String pattern, Number number)
      Formats a number based on the pattern specified. The number can be any subclass of Number.
      Parameters:
      pattern - the pattern as defined in DecimalFormat
      number - the number to format
      Returns:
      the formatted string
    • urlEncode

      String urlEncode(String value)
      Encodes the given UTF-8 string to a URL-safe format.
      Parameters:
      value - input string
      Returns:
      URL safe equivalent of the input string
    • urlDecode

      String urlDecode(String value)
      Decodes the given URL-encoded UTF-8 string.
      Parameters:
      value - URL encoded input string
      Returns:
      Decoded string
    • userAgentInfo

      com.protium.apps.turiya.engine.publisher.UserAgentInfo userAgentInfo()
      Gets user agent info for current request.
      Returns:
      The user agent info.
    • jsonPath

      Object jsonPath(Object object, String jsonPath)
      Evaluates the given jsonpath against the object provided.

      Note: Use this only when absolutely required. Using this in hot workflow paths may result in performance degradation in highly concurrent systems.

      Parameters:
      object - the object on which the jsonpath expression is to be evaluated.
      jsonPath - the jsonpath expression to be evaluated.
    • jumpTo

      void jumpTo(String stageId)
      Jumps to the specified stage id.
      Parameters:
      stageId - the id of the stage to jump to
    • getCurrentStageId

      String getCurrentStageId()
      Gets the unique ID of the current stage.
    • sendMessage

      void sendMessage(String message)
      Send the specified message.
      Parameters:
      message - the name of the message to be sent.
    • extAuth

      AuthenticationResult extAuth(String authenticatorName, String userNameVariable, String passwordVariable, String... extraClaims)
      Authenticates external users using an external authenticator.
      Parameters:
      authenticatorName - name of the authenticator
      userNameVariable - variable that holds the userName
      passwordVariable - variable (transient) that holds the password
      extraClaims - additional claims to include in response
    • authenticate

      AuthenticationResult authenticate(String authenticatorName, String userNameVariable, String passwordVariable, Collection<String> extraClaims)
      Authenticates external users using an external authenticator.

      Note: this is same as 'extAuth' but accepts a collection of extra claims

      Parameters:
      authenticatorName - name of the authenticator
      userNameVariable - variable that holds the userName
      passwordVariable - variable (transient) that holds the password
      extraClaims - additional claims to include in response