1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.action;
16  
17  import com.liferay.portal.NoSuchUserException;
18  import com.liferay.portal.UserReminderQueryException;
19  import com.liferay.portal.kernel.servlet.SessionErrors;
20  import com.liferay.portal.kernel.util.Constants;
21  import com.liferay.portal.kernel.util.ParamUtil;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.security.auth.AuthTokenUtil;
24  import com.liferay.portal.security.auth.PrincipalException;
25  import com.liferay.portal.service.UserServiceUtil;
26  import com.liferay.portal.struts.ActionConstants;
27  import com.liferay.portal.util.PortalUtil;
28  import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
29  
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  
33  import org.apache.struts.action.Action;
34  import org.apache.struts.action.ActionForm;
35  import org.apache.struts.action.ActionForward;
36  import org.apache.struts.action.ActionMapping;
37  
38  /**
39   * <a href="UpdateReminderQueryAction.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   */
43  public class UpdateReminderQueryAction extends Action {
44  
45      public ActionForward execute(
46              ActionMapping mapping, ActionForm form, HttpServletRequest request,
47              HttpServletResponse response)
48          throws Exception {
49  
50          String cmd = ParamUtil.getString(request, Constants.CMD);
51  
52          if (Validator.isNull(cmd)) {
53              return mapping.findForward("portal.update_reminder_query");
54          }
55  
56          try {
57              updateReminderQuery(request, response);
58  
59              return mapping.findForward(ActionConstants.COMMON_REFERER);
60          }
61          catch (Exception e) {
62              if (e instanceof UserReminderQueryException) {
63                  SessionErrors.add(request, e.getClass().getName());
64  
65                  return mapping.findForward("portal.update_reminder_query");
66              }
67              else if (e instanceof NoSuchUserException ||
68                       e instanceof PrincipalException) {
69  
70                  SessionErrors.add(request, e.getClass().getName());
71  
72                  return mapping.findForward("portal.error");
73              }
74              else {
75                  PortalUtil.sendError(e, request, response);
76  
77                  return null;
78              }
79          }
80      }
81  
82      protected void updateReminderQuery(
83              HttpServletRequest request, HttpServletResponse response)
84          throws Exception {
85  
86          AuthTokenUtil.check(request);
87  
88          long userId = PortalUtil.getUserId(request);
89          String question = ParamUtil.getString(request, "reminderQueryQuestion");
90          String answer = ParamUtil.getString(request, "reminderQueryAnswer");
91  
92          if (question.equals(EnterpriseAdminUtil.CUSTOM_QUESTION)) {
93              question = ParamUtil.getString(
94                  request, "reminderQueryCustomQuestion");
95          }
96  
97          UserServiceUtil.updateReminderQuery(userId, question, answer);
98      }
99  
100 }