Calling External Java Functions
There might be a situation where your model would need to use functionalities provided by other Java libraries. ajCustomFunction can be used to call a method in a Java class and return the result to a model. Such a call only happens in the compiled Java code. It does not call the Java method when you run a function point in AlchemyJ Studio. However, you can create a macro that simulates the corresponding return result of the Java method in VBA. For more details, you can refer to ajCustomFunction.
Example
Assuming there is a Jar file named "ajCustomFunctionExample" in D drive which provides a function called "howOldAmI". The function will take the year of birth (as integer) and return the age. The content in BizLogic!B5:D9 will be used as method parameters of the Jar. The parameter table was created via Insert Snippet\Function Parameters on the AlchemyJ ribbon.
The Jar file should be generated by a Maven based project and be installed into your Maven repository.
Get the following Maven information from the pom.xml file of the Jar file.
a. Maven Group ID: com.axisoft.alchemyj.test
b. Maven Artifact ID: ajCustomFunctionExample
c. Maven Version: 1.0.0
Refer to Write Your First REST API in the Get Started section to create an AlchemyJ workbook using the REST API Sample model.
Go to ##RestApi worksheet in the REST API sample model workbook.
In the section 'Maven Dependency', fill in the above Maven information of the Jar file and select 'compile' in the 'Scope' column.
- Go to Bizlogic worksheet, fill in the required parameter for ajCustomFunction. Update the table address in Output Schema table and set the position as 'left'.
- Go to ##RestEndpointGroup worksheet, modify the name of function point and set the method parameter BizLogic!B5 as input parameter.
- Click 'Generate API' to generate REST API and verify the function point 'endpointGroup/customfunction'. The result returned by the Jar will be shown in the response message.