1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 }