コード例 #1
0
ファイル: Assignment3.java プロジェクト: pmsardesai/ECE456
  public static void registerRoom() throws IOException, Exception {
    // get hotel name
    System.out.println("Enter the hotel ID:");
    String hotelID = bufferRead.readLine();

    // get room number
    System.out.println("Enter the room number: ");
    String roomNo = bufferRead.readLine();

    // get guest ID
    System.out.println("Enter the guest ID: ");
    String guestID = bufferRead.readLine();

    // get start date
    System.out.println("Enter the start date (YYYY-MM-DD): ");
    String start = bufferRead.readLine();

    while (!Booking.isDateValid(start)) {
      System.out.println("Invalid: Please enter start date in this format (YYYY-MM-DD):");
      start = bufferRead.readLine();
    }

    // get end date
    System.out.println("Enter the end date (YYYY-MM-DD): ");
    String end = bufferRead.readLine();

    while (!Booking.isDateValid(end)) {
      System.out.println("Invalid: Please enter end date in this format (YYYY-MM-DD):");
      end = bufferRead.readLine();
    }

    // book a room
    Booking.bookRoom(conn, hotelID, roomNo, guestID, start, end);
  }
コード例 #2
0
  @Listener("Book")
  public void book() {
    Travel hotel = view.getSelectedTravel();

    if (view.getStartDate().after(view.getEndDate())) {
      showError("Fechas inválidas.");
      return;
    }

    BookingFactory factory = new BookingFactory(Application.getInstance().getVendor());

    try {
      Booking booking =
          factory.book(
              hotel, Application.getInstance().getClient(), view.getStartDate(), view.getEndDate());
      double price = booking.book();
      Application.getInstance().getPacket().add(booking);

      showMessage("Reserva realizada. Precio: " + price + "€");
    } catch (Exception e) {
      showError("Error reservando el paquete: " + e.getMessage());
      return;
    }

    navigator.goBack();
  }
コード例 #3
0
 public boolean isValid(Booking booking, ConstraintValidatorContext context) {
   if ((booking.getCheckinDate() != null)
       && (booking.getCheckoutDate() != null)
       && booking.getCheckoutDate().before(booking.getCheckinDate())) {
     return false;
   }
   return true;
 }
コード例 #4
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
  private void addNonHumanBookings() {
    ArrayList<Resource> resources = null;
    Random random = new Random(1l);
    try {
      resources =
          resourceDAO.getResourcesByResourceType(
              resourceTypeDAO.getResourceTypeByResourceTypeName("machine"));
      resources.addAll(
          resourceDAO.getResourcesByResourceType(
              resourceTypeDAO.getResourceTypeByResourceTypeName("room")));
    } catch (Exception e) {
      e.printStackTrace();
    }
    ArrayList<Project> allProjects = null;
    try {
      allProjects = projectDAO.getAllProjects();
    } catch (Exception e) {
      e.printStackTrace();
    }
    for (Resource resource : resources) {
      HashSet<Project> projects = new HashSet<Project>();
      for (int i = 0; i < 3; ++i) {
        projects.add(allProjects.get(random.nextInt(allProjects.size())));
      }

      int max = (projects.size() > 0) ? (50 / projects.size()) : 0;
      for (Project project : projects) {
        for (int i = project.getStartWeek(); i <= project.getDeadLine(); ++i) {
          if (random.nextInt(2) == 0) {
            Booking booking = new Booking();
            booking.setProjectID(project.getProjectID());
            booking.setResourceID(resource.getResourceID());
            booking.setWeek(i);
            booking.setRatio(((float) (random.nextInt(max + 1) + max)) / 100);
            try {
              bookingDAO.insertBooking(booking);
            } catch (DAOException e) {
              e.printStackTrace();
            }
            System.out.println(booking);
          }
        }
      }
    }
  }
