Calling External Java Functions
There might be a situation where your model would need to use functionalities provided by other Java libraries. ajCallFunction can be used to call a method in a Java class and return the result to Excel. Such call only happens in the compiled Java code. It does not call the Java method when you run a function point in AlchemyJ Studio. You can, however, create a macro that simulates the corresponding return result of the Java method in VBA. For more details, you can refer to ajCallFunction.
Assuming there is a Jar file named "ajCallFunctionExample" in D drive which provides a function called "howOldAmI". The function will take the year of birth (as integer) and return the age. The parameter string YearOfBirth-##-1990-##-Integer is used as the method parameter. It means passing 1990, which is an integer, to the parameter YearOfBirth.
The Jar file should be generated by Maven based project and installed into your Maven repository.
Get following Maven information from the pom.xml file of the Jar file. a. Maven Group ID: com.axisoft.alchemyj.test b. Maven Artifact ID: ajCallFunctionExample c. Maven Version: 1.0.0
Create an AlchemyJ workbook using REST API Sample model, refer to Write Your First REST API in Get Started section.
Go to ##RestApi worksheet in the REST API sample model workbook.
In section 'Maven Dependency', fill in above Maven information of the Jar file and select 'compile' in 'Scope' column.
- Go to 'Bizlogic' worksheet, fill in the required parameter for ajCallFunction.
- Modify the 'BizLogic' cell B2 formula as below.
- Click 'Generate API' to generate REST API and verify the function point 'endpointGroup/resource1' test result. It is expected that the result shall have wording '30' appended in the input_parameter_1.