Package com.eforce.baby.auth.action

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

/**
*
*
*
*
*
* @author  Niadri Roy
* @version 1.0, 07/08/2004
* @since   EEMS architecture refresh
*/
package com.eforce.baby.auth.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

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

import org.apache.commons.beanutils.BeanUtils;
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.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

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

public class UserAction extends DispatchAction
{
  private Logger log = (Logger)Logger.getInstance(this.getClass().getName());
 
  /**
   * This is called when User is created
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward createUser(   ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response
                  )
                  throws IOException, ServletException
    {   
      log.debug("Creating User ...");
      ActionForward actionFrwd = null;
      UserVO userVO = new UserVO();
      try
      {
       
        BeanUtils.copyProperties( userVO, form );
     
      }
      catch (IllegalAccessException e)
      {
        log.error("ERROR in createUser",e);
      }
      catch (InvocationTargetException e)
      {
        log.error("ERROR in createUser",e);
      }
      log.debug("Asking for UserBD");
      try
      {
        UserBD bd = (UserBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.UserBD");
        log.debug("BD got, calling create User");
               
                HttpSession session = request.getSession();
                SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
        String dsName = sessUser.getDsName();
        String dbType = sessUser.getDbType();
               
                bd.createUser(dsName , dbType, userVO);
        log.debug("User Created Successfully !!!");
       
        request.setAttribute("fwd","/admin/User.do?target=viewUser&id="+userVO.getId());
        actionFrwd=mapping.findForward("pop_success");
       
      }
      catch (BusinessException be)
        {
          // TODO Auto-generated catch block
         
 
          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(be.getMessageKey());
          ActionMessages messages = new ActionMessages();
          messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
          this.saveErrors(request, messages);
         
          actionFrwd = new ActionForward(mapping.getInput());
 
        }
        catch (Exception e1)
        {
          // TODO Auto-generated catch block
          e1.printStackTrace();

          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(IErrorMessageKeys.KEY_FATAL_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 is called when User is viewed
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws ServletException
     */
    public ActionForward viewUser(   ActionMapping mapping,
                      ActionForm form,
                      HttpServletRequest request,
                      HttpServletResponse response
                    )
                      throws IOException, ServletException
    {
      ActionForward actionFrwd = null;
     
      UserBD bd = (UserBD)BusinessDelegateFactory.getInstance().
                  getDelegate("com.eteam.ems.auth.delegates.UserBD");
      log.debug("calling findUser");
      HttpSession session = request.getSession();
      SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
      String dsName = sessUser.getDsName();
      String dbType = sessUser.getDbType();
            UserVO userVO = new UserVO();
      try
            {
        userVO = bd.findUser(dsName, dbType, request.getParameter("id"));
      }
            catch (DAOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      log.debug("returning findUser");
      /* Forward to the View Page  */
      try
      {
        BeanUtils.copyProperties( form, userVO );
      }
      catch( IllegalAccessException ex)
      {
        ex.printStackTrace();
      }
      catch( Exception ex)
      {
        ex.printStackTrace();
      }
           
            DynaActionForm dynaForm = (DynaActionForm) form;
            dynaForm.set(IConstants.FORM_ATTR_REPORT_TYPE, IConstants.REPORT_NAME_USER);

      //request.setAttribute("update" + reportVO.getId(),userVO);
    
    
      actionFrwd = mapping.findForward(request.getParameter("target"));
      return actionFrwd;
     
    }
   
  /**
   *  This is called when User is viewed in update mode
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward viewForUpdateUser(   ActionMapping mapping,
                        ActionForm form,
                        HttpServletRequest request,
                        HttpServletResponse response
                      )
                    throws IOException, ServletException
    {
      ActionForward actionFrwd = null;
     
      UserBD bd = (UserBD)BusinessDelegateFactory.getInstance().
                  getDelegate("com.eteam.ems.auth.delegates.UserBD");
      log.debug("calling findUser");
      HttpSession session = request.getSession();
      SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
      String dsName = sessUser.getDsName();
      String dbType = sessUser.getDbType();
      UserVO userVO = new UserVO();
      try
      {
        userVO = bd.findUser(dsName, dbType, request.getParameter("id"));
      }
      catch (DAOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      log.debug("returning findUser");
      /* Forward to the View Page  */
      try
      {
        BeanUtils.copyProperties( form, userVO );
      }
      catch( IllegalAccessException ex)
      {
        ex.printStackTrace();
      }
      catch( Exception ex)
      {
        ex.printStackTrace();
      }

      //request.setAttribute("update" + reportVO.getId(),userVO);
    
    
      actionFrwd = mapping.findForward(request.getParameter("target"));
      return actionFrwd;
     
    }

  /**
   *  This is called when User is updated
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward updateUser(   ActionMapping mapping,
                      ActionForm form,
                      HttpServletRequest request,
                      HttpServletResponse response
                    )
                    throws IOException, ServletException
      {
        ActionForward actionFrwd = null;
        log.debug("Updating  User ...");
        UserVO userVO = new UserVO();
        try
        {
 
          BeanUtils.copyProperties(userVO,form);
 
        }
        catch (IllegalAccessException e)
        {
          log.error("ERROR in updateUser",e);
        }
        catch (InvocationTargetException e)
        {
          log.error("ERROR in updateUser",e);
        }
        log.debug("Asking for UserBD");
        try
        {
          UserBD bd = (UserBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.UserBD");
          log.debug("BD got, calling updateUser User");
 
          HttpSession session = request.getSession();
          SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
          String dsName = sessUser.getDsName();
          String dbType = sessUser.getDbType();
 
          bd.updateUser(dsName , dbType, userVO);
          log.debug("User Updated Successfully !!!");
 
          request.setAttribute("fwd","/admin/User.do?target=viewUser&id="+userVO.getId());
          actionFrwd=mapping.findForward("pop_success");
 
        }
        catch (BusinessException be)
        {
          // TODO Auto-generated catch block
         
 
          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(be.getMessageKey());
          ActionMessages messages = new ActionMessages();
          messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
          this.saveErrors(request, messages);
         
          actionFrwd = new ActionForward(mapping.getInput());
 
        }
        catch (Exception e1)
        {
          // TODO Auto-generated catch block
          e1.printStackTrace();

          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(IErrorMessageKeys.KEY_FATAL_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 is called when User is deleted
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws IOException
     * @throws ServletException
     */
    public ActionForward deleteUser(   ActionMapping mapping,
                      ActionForm form,
                      HttpServletRequest request,
                      HttpServletResponse response
                    )
                    throws IOException, ServletException
      {
        ActionForward actionFrwd = null;
             
        try
        {
          UserBD bd = (UserBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.UserBD");
          HttpSession session = request.getSession();
          SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
          String dsName = sessUser.getDsName();
          String dbType = sessUser.getDbType();
           
          bd.delete( dsName, dbType,request.getParameter("id"));
         
          actionFrwd = mapping.findForward(request.getParameter("target"));
        }
        catch (BusinessException be)
        {
          // TODO Auto-generated catch block
         
 
          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(be.getMessageKey());
          ActionMessages messages = new ActionMessages();
          messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
          this.saveErrors(request, messages);
         
          actionFrwd = new ActionForward(mapping.getInput());
 
        }
        catch (Exception e1)
        {
          // TODO Auto-generated catch block
          e1.printStackTrace();

          // If some business error occured, will return to the input page
          ActionMessage message = new ActionMessage(IErrorMessageKeys.KEY_FATAL_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.UserAction

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.