001    /**
002     * Copyright (c) 2000-2013 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            @Override
046            public ActionForward render(
047                            ActionMapping actionMapping, ActionForm actionForm,
048                            PortletConfig portletConfig, RenderRequest renderRequest,
049                            RenderResponse renderResponse)
050                    throws Exception {
051    
052                    ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(
053                            WebKeys.THEME_DISPLAY);
054    
055                    Group group = GroupLocalServiceUtil.getGroup(
056                            themeDisplay.getScopeGroupId());
057    
058                    User user = themeDisplay.getUser();
059    
060                    if (group.isUser()) {
061                            user = UserLocalServiceUtil.getUserById(group.getClassPK());
062                    }
063    
064                    if (UserPermissionUtil.contains(
065                                    themeDisplay.getPermissionChecker(), user.getUserId(),
066                                    ActionKeys.UPDATE)) {
067    
068                            List<SocialRequest> requests =
069                                    SocialRequestLocalServiceUtil.getReceiverUserRequests(
070                                            user.getUserId(), SocialRequestConstants.STATUS_PENDING, 0,
071                                            100);
072    
073                            renderRequest.setAttribute(WebKeys.SOCIAL_REQUESTS, requests);
074                    }
075    
076                    return actionMapping.findForward("portlet.requests.view");
077            }
078    
079    }