Providing actions for consumers

In some cases you can need to add some actions that are not related to the runtime. For example, enabling clients - the users of the plugin/library - to test if a connection works properly.

To do so, you need to define an @Action, which is a method with a name (representing the event name), in a class decorated with @Service:

@Service
public class MyDbTester {
    @Action(family = "mycomp", "test")
    public Status doTest(final IncomingData data) {
        return ...;
    }
}
Services are singleton. If you need some thread safety, make sure that they match that requirement. Services should not store any status either because they can be serialized at any time. Status are held by the component.

Services can be used in components as well (matched by type). They allow to reuse some shared logic, like a client. Here is a sample with a service used to access files:

@Emitter(family = "sample", name = "reader")
public class PersonReader implements Serializable {
    // attributes skipped to be concise

    public PersonReader(@Option("file") final File file,
                        final FileService service) {
        this.file = file;
        this.service = service;
    }

    // use the service
    @PostConstruct
    public void open() throws FileNotFoundException {
        reader = service.createInput(file);
    }

}

The service is automatically passed to the constructor. It can be used as a bean. In that case, it is only necessary to call the service method.

Particular action types

Some common actions need a clear contract so they are defined as API first-class citizen. For example, this is the case for wizards or health checks. Here is the list of the available actions:

API Type Description Return type Sample returned type

@o.t.s.c.api.service.completion.DynamicValues

dynamic_values

Mark a method as being useful to fill potential values of a string option for a property denoted by its value. You can link a field as being completable using @Proposable(value). The resolution of the completion action is then done through the component family and value of the action. The callback doesn’t take any parameter.

Values

{  "items":[    {      "id":"value",      "label":"label"    }  ]}

@o.t.s.c.api.service.healthcheck.HealthCheck

healthcheck

This class marks an action doing a connection test

HealthCheckStatus

{  "comment":"Something went wrong",  "status":"KO"}

@o.t.s.c.api.service.schema.DiscoverSchema

schema

Mark an action as returning a discovered schema. Its parameter MUST be the type decorated with @Structure.

Schema

{  "entries":[    {      "name":"column1",      "type":"STRING"    }  ]}

@o.t.s.c.api.service.completion.Suggestions

suggestions

Mark a method as being useful to fill potential values of a string option. You can link a field as being completable using @Suggestable(value). The resolution of the completion action is then done when the user requests it (generally by clicking on a button or entering the field depending the environment).

SuggestionValues

{  "cacheable":false,  "items":[    {      "id":"value",      "label":"label"    }  ]}

@o.t.s.c.api.service.Action

user

-

any

-

@o.t.s.c.api.service.asyncvalidation.AsyncValidation

validation

Mark a method as being used to validate a configuration. IMPORTANT: this is a server validation so only use it if you can’t use other client side validation to implement it.

ValidationResult

{  "comment":"Something went wrong",  "status":"KO"}

Internationalization

Internationalization is supported through the injection of the $lang parameter, which allows you to get the correct locale to use with an @Internationalized service:

public SuggestionValues findSuggestions(@Option("someParameter") final String param,
                                        @Option("$lang") final String lang) {
    return ...;
}
You can combine the $lang option with the @Internationalized and @Language parameters.
Scroll to top