001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.action;
016    
017    import com.liferay.portal.NoSuchUserException;
018    import com.liferay.portal.UserReminderQueryException;
019    import com.liferay.portal.kernel.servlet.SessionErrors;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.kernel.util.Validator;
023    import com.liferay.portal.security.auth.AuthTokenUtil;
024    import com.liferay.portal.security.auth.PrincipalException;
025    import com.liferay.portal.service.UserServiceUtil;
026    import com.liferay.portal.struts.ActionConstants;
027    import com.liferay.portal.util.PortalUtil;
028    import com.liferay.portlet.enterpriseadmin.util.EnterpriseAdminUtil;
029    
030    import javax.servlet.http.HttpServletRequest;
031    import javax.servlet.http.HttpServletResponse;
032    
033    import org.apache.struts.action.Action;
034    import org.apache.struts.action.ActionForm;
035    import org.apache.struts.action.ActionForward;
036    import org.apache.struts.action.ActionMapping;
037    
038    /**
039     * @author Brian Wing Shun Chan
040     */
041    public class UpdateReminderQueryAction extends Action {
042    
043            public ActionForward execute(
044                            ActionMapping mapping, ActionForm form, HttpServletRequest request,
045                            HttpServletResponse response)
046                    throws Exception {
047    
048                    String cmd = ParamUtil.getString(request, Constants.CMD);
049    
050                    if (Validator.isNull(cmd)) {
051                            return mapping.findForward("portal.update_reminder_query");
052                    }
053    
054                    try {
055                            updateReminderQuery(request, response);
056    
057                            return mapping.findForward(ActionConstants.COMMON_REFERER);
058                    }
059                    catch (Exception e) {
060                            if (e instanceof UserReminderQueryException) {
061                                    SessionErrors.add(request, e.getClass().getName());
062    
063                                    return mapping.findForward("portal.update_reminder_query");
064                            }
065                            else if (e instanceof NoSuchUserException ||
066                                             e instanceof PrincipalException) {
067    
068                                    SessionErrors.add(request, e.getClass().getName());
069    
070                                    return mapping.findForward("portal.error");
071                            }
072                            else {
073                                    PortalUtil.sendError(e, request, response);
074    
075                                    return null;
076                            }
077                    }
078            }
079    
080            protected void updateReminderQuery(
081                            HttpServletRequest request, HttpServletResponse response)
082                    throws Exception {
083    
084                    AuthTokenUtil.check(request);
085    
086                    long userId = PortalUtil.getUserId(request);
087                    String question = ParamUtil.getString(request, "reminderQueryQuestion");
088                    String answer = ParamUtil.getString(request, "reminderQueryAnswer");
089    
090                    if (question.equals(EnterpriseAdminUtil.CUSTOM_QUESTION)) {
091                            question = ParamUtil.getString(
092                                    request, "reminderQueryCustomQuestion");
093                    }
094    
095                    UserServiceUtil.updateReminderQuery(userId, question, answer);
096            }
097    
098    }