/** * 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-----------"); }
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(); }