Search code examples
liferayliferay-6

Intercept user visits a group


I am new to liferay and I need to enhance my User Object with a Map(groupId, lastVisitedDate) after a user visited a group. Any ideas when, where and how I can intercept this request and enhance my user with the called groupId and the current Date?


Solution

  • I solved my issue by creating a hook which extends the portal.properties. In this properties file I created this property

    servlet.service.events.pre=org.my.company.project.event.MyCustomAction
    

    the MyCustomAction Class extends Action.

    This is how I got the necessary informations

        @Override
        public void run(HttpServletRequest request, HttpServletResponse response)
            throws ActionException {
    
          try {
            User user = PortalUtil.getUser(request);
    
            ThemeDisplay themeDisplay = (ThemeDisplay) request
            .getAttribute(WebKeys.THEME_DISPLAY);
    
             Group group = themeDisplay.getLayout().getGroup();
              [...]
          } catch (Exception e) {
              throw new ActionException(e);
          }
    
        }