1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.requests.action;
16  
17  import com.liferay.portal.model.Group;
18  import com.liferay.portal.model.User;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.service.GroupLocalServiceUtil;
21  import com.liferay.portal.service.UserLocalServiceUtil;
22  import com.liferay.portal.service.permission.UserPermissionUtil;
23  import com.liferay.portal.struts.PortletAction;
24  import com.liferay.portal.theme.ThemeDisplay;
25  import com.liferay.portal.util.WebKeys;
26  import com.liferay.portlet.social.model.SocialRequest;
27  import com.liferay.portlet.social.model.SocialRequestConstants;
28  import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
29  
30  import java.util.List;
31  
32  import javax.portlet.PortletConfig;
33  import javax.portlet.RenderRequest;
34  import javax.portlet.RenderResponse;
35  
36  import org.apache.struts.action.ActionForm;
37  import org.apache.struts.action.ActionForward;
38  import org.apache.struts.action.ActionMapping;
39  
40  /**
41   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   */
45  public class ViewAction extends PortletAction {
46  
47      public ActionForward render(
48              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
49              RenderRequest renderRequest, RenderResponse renderResponse)
50          throws Exception {
51  
52          ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
53              WebKeys.THEME_DISPLAY);
54  
55          Group group = GroupLocalServiceUtil.getGroup(
56              themeDisplay.getScopeGroupId());
57  
58          User user = themeDisplay.getUser();
59  
60          if (group.isUser()) {
61              user = UserLocalServiceUtil.getUserById(group.getClassPK());
62          }
63  
64          if (!UserPermissionUtil.contains(
65                  themeDisplay.getPermissionChecker(), user.getUserId(),
66                  ActionKeys.UPDATE)) {
67  
68              renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
69          }
70          else {
71              List<SocialRequest> requests =
72                  SocialRequestLocalServiceUtil.getReceiverUserRequests(
73                      user.getUserId(), SocialRequestConstants.STATUS_PENDING, 0,
74                      100);
75  
76              if (requests.size() == 0) {
77                  renderRequest.setAttribute(
78                      WebKeys.PORTLET_DECORATE, Boolean.FALSE);
79              }
80              else {
81                  renderRequest.setAttribute(WebKeys.SOCIAL_REQUESTS, requests);
82              }
83          }
84  
85          return mapping.findForward("portlet.requests.view");
86      }
87  
88  }