Package com.eforce.baby.auth.action

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

/**
*
*
*
*
*
* @author  Niladri Roy
* @version 1.0, Jul 21, 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.vo.RoleVO;
import com.eforce.baby.auth.vo.SessionUserVO;
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.auth.delegates.RoleBD;
import com.eforce.baby.utils.IConstants;
import com.eforce.baby.utils.IErrorMessageKeys;

/**
* @author nroy
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public final class RoleAction extends DispatchAction
{

  private Logger log = (Logger)Logger.getInstance(this.getClass().getName());
 
  /**
   * This is called when Role Report is viewed
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward viewRole( ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response)
                  throws IOException, ServletException
  {
    ActionForward actionFrwd = null;
 
    RoleBD bd = (RoleBD)BusinessDelegateFactory.getInstance().
                getDelegate("com.eteam.ems.auth.delegates.RoleBD");
    log.debug("calling get Role");
    HttpSession session = request.getSession();
    SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
    String dsName = sessUser.getDsName();
    String dbType = sessUser.getDbType();
    RoleVO roleVO = new RoleVO();
    try
    {
      roleVO = bd.getRole(dsName, dbType, request.getParameter("id"));
    }
    catch (Exception e) {
      log.error("ERROR in viewforupdaterole" +e);
    }
    log.debug("returning findUser");
    /* Forward to the View Page  */
    try
    {
      BeanUtils.copyProperties( form, roleVO );
    }
    catch( IllegalAccessException ex)
    {
      ex.printStackTrace();
    }
    catch( Exception ex)
    {
      ex.printStackTrace();
    }
       
        DynaActionForm dynaForm = (DynaActionForm) form;
        dynaForm.set("reportType", IConstants.REPORT_NAME_ROLE);

    actionFrwd = mapping.findForward(request.getParameter("target"));
    return actionFrwd;
 
  }
 
  /**
   * This is called when Role Report is viewed in update mode
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward viewForUpdateRole( ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response)
                    throws IOException, ServletException
  {
    ActionForward actionFrwd = null;

    RoleBD bd = (RoleBD)BusinessDelegateFactory.getInstance().
                getDelegate("com.eteam.ems.auth.delegates.RoleBD");
    log.debug("calling get Role");
    HttpSession session = request.getSession();
    SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
    String dsName = sessUser.getDsName();
    String dbType = sessUser.getDbType();
    RoleVO roleVO = new RoleVO();
    try
    {
      roleVO = bd.getRole(dsName, dbType, request.getParameter("id"));
    }
    catch (Exception e) {
      log.error("ERROR in viewforupdaterole" +e);
    }
    log.debug("returning findUser");
    /* Forward to the View Page  */
    try
    {
      BeanUtils.copyProperties( form, roleVO );
    }
    catch( IllegalAccessException ex)
    {
      ex.printStackTrace();
    }
    catch( Exception ex)
    {
      ex.printStackTrace();
    }
    actionFrwd = mapping.findForward(request.getParameter("target"));
    return actionFrwd;
  }
 
 
  /**
   * This is called when Role Report is Created
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward createRole(   ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response
                  )
                  throws IOException, ServletException 
  {   
    log.debug("Creating Role ...");
    ActionForward actionFrwd = null;
    RoleVO roleVO = new RoleVO();
    try
    {
 
      BeanUtils.copyProperties( roleVO, form );
   

    }
    catch (IllegalAccessException e)
    {
      log.error("ERROR in createRole",e);
    }
    catch (InvocationTargetException e)
    {
      log.error("ERROR in createRole",e);
    }
    log.debug("Asking for RoleBD");
    try
    {
      RoleBD bd = (RoleBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.RoleBD");
 
      log.debug("BD got, calling create Role");
   
      HttpSession session = request.getSession();
      SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
      String dsName = sessUser.getDsName();
      String dbType = sessUser.getDbType();
   
      bd.createDistGroup(dsName , dbType, roleVO);
      log.debug("Role Created Successfully !!!");
 
      request.setAttribute("fwd","/admin/Role.do?target=viewRole&id="+roleVO.getId());
      actionFrwd=mapping.findForward("pop_success");
 
    } catch(DAOException e){
      ActionMessage message;
      log.debug("Message Key:= "+e.getMessageKey());
      log.debug("Error Message := "+IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE);
      if( e.getMessageKey().equals(IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE)){
        message =  new ActionMessage(IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE);
      }
      else{
        message =  new ActionMessage(IErrorMessageKeys.KEY_DATABASE_ERROR);
      }
      //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());
    }
    catch (BusinessException be)
    {
      log.error("ERROR in createRole",be);

      // 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)
    {
      log.error("ERROR in createRole",e1);

      // 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 Role Report is updated
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward updateRole(   ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response
                  )
                  throws IOException, ServletException
    {
      ActionForward actionFrwd = null;
      log.debug("Updating  Role ...");
      RoleVO roleVO = new RoleVO();
      try
      {

        BeanUtils.copyProperties(roleVO,form);

      }
      catch (IllegalAccessException e)
      {
        log.error("ERROR in updateRole",e);
      }
      catch (InvocationTargetException e)
      {
        log.error("ERROR in updateRole",e);
      }
      log.debug("Asking for DistGroupBD");
      try
      {
        RoleBD bd = (RoleBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.RoleBD");
        log.debug("BD got, calling updateRole");

        HttpSession session = request.getSession();
        SessionUserVO sessUser = (SessionUserVO) session.getAttribute(IConstants.SESSION_ATTR_USER_SESSION_INFO);
        String dsName = sessUser.getDsName();
        String dbType = sessUser.getDbType();

        bd.updateRole(dsName , dbType, roleVO);
        log.debug("Role Updated Successfully !!!");

        request.setAttribute("fwd","/admin/Role.do?target=viewRole&id="+roleVO.getId());
        actionFrwd=mapping.findForward("pop_success");

      } catch(DAOException e){
        ActionMessage message;
        log.debug("Message Key:= "+e.getMessageKey());
        log.debug("Error Message := "+IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE);
        if( e.getMessageKey().equals(IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE)){
          message =  new ActionMessage(IErrorMessageKeys.KEY_ERROR_DUPLICATE_ROLE);
        }
        else{
          message =  new ActionMessage(IErrorMessageKeys.KEY_DATABASE_ERROR);
        }
        //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("/admin/Role.do?target=viewForUpdateRole&id="+roleVO.getId());
      }
      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("/admin/Role.do?target=viewForUpdateRole&id="+roleVO.getId());

      }
      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("/admin/Role.do?target=viewForUpdateRole&id="+roleVO.getId());

      }
      return actionFrwd;
    }
  /**
   * This is called when Role Report is Deleted
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward deleteRole(   ActionMapping mapping,
                    ActionForm form,
                    HttpServletRequest request,
                    HttpServletResponse response
                  )
                  throws IOException, ServletException
    {
      ActionForward actionFrwd = null;
             
      try
      {
        RoleBD bd = (RoleBD)BusinessDelegateFactory.getInstance().getDelegate("com.eteam.ems.auth.delegates.RoleBD");
        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.RoleAction

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.