Example #1
1
 /**
  * The list of current rentals with who, what and when
  *
  * @return a list of all rentals with fields populated in the right fashion
  */
 public static List<Rental> getAllRentals() {
   List<Rental> rentals = new ArrayList<Rental>();
   List<Video> videos = Ebean.find(Video.class).where().isNotNull("rentedTo").findList();
   Ebean.sort(videos, "rentalDate asc");
   Rental rental = null;
   User user = null;
   for (Video v : videos) {
     rental = new Rental();
     rental.setWhatId(v.getId());
     rental.setWhat(v.getInputTitle());
     user = Ebean.find(User.class, v.getRentedTo());
     rental.setWho(user.getFullName());
     rental.setWhoId(v.getRentedTo());
     rental.setEmail(user.getEmail());
     rental.setWhen(v.getRentalDate());
     rentals.add(rental);
   }
   return rentals;
 }
Example #2
0
 /**
  * Used to obtain a list of rentals for a specific user
  *
  * @param userId the user whose rentals we're interested into
  * @return the list of rentals for the user
  */
 public static List<Rental> getRentalsByUserId(Long userId) {
   List<Rental> rentals = new ArrayList<Rental>();
   List<Video> videos = Ebean.find(Video.class).where().eq("rentedTo", userId).findList();
   Rental rental = null;
   User user = null;
   for (Video v : videos) {
     rental = new Rental();
     rental.setWhatId(v.getId());
     rental.setWhat(v.getInputTitle());
     user = Ebean.find(User.class, v.getRentedTo());
     rental.setWho(user.getFullName());
     rental.setWhoId(v.getRentedTo());
     rental.setEmail(user.getEmail());
     rental.setWhen(v.getRentalDate());
     rentals.add(rental);
   }
   return rentals;
 }