Example #1
0
 /**
  * Goes trough the table auction and checks which auctions are over. If the auction is over, finds
  * all bids for that auction, selects the highest bid and sends winning message, also sends to all
  * other users message that auction is over.
  */
 public static void checkAuctionOutcome() {
   // Declaring list of all auctions.
   List<Auction> auctions = finder.all();
   // Declaring variable that represents current date.
   Date currentDate = new Date();
   // Going trough all auctions.
   for (int i = 0; i < auctions.size(); i++) {
     // Declaring variable that represents auction ending date.
     Date auctionEndingDate = auctions.get(i).endingDate;
     // Checking if the auction is active and if the auction ending date is before current date.
     if (auctions.get(i).isActive && auctionEndingDate.before(currentDate)) {
       // Finding all auction bids.
       List<Bid> bids = Bid.getAuctionBids(auctions.get(i));
       // Declaring variable that represents highest bid.
       Bid highestBid = bids.get(0);
       // Declaring string variable that represents winning message.
       String winningMessage =
           "Congratulations!!! You won bitBay auction for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + ".\n\r \n\r To proceed with transaction please contact: "
               + auctions.get(i).product.user.email;
       // Declaring and saving winning message.
       Message message =
           new Message(
               CommonHelpers.serviceUser(), highestBid.user, "Auction Winning", winningMessage);
       message.save();
       // Sending SMS notification to auction winner.
       String sms =
           "Congratulations!!! You won bitBay auction for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + ". "
               + "This product has been sent to your cart";
       if (highestBid.user.phoneNumber != null) {
         SmsHelper.sendSms(sms, highestBid.user.phoneNumber);
       }
       // After user won on auction create new cart if user don't have one, and put auction item to
       // his cart
       Cart cart = Cart.findCartByUser(highestBid.user);
       if (cart == null) {
         Cart newCart = new Cart();
         newCart.user = highestBid.user;
         newCart.save();
         CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, newCart);
         cartItem.save();
       } else {
         CartItem cartItem = new CartItem(auctions.get(i).product, highestBid.user, cart);
         cartItem.save();
       }
       // Declaring string set that will contain emails of all users that have not had highest bid.
       Set<String> bidUsers = new HashSet<>();
       // Adding all user emails to the set.
       for (int j = 0; j < bids.size(); j++) {
         bidUsers.add(bids.get(j).user.email);
       }
       // Removing email of highest bit user from the set.
       bidUsers.remove(highestBid.user.email);
       // Declaring string variable that represents losing message.
       String losingMessage =
           "Biding for item #"
               + auctions.get(i).product.id
               + " - "
               + auctions.get(i).product.name
               + " is over.\n\r \n\r We are sorry to inform you that your bid was not enough.";
       // Declaring iterator list of all user emails.
       Iterator<String> iter = bidUsers.iterator();
       // Going trough all emails and sending message.
       while (iter.hasNext()) {
         User receiver = User.getUserByEmail(iter.next());
         Message msg =
             new Message(CommonHelpers.serviceUser(), receiver, "Auction results", losingMessage);
         msg.save();
       }
       // Setting auction status to inactive.
       auctions.get(i).isActive = false;
       auctions.get(i).update();
     }
   }
 }
 public static List<IdentityDocType> all() {
   return find.all();
 }
Example #3
0
 public static List<Teacher> list() {
   return finder.all();
 }
Example #4
0
 public static List<Doctor> allDoctors() {
   return find.all();
 }
Example #5
0
 public static List<AppUser> getAllUsers() {
   return finder.all();
 }