This documentation supports the 20.02 version of BMC Helix Platform. 
To view an earlier version, select 19.11 from the Product version menu.

Creating a custom service in Java

A custom service provides business logic to an application or library. You can create a custom service so that the application business analyst can use these services as elements in BMC Helix Innovation Studio to build processes and business rules.

Each method that you define in the service can be exposed to BMC Helix Innovation Studio as an Action Type, which can be used to create a Service Task in business processes or to create Custom Rule Action in business rules.

To create a service class

When you create a service class, you must first implement it as a service interface, which is a marker interface that makes your service and its actions discoverable by the platform. Your service class can depend on other services. Framework services are available through ServiceLocator; for example, ServiceLocator.getRecordService() returns Record Service. To access services defined in other bundles, you can use Bundle Service, ServiceLocator.getBundleService.getService(serviceName).

The following video (6:52) helps you to use a custom view component in a view or use a custom activity in a process.

The video shows an older version of BMC Helix Platform. The previous product name was BMC Helix Innovation Suite. Although there might be minor changes in the UI, the overall functionality remains the same.

 https://youtu.be/bVvcC6IKaLA

  1. 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 {
    . . .
        
    }
    
  2. Add methods for business logic to the service class.
  3. 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());
           . . .
        }
    . . .
    }
    


  4. 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.
  5. Compile the code by using Maven.
  6. Deploy the service interface by issuing the following command:

    mvn clean install -Pexport -Pdeploy


  7. From the Workspace tab, navigate to the application for which you created the service interface. 
  8. 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) {
...
   }
}

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>

To indicate a service is deprecated

To update any processes or rules that are still using a deprecated service, before you remove the service and replace the service by a new one, you can add an indicator to the service which informs the user that the service is deprecated.

To indicate that a service is deprecated, you can use the @Action annotation with the following properties:

PropertyDescription
displayNameName of the service that is displayed in the action palette.
isDeprecatedBoolean flag to indicate that the service is deprecated. The default value is false.
deprecatedTextMessage that is displayed if you continue to use this service.

To identify that the service is deprecated, a  symbol is displayed on the service and the following message is displayed in the Properties pane each time you use the service:

Process Action Deprecated.

The following sample code illustrates how to indicate that a service is deprecated:

@Action(name = "validateEmailId', scope = Scope.PUBLIC, displayName = "Old Validate Email ID", isDeprecated = true, deprecatedText = "Validate Email has been deprecated and is scheduled for removal")
public boolean isValid(@ActionParameter(name = "emailIdField") @Valid @NotNull String emailId)
{
    return true;
}

Related topics

Defining the application business logic through processes

Enabling logging for a Digital Service application

Enabling browser logging in a Digital Service application

Was this page helpful? Yes No Submitting... Thank you

Comments