private Booking createTestBooking() {
   Hotel hotel = new Hotel();
   hotel.setId(1L);
   hotel.setName("Jameson Inn");
   User user = new User("keith", "pass", "Keith Donald");
   Booking booking = new Booking(hotel, user);
   return booking;
 }
 /**
  * Show the hotels information and its rooms and reservations
  *
  * @param name
  */
 public void showHotelInfo(String name) {
   Hotel hotel = searchHotel(name);
   System.out.println("Hotel: " + hotel.getName() + "\nDescription: " + hotel.getBrief());
   System.out.println("\nHotel Rooms: ");
   hotel.listRoom();
   System.out.println("\n-----------");
   hotel.listReservation();
   System.out.println("\n-----------");
 }
Ejemplo n.º 3
0
 public void sincronizar() throws Exception {
   enviarDadosPendentes();
   List<Hotel> hoteis = getHoteis();
   ContentResolver cr = mContext.getContentResolver();
   for (Hotel hotel : hoteis) {
     hotel.status = Hotel.Status.OK;
     mRepositorio.inserirLocal(hotel, cr);
   }
 }
 public void updateHotel(
     Hotel hotel, String name, Blob description, Integer stars, City city, List<Room> rooms) {
   Session session = sessionFactory.getCurrentSession();
   hotel.setName(name);
   hotel.setDescription(description);
   hotel.setStars(stars);
   hotel.setCity(city);
   hotel.setRooms(rooms);
   rooms.forEach(room -> room.setHotel(hotel));
   session.update(hotel);
 }
Ejemplo n.º 5
0
  private boolean enviarHotel(String metodoHttp, Hotel hotel) throws Exception {
    boolean sucesso = false;
    boolean doOutput = !"DELETE".equals(metodoHttp);
    String url = BASE_URL;
    if (!doOutput) {
      url += "/" + hotel.idServidor;
    }
    HttpURLConnection conexao = abrirConexao(url, metodoHttp, doOutput);

    if (doOutput) {
      OutputStream os = conexao.getOutputStream();
      os.write(hotelToJsonBytes(hotel));
      os.flush();
      os.close();
    }
    int responseCode = conexao.getResponseCode();
    if (responseCode == HttpURLConnection.HTTP_OK) {
      InputStream is = conexao.getInputStream();
      String s = streamToString(is);
      is.close();

      JSONObject json = new JSONObject(s);
      int idServidor = json.getInt("id");
      hotel.idServidor = idServidor;
      sucesso = true;

    } else {
      throw new RuntimeException("Erro ao realizar operação");
    }
    conexao.disconnect();
    return sucesso;
  }
  @Override
  public ReviewsSummary getReviewSummary(Hotel hotel) {
    Collection<RatingCount> ratingCounts =
        ratingCountListCacheRedisRepository.get(
            "ratingcounts:hotel:" + hotel.getId(), RatingCount.class);

    if (ratingCounts == null || ratingCounts.isEmpty()) {
      ratingCounts = this.hotelRepository.findRatingCounts(hotel);
      if (ratingCounts != null) {
        ratingCountListCacheRedisRepository.multiAdd(
            "ratingcounts:hotel:" + hotel.getId(), ratingCounts, true);
        ratingCountListCacheRedisRepository.expire(
            "ratingcounts:hotel:" + hotel.getId(), 60, TimeUnit.SECONDS);
      }
    }

    return new ReviewsSummaryImpl(new ArrayList<>(ratingCounts));
  }
Ejemplo n.º 7
0
 private void atualizar(Hotel hotel) {
   try {
     if (enviarHotel("PUT", hotel)) {
       hotel.status = Hotel.Status.OK;
       mRepositorio.atualizarLocal(hotel, mContext.getContentResolver());
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void createHotel(
     String name, Blob description, Integer stars, City city, User owner, List<Room> rooms) {
   Session session = sessionFactory.getCurrentSession();
   Hotel hotel = new Hotel();
   hotel.setName(name);
   hotel.setDescription(description);
   hotel.setStars(stars);
   hotel.setCity(city);
   hotel.setOwner(owner);
   hotel.setRooms(rooms);
   rooms.forEach(room -> room.setHotel(hotel));
   session.save(hotel);
 }
 @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);
 }
Ejemplo n.º 10
0
  /** This method loads the csv file to a hashmap with city name as the key. */
  private static void loadCSV() {
    String csvFile = "hoteldb.csv";
    InputStream is = Model.class.getClassLoader().getResourceAsStream(csvFile);
    BufferedReader br = null;
    String line;
    String cvsSplitBy = ",";

    try {
      br = new BufferedReader(new InputStreamReader(is));
      String[] headersrow = br.readLine().split(cvsSplitBy);
      HashMap<String, Integer> headersmap = new HashMap<String, Integer>();
      for (int i = 0; i < headersrow.length; i++) {
        headersmap.put(headersrow[i], i);
      }

      while ((line = br.readLine()) != null) {
        String[] row = line.split(cvsSplitBy);
        Hotel hotel = new Hotel();
        for (int i = 0; i < row.length; i++) {
          if (i == headersmap.get("CITY")) hotel.setCity(row[i]);
          else if (i == headersmap.get("HOTELID")) hotel.setHotelId(Integer.parseInt(row[i]));
          else if (i == headersmap.get("ROOM")) hotel.setRoom(row[i]);
          else if (i == headersmap.get("PRICE")) hotel.setPrice(Double.parseDouble(row[i]));
        }
        if (!hotelDetails.containsKey(hotel.getCity())) {
          ArrayList<Hotel> arr = new ArrayList<Hotel>();
          arr.add(hotel);
          hotelDetails.put(hotel.getCity(), arr);
        } else {
          hotelDetails.get(hotel.getCity()).add(hotel);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
Ejemplo n.º 11
0
 @Test
 public void validarQueseIngreseNombreDeHotel() {
   Hotel hotel = new Hotel("Horel rivera", "http://hotelrivera.clerk.im", "Alberto Fernandez");
   assertFalse(hotel.verificaNombreHotel(null));
   System.out.println("Debe Ingresar nombre de hotel");
 }
 public void showQueenSizeAvailableRooms() {
   System.out.println(Hotel.getAvailableRoomsQueen());
 }
 public void showTotalAvailableRooms() {
   System.out.println(Hotel.getTotalAvailableRooms());
 }
 /**
  * method that removes a hotel from the list by its name
  *
  * @param name
  */
 public void removeHotel(String name) {
   Hotel hotel = searchHotel(name);
   hotels.remove(hotel);
   Hotel.setAvailableRoomsKing(Hotel.getAvailableRoomsKing() - 2);
   Hotel.setAvailableRoomsQueen(Hotel.getAvailableRoomsQueen() - 2);
 }
  public String prepareSuitableHotelsInformation(
      List<Room> freeRooms, City city, List<RoomType> roomTypes) throws IOException, SQLException {

    Session session = sessionFactory.getCurrentSession();

    List<Room> freeRoomsInCity =
        freeRooms
            .stream()
            .filter(
                room ->
                    city == null || room.getHotel().getCity().getCityId().equals(city.getCityId()))
            .collect(Collectors.toList());

    JSONArray hotelsInformation = new JSONArray();
    for (Room room : freeRoomsInCity) {
      Hotel hotel = room.getHotel();

      JSONObject hotelInformation = null;
      for (Object hotelInformationObject : hotelsInformation) {
        JSONObject object = (JSONObject) hotelInformationObject;
        if (object.get("hotelId").equals(hotel.getHotelId())) {
          hotelInformation = object;
        }
      }
      if (hotelInformation == null) {
        hotelInformation = new JSONObject();
        hotelInformation.put("hotelId", hotel.getHotelId());
        hotelInformation.put("hotelName", hotel.getName());
        hotelInformation.put("hotelStars", hotel.getStars());
        session.update(hotel);
        List<Room> hotelRooms = hotel.getRooms();
        hotelInformation.put("hotelRooms", hotelRooms.size());
        hotelInformation.put("hotelDescription", hotel.getStringDescription());
        Photo mainPhoto = photoService.getMainPhoto(hotel);
        hotelInformation.put(
            "hotelMainPhoto",
            mainPhoto == null
                ? "../../../resources/images/no_photo_icon.PNG"
                : "../../uploadFiles/" + mainPhoto.getFileName());
        hotelInformation.put("roomsQuantity", 0);
        int cheapestRoom =
            hotelRooms
                .stream()
                .min((o1, o2) -> Integer.compare(o1.getPricePerNight(), o2.getPricePerNight()))
                .get()
                .getPricePerNight();
        hotelInformation.put("cheapestRoom", cheapestRoom);
        int mostExpansiveRoom =
            hotelRooms
                .stream()
                .max((o1, o2) -> Integer.compare(o1.getPricePerNight(), o2.getPricePerNight()))
                .get()
                .getPricePerNight();
        hotelInformation.put("mostExpansiveRoom", mostExpansiveRoom);
        hotelsInformation.put(hotelInformation);
        JSONArray roomsInformation = new JSONArray();
        for (RoomType roomType : roomTypes) {
          JSONObject roomTypeInformation = new JSONObject();
          roomTypeInformation.put("roomTypeId", roomType.getRoomTypeId());
          roomTypeInformation.put("roomTypeName", roomType.getDescription());
          roomTypeInformation.put("quantity", 0);
          roomTypeInformation.put("price", 0);
          roomsInformation.put(roomTypeInformation);
        }
        hotelInformation.put("rooms", roomsInformation);
      }

      hotelInformation.put("roomsQuantity", (int) hotelInformation.get("roomsQuantity") + 1);
      JSONArray roomsInformation = (JSONArray) hotelInformation.get("rooms");
      JSONObject roomTypeInformation = new JSONObject();
      for (Object o : roomsInformation) {
        JSONObject jsonObject = (JSONObject) o;
        if (jsonObject.get("roomTypeId").equals(room.getRoomType().getRoomTypeId())) {
          roomTypeInformation = jsonObject;
        }
      }
      roomTypeInformation.put("quantity", (int) roomTypeInformation.get("quantity") + 1);
      roomTypeInformation.put("price", room.getPricePerNight());
    }

    return new JSONObject().put("hotelsInformation", hotelsInformation).toString();
  }
Ejemplo n.º 16
0
 // checks if a User manages a hotel
 public boolean managesHotel(User user, long hotelId) {
   Hotel hotel = hotels.findOne(hotelId);
   return hotel != null
       && hotel.getManager() != null
       && user.getUsername().equals(hotel.getManager().getEmail());
 }
Ejemplo n.º 17
0
 @Override
 public int compareTo(Hotel o) {
   return Integer.compare(this.getRating(), o.getRating());
 }
Ejemplo n.º 18
0
 public String getKey() {
   return Hotel.getKey(getLocation());
 }
Ejemplo n.º 19
0
 public int getPrice() {
   return new BigDecimal(hotel.getPriceForStay(stay)).intValue();
 }
 public void showKingSizeAvailableRooms() {
   System.out.println(Hotel.getAvailableRoomsKing());
 }