External Groovy Libraries
External Groovy libraries are libraries that can be added into 1Gateway, these can be included into Groovy scripts using option.include(name)
External Groovy libraries cannot use the Groovy objects that can be used in 1Gateway Groovy scripts unless they are passed to the library, via an argument to a function for example.
How To Add a Library
To add external Groovy libraries to 1Gateway, click on the menu on the top left (the 3 horizontal lines), then on setup to go to the setup page and then click on choose a file and select the library, or drag and drop it instead.
Show Libraries
On the setup page, you can click on the arrow next to the Libraries text to show all the libraries you have added. There is a search bar on top, and a download button on the right of every library.
Example
In The Groovy Library
def getPluginConfig(option, name) {
url = "https://dev2.dev.1bonding.com/api/v3/plugin/" + name // url to get plugin configuration
return configres = option.rest.get(url)
}
This function is able to use the option 1Gateway Groovy object if it is passed to it in the option parameter.
In a Plugin
if (e.value.CurrentState == "error") {
util = option.include("1GatewayAPIUtil.groovy") // include library
configres = util.getPluginConfig(option, e.value.Plugin) // use library
configmap = parser.asMap(configres)
// add the result to the map
if (configmap != null)
e.value.put("config", configmap)
}
api.publish(e.value, "PluginStatus")
As shown in the example above, option.include(name) is used to include a library. It returns a Groovy object and in the example gets put in the variable util.
Since the functions in the library become the methods of the object, calling util.getPluginConfig(option, e.value.Plugin) calls the getPluginConfig defined in the library.
As mentioned above, it can only use the option Groovy object since it is passed as an argument to the function.