Package com.eforce.baby.auth.action

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

package com.eforce.baby.auth.action;

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

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.DistributionGroupBD;
import com.eforce.baby.auth.vo.DistributionGroupVO;
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.utils.IConstants;
import com.eforce.baby.utils.IErrorMessageKeys;

/**
* Implementation of <strong>Action</strong> that validates a multi-page
* registration form.

*/
public final class DistributionGroupAction extends DispatchAction {

  private Logger log = (Logger) Logger.getInstance(this.getClass().getName());

  /**
   * Called when new DistributionGroup Report is created
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward createDistGroup(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    log.debug("Creating group ...");
    ActionForward actionFrwd = null;
    DistributionGroupVO distGroupVO = new DistributionGroupVO();
    try {

      BeanUtils.copyProperties(distGroupVO, form);

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

      log.debug("BD got, calling create distribution group");

      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, distGroupVO);
      log.debug("Distribution Group Created Successfully !!!");

      request.setAttribute(
        "fwd",
        "/admin/DistributionGroup.do?target=viewDistGroup&id="
          + distGroupVO.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_DIST_GROUP);
      if( e.getMessageKey().equals(IErrorMessageKeys.KEY_ERROR_DUPLICATE_DIST_GROUP)){
        message =  new ActionMessage(IErrorMessageKeys.KEY_ERROR_DUPLICATE_DIST_GROUP);
      }
      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 e){
      ActionMessage message = new ActionMessage(e.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 createDistGroup", 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;
  }

  /**
   * Called when report is viewed
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward viewDistGroup(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    ActionForward actionFrwd = null;

    DistributionGroupBD bd =
      (DistributionGroupBD) BusinessDelegateFactory
        .getInstance()
        .getDelegate(
        "com.eteam.ems.auth.delegates.DistributionGroupBD");
    log.debug("calling findDistGroup");
    HttpSession session = request.getSession();
    SessionUserVO sessUser =
      (SessionUserVO) session.getAttribute(
        IConstants.SESSION_ATTR_USER_SESSION_INFO);
    String dsName = sessUser.getDsName();
    String dbType = sessUser.getDbType();
    DistributionGroupVO distGroupVO = new DistributionGroupVO();
    try {
      distGroupVO =
        bd.getDistGroup(dsName, dbType, request.getParameter("id"));
    } catch(DAOException e){
      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 e){
      ActionMessage message = new ActionMessage(e.getMessageKey());
      ActionMessages messages = new ActionMessages();
      messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
      this.saveErrors(request, messages);

      actionFrwd = new ActionForward(mapping.getInput());
    }
    log.debug("returning findUser");
    /* Forward to the View Page  */
    try {
      BeanUtils.copyProperties(form, distGroupVO);
    } catch (IllegalAccessException ex) {
      log.error("Error:" + ex);
    } catch (Exception ex) {
      log.error("Error:" + ex);
    }
       
        DynaActionForm dynaForm = (DynaActionForm) form;
        dynaForm.set(IConstants.FORM_ATTR_REPORT_TYPE, IConstants.REPORT_NAME_DIST_GROUP);

