Tutorial: How to extend the eXo Platform notification system

Extending-Platform-Notifications

In the last tutorial, we walked through simple steps to create a gadget using an Ajax DOM Object to consume the eXo API. However, you saw those steps outside the eXo Platform. I’m sure you are eager to go deeper inside its working mechanism. The first topic I want to focus on is the eXo notification system. Yes, I said the first— we will focus on another topic in an upcoming tutorial. Let’s get started!

The eXo Platform provides a notification system that you can extend using two mechanisms:

  • the channels of notification, such as email, directly online, through pushing, etc.; and
  • the types of notifications, such as connection invitations, space activities, etc.

This guide will show you how to use both of these mechanisms by:

  • creating a new notification channel to push notification information to the console panel; and
  • creating a new notification type to indicate when a user in your network changes his or her profile.

You can use the steps below to create a complete extension with these features.

1. Create a new Maven project as shown below:

notif_whole_structure

2. Add the following dependencies to the pom.xml file:

3. Create a pom.xml file and two configuration.xml files inside the config folder as shown below:

notif_config_structure

4. Add the following information to config/pom.xml:

5. Add the configurations below to conf/configuration.xml:

6. Add the following configurations to portal/configuration.xml:

This file does the following:

  • Registers SocialProfileListener as a profile event listener plugin with the IdentityManager component. This plugin listens to user profile updating events.
  • Registers the new console.channel plugin with the ChannelManager component. This plugin pushes notifications to the console panel.
  • Registers the new UpdateProfilePlugin with the PluginContainer component. This plugin declares and initializes parameters for the new notification type. The initial parameters include the following:
    template.UpdateProfilePlugin—the template for UpdateProfilePlugin
    pluginId—the ID of the plugin defined in the class UpdateProfilePlugin
    resourceBundleKey—the key that will be provided in the resource bundle files for each locale
    order—the order in which the new type will be displayed in the notification group
    groupId—the ID of the group this notification type belongs to
    bundlePath—the path to the local resource
    defaultConfig—the default settings for this notification type at start up

7. Create another project under the lib folder with the xml file as shown below:

notif_lib_structure

8. Implement the class UpdateProfilePlugin.java as follows:

  • This class extends the BaseNotificationPlugin, which retrieves information from the new notification type for the user profile updating event.
  • The makeNotification() method was overridden to generate essential information for a notification.

9. Implement the class SocialProfileListener.java as shown below:

This class extends the ProfileListenerPlugin to trigger user profile updating events and plug them into UpdateProfilePlugin as notifications. An instance of UpdateProfilePlugin will be used to generate and send messages to all notification channels.

avatarUpdated()—trigger an avatar updating event
experienceSectionUpdated()—trigger a user experience updating event
contactSectionUpdated()—trigger a user contact information updating event
createProfile()—trigger a user profile creating event

10. Implement the class java to obtain the following code:

  • This concrete class extends AbstractChannel to define a new notification channel that sends messages to the console panel. Any new channel must implement this interface and use an external-component-plugin configuration to be registered in the ChannelManager.
  • The dispatch() method was overridden to write notification contents to the console panel.

11. Create a new Maven project inside the webapp folder with the following pom.xml file:

notif_webapp_structure

12. Add the following configurations to WEB-INF/web.xml:

display-name — must be the same as the context name of the portal extension

13. Open the Notification_en.properties file and add this text:

This is an English-language resource bundle. The UINotification.title.UpdateProfilePlugin and UINotification.label.UpdateProfilePlugin values will be used to display the English name of the new notification type through the user interface.

14. Go up to the parent project’s folder and build the project using the mvn clean install command

15. After successfully building the project, copy the generated jar and war files into the corresponding deployment folders in which you unpacked the eXo Platform installation.

16. Start the eXo Platform, and you will see your new functions appear in Notification Settings:

notification_setting

Remember to enable notification plugins on the administrator account, and then test these functions by updating any user’s avatar or experience. A message regarding this activity will be pushed to all notification channels, as shown below:

intranet_notification

Alternatively, a message will be shown on the console for each user connecting with the above user, as shown below:

James will receive the message from pluginId: UpdateProfilePlugin

The source code used in this tutorial is available on github here.

Finally, I would like to thank the eXo DOC and SOC teams for their great comments!

(This article was originally posted on my blog: Lan Nguyen ~ Writing is sharing.)

Join the eXo tribe by registering for the community and get updates, tutorials, support, and access to the Platform and add-on downloads!

Make the most out of eXo Platform 4

Register to the next weekly live demo session and get a complete overview of what you can do with eXo Platform 4. Reserve your seat now!

Be part of the discussion, share your comments

comments