Creating a Project Function

How Do I Create a Project Function?

Fabric Project functions are user-defined Java functions that are added to the project implementation to perform complex data manipulations or to execute queries on a specific Instance ID.

Functions can be edited in the Fabric Studio by opening the function’s code from the Project Tree.

Functions can be created in Logical Units, References, Web Services, Shared Objects or from existing Table Populations (using an LuFunction Actor).

To create a new function, either open an existing Logic.java file under the Logical Unit or click on Logical Units > [LU Name] > Java > right click on src > New Java Logic File (when you want to create a new Category).

The Web Studio provides a snippet syntax helper: type Ctrl+Space and then type fabric for Fabric snippets. For functions you can type FF. This will show you several function types. Once you have selected a function, the syntax helper will offer you the syntax along with some options.

For example, selecting fabric-function-trigger will provide the following function template:

@desc("")
@type(TriggerFunction)
public static void functionName(TableDataChange tableDataChange) throws Exception {

}
  1. To create a function from an existing Table Population, go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] and double click [Population Name] to open the existing population. Then do either:
    • Right click in the working area and select Insert New Function.
    • Click the Objects tab in the right panel of the working area, select Functions and double click Create New Function.
    1. To create a function from the Project Tree do either:
    • Click Logical Units > [LU Name], right click Java > New Function.
    • Click Shared Objects > [LU Name], right click Java > New Function.

image

  1. Do the following to complete the function's creation:
    • Populate the Category or select the existing value from the dropdown list. The Category defines the function’s Java Logic file.
    • Populate the Function Type by selecting the value from the dropdown list.
    • (Optional) Populate the Description.
    • Define the function’s Input and Output settings either manually or automatically.
    • Type the function’s Java code to generate the code.
    • Click Save to display the New Item dialog box.
    • Complete the Name field and then click OK.

How Do I Define a Function's Parameters Manually?

The Function Manager window displays the following panes on the right of the window:

  • Input Parameters.
  • Output Parameters.

Both panes include the following components:

  • List panel, displays a list of the parameter’s Name, Data Type and Comments.
  • Text entry fields, displays the parameter’s Name, Data Type and Comments.

To define Input and Output settings manually, do the following:

  1. Complete the Name field.
  2. In the Data Type field either, select the Data Type from the dropdown list or type it in manually if the type is not displayed in the list.
  3. Optional: type comments in the Comment field.

How Do I Bulk Load Parameters to a Function Manually?

The Bulk Load Parameters option can be used to upload multiple parameters to a function.

  1. Right click the Input / Output Parameters pane to display the Input / Output Parameters dialog box.

image

  1. Click Bulk Load Parameters to display the Bulk Load Parameters dialog box.
  2. Enter the parameters and click OK to load them to the Parameters pane.

image

  1. (Optional) Modify the Data Type.

image

How Are a Function's Parameters Defined Automatically?

Input / Output settings can be automatically defined based on DB objects either from a source DB or LU objects using the Objects / Database pane in the Function Manager window.

  1. Go to the Objects / Database pane (left side) and click the Database tab.
  2. Click DB Connection and select the Interface from the dropdown menu (top of the pane).
  3. Click a Table in the database hierarchy.
  4. Right click the selected Column Names or the Table and select either Add Selected to Input Parameters or Add Selected to Output Parameters. New parameters are added to the parameters list in the Parameters pane. The new parameter’s name is the name of the column and data type is the column data type.

image

How Do I Update a Function's Parameters?

  1. Go to the Function Manager window.
  2. Click the Parameter in the Parameters List to edit the parameter’s Name, Type and Comments fields. The updated Input / Output parameter names are automatically applied to all occurrences of the parameter in the function’s Java code.

How Do I Delete a Function's Parameters?

  1. Select a parameter in the Parameter List.
  2. Press Delete on your keyboard or click the Delete icon next to the parameter to remove it from the parameters list.

How is Code Generated for a Function Automatically?

  1. Go to the Objects / Database pane (left of the Function Manager) and click the Database tab.
  2. Click DB Connection and select an Interface from the dropdown menu (top of the pane).
  3. Click a Table in the database hierarchy.
  4. Right click the Column Name(s) to use as the basis for the generated code and then select Generate Code.

Example of the code generated for the function with Input = CUSTOMER_ID from the CUSTOMER table:

String sql = "SELECT CUSTOMER_ID FROM CUSTOMER";
db("CRM_DB").fetch(sql, <val1>, <val2>, ...).each(row->{
});

Notes

  • The code generated in the above example acts as the basis for a function and should be further updated according to the function’s requirements.
  • When writing Java code, other Java methods can be used in addition to Fabric methods.
  • It is recommended to use binding parameters in SQL statements for prepared statements.

Click to display the Fabric API list: http://[Fabric IP address]:3213/static/doc/user-api/index.html

How Do I Invoke a Project Function From Another Category?

To invoke a project function from another category in the same LU, do the following to add an import:

  1. Open the function using IntelliJ.
  2. Position the mouse on the invoked function (marked in red), press ALT+ENTER and select the option to add the required import.
  3. Save the function.

To see the import, open the source file of the function's category. For example, when adding an invocation to the fnCheckSourceEnv() function which belongs to the DECISION category in the CRM Logical Unit, the following import is added:

import static com.k2view.cdbms.usercode.lu.CRM.DECISION.Logic.fnCheckSourceEnv;

To invoke several functions in the same category, modify the import as follows:

import static com.k2view.cdbms.usercode.lu.CRM.DECISION.Logic.*;

Previous

Creating a Project Function

