Notification API Developer User Guide
Notification API has been designed for the developers of the community to integrate notifications with their developed functionality.
Consider a case where, when a client is generated you want to notify some users of the organization that a client was created. Follow the below given steps to add the code just before the return statement of the method which creates a client or at the end of a method if return statement does not exist.
Steps to add Notification in a functionality
- Create a notification queue
Queue queue = new ActiveMQQueue(nameOfTheQueue);
Note :- Use the name of the queue to be "NotificationQueue" because this is the name of a queue at which the listener listens for incoming messages. Create a NotificationData object.
NotificationData notificationData = new NewNotificationBuilder()
.withUserId(idOfTheUserToBeNotified)
.withObjectType(nameOfObjectOnWhichActionHappened)
.withObjectIdentifier(idOfObjectOnWhichActionHappened)
.withNotificationContent(contentOfNotification)
.withAction(theActionWhichResultedInThisNotification)
.withActor(idOfUserWhoDidIt)
.withTenantIdentifier(nameOfTheTenant)
.withOfficeId(idOfOfficeForWhichNotificationIsGenerated)
.build();
For E.g :- If we want to send the notification to user1 with id 1 that "A new client with name ABC was created". Consider object id to be 72, a user which creates it to be "mifos" and with "default" as a tenant identifier and id of the office for which the notification is generated to be 1.
NotificationData notificationData = new NewNotificationBuilder()
.withUserId(1)
.withObjectType("client")
.withObjectIdentifier(72)
.withNotificationContent( "A new with name ABC client was created")
.withAction("created")
.withActor("mifos")
.withTenantIdentifier("default")
.withOfficeId(1)
.build();
To know more about the attributes of notification like what an object in a generated notification means then navigate to this link.Name Of Arguement Type nameOfTheQueue String idOfTheUserToBeNotified Long || List<Long>(There can be more than one users to be notified) nameOfObjectOnWhichActionHappened String idOfObjectOnWhichActionHappened Long contentOfNotification String theActionWhichResultedInThisNotification String idOfUserWhoDidIt String nameOfTheTenant String idOfOfficeForWhichNotificationIsGenerated Long Broadcast the notification
- Autowire NotificationEvent class.
- For E.g
@Autowired
NotificationEvent notificationEvent; - Broadcast the event
notificationEvent.broadcastNotification(nameOfTheQueue, notificationData);