Skip to content

Commit

Permalink
We should not store notificaitons information in the Session
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Oct 29, 2024
1 parent 3d52213 commit 1eb2a9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.ehcache.UserManagedCache;
import org.ehcache.config.builders.UserManagedCacheBuilder;
import org.orcid.core.common.manager.EmailFrequencyManager;
import org.orcid.core.manager.ClientDetailsEntityCacheManager;
import org.orcid.core.manager.EncryptionManager;
Expand All @@ -18,7 +20,6 @@
import org.orcid.core.manager.v3.NotificationManager;
import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly;
import org.orcid.core.oauth.OrcidProfileUserDetails;
import org.orcid.frontend.web.controllers.helper.UserSession;
import org.orcid.jaxb.model.v3.release.common.Source;
import org.orcid.jaxb.model.v3.release.common.SourceClientId;
import org.orcid.jaxb.model.v3.release.notification.Notification;
Expand Down Expand Up @@ -55,9 +56,6 @@ public class NotificationController extends BaseController {
@Resource
private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;

@Resource
private UserSession userSession;

@Resource
private PreferenceManager preferenceManager;

Expand All @@ -75,6 +73,13 @@ public ModelAndView getNotifications() {
return new ModelAndView("notifications");
}

UserManagedCache<String, Boolean> isObsoleteNotificationAlertsCheckDone =
UserManagedCacheBuilder.newUserManagedCacheBuilder(String.class, Boolean.class).build(true);

public void shutdown() {
isObsoleteNotificationAlertsCheckDone.close();
}

@RequestMapping("/notifications.json")
public @ResponseBody List<Notification> getNotificationsJson(@RequestParam(value = "firstResult", defaultValue = "0") int firstResult,
@RequestParam(value = "maxResults", defaultValue = "10") int maxResults,
Expand All @@ -88,20 +93,10 @@ public ModelAndView getNotifications() {
return notifications;
}

@RequestMapping("/notification-alerts.json")
public @ResponseBody List<Notification> getNotificationAlertJson() {
String currentOrcid = getCurrentUserOrcid();
List<Notification> notifications = notificationManager.findNotificationAlertsByOrcid(currentOrcid);
notifications = archiveObsoleteNotifications(currentOrcid, notifications);
notifications = notifications.stream().filter(n -> !userSession.getSuppressedNotificationAlertIds().contains(n.getPutCode())).collect(Collectors.toList());
addSubjectToNotifications(notifications);
return notifications;
}

private List<Notification> archiveObsoleteNotifications(String currentOrcid, List<Notification> notifications) {
if (!userSession.isObsoleteNotificationAlertsCheckDone()) {
if (!isObsoleteNotificationAlertsCheckDone.containsKey(currentOrcid)) {
notifications = notificationManager.filterActionedNotificationAlerts(notifications, currentOrcid);
userSession.setObsoleteNotificationAlertsCheckDone(true);
isObsoleteNotificationAlertsCheckDone.putIfAbsent(currentOrcid, Boolean.TRUE);
}
return notifications;
}
Expand Down Expand Up @@ -197,12 +192,6 @@ public ModelAndView executeAction(@PathVariable("encryptedId") String encryptedI
notificationManager.setActionedAndReadDate(notificationOrcid, id);
return new ModelAndView("redirect:" + redirectUrl);
}

@RequestMapping(value = "{id}/suppressAlert.json")
public @ResponseBody void suppressAlert(HttpServletResponse response, @PathVariable("id") String id) {
userSession.getSuppressedNotificationAlertIds().add(Long.valueOf(id));
response.addHeader("X-Robots-Tag", "noindex");
}

@RequestMapping(value = "/frequencies/view", method = RequestMethod.GET)
public @ResponseBody Map<String, String> getNotificationFrequencies() {
Expand Down

This file was deleted.

6 changes: 1 addition & 5 deletions orcid-web/src/main/resources/orcid-frontend-web-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@
<constructor-arg value="${org.orcid.recaptcha.verify_url}" />
<constructor-arg value="${org.orcid.recaptcha.secret}" />
</bean>

<bean id="userSession" class="org.orcid.frontend.web.controllers.helper.UserSession" scope="session">
<aop:scoped-proxy/>
</bean>


<bean id="worksPaginator" class="org.orcid.frontend.web.pagination.WorksPaginator" >
<property name="worksCacheManager" ref="worksCacheManager" />
<property name="worksExtendedCacheManager" ref="worksExtendedCacheManager" />
Expand Down

0 comments on commit 1eb2a9c

Please sign in to comment.