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