How Do I Create a Project Function?

Fabric Project functions are user-defined Java functions that are added to the project implementation to perform complex data manipulations or to execute queries on a specific Instance ID.

Functions can be edited in the Fabric Studio by opening the function’s code from the Project Tree.

Functions can be created in Logical Units, References, Web Services, Shared Objects or from existing Table Populations (using an LuFunction Actor).

To create a new function, either open an existing Logic.java file under the Logical Unit or click on Logical Units > [LU Name] > Java > right click on src > New Java Logic File (when you want to create a new Category).

The Web Studio provides a snippet syntax helper: type Ctrl+Space and then type fabric for Fabric snippets. For functions you can type FF. This will show you several function types. Once you have selected a function, the syntax helper will offer you the syntax along with some options.

For example, selecting fabric-function-trigger will provide the following function template:

@desc("")
@type(TriggerFunction)
public static void functionName(TableDataChange tableDataChange) throws Exception {

}
  1. To create a function from an existing Table Population, go to Project Tree > Logical Units > [LU Name] > Tables > [Table Name] and double click [Population Name] to open the existing population. Then do either:
    • Right click in the working area and select Insert New Function.
    • Click the Objects tab in the right panel of the working area, select Functions and double click Create New Function.
    1. To create a function from the Project Tree do either:
    • Click Logical Units > [LU Name], right click Java > New Function.
    • Click Shared Objects > [LU Name], right click Java > New Function.

image

  1. Do the following to complete the function's creation:
    • Populate the Category or select the existing value from the dropdown list. The Category defines the function’s Java Logic file.
    • Populate the Function Type by selecting the value from the dropdown list.
    • (Optional) Populate the Description.
    • Define the function’s Input and Output settings either manually or automatically.
    • Type the function’s Java code to generate the code.
    • Click Save to display the New Item dialog box.
    • Complete the Name field and then click OK.

How Do I Define a Function's Parameters Manually?

The Function Manager window displays the following panes on the right of the window:

  • Input Parameters.
  • Output Parameters.

Both panes include the following components:

  • List panel, displays a list of the parameter’s Name, Data Type and Comments.
  • Text entry fields, displays the parameter’s Name, Data Type and Comments.

To define Input and Output settings manually, do the following:

  1. Complete the Name field.
  2. In the Data Type field either, select the Data Type from the dropdown list or type it in manually if the type is not displayed in the list.
  3. Optional: type comments in the Comment field.

How Do I Bulk Load Parameters to a Function Manually?

The Bulk Load Parameters option can be used to upload multiple parameters to a function.

  1. Right click the Input / Output Parameters pane to display the Input / Output Parameters dialog box.

image

  1. Click Bulk Load Parameters to display the Bulk Load Parameters dialog box.
  2. Enter the parameters and click OK to load them to the Parameters pane.

image

  1. (Optional) Modify the Data Type.

image

How Are a Function's Parameters Defined Automatically?

Input / Output settings can be automatically defined based on DB objects either from a source DB or LU objects using the Objects / Database pane in the Function Manager window.

  1. Go to the Objects / Database pane (left side) and click the Database tab.
  2. Click DB Connection and select the Interface from the dropdown menu (top of the pane).
  3. Click a Table in the database hierarchy.
  4. Right click the selected Column Names or the Table and select either Add Selected to Input Parameters or Add Selected to Output Parameters. New parameters are added to the parameters list in the Parameters pane. The new parameter’s name is the name of the column and data type is the column data type.

image

How Do I Update a Function's Parameters?

  1. Go to the Function Manager window.
  2. Click the Parameter in the Parameters List to edit the parameter’s Name, Type and Comments fields. The updated Input / Output parameter names are automatically applied to all occurrences of the parameter in the function’s Java code.

How Do I Delete a Function's Parameters?

  1. Select a parameter in the Parameter List.
  2. Press Delete on your keyboard or click the Delete icon next to the parameter to remove it from the parameters list.

How is Code Generated for a Function Automatically?

  1. Go to the Objects / Database pane (left of the Function Manager) and click the Database tab.
  2. Click DB Connection and select an Interface from the dropdown menu (top of the pane).
  3. Click a Table in the database hierarchy.
  4. Right click the Column Name(s) to use as the basis for the generated code and then select Generate Code.

Example of the code generated for the function with Input = CUSTOMER_ID from the CUSTOMER table:

String sql = "SELECT CUSTOMER_ID FROM CUSTOMER";
db("CRM_DB").fetch(sql, <val1>, <val2>, ...).each(row->{
});

Notes

  • The code generated in the above example acts as the basis for a function and should be further updated according to the function’s requirements.
  • When writing Java code, other Java methods can be used in addition to Fabric methods.
  • It is recommended to use binding parameters in SQL statements for prepared statements.

Click to display the Fabric API list: http://[Fabric IP address]:3213/static/doc/user-api/index.html

How Do I Invoke a Project Function From Another Category?

To invoke a project function from another category in the same LU, do the following to add an import:

  1. Open the function using IntelliJ.
  2. Position the mouse on the invoked function (marked in red), press ALT+ENTER and select the option to add the required import.
  3. Save the function.

To see the import, open the source file of the function's category. For example, when adding an invocation to the fnCheckSourceEnv() function which belongs to the DECISION category in the CRM Logical Unit, the following import is added:

import static com.k2view.cdbms.usercode.lu.CRM.DECISION.Logic.fnCheckSourceEnv;

To invoke several functions in the same category, modify the import as follows:

import static com.k2view.cdbms.usercode.lu.CRM.DECISION.Logic.*;

Previous