@Override
 public void releaseHoldOrders() {
   for (SeatHold seatHold : MockData.holdsMap.values()) {
     if (ReservationStatusType.HOLD.equals(seatHold.getStatus())) {
       synchronized (seatHold) {
         if (Calendar.getInstance().getTimeInMillis() - seatHold.getHoldTimestamp()
             > holdTimeInSeconds * 1000) {
           for (Seat seat : seatHold.getSeats()) {
             seat.setStatus(SeatStatusType.AVAILABLE);
             MockData.seatsMap.get(seat.getVenueLevel()).add(seat);
           }
           seatHold.setStatus(ReservationStatusType.RELEASED);
         }
       }
     }
   }
 }
  @Override
  public String reserveSeats(int seatHoldId, String customerEmail) {
    SeatHold seatHold = MockData.holdsMap.get(seatHoldId);
    if (seatHold == null) {
      throw new DataInvalidException(
          CommonErrorCodeEnumDto.INVALID_INPUT_DATA, "Invalid seatHoldId.");
    } else {
      for (Seat seat : seatHold.getSeats()) {
        seat.setStatus(SeatStatusType.BOOKED);
      }
    }
    seatHold.setStatus(ReservationStatusType.CONFIRMED);
    String reserveToken = RESERVE_PREFIX + RandomUtils.nextLong();

    MockData.reservedMap.put(reserveToken, seatHold);

    return reserveToken;
  }
  @Override
  public SeatHold findAndHoldSeats(
      int numSeats, Optional<Integer> minLevel, Optional<Integer> maxLevel, String customerEmail) {

    List<Seat> seatsList = new ArrayList<Seat>();

    int seatsHoldCount = 0;

    EXTLOOP:
    for (VenueLevel level : MockData.levels) {
      if ((!minLevel.isPresent() || level.getLevelId() >= minLevel.get())
          && (!maxLevel.isPresent() || level.getLevelId() <= maxLevel.get())) {
        synchronized (MockData.seatsMap.get(level)) {
          Iterator<Seat> itr = MockData.seatsMap.get(level).iterator();
          while (itr.hasNext()) {
            Seat seat = itr.next();
            // if
            // (SeatStatusType.AVAILABLE.equals(seat.getStatus())) {
            MockData.seatsMap.get(level).remove(seat);
            seatsList.add(seat);
            seatsHoldCount++;
            // }
            if (seatsHoldCount == numSeats) {
              break EXTLOOP;
            }
          }
        }
      }
    }

    SeatHold seatHold = new SeatHold();

    if (seatsHoldCount < numSeats) {
      this.releaseSeats(seatsList);
      throw new SeatsUnAvailableException("Seats not available.");
    } else {
      seatHold.setHoldId(RandomUtils.nextInt());
      seatHold.setStatus(ReservationStatusType.HOLD);
      seatHold.setHoldTimestamp(Calendar.getInstance().getTimeInMillis());
      // seatHold.setSeats(seatsList);
      seatHold.setCustomer(new Customer(RandomUtils.nextLong(), null, customerEmail));
      for (Seat seat : seatsList) {
        seat.setStatus(SeatStatusType.HOLD);
        seatHold.getSeats().add(seat);
      }
      MockData.holdsMap.put(seatHold.getHoldId(), seatHold);
    }
    return seatHold;
  }