1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.requests.action;
21  
22  import com.liferay.portal.model.Group;
23  import com.liferay.portal.model.User;
24  import com.liferay.portal.security.permission.ActionKeys;
25  import com.liferay.portal.service.GroupLocalServiceUtil;
26  import com.liferay.portal.service.UserLocalServiceUtil;
27  import com.liferay.portal.service.permission.UserPermissionUtil;
28  import com.liferay.portal.struts.PortletAction;
29  import com.liferay.portal.theme.ThemeDisplay;
30  import com.liferay.portal.util.WebKeys;
31  import com.liferay.portlet.social.model.SocialRequest;
32  import com.liferay.portlet.social.model.SocialRequestConstants;
33  import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
34  
35  import java.util.List;
36  
37  import javax.portlet.PortletConfig;
38  import javax.portlet.RenderRequest;
39  import javax.portlet.RenderResponse;
40  
41  import org.apache.struts.action.ActionForm;
42  import org.apache.struts.action.ActionForward;
43  import org.apache.struts.action.ActionMapping;
44  
45  /**
46   * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   */
51  public class ViewAction extends PortletAction {
52  
53      public ActionForward render(
54              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
55              RenderRequest renderRequest, RenderResponse renderResponse)
56          throws Exception {
57  
58          ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
59              WebKeys.THEME_DISPLAY);
60  
61          Group group = GroupLocalServiceUtil.getGroup(
62              themeDisplay.getScopeGroupId());
63  
64          User user = themeDisplay.getUser();
65  
66          if (group.isUser()) {
67              user = UserLocalServiceUtil.getUserById(group.getClassPK());
68          }
69  
70          if (!UserPermissionUtil.contains(
71                  themeDisplay.getPermissionChecker(), user.getUserId(),
72                  ActionKeys.UPDATE)) {
73  
74              renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
75          }
76          else {
77              List<SocialRequest> requests =
78                  SocialRequestLocalServiceUtil.getReceiverUserRequests(
79                      user.getUserId(), SocialRequestConstants.STATUS_PENDING, 0,
80                      100);
81  
82              if (requests.size() == 0) {
83                  renderRequest.setAttribute(
84                      WebKeys.PORTLET_DECORATE, Boolean.FALSE);
85              }
86              else {
87                  renderRequest.setAttribute(WebKeys.SOCIAL_REQUESTS, requests);
88              }
89          }
90  
91          return mapping.findForward("portlet.requests.view");
92      }
93  
94  }