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.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    }