1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.requests.action;
21  
22  import com.liferay.portal.kernel.servlet.SessionErrors;
23  import com.liferay.portal.kernel.util.ParamUtil;
24  import com.liferay.portal.model.Group;
25  import com.liferay.portal.model.User;
26  import com.liferay.portal.security.auth.PrincipalException;
27  import com.liferay.portal.security.permission.ActionKeys;
28  import com.liferay.portal.service.GroupLocalServiceUtil;
29  import com.liferay.portal.service.UserLocalServiceUtil;
30  import com.liferay.portal.service.permission.UserPermissionUtil;
31  import com.liferay.portal.struts.PortletAction;
32  import com.liferay.portal.theme.ThemeDisplay;
33  import com.liferay.portal.util.WebKeys;
34  import com.liferay.portlet.social.NoSuchRequestException;
35  import com.liferay.portlet.social.service.SocialRequestLocalServiceUtil;
36  
37  import javax.portlet.ActionRequest;
38  import javax.portlet.ActionResponse;
39  import javax.portlet.PortletConfig;
40  
41  import org.apache.struts.action.ActionForm;
42  import org.apache.struts.action.ActionMapping;
43  
44  /**
45   * <a href="UpdateRequestAction.java.html"><b><i>View Source</i></b></a>
46   *
47   * @author Brian Wing Shun Chan
48   *
49   */
50  public class UpdateRequestAction extends PortletAction {
51  
52      public void processAction(
53              ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54              ActionRequest actionRequest, ActionResponse actionResponse)
55          throws Exception {
56  
57          try {
58              ThemeDisplay themeDisplay =
59                  (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
60  
61              Group group = GroupLocalServiceUtil.getGroup(
62                  themeDisplay.getScopeGroupId());
63  
64              User user = themeDisplay.getUser();
65  
66              if (group.isUser()) {
67                  user = UserLocalServiceUtil.getUserById(group.getClassPK());
68              }
69  
70              if (!UserPermissionUtil.contains(
71                      themeDisplay.getPermissionChecker(), user.getUserId(),
72                      ActionKeys.UPDATE)) {
73  
74                  throw new PrincipalException();
75              }
76  
77              updateRequest(actionRequest);
78  
79              String redirect = ParamUtil.getString(actionRequest, "redirect");
80  
81              actionResponse.sendRedirect(redirect);
82          }
83          catch (Exception e) {
84              if (e instanceof NoSuchRequestException ||
85                  e instanceof PrincipalException) {
86  
87                  SessionErrors.add(actionRequest, e.getClass().getName());
88  
89                  setForward(actionRequest, "portlet.requests.error");
90              }
91              else {
92                  throw e;
93              }
94          }
95      }
96  
97      protected void updateRequest(ActionRequest actionRequest) throws Exception {
98          ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
99              WebKeys.THEME_DISPLAY);
100 
101         long requestId = ParamUtil.getLong(actionRequest, "requestId");
102         int status = ParamUtil.getInteger(actionRequest, "status");
103 
104         SocialRequestLocalServiceUtil.updateRequest(
105             requestId, status, themeDisplay);
106     }
107 
108 }