Skip to main content
avillanueva
23-Emerald I
23-Emerald I
July 26, 2023
Solved

Throttling user messages on screen

  • July 26, 2023
  • 2 replies
  • 1549 views

We've developed a customization that uses the lightbox (yellow message banner) that executes on the user's home tab to relay actionable information. Each time the page is refreshed, the message appears but would not like to throttle that message to be periodic. Some of our thoughts were:

  • Accessing the user's session creation and spacing out execution based on that time.
  • Accessing the user's login time and doing same thing.
  • Creating a singleton which keeps track of the user's last execution time limiting based on some timer.

For the last option, how would that work across multiple method servers? Would each MS having its own JVM, have its own copy of the singleton? Not a huge issue but is there a system wide solution?

Example solution would be to display a message no more than once every two hours.

Open to any other solutions.

Best answer by avillanueva

Thanks to @jbailey  for the solution using a session variable. This addition to our JSP puts a timestamp when the last time the user was notified of our special alert message supplied by OpenTasks.getOpenTasks(). This is just a static class that returns values for some queries on late tasks. The messages are displayed in the standard banner at the top of the page and disappear after a few seconds. Subsequent refreshes of the page show nothing until the timer exceeds a certain number of hours since last execution. This way the users are not harassed non-stop, a more gentle poke in the side. Thanks to my intern Ben for this work.

<%
	//Get current timestamp
	Timestamp timestamp = new Timestamp(System.currentTimeMillis());
	String messageAlreadySent = (String) session.getAttribute("messageAlreadySent");
	PropertyResourceBundle properties=(PropertyResourceBundle)PropertyResourceBundle.getBundle("customization.openTasks.homeAssignments");
	int[] summary;
	
	if(messageAlreadySent == null){
		wt.org.WTPrincipal user = wt.session.SessionHelper.getPrincipal();
		summary = OpenTasks.getOpenTasks(user);
		session.setAttribute("messageAlreadySent", timestamp.toString());
	}else{
		Timestamp lastMessage = Timestamp.valueOf(messageAlreadySent);
		long delay = (long)(Double.parseDouble(properties.getString("delay")) * 60 * 60 * 1000);
		lastMessage.setTime(lastMessage.getTime() + delay);
		
		if(lastMessage.compareTo(timestamp) < 0){
			wt.org.WTPrincipal user = wt.session.SessionHelper.getPrincipal();
			summary = OpenTasks.getOpenTasks(user);
			session.setAttribute("messageAlreadySent", timestamp.toString());
		}else{
			int[] temp = {0,0,0};
			summary = temp;
			session.setAttribute("messageAlreadySent", messageAlreadySent);
		}
	}
%>

  

2 replies

jbailey
18-Opal
July 26, 2023

On my banners I create a session variable to store whether or not the banner has been seen (when they acknowledge a security warning by clicking a button).

 

Might you be able to set a timer in the session that looks if they clicked the button in the last xxx minutes?

avillanueva
23-Emerald I
23-Emerald I
July 26, 2023

Do you have an example of the session variable?

jbailey
18-Opal
July 26, 2023

I will email

avillanueva
23-Emerald I
avillanueva23-Emerald IAuthorAnswer
23-Emerald I
July 26, 2023

Thanks to @jbailey  for the solution using a session variable. This addition to our JSP puts a timestamp when the last time the user was notified of our special alert message supplied by OpenTasks.getOpenTasks(). This is just a static class that returns values for some queries on late tasks. The messages are displayed in the standard banner at the top of the page and disappear after a few seconds. Subsequent refreshes of the page show nothing until the timer exceeds a certain number of hours since last execution. This way the users are not harassed non-stop, a more gentle poke in the side. Thanks to my intern Ben for this work.

<%
	//Get current timestamp
	Timestamp timestamp = new Timestamp(System.currentTimeMillis());
	String messageAlreadySent = (String) session.getAttribute("messageAlreadySent");
	PropertyResourceBundle properties=(PropertyResourceBundle)PropertyResourceBundle.getBundle("customization.openTasks.homeAssignments");
	int[] summary;
	
	if(messageAlreadySent == null){
		wt.org.WTPrincipal user = wt.session.SessionHelper.getPrincipal();
		summary = OpenTasks.getOpenTasks(user);
		session.setAttribute("messageAlreadySent", timestamp.toString());
	}else{
		Timestamp lastMessage = Timestamp.valueOf(messageAlreadySent);
		long delay = (long)(Double.parseDouble(properties.getString("delay")) * 60 * 60 * 1000);
		lastMessage.setTime(lastMessage.getTime() + delay);
		
		if(lastMessage.compareTo(timestamp) < 0){
			wt.org.WTPrincipal user = wt.session.SessionHelper.getPrincipal();
			summary = OpenTasks.getOpenTasks(user);
			session.setAttribute("messageAlreadySent", timestamp.toString());
		}else{
			int[] temp = {0,0,0};
			summary = temp;
			session.setAttribute("messageAlreadySent", messageAlreadySent);
		}
	}
%>