Exemplo n.º 1
0
  /**
   * the action method for inserting new hotel contract to db
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward insert(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    Hotel hotel = this.getHotelFromRequest(request);
    this.checkHotel(hotel, request);

    BeanForm hotelContractForm = (BeanForm) form;
    HotelContract hotelContract = new HotelContract();
    hotelContractForm.populate(hotelContract, BeanForm.TO_BEAN);
    hotelContract.setHotel(hotel);

    FormFile file = (FormFile) hotelContractForm.get("fileContent");
    hotelContract.setFileName(file.getFileName());

    HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request);
    HotelContract newHc = null;
    if (file.getFileSize() > 0) {
      hotelContract.setFileSize(file.getFileSize());
      newHc = hotelContractManager.insertHotelContract(hotelContract, file.getInputStream());
    } else {
      throw new ActionException("hotelContract.error.fileSize.zero");
    }
    request.setAttribute("X_OBJECT", newHc);
    request.setAttribute("X_ROWPAGE", "hotelContract/row.jsp");

    return mapping.findForward("success");
  }
Exemplo n.º 2
0
  /**
   * the action method for downloading hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward download(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HotelContract hotelContract = this.getHotelContractFromRequest(request);
    Hotel hotel = hotelContract.getHotel();
    this.checkHotel(hotel, request);

    InputStream in =
        ServiceLocator.getHotelContractManager(request)
            .getHotelContractContent(hotelContract.getId());
    if (in != null) {
      try {
        if (hotelContract.getFileSize() == 0) {
          throw new ActionException("hotelContract.error.fileSize.zero");
        } else {
          DownloadUploadHelper.download(
              in,
              hotelContract.getFileName(),
              DownloadUploadHelper.getMime(hotelContract.getFileName()),
              hotelContract.getFileSize(),
              request,
              response,
              true);
        }
      } finally {
        in.close();
      }
    }
    return null;
  }
Exemplo n.º 3
0
 private HotelContract getHotelContractFromRequest(HttpServletRequest request) throws Exception {
   Integer id = ActionUtils.parseInt(request.getParameter("id"));
   HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request);
   HotelContract hotelContract = hotelContractManager.getHotelContract(id);
   if (hotelContract == null) throw new ActionException("hotelContract.notFound", id);
   return hotelContract;
 }
Exemplo n.º 4
0
  /**
   * the action method for searching hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward list(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HotelContractQueryForm queryForm = (HotelContractQueryForm) form;
    getHotelFromRequest(request);

    Map conditions = constructQueryMap(queryForm);

    HotelContractManager fm = ServiceLocator.getHotelContractManager(request);
    List result = fm.getHotelContractList(conditions, 0, -1, HotelContractQueryOrder.ID, false);
    request.setAttribute("X_RESULTLIST", result);
    return mapping.findForward("page");
  }
Exemplo n.º 5
0
  /**
   * the action method for updating hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward update(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    Hotel hotel = this.getHotelFromRequest(request);
    this.checkHotel(hotel, request);

    BeanForm hotelContractForm = (BeanForm) form;
    HotelContract hotelContract = new HotelContract();
    hotelContractForm.populate(hotelContract, BeanForm.TO_BEAN);

    HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request);
    request.setAttribute("X_OBJECT", hotelContractManager.updateHotelContract(hotelContract));
    request.setAttribute("X_ROWPAGE", "hotelContract/row.jsp");

    return mapping.findForward("success");
  }