Martini Services Creating Groovy Annotations
Introduction to Service Annotations
Service annotations in Martini are a collection of Java annotations designed to enhance Groovy services and Java code. These annotations are crucial for providing additional details about service functionality, including usage, inputs, and outputs. This guide will show you how to apply these annotations to improve the integration and usability of your Groovy services within Martini.
Applying Service Annotations
Adding annotations to Groovy services is straightforward. By integrating these annotations into service methods, developers can easily manage input and output models, document services, and control their visibility in the Martini Navigator.
Key Points: - Method Visibility: Methods hidden from the Navigator can still be invoked using script steps in Groovy. - Editor Integration: The Martini Desktop Groovy service editor supports the addition of annotations directly through the Input/Output view, updating the Groovy source code in real-time.
Overview of Service Annotations
Here's a summary of the available service annotations in Martini, along with their descriptions and use cases:
Annotation | Description |
---|---|
ServiceComment |
Adds descriptions to services or parameters for enhanced clarity in various views. |
ServiceHide |
Prevents methods from appearing in the Navigator view. |
ServiceParameter |
Details information about service inputs and outputs, similar to properties. |
ObjectParameter |
Specifies the properties and structure of a model used in the service. |
Implementing Service Annotations in Groovy Services
As an example, let's use a simple Calculator
class with a public static method:
1 2 3 4 5 6 7 |
|
After saving this method without compilation errors, it will be visible in the Navigator view.
Annotation Examples:
-
@ServiceComment: Adds documentation to the service method for better understanding.
1 2 3 4
class Calculator { @ServiceComment('Calculates the sum of integers') static Integer getSum(Integer... input) { /* ... */ } }
-
@ServiceHide: Hides specific utility methods from the Navigator, keeping them accessible for internal use.
1 2 3 4 5
class Calculator { @ServiceHide @ServiceComment('Internal utility method') static Integer utilityMethod() { /* ... */ } }
-
@ServiceParameter and @ObjectParameter: Use these annotations to provide detailed information about method behaviors and data expectations.
Utilizing the Groovy Service Editor
The Groovy service editor's Input/Output view in Martini Desktop updates dynamically to reflect the parameters and return types of the method you're editing. To annotate your code, simply place the cursor in the desired section and use the Input/Output view.