Business Logic with Service Builder

Once you’ve defined your application’s entities and run Service Builder to generate your service and persistence layers, you can begin adding business logic. Each entity generated by Service Builder contains a model implementation, local service implementation, and optionally a remote service implementation class. Your application’s business logic can be implemented in these classes. The generated service layer contains default methods that call CRUD operations from the persistence layer. Once you’ve added your business logic, running Service Builder again regenerates your application’s interfaces and makes your new logic available for invocation.

The heart of your service is its *LocalServiceImpl class. This class is your entity’s local service extension point. Local services are invoked from your application or by other applications running on the same instance as your application.

Creating services takes these steps:

  1. Deciding to Create Local and Remote Services.

  2. Implementing the add Method.

  3. Implementing the update and delete Methods.

  4. Implementing get and get*Count Methods

  5. Implementing Other Business Logic

  6. Integrating with Liferay’s Services.

Start with deciding the service types you need.

Defining your object model involves choosing whether to generate local and or remote service interfaces. Local services can only be invoked from the Liferay server on which they’re deployed. Remote services are accessible to clients outside of the Liferay server. Before implementing local or remote services, consider the best practices described here:

  1. If you plan to have remote services, enable local services too.

  2. Implement your business logic in *LocalServiceImpl.

  3. Create corresponding remote services methods in your *ServiceImpl.

  4. Use the remote service methods to call the local service, wrapping the calls in permission checks.

  5. In your application, call only the remote services. This ensures that your service methods are secured and that you don’t have to duplicate permissions code.

If you are turning on local or remote services in your service.xml file just now, make sure to run Service Builder again to generate the service interfaces.

Now you’re ready to implement your business logic.

« Migrating a Service Builder Module from Spring DI to OSGi DSImplementing an Add Method »
Was this article helpful?
0 out of 0 found this helpful