Skip to content

Commit

Permalink
furthe java code fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
mofterdinger committed Nov 14, 2023
1 parent d8f0919 commit e5e375d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion java/application-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class CatalogServiceHandler implements EventHandler {

As of version 2.4.0, the [CAP Java SDK Maven Plugin](./development/#cds-maven-plugin) is capable of generating specific interfaces for services in the CDS model. These service interfaces are providing Java methods for actions and functions modeled on the service. These methods allow direct access to the action / functions parameters and they can be easily called by custom Java code to trigger them. If an action or function is bound to an entity, the first argument of the method is an entity reference providing the required information to address the entity instance.

The corresponding generated Java service interface for the CDS model above:
For the CDS model above, the corresponding generated Java service interface will look like the following:

```java
@CdsName(CatalogService_.CDS_NAME)
Expand Down Expand Up @@ -311,6 +311,18 @@ public interface ReviewEventContext extends EventContext {
}
```

To trigger the action or function, the event context needs to be filled with the parameter values and emitted on the service:

```java
ReviewEventContext context = ReviewEventContext.create();
context.setCqn(Select.from(BOOKS).byId("myBookId"));
context.setStars(review.getRating());

this.catService.emit(context);

Reviews result = context.getResult();
```

::: tip
The unused methods `setCqn(CqnSelect)`, `setStars(Integer)`, and `getResult()` are useful when [triggering the event](consumption-api#customevents) on the service.
:::
Expand Down

0 comments on commit e5e375d

Please sign in to comment.