001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.requests.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.security.auth.PrincipalException;
021    import com.liferay.portal.struts.PortletAction;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.portal.util.WebKeys;
025    import com.liferay.portlet.social.NoSuchRequestException;
026    import com.liferay.portlet.social.service.SocialRequestServiceUtil;
027    
028    import javax.portlet.ActionRequest;
029    import javax.portlet.ActionResponse;
030    import javax.portlet.PortletConfig;
031    
032    import org.apache.struts.action.ActionForm;
033    import org.apache.struts.action.ActionMapping;
034    
035    /**
036     * @author Brian Wing Shun Chan
037     */
038    public class UpdateRequestAction extends PortletAction {
039    
040            @Override
041            public void processAction(
042                            ActionMapping actionMapping, ActionForm actionForm,
043                            PortletConfig portletConfig, ActionRequest actionRequest,
044                            ActionResponse actionResponse)
045                    throws Exception {
046    
047                    try {
048                            updateRequest(actionRequest);
049    
050                            String redirect = PortalUtil.escapeRedirect(
051                                    ParamUtil.getString(actionRequest, "redirect"));
052    
053                            if (Validator.isNotNull(redirect)) {
054                                    actionResponse.sendRedirect(redirect);
055                            }
056                    }
057                    catch (Exception e) {
058                            if (e instanceof NoSuchRequestException ||
059                                    e instanceof PrincipalException) {
060    
061                                    SessionErrors.add(actionRequest, e.getClass());
062    
063                                    setForward(actionRequest, "portlet.requests.error");
064                            }
065                            else {
066                                    throw e;
067                            }
068                    }
069            }
070    
071            protected void updateRequest(ActionRequest actionRequest) throws Exception {
072                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
073                            WebKeys.THEME_DISPLAY);
074    
075                    long requestId = ParamUtil.getLong(actionRequest, "requestId");
076                    int status = ParamUtil.getInteger(actionRequest, "status");
077    
078                    SocialRequestServiceUtil.updateRequest(requestId, status, themeDisplay);
079            }
080    
081    }