コード例 #5
0
ファイル: Assignment3.java プロジェクト: pmsardesai/ECE456
  public static void searchHotels() throws IOException, Exception {
    // get hotel name
    System.out.println("Enter the hotel name, or press enter to skip: ");
    String hotel = bufferRead.readLine();
    hotel = hotel.length() == 0 ? null : hotel;

    // get city input
    System.out.println("Enter the city (Waterloo, Guelph, Kitchener), or press enter to skip: ");
    String city = bufferRead.readLine();
    city = city.length() == 0 ? null : city;

    // get price input
    System.out.println("Enter the room price (between 50.00 and 250.00), or press enter to skip: ");
    String price = bufferRead.readLine();
    price = price.length() == 0 ? null : price;

    // get room type
    System.out.println(
        "Enter the room type (Single, Double, King, Queen), or press enter to skip: ");
    String type = bufferRead.readLine();
    type = type.length() == 0 ? null : type;

    // get start date
    System.out.println("Enter the start date (YYYY-MM-DD): ");
    String start = bufferRead.readLine();

    while (!Booking.isDateValid(start)) {
      System.out.println("Invalid: Please enter start date in this format (YYYY-MM-DD):");
      start = bufferRead.readLine();
    }

    // get end date
    System.out.println("Enter the end date (YYYY-MM-DD): ");
    String end = bufferRead.readLine();

    while (!Booking.isDateValid(end)) {
      System.out.println("Invalid: Please enter end date in this format (YYYY-MM-DD):");
      end = bufferRead.readLine();
    }

    // check valid rooms
    Booking.findRoom(conn, start, end, hotel, city, price, type);
  }
コード例 #6
0
 @org.junit.Before
 public void setUp() throws Exception {
   hcontroller = new HotelController();
   hotel = hcontroller.getHotel("Hilton");
   book = new Booking();
   book.setEmail("*****@*****.**");
   book.setHotelId(hotel.getId());
   book.setRoomId(20);
   book.setPhoneNr("894-7896");
   book.setCreditCardNr("4567894512345698");
   book.setCustomerName("palli");
   book.setStartDate("2016-05-19");
   book.setEndDate("2016-05-20");
   book = bcontroller.saveBooking(book);
 }
コード例 #7
0
 public boolean canDeleteBooking(User user, long bookingId) {
   Booking booking = bookings.findOne(bookingId);
   return booking != null
       && ((booking.getGuest() != null && user.getUsername().equals(booking.getGuest().getEmail()))
           || (booking.getHotel() != null
               && booking.getHotel().getManager() != null
               && user.getUsername().equals(booking.getHotel().getManager().getEmail())));
 }
コード例 #8
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
 private void addHumanBookings() {
   ArrayList<Resource> workers = null;
   Random random = new Random(1l);
   try {
     workers =
         resourceDAO.getResourcesByResourceType(
             resourceTypeDAO.getResourceTypeByResourceTypeName("human"));
   } catch (Exception e) {
     e.printStackTrace();
   }
   for (Resource worker : workers) {
     ArrayList<Project> projects = null;
     try {
       projects = projectDAO.getProjectsByWorker(worker);
     } catch (Exception e) {
       e.printStackTrace();
     }
     int max = (projects.size() > 0) ? (50 / projects.size()) : 0;
     for (Project project : projects) {
       for (int i = project.getStartWeek(); i <= project.getDeadLine(); ++i) {
         if (random.nextInt(2) == 0) {
           Booking booking = new Booking();
           booking.setProjectID(project.getProjectID());
           booking.setResourceID(worker.getResourceID());
           booking.setWeek(i);
           booking.setRatio(((float) (random.nextInt(max + 1) + max)) / 100);
           try {
             bookingDAO.insertBooking(booking);
           } catch (DAOException e) {
             e.printStackTrace();
           }
           System.out.println(booking);
         }
       }
     }
   }
 }
コード例 #9
0
  /**
   * Assign passenger p who has a booking but no seat to the specified seat.
   *
   * @param p the passenger to be given a seat
   * @param seat the seat for the passenger
   * @precond p != null && isSeatAvailable(seat) && p.hasBookingOn(this) && !p.hasSeatOn(this)
   */
  public void assignSeat(Passenger p, String seat) {
    if (p == null) throw new RuntimeException("Cannot assign a seat for a null passenger.");
    if (!isSeatAvailable(seat))
      throw new RuntimeException(
          "Seat " + seat + " is invalid or already occupied " + "so cannot book it.");
    if (p.hasSeatOn(this))
      throw new RuntimeException(
          p.getName()
              + " already has a seat on flight "
              + getNumber()
              + " so cannot book another one.");

    Iterator<Booking> waitingIter = waitingSeatList.iterator();
    while (waitingIter.hasNext()) {
      Booking curBooking = waitingIter.next();
      if (curBooking.getPerson() == p) {
        waitingIter.remove();
        curBooking.setSeat(seat);
        setSeat(curBooking);
        return;
      }
    }
    throw new RuntimeException("Cannot assign a seat if not already booked and waiting.");
  }
