001    /**
002     * Copyright (c) 2000-2012 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 mapping, ActionForm form, PortletConfig portletConfig,
043                            ActionRequest actionRequest, ActionResponse actionResponse)
044                    throws Exception {
045    
046                    try {
047                            updateRequest(actionRequest);
048    
049                            String redirect = PortalUtil.escapeRedirect(
050                                    ParamUtil.getString(actionRequest, "redirect"));
051    
052                            if (Validator.isNotNull(redirect)) {
053                                    actionResponse.sendRedirect(redirect);
054                            }
055                    }
056                    catch (Exception e) {
057                            if (e instanceof NoSuchRequestException ||
058                                    e instanceof PrincipalException) {
059    
060                                    SessionErrors.add(actionRequest, e.getClass());
061    
062                                    setForward(actionRequest, "portlet.requests.error");
063                            }
064                            else {
065                                    throw e;
066                            }
067                    }
068            }
069    
070            protected void updateRequest(ActionRequest actionRequest) throws Exception {
071                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
072                            WebKeys.THEME_DISPLAY);
073    
074                    long requestId = ParamUtil.getLong(actionRequest, "requestId");
075                    int status = ParamUtil.getInteger(actionRequest, "status");
076    
077                    SocialRequestServiceUtil.updateRequest(requestId, status, themeDisplay);
078            }
079    
080    }