Creating a Custom Service in Java - Documentation for Bmc Helix Platform 20.08
Create a Java Class That Implements Com. Bmc. Arsys. Rx. Services. Common. Service. the Following Sample Code Illustrates How to Create a Java Class That...
Create a Java class that implements
com.bmc.arsys.rx.services.common.Service.
The following sample code illustrates how to create a Java class that implements a service:package com.example.taskmanager.service; . . . /** * The Class TaskService that manages tasks. */ public class TaskService implements Service { . . . }- Add methods for business logic to the service class.
Register the service in the bundle class.
The following sample code illustrates how to register the service in the bundle class:package com.example.taskmanager.bundle; . . . import com.bmc.arsys.rx.services.common.RxBundle; import com.example.taskmanager.service.TaskService; . . . /** * Task Manager application bundle. */ public class TaskManagerApplication extends RxBundle { . . . @Override protected void register() { . . . registerService(new TaskService()); . . . } . . . }For service methods that need to be available in BMC Helix Innovation Studio as an Action Type, annotate them with @Action.
When you deploy the smart bundle, Action Types show up in the designer palette. For more information, see Annotating methods as actions.
The following sample code illustrates how to add service methods as action types:package com.example.taskmanager.service; . . . /** * The Class TaskService that manages tasks. */ public class TaskService implements Service { . . . @Action public void updateTaskStatus(@ActionParameter(name = "taskID") @NotBlank String taskId,, @ActionParameter(name = "status") @NotBlank String status) { . . . } . . . }Notes
- In a smart bundle, do not name actions the same as services. For example, if a bundle has two different services, service1 and service2, you should not create an action with the same name for service1 and for service2.
- If you have duplicate action names, you can use the @Action annotation name property.
- Compile the code by using Maven.
Deploy the service interface by issuing the following command:
mvn clean install -Pexport -Pdeploy- From the Workspace tab, navigate to the application for which you created the service interface.
- Open the Process designer or Rule designer and test the service that you have created and deployed.
To annotate methods as actions
You can develop reusable methods with declared parameters that can be used by process definitions and rule definitions. To annotate the required parameters with the following standard bean validations:
- @NotNull—The CharSequence, Collection, Map or Array object is not null, but it can be empty.
- @NotEmpty—The CharSequence, Collection, Map or Array object is not empty.
- @NotBlank—The string is not null, and the trimmed length is greater than zero.
For example:
package com.example.taskmanager.service;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotBlank;
public class TaskService implements Service {
. . .
@Action
public TaskResult createTask(@ActionParameter(name = "submitter") @NotBlank String submitter,
@ActionParameter(name = "summary") @NotBlank String summary,
@ActionParameter(name = "taskName") String taskName,
@ActionParameter(name = "priority") @NotBlank String priority) {
...
}
}
Must Read
To validate action parameters
To validate action parameters, add the following code to the pom.xml file in the custom bundle.
<!-- For validating action parameters -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>${javax.validation.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
<scope>provided</scope>
</dependency>
<!-- Need to compile with -parameters option to get parameter names through reflection API.
These parameter names are used while exposing @Action within the bundle.-->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>