Groovy is an extension of the Java programming language. It supports Java-like agile and dynamic programming without having to rebuild the application.
In N4, you can use Groovy code to perform additional tasks, such as recording an additional service event when N4 processes a notice request or gate transaction.
For more information on the Groovy programming language, go to http://groovy-lang.org.
You can use a Groovy code compiler to check your code for errors. For information, go to http://docs.groovy-lang.org/latest/html/documentation/#_compiling_groovy.
Within N4, there are different execution methods for Groovy plug-ins:
Groovy hooks: Groovy hooks exist throughout N4. They look for and run Groovy plug-ins with a specific name. N4 automatically loads and treats a Groovy hook as a business flow interceptor that is invoked at a particular point in the application flow, allowing extra validations. You can use Groovy hooks for TDB unit validations and substitutions, custom RDT validations, Navis N4 Mobile Reefer Monitor, Navis N4 Mobile Yard Inventory Generic Web Services, to cancel truck transactions, and so on. For a list of all Groovy hooks currently available in N4 code, see the Navis N4: SDK documentation. (on page 1)
To make use of a Groovy hook, you create a Groovy plug-in and name it as per the desired injection point. For example, if you want to inject Groovy code before the tbdunits validations, you should name the Groovy hook TbdUnitValidationGroovyImpl. Sample plug-ins are also available in the Navis N4: SDK documentation.
Groovy events: Execute directly injected Groovy code when a specific event occurs.
You can attach:
Custom events to units, vessel visits, train visits, equipment, truck visits, appointments, bookings, and so on
General Notices to custom events
Groovy to General Notices to create, update, and delete data
To attach a Groovy plug-in to an event, check in the Event Types view if the specific event type is notifiable. If it is, go to the General Notices view and create a general notice for the specific event type, where the action to perform is Execute Code. Then, in the designated text field, specify the name of the Groovy plug-in as api.getGroovyClassInstance("<PlugInName>").execute(event), such as api.getGroovyClassInstance("SendWQContents").execute(event).
Gate business tasks: Execute directly injected Groovy code during a specific business task at the gate, such as at the truck visit or truck transaction level.
To attach a Groovy plug-in to a business task, you create the Groovy plug-in in the Groovy plug-ins view (on page 1). Then, in the Gate Configurations view, in the Tran Type or Trk Visit form, click Edit Business Tasks. In the Business Tasks form, select the business task to which you want to attach the Groovy plug-in and select Actions Customize. In the form that opens, the following code to call the plug-in:
def myGroovy = api.getGroovyClassInstance("<Plug-InName>")
myGroovy.execute(inDao)
myGroovy = null
Groovy code injections: Groovy code snippets directly inserted into N4 and executed by an external command sent through a Web service or JMS message. Executing Groovy code via Web service or JMS message makes it possible to invoke Groovy externally and allow integration with external applications. In addition, Web services Groovy augments the existing basic API calls, such as Holds/Permissions Update (HPU), Incremental Container Update (ICU), and Gate SDK, and allows you to combine several actions into one unit of work.
You can use Groovy code injections for TBD unit validations, Navis N4 Mobile Reefer Monitor, and gate workflow transaction manager. For example, the gate operating system (GOS) can run a validation when a truck passes a certain area. In this case, the GOS would run a Web service or JMS message that includes the name of the Groovy plug-in.
To make use of Groovy code injections, you create the Groovy plug-in in the Groovy plug-ins view and then provide the external application with the name of the plug-in to execute.
For more information, see "Groovy Code Injection" in the Navis N4: SDK documentation.
Groovy jobs: Background jobs that execute Groovy plug-ins at periodic intervals and let you send out notifications by email.
To make use of Groovy jobs, you create the Groovy plug-in in the Groovy plug-ins view and then create a Groovy job that includes the respective plug-in in the Groovy Jobs view (on page 1).
In other words, you can trigger custom code either:
During normal application execution, such as:
On service event
During a gate business task, for example at the truck visit or truck transaction level, or via the Web service interface for an external system
In N4 Mobile applications during hatch clerk, reefer, or inspection operations
When business entities get created, updated, or deleted
On application startup
On demand:
By a code injection call via an external web service or JMS message
You can test web service calls using Script Runner (Administration DBA
Script Runner) or argoserviceTester (Administration
Debug
argoservice Tester).
Through a user-triggered custom action in a table view
As a scheduled Groovy background job
You can restrict access to Groovy code and plug-ins using Groovy privileges (on page 1). You can turn Groovy-based functionality for an N4 installation on or off using Groovy settings (on page 1).
For more information, see "Code Extensibility Mechanisms in N4" in the Navis N4: SDK documentation.
For information on the Java API, see the documentation provided under Help Java API Docs.
In some N4 versions, the link to this resource is not working. As a workaround, you can access the Java API docs directly from the N4 footprint installed on your server. From within the N4 application footprint, manually open the index.html file that is located at the following location (you should only see one of the following directory paths, not both):
Navis/sparcsn4/webapps/apex/argo/api/index.html
Navis/sparcsn4/webapps/apex/model/index.html
Notes
For any future development, it is recommended that you use code extensions rather than Groovy plug-ins.
You can only attach a General Notice that executes a Groovy plug-in to an event that is marked as Notifiable.
For gate business tasks, theoretically, you can include the Groovy code directly in the Custom field. However, if the business task fails, you cannot find out if the Groovy code caused the error unless you have debug messages. Therefore, it is recommended that you use a proper Groovy plug-in and call the plug-in from the business task.
When upgrading, it is essential that you know the version of Groovy used at your site. To find out the Groovy version, go to the JVM Packages view (Administration Debug
JVM Packages) and enter *groovy* in the search field. This brings up a list of all related jars and their versions.
In this Section: