001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.requests.action;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.User;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.GroupLocalServiceUtil;
021    import com.liferay.portal.service.UserLocalServiceUtil;
022    import com.liferay.portal.service.permission.UserPermissionUtil;
023    import com.liferay.portal.struts.PortletAction;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.WebKeys;
026    import com.liferay.portlet.social.model.SocialRequest;
027    import com.liferay.portlet.social.model.SocialRequestConstants;
028    import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
029    
030    import java.util.List;
031    
032    import javax.portlet.PortletConfig;
033    import javax.portlet.RenderRequest;
034    import javax.portlet.RenderResponse;
035    
036    import org.apache.struts.action.ActionForm;
037    import org.apache.struts.action.ActionForward;
038    import org.apache.struts.action.ActionMapping;
039    
040    /**
041     * @author Brian Wing Shun Chan
042     */
043    public class ViewAction extends PortletAction {
044    
045            public ActionForward render(
046                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
047                            RenderRequest renderRequest, RenderResponse renderResponse)
048                    throws Exception {
049    
050                    ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
051                            WebKeys.THEME_DISPLAY);
052    
053                    Group group = GroupLocalServiceUtil.getGroup(
054                            themeDisplay.getScopeGroupId());
055    
056                    User user = themeDisplay.getUser();
057    
058                    if (group.isUser()) {
059                            user = UserLocalServiceUtil.getUserById(group.getClassPK());
060                    }
061    
062                    if (!UserPermissionUtil.contains(
063                                    themeDisplay.getPermissionChecker(), user.getUserId(),
064                                    ActionKeys.UPDATE)) {
065    
066                            renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
067                    }
068                    else {
069                            List<SocialRequest> requests =
070                                    SocialRequestLocalServiceUtil.getReceiverUserRequests(
071                                            user.getUserId(), SocialRequestConstants.STATUS_PENDING, 0,
072                                            100);
073    
074                            if (requests.size() == 0) {
075                                    renderRequest.setAttribute(
076                                            WebKeys.PORTLET_DECORATE, Boolean.FALSE);
077                            }
078                            else {
079                                    renderRequest.setAttribute(WebKeys.SOCIAL_REQUESTS, requests);
080                            }
081                    }
082    
083                    return mapping.findForward("portlet.requests.view");
084            }
085    
086    }