    actionFrwd = mapping.findForward(request.getParameter("target"));
    return actionFrwd;

  }

  /**
   * Called when report is viewed for update
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward viewForUpdateDistGroup(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    ActionForward actionFrwd = null;

    DistributionGroupBD bd =
      (DistributionGroupBD) BusinessDelegateFactory
        .getInstance()
        .getDelegate(
        "com.eteam.ems.auth.delegates.DistributionGroupBD");
    log.debug("calling findDistGroup");
    HttpSession session = request.getSession();
    SessionUserVO sessUser =
      (SessionUserVO) session.getAttribute(
        IConstants.SESSION_ATTR_USER_SESSION_INFO);
    String dsName = sessUser.getDsName();
    String dbType = sessUser.getDbType();
    DistributionGroupVO distGroupVO = new DistributionGroupVO();
    try {
      distGroupVO =
        bd.getDistGroup(dsName, dbType, request.getParameter("id"));
    } catch(DAOException e){
      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 e){
      ActionMessage message = new ActionMessage(e.getMessageKey());
      ActionMessages messages = new ActionMessages();
      messages.add(IConstants.PAGE_ERROR_MSG_ERROR_MESSAGE, message);
      this.saveErrors(request, messages);

      actionFrwd = new ActionForward(mapping.getInput());
    }
    log.debug("returning findUser");
    /* Forward to the View Page  */
    try {
      BeanUtils.copyProperties(form, distGroupVO);
    } catch (IllegalAccessException ex) {
      log.error("Error:" + ex);
    } catch (Exception ex) {
      log.error("Error:" + ex);
    }

    actionFrwd = mapping.findForward(request.getParameter("target"));
    return actionFrwd;

  }
  /**
   * Called when report is viewed for update and 'Submit' button is pressed
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward updateDistGroup(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    ActionForward actionFrwd = null;
    log.debug("Updating  Dist Group ...");
    DistributionGroupVO distGroupVO = new DistributionGroupVO();
    try {

      BeanUtils.copyProperties(distGroupVO, form);

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

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

      bd.updateDistGroup(dsName, dbType, distGroupVO);
      log.debug("distGroup Updated Successfully !!!");

      request.setAttribute(
        "fwd",
        "/admin/DistributionGroup.do?target=viewDistGroup&id="
          + distGroupVO.getId());
      actionFrwd = mapping.findForward("pop_success");

    } catch (BusinessException 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(DAOException e){
      ActionMessage message;
      log.debug("Message Key:= "+e.getMessageKey());
      log.debug("Error Message := "+IErrorMessageKeys.KEY_ERROR_DUPLICATE_DIST_GROUP);
      if( e.getMessageKey().equals(IErrorMessageKeys.KEY_ERROR_DUPLICATE_DIST_GROUP)){
        message =  new ActionMessage(IErrorMessageKeys.KEY_ERROR_DUPLICATE_DIST_GROUP);
      }
      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());
      actionFrwd = new ActionForward("/admin/DistributionGroup.do?target=viewForUpdateDistGroup&id="+distGroupVO.getId());
    } catch (Exception e1) {
      // TODO Auto-generated catch block
      log.error("Error:" + 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());
      actionFrwd = new ActionForward("/admin/DistributionGroup.do?target=viewForUpdateDistGroup&id="+distGroupVO.getId());
    }
    return actionFrwd;
  }

  /**
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward findGroupsForDsitribution(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    DistributionGroupBD bd =
      (DistributionGroupBD) BusinessDelegateFactory
        .getInstance()
        .getDelegate(
        IConstants.CLASS_DIST_GROUP_BD);
    HttpSession session = request.getSession();
    SessionUserVO sessUser =
      (SessionUserVO) session.getAttribute(
        IConstants.SESSION_ATTR_USER_SESSION_INFO);
    ArrayList list = null;
    try {
      list =
        bd.findGroupsForDistribution(
          sessUser.getDsName(),
          sessUser.getDbType());
    } catch (BusinessException 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(DAOException e){
      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());
    }
    request.setAttribute(IConstants.REQ_ATTR_DIST_GROUP_LIST, list);
    return mapping.findForward(IConstants.FRWD_DISTRIBUTION_GROUP);
  }

  /**
   * This is to delete a distribution group
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws IOException
   * @throws ServletException
   */
  public ActionForward deleteDistGroup(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {
    ActionForward actionFrwd = null;

    try {
      DistributionGroupBD bd =
        (DistributionGroupBD) BusinessDelegateFactory
          .getInstance()
          .getDelegate(
          "com.eteam.ems.auth.delegates.DistributionGroupBD");
      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(DAOException e){
      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 (Exception e1) {
      // TODO Auto-generated catch block
      log.error("Error:" + 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;
  }

}
TOP

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

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.