Search in sources :

Example 1 with ActionableNotificationEntity

use of org.orcid.persistence.jpa.entities.ActionableNotificationEntity in project ORCID-Source by ORCID.

the class NotificationController method executeAction.

@RequestMapping(value = "/encrypted/{encryptedId}/action", method = RequestMethod.GET)
public ModelAndView executeAction(@PathVariable("encryptedId") String encryptedId) {
    String idString;
    try {
        idString = encryptionManager.decryptForExternalUse(new String(Base64.decodeBase64(encryptedId), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Problem decoding " + encryptedId, e);
    }
    Long id = Long.valueOf(idString);
    ActionableNotificationEntity notification = (ActionableNotificationEntity) notificationManager.findActionableNotificationEntity(id);
    String redirectUrl = notification.getAuthorizationUrl();
    String notificationOrcid = notification.getProfile().getId();
    OrcidProfileUserDetails user = getCurrentUser();
    if (user != null) {
        // The user is logged in
        if (!user.getOrcid().equals(notificationOrcid)) {
            return new ModelAndView("wrong_user");
        }
    } else {
        redirectUrl += "&orcid=" + notificationOrcid;
    }
    notificationManager.setActionedAndReadDate(notificationOrcid, id);
    return new ModelAndView("redirect:" + redirectUrl);
}
Also used : ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) ModelAndView(org.springframework.web.servlet.ModelAndView) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)1 ActionableNotificationEntity (org.orcid.persistence.jpa.entities.ActionableNotificationEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1