示例#1
0
 private void logReservationRejected(
     User user, Apartment apartment, Date start, Date end, String message) {
   SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy");
   log.info(
       Joiner.on("")
           .join(
               "Reservation rejected: UserID='",
               user.getId(),
               "', apartmentID='",
               apartment.getId(),
               "', start='",
               format.format(start),
               "', end='",
               format.format(end),
               "' | Reason - ",
               message));
 }
示例#2
0
  public boolean makeReservation(
      User user, Apartment apartment, Date start, Date end, String comment) {
    if (end.before(start)) {
      if (log.isInfoEnabled()) {
        logReservationRejected(user, apartment, start, end, "Invalid date");
      }
      return false;
    }

    if (isAvailable(apartment, start, end)) {
      if (log.isInfoEnabled()) {
        SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy");
        log.info(
            Joiner.on("")
                .join(
                    "Reservation accepted: UserID='",
                    user.getId(),
                    "', apartmentID='",
                    apartment.getId(),
                    "', start='",
                    format.format(start),
                    "', end='",
                    format.format(end),
                    "'"));
      }
      Reservation reservation = new Reservation(user, apartment, start, end, comment);
      SortOfDataBase.reservations.put(reservation.getId(), reservation);
      return true;
    }

    if (log.isInfoEnabled()) {
      logReservationRejected(
          user, apartment, start, end, "Apartment is unavailable for this dates");
    }
    return false;
  }
示例#3
0
 @Override
 public List<Apartment> getAllByUser(User user) {
   return getAllByUser(user.getId());
 }