Package com.eforce.baby.auth.action

Source Code of com.eforce.baby.auth.action.MenuAction

package com.eforce.baby.auth.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;

import com.eforce.baby.auth.delegates.MenuBD;
import com.eforce.baby.auth.vo.SessionUserVO;
import com.eforce.baby.common.dao.DAOException;
import com.eforce.baby.common.factory.BusinessDelegateFactory;
import com.eforce.baby.utils.IConstants;
import com.eforce.baby.utils.IErrorMessageKeys;

/**
* This class is used for handling the "modify menu"
* and "set default menu" requests that comes from the
* left navigation menu.
*
*/
public class MenuAction extends DispatchAction
{
    private Logger log = Logger.getLogger(this.getClass().getName());
    
    /**
     * This method is called when modify menu is clicked.
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward modifyMenu( ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response
                              throws IOException, ServletException
    {
       
        log.debug("modifyMenu() : ENTER");
        ActionForward actionFrwd = null;
        try
        {
            String enableList = (String) request.getParameter("menuEnabledList");
            String disableList = (String) request.getParameter("menuDisabledList");
           
           
            if (enableList != null)
            {
                if (enableList.startsWith(","))
                {
                    enableList = enableList.substring(1 , enableList.length());
                }
                if (enableList.endsWith(","))
                {
                    enableList = enableList.substring(0, enableList.lastIndexOf(","));
                }
            }
            else
            {
                enableList = "";
            }
           
            if (disableList != null)
            {
                if (disableList.startsWith(","))
                {
                    disableList = disableList.substring(1, disableList.length());
                }
                if (disableList.endsWith(","))
                {
                    disableList = disableList.substring(0, disableList.lastIndexOf(","));
                }
            }
            else
            {
                disableList = "";
            }
           
            log.debug("Enable List: " + enableList);
            log.debug("Disable List: " + disableList);
           
            int totalChanges = 0;
            int count = 0;
            if (!enableList.equals(disableList))
            {
                HttpSession session = request.getSession();
                SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
                String dsName = sessUser.getDsName();
                String dbType = sessUser.getDbType();
                String userId = sessUser.getUserId();
               
                //Enable Menus
                MenuBD menuBD = (MenuBD) BusinessDelegateFactory.getInstance().getDelegate(IConstants.CLASS_MENU_BD);
               
                if(enableList.length() > 0)
                {
                    int enableCount = menuBD.enableMenuItems(dsName, dbType, userId, enableList);
                    totalChanges = totalChanges + enableCount;
                }
               
                // Disable Disable
                ArrayList menuList = new ArrayList();
                StringTokenizer st = new StringTokenizer(disableList, ",");
                while (st.hasMoreTokens())
                {
                    menuList.add(st.nextToken());
                }
               
               
                if (menuList.size() > 0)
                {
                    for(int i = 0; i < menuList.size(); i++)
                    {
                        menuBD.disableMenuItems(dsName, dbType, userId, (String)menuList.get(i));
                        count = count + 1;
                    }
                }
               
            }
           
            totalChanges = totalChanges + count;
           
            log.debug("modifyMenu() : EXIT");
           
            PrintWriter out = response.getWriter();
            out.println("<html><body><script>alert('Total Changes = " + totalChanges +"'); eval('parent.frame_top_menu.location.href=\"../common/topnav.jsp\";'); eval('parent.frame_left_menu.location.href=\"../common/leftnav.jsp?menu=full\";')</script></body></html>");
        }
        catch(DAOException de)
        {
            ActionMessage message = new ActionMessage(IErrorMessageKeys.KEY_DATABASE_ERROR);
            ActionMessages messages = new ActionMessages();
            messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
            this.saveErrors(request, messages);
            actionFrwd = new ActionForward(mapping.getInput());
        }
           
        return actionFrwd;
    }
   
    /**
     * This method is called when the set Default menu item is clicked
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward setDefaultMenu( ActionMapping mapping,
                                       ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response
                                  throws IOException, ServletException
    {
        ActionForward actionFrwd = null;
        try
        {
            log.debug("modifyMenu() : ENTER");
       
            String defaultMenu = (String) request.getParameter("defaultMenu");
            log.debug("defaultMenu: " + defaultMenu);
           
            HttpSession session = request.getSession();
            SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
            String dsName = sessUser.getDsName();
            String dbType = sessUser.getDbType();
            String profileId = sessUser.getProfileId();
           
            MenuBD menuBD = (MenuBD) BusinessDelegateFactory.getInstance().getDelegate(IConstants.CLASS_MENU_BD);
           
            menuBD.setDefaultPage(dsName, dbType, profileId, defaultMenu);
           
           
            log.debug("profileId: " + sessUser.getProfileId());
       
            log.debug("modifyMenu() : EXIT");
       
            PrintWriter out = response.getWriter();
            out.println("<html><body><script>eval('parent.frame_top_menu.location.href=\"../common/topnav.jsp\";'); eval('parent.frame_left_menu.location.href=\"../common/leftnav.jsp?menu=full\";')</script></body></html>");
        }
        catch(DAOException de)
        {
            ActionMessage message = new ActionMessage(IErrorMessageKeys.KEY_DATABASE_ERROR);
            ActionMessages messages = new ActionMessages();
            messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
            this.saveErrors(request, messages);
            actionFrwd = new ActionForward(mapping.getInput());
        }
        return actionFrwd;
    }
   
}
TOP

Related Classes of com.eforce.baby.auth.action.MenuAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.