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:
-
Deciding to Create Local and Remote Services.
-
Implementing the
add
Method. -
Implementing the
update
anddelete
Methods. -
Implementing
get
andget*Count
Methods -
Implementing Other Business Logic
-
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:
-
If you plan to have remote services, enable local services too.
-
Implement your business logic in
*LocalServiceImpl
. -
Create corresponding remote services methods in your
*ServiceImpl
. -
Use the remote service methods to call the local service, wrapping the calls in permission checks.
-
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.