Exemple #1
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse reponse) {

    S_IFC_Form form = (S_IFC_Form) actionForm;
    String nextAction = form.getNextAction();
    ActionForward forward = null;
    int id_set = form.getId_set();

    boolean dbException = false;
    try {
      Session session = HibernateUtil.getCurrentSession();
      HibernateUtil.beginTransaction();

      if (nextAction.equals("save")) {
        Shared_IFC_Set shared_ifc_set;

        if (id_set == -1) {
          // create
          shared_ifc_set = new Shared_IFC_Set();
          shared_ifc_set.setName(form.getName());
          shared_ifc_set.setPriority(form.getPriority());
          shared_ifc_set.setId_ifc(form.getId_ifc());

          int max_id_set = Shared_IFC_Set_DAO.get_max_id_set(session);
          shared_ifc_set.setId_set(max_id_set + 1);
          Shared_IFC_Set_DAO.insert(session, shared_ifc_set);
          id_set = max_id_set + 1;
          form.setId_set(id_set);

        } else {
          // update
          Shared_IFC_Set_DAO.update_all_from_set(session, id_set, form.getName());
        }

        forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
        forward = new ActionForward(forward.getPath() + "?id_set=" + id_set);
      } else if (nextAction.equals("refresh")) {
        Shared_IFC_Set shared_ifc_set =
            (Shared_IFC_Set) Shared_IFC_Set_DAO.get_by_set_ID(session, id_set);

        if (!S_IFC_Load.setForm(form, shared_ifc_set)) {
          logger.error(
              "The Shared IFC Set with the ID:" + id_set + " was not loaded from database!");
        }
        forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
        forward = new ActionForward(forward.getPath() + "?id_set=" + id_set);
      } else if (nextAction.equals("delete")) {
        Shared_IFC_Set_DAO.delete_set_by_ID(session, id_set);
        forward = actionMapping.findForward(WebConstants.FORWARD_DELETE);
      } else if (nextAction.equals("attach_ifc")) {
        Shared_IFC_Set shared_ifc_set = new Shared_IFC_Set();
        shared_ifc_set.setId_set(id_set);
        shared_ifc_set.setName(form.getName());
        shared_ifc_set.setId_ifc(form.getId_ifc());
        shared_ifc_set.setPriority(form.getPriority());
        Shared_IFC_Set_DAO.insert(session, shared_ifc_set);

        forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
        forward = new ActionForward(forward.getPath() + "?id_set=" + id_set);
      } else if (nextAction.equals("detach_ifc")) {
        int cnt = Shared_IFC_Set_DAO.get_cnt_for_set(session, id_set);
        Shared_IFC_Set_DAO.delete_ifc_from_set(session, id_set, form.getAssociated_ID());
        if (cnt == 1) {
          forward = actionMapping.findForward(WebConstants.FORWARD_DELETE);
        } else {
          forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
          forward = new ActionForward(forward.getPath() + "?id_set=" + id_set);
        }
      }

      S_IFC_Load.prepareForward(session, form, request, id_set);
    } catch (DatabaseException e) {
      logger.error("Database Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;

      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } catch (HibernateException e) {
      logger.error("Hibernate Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;

      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } finally {
      if (!dbException) {
        HibernateUtil.commitTransaction();
      }
      HibernateUtil.closeSession();
    }
    return forward;
  }
Exemple #2
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse reponse) {

    IFC_SearchForm form = (IFC_SearchForm) actionForm;
    Object[] queryResult = null;
    IFC uniqueResult = null;
    ActionForward forward = null;

    int rowsPerPage = Integer.parseInt(form.getRowsPerPage());
    int currentPage = Integer.parseInt(form.getCrtPage()) - 1;
    int firstResult = currentPage * rowsPerPage;

    boolean dbException = false;
    try {
      Session session = HibernateUtil.getCurrentSession();
      HibernateUtil.beginTransaction();

      if (form.getId_ifc() != null && !form.getId_ifc().equals("")) {
        uniqueResult = IFC_DAO.get_by_ID(session, Integer.parseInt(form.getId_ifc()));
      } else if (form.getName() != null && !form.getName().equals("")) {
        queryResult =
            IFC_DAO.get_by_Wildcarded_Name(session, form.getName(), firstResult, rowsPerPage);
      } else if (form.getName_application_server() != null
          && !form.getName_application_server().equals("")) {
        queryResult =
            IFC_DAO.get_by_Wildcarded_AS_Name(
                session, form.getName_application_server(), firstResult, rowsPerPage);
      } else if (form.getName_tp() != null && !form.getName_tp().equals("")) {
        queryResult =
            IFC_DAO.get_by_Wildcarded_TP_Name(session, form.getName_tp(), firstResult, rowsPerPage);
      } else {
        queryResult = IFC_DAO.get_all(session, firstResult, rowsPerPage);
      }

      int maxPages = 1;
      if (queryResult != null) {
        // more than one result
        maxPages = ((((Integer) queryResult[0]).intValue() - 1) / rowsPerPage) + 1;
        request.setAttribute("resultList", (List) queryResult[1]);
      } else {
        List list = new LinkedList();
        if (uniqueResult != null) {
          list.add(uniqueResult);
        }
        request.setAttribute("resultList", list);
      }

      if (currentPage > maxPages) {
        currentPage = 0;
      }

      request.setAttribute("maxPages", String.valueOf(maxPages));
      request.setAttribute("currentPage", String.valueOf(currentPage));
      request.setAttribute("rowPerPage", String.valueOf(rowsPerPage));

      forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
    } catch (DatabaseException e) {
      logger.error("Database Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;
      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } catch (HibernateException e) {
      logger.error("Hibernate Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;
      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } finally {
      if (!dbException) {
        HibernateUtil.commitTransaction();
      }
      HibernateUtil.closeSession();
    }

    return forward;
  }
Exemple #3
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse reponse) {

    VN_Form form = (VN_Form) actionForm;
    String nextAction = form.getNextAction();
    ActionForward forward = null;
    int id = form.getId();

    boolean dbException = false;
    try {
      Session session = HibernateUtil.getCurrentSession();
      HibernateUtil.beginTransaction();

      if (nextAction.equals("save")) {
        VisitedNetwork visited_network;

        if (id == -1) {
          // create
          visited_network = new VisitedNetwork();
        } else {
          // update
          visited_network = VisitedNetwork_DAO.get_by_ID(session, id);
        }

        // make the changes
        visited_network.setIdentity(form.getIdentity());

        if (id == -1) {
          VisitedNetwork_DAO.insert(session, visited_network);
          id = visited_network.getId();
          form.setId(id);
        } else {
          VisitedNetwork_DAO.update(session, visited_network);
        }

        forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
        forward = new ActionForward(forward.getPath() + "?id=" + id);
      } else if (nextAction.equals("refresh")) {
        VisitedNetwork visited_network = (VisitedNetwork) VisitedNetwork_DAO.get_by_ID(session, id);

        if (!VN_Load.setForm(form, visited_network)) {
          logger.error("The VisitedNetwork withe the ID:" + id + " was not loaded from database!");
        }
        forward = actionMapping.findForward(WebConstants.FORWARD_SUCCESS);
        forward = new ActionForward(forward.getPath() + "?id=" + id);

      } else if (nextAction.equals("delete")) {
        VisitedNetwork_DAO.delete_by_ID(session, id);
        forward = actionMapping.findForward(WebConstants.FORWARD_DELETE);
      }

      VN_Load.prepareForward(session, form, request, id);
    } catch (DatabaseException e) {
      logger.error("Database Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;

      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } catch (HibernateException e) {
      logger.error("Hibernate Exception occured!\nReason:" + e.getMessage());
      e.printStackTrace();
      dbException = true;

      forward = actionMapping.findForward(WebConstants.FORWARD_FAILURE);
    } finally {
      if (!dbException) {
        HibernateUtil.commitTransaction();
      }
      HibernateUtil.closeSession();
    }
    return forward;
  }