コード例 #10
0
  /**
   * Import bookings
   *
   * @param nodes
   * @return
   */
  private Boolean processBookings(NodeList nodes) {
    NodeList bookings = nodes.item(0).getChildNodes();

    for (int i = 0; i < bookings.getLength(); i++) {
      if (bookings.item(i).getNodeType() == Node.ELEMENT_NODE) {
        Element bookingNode = (Element) bookings.item(i);

        Booking booking = new Booking();

        booking.setIdbooking(Integer.parseInt(getTagValue("idbooking", bookingNode)));
        booking.setState(Integer.parseInt(getTagValue("state", bookingNode)));
        booking.setDate(
            DatatypeConverter.parseDateTime(getTagValue("date", bookingNode)).getTime());

        Book book = bookMgr.findByIdbook(Integer.parseInt(getTagValue("book", bookingNode)));
        if (book == null) {
          continue;
        }

        booking.setBook(book);

        User user = userMgr.findByIduser(Integer.parseInt(getTagValue("user", bookingNode)));
        if (user == null) {
          continue;
        }

        booking.setUser(user);

        try {
          bookingMgr.Save(booking);
        } catch (EJBException ex) {
          ex.printStackTrace(System.out);
        }
      }
    }
    return true;
  }
コード例 #11
0
 public Endorsement getEndorsement() {
   return booking.getPaymentMethod() instanceof Endorsement
       ? (Endorsement) booking.getPaymentMethod()
       : null;
 }
コード例 #12
0
 public CreditCard getCreditCard() {
   return booking.getPaymentMethod() instanceof CreditCard
       ? (CreditCard) booking.getPaymentMethod()
       : null;
 }
コード例 #13
0
 // ath hvort skili ekki error ef við setjum inn streng með tölum (aðferðin ætti að parsa það yfir
 // í int)
 @org.junit.Test
 public void testIntStringGetBooking() throws Exception {
   String id = "" + book.getId();
   testbooking = bcontroller.getBooking(id);
   assertEquals(testbooking.getId(), book.getId());
 }
コード例 #14
0
  @Test
  public void testEquals_EmailNotEquals_returnFalse() {
    final String bookingId = "1";
    final String mail = "*****@*****.**";
    final String diffEmail = "test2.mail.com";
    final SeatHold hold = new SeatHold();

    Booking sourceBooking = new Booking();
    sourceBooking.setBooked(false);
    sourceBooking.setBookingId(bookingId);
    sourceBooking.setEmailAddress(mail);
    sourceBooking.setSeatHold(hold);

    Booking targetBooking = new Booking();
    targetBooking.setBooked(false);
    targetBooking.setBookingId(bookingId);
    targetBooking.setEmailAddress(diffEmail);
    targetBooking.setSeatHold(hold);

    boolean result = sourceBooking.equals(targetBooking);
    assertThat(result, equalTo(false));
  }
コード例 #15
0
  @Test
  public void testEquals_onlyEmailIsEqual_returnTrue() {
    final String bookingId = "1";
    final String mail = "*****@*****.**";
    final SeatHold hold = new SeatHold();

    Booking sourceBooking = new Booking();
    sourceBooking.setBooked(true);
    sourceBooking.setBookingId(bookingId);
    sourceBooking.setEmailAddress(mail);
    sourceBooking.setSeatHold(hold);

    Booking targetBooking = new Booking();
    targetBooking.setBooked(false);
    targetBooking.setBookingId(bookingId + "test");
    targetBooking.setEmailAddress(mail);
    targetBooking.setSeatHold(null);

    boolean result = sourceBooking.equals(targetBooking);
    assertThat(result, equalTo(true));
  }
コード例 #16
0
 @org.junit.Test
 public void testgetBooking() throws Exception {
   Booking btest = bcontroller.getBooking(book.getId());
   assertNotNull(btest);
   assertEquals(btest.getId(), book.getId());
 }
コード例 #17
0
 @org.junit.Test
 public void testgetBookings() throws Exception {
   Booking[] bfylki = bcontroller.getBookings(hotel);
   assertNotNull(bfylki);
   assertEquals(bfylki[1].getId(), book.getId());
 }
コード例 #18
0
 @org.junit.After
 public void tearDown() throws Exception {
   bcontroller.deleteBooking(book.getId());
   bcontroller = null;
 }
コード例 #19
0
 public boolean canEditBooking(User user, long bookingId) {
   Booking booking = bookings.findOne(bookingId);
   return booking != null
       && booking.getGuest() != null
       && user.getUsername().equals(booking.getGuest().getEmail());
 }