Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A CAP Java plugin that integrates SAP Alert Notification service (ANS) with the

The `cds-feature-notifications` plugin enables out-of-the-box notification handling for CAP Java applications. Annotate CDS events with `@notification`, emit them from a handler or annotate entities with `@notifications` for automatic delivery triggered by CRUD events, actions, or functions. The plugin takes care of the rest and delivers notifications via [SAP Alert Notification service (ANS)](https://help.sap.com/docs/alert-notification).

In **local mode**, notifications are logged to the console with no ANS binding required. In **production mode**, notifications are delivered through Web (SAP Build Work Zone) and Email channels. You can either create a standalone ANS service instance or use Work Zone's built-in notification credentials. Both approaches are covered in the [Production Mode](#production-mode) section.
In **local mode**, notifications are logged to the console with no ANS binding required. In **production mode**, notifications are delivered through Web (SAP Build Work Zone) and Email channels. Production mode is activated automatically when an `alert-notification` service binding is detected, or can be enabled explicitly via configuration. You can either create a standalone ANS service instance or use Work Zone's built-in notification credentials. Both approaches are covered in the [Production Mode](#production-mode) section.

## Table of Contents

Expand Down Expand Up @@ -387,7 +387,7 @@ Both approaches require the same setup: enable production mode, then provide an

### Enable Production Mode

In `srv/src/main/resources/application.yaml`, enable production mode:
Production mode is activated automatically when an `alert-notification` service binding is detected at startup. You can also enable it explicitly in `srv/src/main/resources/application.yaml`, for example for hybrid testing against a remote ANS instance without a local binding:

```yaml
cds:
Expand All @@ -396,7 +396,7 @@ cds:
enabled: true
```
> **Note:** If this property is omitted, the plugin defaults to local mode (console output only, no ANS required).
If neither a binding is present nor the property is set, the plugin defaults to local mode (console output only, no ANS required).
In production mode:
- **`ProductionHandler`** sends notifications to ANS (instead of console logging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,24 @@ public void eventHandlers(CdsRuntimeConfigurer configurer) {
OutboxService.PERSISTENT_ORDERED_NAME);
}

if (Boolean.TRUE.equals(environment.getProduction().isEnabled())) {
logger.info("Production mode enabled - using ProductionHandler");
boolean ansBindingPresent =
configurer
.getCdsRuntime()
.getEnvironment()
.getServiceBindings()
.anyMatch(
b -> b.getServiceName().map(n -> n.equals("alert-notification")).orElse(false));

boolean productionEnabled =
environment.getProduction() != null
&& Boolean.TRUE.equals(environment.getProduction().isEnabled());

if (productionEnabled || ansBindingPresent) {
if (ansBindingPresent && !productionEnabled) {
logger.info("alert-notification binding detected - using ProductionHandler");
} else {
logger.info("Production mode enabled - using ProductionHandler");
}
configurer.eventHandler(new ProductionHandler(outboxedSvc, configurer.getCdsRuntime()));
// Register handler for auto-provisioning standalone templates on application prepared event
configurer.eventHandler(
Expand Down Expand Up @@ -135,7 +151,7 @@ public void environment(CdsRuntimeConfigurer configurer) {
runtime
.getEnvironment()
.getServiceBindings()
.filter(b -> b.getServiceName().get().equals("alert-notification"))
.filter(b -> b.getServiceName().map(n -> n.equals("alert-notification")).orElse(false))
.findFirst()
.orElse(null);

Expand Down
Loading