In the Part 4 of this blog series you showed user’s achievements in the profile page. In this blog post you will show notifications from the game.

It is important to provide immediate feedback on achievements to the users. Here you will use pop-up messages to notify the users about Experience Points assigned to him for creating issues.

In order to implement this, first you will retrieve notifications using gamification service API and then you will show the relevant notification by creating a pop-up message.

1) Retrieve notifications:

1. Replace the code in the file located at package with code provided as the additional file to this blog. Unzip the file and copy-and-paste the contents to the file

The class GamificationProxy

The class GamificationProxy has a method getPlayerNotifications() which uses Technical Endpoint to retrieve notifications by invoking gamification service method getNotificationsForPlayer(). The HTTP POST request will look like the following:

https://<gamification service host>/gamification/api/tech/JsonRPC?json={“method”:”getNotificationsForPlayer”,params”:[““,1442061177178]}&app=JIRA

Query parameter



method getNotificationsForPlayer() and parameters (retrieves notifications for given player which have been created after the provided timestamp)


JIRA (name of the app which contains the game mechanics as defined in the gamification workbench)

Input parameter



Player name/Player email id


Timestamp (to retrieve notifications created just after this)

The class Gamification Proxy has another method getServerTime() which uses Technical Endpoint to retrieve current server time by invoking gamification method getCurrentServerTime(). The HTTP POST request will look like the following:

https://<gamification service host>/gamification/api/tech/JsonRPC?

json= {“method”:”getCurrentServerTime”,”params”:[ ]} &app=JIRA

Query parameter



method getCurrentServerTime() and parameters (retrieves the current server time )


JIRA (name of the app which contains the game mechanics as defined in the gamification workbench)

Test the class GamificationProxy: 

The class GamificationProxy defines a method main() to test retrieving notifications using gamification service API.

public static void main(String arg[]) throws Exception{

   // arg[0] – player id

   //reading Environments values


   GamificationProxy gamificationProxy= new GamificationProxy();

   // Step 1: Getting the server time

   String serverTimeResp=gamificationProxy.getSeverTime();

   String serverTime = serverTimeResp.split(“,”)[0].split(“:”)[1];

   System.out.println(“Server Time “+ serverTime);

   // Step 2: Sending ‘issueCreated’ event to the gamification service    

   String eventName=”issueCreated”;

   gamificationProxy.sendEvent(arg[0], “Major”, eventName);

   //Step 3: Retrieving notifications created after the provided server time

   String notifications = gamificationProxy. getPlayerNotifications (




1. Run the configuration (which you created in the previous blog) to execute the class GamificationProxy. As a result following output will be displayed in console

Server Time 1442061177178

{“result”:[{“id”:672384,”message”:”Ticket created”,”category”:”POINT“,”type”:”ADD“,”subject”:”Experience Points”,”detail”:”2″,”dateCreated”:1442061178360}],”error”:null,”type”:null}

Now let’s see how this was achieved. In step 1 server time is calculated and in step 2 gamification relevant event issueCreated is sent. Step 3 retrieves the notifications created after the provided server time and in the current case only one event is sent which means only one notification is created.

Create Rest service for notifications

1. Add the following lines of code to the method doGet() of class UserAchievementsServlet.

if (request.getPathInfo().equalsIgnoreCase(“/servertime”)) {

      String serverTime = null;

      try {

              serverTime = gamificationProxy.getSeverTime();

      }  catch (Exception e) {

                log.error(” Error during accessing server time”, e.getMessage());

      }“Server time response”, serverTime);



else if (request.getPathInfo().equalsIgnoreCase(“/notifications”)) {

      String serverTime = request.getParameter(“serverTime”);

      String playerNotifications = null;

        try {


          } catch (Exception e) {

                  log.error(” Error during accessing player notifications”,e.getMessage());

        }“Player’s notification response”, playerNotifications);



The doGet() method should look like the following:


2.) Show notification:

To show notification, you need to create a JavaScript file and embed it in JIRA pages.

1. Create a folder with name widgets in folder /src/main/resources as shown in the screenshot below


2. Create a file with name sap_gs_notifications.js and place it at folder location /src/main/resources/widgets. Substitute the code from provided as the additional file to this blog. Unzip the file and copy-and-paste the contents to the file sap_gs_notifications.js.

The web resource Plugin Module:

The web resource Plugin Module allows JIRA plugins to define downloadable resources. If your plugin requires the application to serve additional static Javascript or CSS files, you will need to use downloadable web resources to make them available.

In the current case, JavaScript file sap_gs_notifications.js will be used as downloadable web resource to shows notification exactly the time when an issue is created in the JIRA. Now let’s understand how it works?

The file sap_gs_notifications.js has functions _getNotificationsForPlayer() and _getCurrentServerTime() which retrieves notifications and server time by making Ajax calls to the REST service.

The function _poll() schedule the repeating execution of these functions to continually check whether any gamification relevant event has occurred for which there is a notification to the user. If there are notifications they will be shown on the screen using the function _prepareAndInjectNotifications().

_prepareAndInjectNotifications() uses following JIRA API to show notification message


Embed the JavaScript file in JIRA pages

1. Add the following web-resource Plugin module in the atlassian-plugin element of jira-gamification-plugin/atlassian-plugin.xml.

<web-resource name=”Resources” key=”resources”>

  <resource name=”sap_gs_notifications.js” type=”download” location=”widgets/sap_gs_notifications.js”/>




Here, web resource context is atl.general which means the widget sap_gs_notifications.js will be included on all screens of JIRA except administration screens.

The atlassian-plugin.xml should look like:


Test Integration with JIRA:

1. Open a command prompt and run the following set of commands to set environment variables.

set user_name=<HANA Cloud Platform user name>

set user_password=<HANA Cloud Platform password>

set host = < gamification service host>

If you are running this application behind the firewall you also need to set http_proxy_host and http_proxy_port by using following commands.

set http_proxy_host= <Http proxy name> 

set http_proxy_port= <Http port number>

2. Change directory to the folder jira-gamification-plugin and run the following command


3. Once JIRA has started successfully, open the URL printed in the message.


4. Log in with username and create an issue as described in the previous blog and notification would be visible as shown in the snapshot below


Congratulation!! 🙂 You are done with Part 5 and with this integration of SAP HCP gamification service with JIRA is complete 🙂 🙂 .  Next blog post Part 6 you will introduce the advance game mechanics like levels, badges, leaderboard and these elements will be visible in the User profile page.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply