LSPS documentation logo
LSPS Documentation
Custom Functions

In LSPS, a function is declared in a function definition file. The file can be then distributed in a library module to allow other users to make use of the function.

Once declared a function can be implemented in Java or in the Expression Language. For Java implementation, you will need to create and deploy a class with the method that the function will call, while if using the Expression Language the expression is defined directly in the function definition.

Creating a Custom Function

To create a custom function with implementation in Java or the Expression Language, do the following:

  1. In the Modeling perspective, create or open a function definition file.
  2. Add a new function and define the function main details:

    • Name: name used to call the function
    • Return type: data type of the return value
    • Generic types: comma-separated list of abstractions of data types used in parameters

      Generic types allow functions to operate over a parameter that can be of various data types (not only a single data type) in different calls. The concept is based on generics as used in Java. You can also make a generic data type extend another data type with the extends keyword. The syntax is then <generic_type_1> extends <type1>, <generic_type_2> extends <type2> (for details, refer to the Expression Language User Guide).

    • Public: function visibility
    • Variadic: function arity

      A function is variadic if its last parameter can be declared variadic, that is, zero or more occurrences of that last parameter are allowed.

    • Has side effects: if true, on validation, the info notification about the function having a side effect is suppressed

      A function is considered to have side effects if one of the following is true:

      • The function modifies a variable outside of the function scope.
      • The function creates a shared record.
      • The function modifies a record field.
      • The function calls a function that causes a side effect.
    • Deprecated: if true, on validation, a notification about that the called function is deprecated is displayed.
    functionDefinition.png
    Example Function with Generic Parameters
  3. Define the input parameters. For every parameter you need to define the following:
    • Name: parameter name unique within the function declaration
    • Type: data type of the parameter
    • Required: if checked, every function calls must define the parameter. The required property does not provide any additional runtime check of the parameter value.
    • Description: optional description of the parameter

      Note: Functions can be overloaded: functions with the same name but different parameters are considered different functions.

  4. Define the implementation:
    • Expression: function implementation in the Expression Language
      new ITEmployee(
      Name -> &newEmployee.name,
      Birthdate -> &newEmployee.birthdate,
      Salary -> "You need to set the salary",
      CurrentPosition -> getPosition(newEmployee);
      return true)
    • Java method implementation: define the path to the method that implements the function (package, class, and method name)
      org.example.eko.Systemutils.getWeekday
  5. In the ejb project of your application, create the package and class with the method.
  6. Deploy the implementation as part of your Application User Interface.

You can now use the function call in your Module. Consider distributing the Module with the function declaration as a library.