Java command annotations are used for the developing Java commands in PAK. This chapter describes the functionality of the @CommandService annotation. It also gives an example of how you can use this annotation in your implementation.

1. Basics

The @CommandService annotation basically works like @Service. It marks a Service as injected. The main difference is, that only Services, extending the ICommandService marker-interface, can be injected by using @CommandService. It was introduced to differentiate between a normal Service- and a CommandService-injection. If the usage of @Service is not wanted, or simply too expensive, an ICommandService can be injected, using @CommandService, which provides the option of creating utility-Services.

2. Usage

Like previously mentioned, Services must extend or implement ICommandService in order to be annotated by @CommandService. This class should then operate as a Service within the Command.

Listing 1 shows how to use the @CommandService annotation.

Listing 1. Example Command, using @CommandService
/**
 * @workflowDocu This is a sample-command
 */
@JavaCommand
@CommandGroup("Generic.Sample")
public class SampleCommand {
	/**
	 * @workflowDocu ICommandRestService injected as a CommandService in order to provide the functionality to
	 *                conduct simple rest-calls
	 */
	@CommandService (1)
	private ICommandRestService restService;


	/**
	 * @workflowDocu Store response in this map
	 */
	@Persistent(scope = FieldScope.WRITE_ONLY)
	private Map<String, Object> responseMap;

	@Run
    public void run() {

	    final IEndpointClientService endpointClientService = this.restService.createEndpointClientServiceFor("myRequesterId"); (2)
		endpointClientService.register(JacksonFeature.class);
		final Response response = endpointClientService.getBaseTarget().path("/service/rest/v1/tasks").request().get(); (3)
		this.responseMap = response.readEntity(new GenericType<>() {
		}); (4)
    }
}
1 Use of @CommandService, to inject a implementation of ICommandService.
2 Create an IEndpointClientService, using ICommandRestService, by passing specific requesterId.
3 Fetch response from IEndpointClientService.
4 Save response as map.