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