Setting Up Custom Notifications to the Notification Center

Presentation

The notification centre is a tool for collecting information messages or alert generated by the application for users.

 

  1. New message indicator

  2. Delete all notification messages

  3. Delete the current notification message

Notification object

Notifications are stored in the usermention object. If it’s not present on your application you can restore it from the archives present in the engine (NAR).

Notification Source

The source of a notification allows the application to identify from which component or object originates the message to the user.

The source is a character string and is stored in the The source of the object usermention. It can represent an object under the form of its uid.

Note

An UID is a character string comprising the object name and identifier separated by the _ character, for example user_22.

If the source is equal to the UID of an instance of an object in the system and the recipient has the right to view this object, then the recipient will be able to directly access the source of the object by clicking on the message in its notification centre.

Notifications types

The notifications are typed in order to manage the displays and actions to be carried out according to their nature and sources.

A type is a string of characters and is stored in the type property of the object usermention.

Types natively managed by the application

COMMENT

Used when a user mentions another user in a comment.

DAM_INDEXATION_STARTED

Used when automatic indexing is started in the background in the indexing basket. It allows the user to specify that the task of indexation is underway.

DAM_INDEXATION_ENDED

Used when automatic indexing in the background is completed.

SYSTEM

Used by the engine to inform the user of generic messages.

MESSAGE

Used to send simple messages to users.

Notification levels

They provide the user with information about the importance of the message. The levels available in the application are as follows:

  • ERROR

  • SUCCESS

  • DANGER

  • WARNING

  • INFO

 

Figure 1. The display style automatically adapts to the notification level.

Operation

A notification is an instance of the object usermention.

Tip

The usermention object can be installed from the WXM nar located in the WAR if it is not already present on your application.

Notification creation

The easiest way to create a new notification is to use the com.noheto.bov3.UserMention(CTSurfer surfer) class which will create a new mention

  • of type TYPE.MESSAGE.

  • with level LEVEL.INFO

  • with an expiry period of 1 month

  • with recipient equals to the surfer passed in parameter

All that remains is to define the recipient via one of the setTo methods as well as the message via the setMessage method and then invoke the save method.

Notification Creation

// create a new notification from the current user new com.noheto.bov3.UserMention(wsnoheto.engine.CTSurfer.from(request)) .setTo("user_29") // set the recipient .setMessage( "Hello !" ) // set the message .setSource("news_18") // set the source of the message .save(); // send the message Advanced method String mentionKey = // create a new notification from the current user new com.noheto.bov3.UserMention( wsnoheto.engine.CTSurfer.from(request) ) // defines the user with ID=50 as the recipient of the notification .setTo("user_50") // set the message content .setMessage( "Hello there !" ) // defines the instance of news with ID=53 as the source of the notification, // it might be a useful information later .setSource( "news_53" ) // set the type of the notification, may be useful to personalize the // displayed message in the notification center .setType("MY_TYPE") // set the level of the notification .setLevel( UserMention.LEVEL.DANGER ) // stores the UserMention in the application and returns the key // of the notification .save();

Notification update

In some cases, it may be necessary to update a notification. For example, in the case of a process that can be quite long, it can be desired to notify the user of the start of the process, in order to inform him that its request is being processed, and at the end of the process execution to inform him that it is finished. In this case, we would like to put update the notification rather than create a new one.

To update a notification, you need to know the key that has been returned by the API when the initial notification was created by the method UserMention. save.

Caution

Only the owner of a mention is able to modify it.

Updating a notification

import com.noheto.bov3.UserMention; // key of the notification to update String mentionKey = "xxx"; UserMention.getByKey( wsnoheto.engine.CTSurfer.from( request ) , mentionKey ) .setMessage("New message") .setLevel(UserMention.LEVEL.SUCCESS) .save();