Пример #1
0
 private long hashTheBooking(Booking booking) {
   String toHash = booking.getRoomName() + booking.getUserMail();
   SimpleDateFormat ft = new SimpleDateFormat("HHddMMyyyy");
   toHash += ft.format(booking.getDate());
   toHash += ft.format(booking.getCreationDate());
   toHash += booking.getSpectacle().getName();
   toHash += booking.getTotalPrice();
   return toHash.hashCode();
 }
Пример #2
0
  /**
   * Handles the HTTP <code>POST</code> method.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    LinkedList<Booking> bookings =
        (LinkedList<Booking>) request.getSession().getAttribute("bookings");
    if (this.checkBookings(request)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    } else {
      Iterator<Booking> iterator = bookings.iterator();
      LinkedList<Sale> sales = new LinkedList<Sale>();
      LinkedList<Case> cases = new LinkedList<Case>();
      while (iterator.hasNext()) {
        Booking currentBooking = iterator.next();
        Case currentCase = new Case();
        currentCase.setNumber(this.hashTheBooking(currentBooking));
        currentCase.setTicketNumber(currentCase.getNumber());
        currentCase.setUserMail(currentBooking.getUserMail());
        currentCase.setRoomName(currentBooking.getRoomName());
        currentCase.setDate(currentBooking.getDate());
        currentCase.setSpectacleName(currentBooking.getSpectacle().getName());
        cases.add(currentCase);
        try {
          this.daoCase.create(currentCase);
          Sale currentSale = this.daoSale.createFromBooking(currentBooking, currentCase);
          sales.add(currentSale);
          bookings.remove(currentBooking);
        } catch (Exception e) {
          this.daoBooking.create(currentBooking);
          response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
      }
      LinkedList<Sale> salesSession = this.getSales(request);
      LinkedList<Case> casesSession = this.getCases(request);
      if (salesSession != null) sales.addAll(salesSession);
      if (casesSession != null) cases.addAll(casesSession);
      request.getSession().setAttribute("sales", sales);
      request.getSession().setAttribute("cases", cases);
      request.getSession().setAttribute("bookings", bookings);
    }
  }