Table below provides a quick summary for the configuration options:
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
server | String | http://localhost:2100 | Yes* | Server URL |
amqp | AmqpConfiguration | Yes | AMQP Configuration | |
templates | TemplatesConfiguration | No | Templates Configuration | |
connection | ConnectionConfiguration | No | Connection Settings | |
registration | NotificationsRegistration | No | Application Registration Descriptor | |
enabled | Boolean | No | True if remote server is configured |
notifications:
server : "https://notifications.mydomain.com"
amqp:
notifications-queue: myapp
NotificationsRegistration
:
Table below provides a quick summary for the configuration options:
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
auto | boolean | false | No | True to auto register application on startup. |
application | Application | Yes | Application descriptor. | |
types | List<NotificationType> | No | NotificationTypes to Register | |
templates | List<Template> | No | List of Templates to Register | |
properties | Map<String, Object> | No | Server Properties to set. |
notifications:
server : "https://notifications.mydomain.com"
amqp:
notifications-queue: myapp
templates:
uri: "https://cdn.mydomain.com/templates/myapp"
app: notifications/app
sms: notifications/sms
mail: notifications/mail
registration:
templates:
- name: "Customer Invitation"
medium: EMAIL
category: SYSTEM
uri: "invitation.html"
subject: "Invitation from ${principal.name} to Join the ACME Community"
types:
- source-type: Customer
action-type: create
label: "Do you want to receive notification when a Customer is Created ?"
category: Customer
subcategory: CRUD
admin: false
mail-template:
name: "Customer Created"
uri: customer.html
subject: "A new Customer has been Created"
public static final String CUSTOMER = "Customer";
public Event makeCustomerEvent(Customer customer, String actionType, String... targets) {
Source source = (Source)new Source().withType(CUSTOMER).withDetails(MappingUtils.toMap(customer));
Action action = new Action(actionType);
return new Event()
.withSource(source)
.withAction(action)
.withPrincipal(PrincipalDetails.principal())
.withTargets(TargetParser.makeTargets(targets));
}
public void publishCreateEvent(Customer customer) {
Event event = makeCustomerEvent(ActionType.CREATED);
client.publishEvent(event, ".customer-manager");
}
Page<Notification> notifications = client.listNotifications(null, new PageRequest(0,20), null);
NotificationFilter filter = (NotificationFilter)new NotificationFilter().withType(CUSTOMER + ":" + ActionType.CREATE);
Long n = client.countNotifications(filter, null);
@NotificationSelector(source=@SourceSelector(CUSTOMER), action=@ActionSelector(ActionType.CREATE))
public class CustomerCreationListener implements NotificationListener {
@Override
public void onNotification(Notification notification) throws Exception {
Customer customer = MappingUtil.convert(notification.getSource().getDetails(), Customer.class);
//...
}
}
@NotificationSelector(source=@SourceSelector(CUSTOMER), action=@ActionSelector(ActionType.CREATE))
public class CustomerCreationListener implements NotificationListener {
@NotificationSelector(action=@ActionSelector(ActionType.CREATE))
public void onCustomerCreate(Customer customer) {
//...
}
@NotificationSelector(action=@ActionSelector(ActionType.UPDATE))
public void onCustomerUpdate(Customer customer, Notification notification) {
String username = notification.getPrincipalDetails().getId();
//...
}
@NotificationSelector(action=@ActionSelector(ActionType.DELETE))
public void onCustomerDelete(Customer customer) {
//...
}
@NotificationSelector(action=@ActionSelector(CUSTOMER_LEAD_CREATED))
public void onCustomerLeadCreation(Customer customer, Notification notification) {
//...
}
}
This section describes the REST endpoints automatically setup the the einnovator-notifications-starter.
Table below provides a quick summary:
NotificationsRestController:
Method | Path | Query Parameters | Request Body | Response Body | Status | Log | Security | Description |
---|---|---|---|---|---|---|---|---|
GET | /api/notification | NotificationFilter | Page | OK | notifications | owner ADMIN CLIENT | Get Notifications (of Principal, by default) | |
DELETE | /api/notification/ | NotificationOptions | NO_CONTENT | delete | owner ADMIN CLIENT | Delete Notification |
PreferencesRestController
:
Method | Path | Query Parameters | Request Body | Response Body | Status | Log | Security | Description |
---|---|---|---|---|---|---|---|---|
GET | /api/preference | key | Preference (JSON) | NO_CONTENT | getPreference | owner ADMIN CLIENT | Update Preference | |
POST PUT | /api/preference | key value | {? Preference (JSON)} | NO_CONTENT | setPreference | owner ADMIN CLIENT | Create Preference | |
DELETE | /api/preference | NO_CONTENT | removePreference | owner ADMIN CLIENT | Delete Preferece |
Comments and Discussion