1 package com.jbidwatcher.auction; 2 3 import com.jbidwatcher.util.Constants; 4 import com.jbidwatcher.util.Currency; 5 import com.jbidwatcher.util.db.ActiveRecord; 6 7 import java.io.File; 8 import java.util.Date; 9 import java.util.HashMap; 10 import java.util.Map; 11 12 /** 13 * User: mrs 14 * Date: 3/9/13 15 * Time: 6:32 PM 16 * 17 * This contains the core auction information. 18 */ 19 public abstract class AuctionCore extends ActiveRecord { 20 private static Map<String, String> mKeys; 21 protected String mThumbnailPath; 22 setupKeys()23 private static void setupKeys() { 24 mKeys = new HashMap<String, String>(); 25 mKeys.put("startDate", "started_at"); 26 mKeys.put("start", "started_at"); 27 mKeys.put("endDate", "ending_at"); 28 mKeys.put("seller", "seller_id"); 29 mKeys.put("end", "ending_at"); 30 mKeys.put("highbidder", "high_bidder"); 31 mKeys.put("highBidder", "high_bidder"); 32 mKeys.put("highBidderEmail", "high_bidder_email"); 33 mKeys.put("itemLocation", "location"); 34 mKeys.put("numBids", "bid_count"); 35 mKeys.put("bidcount", "bid_count"); 36 mKeys.put("insurance_optional", "optional_insurance"); 37 mKeys.put("insuranceOptional", "optional_insurance"); 38 mKeys.put("noThumbnail", "no_thumbnail"); 39 mKeys.put("reserveMet", "reserve_met"); 40 mKeys.put("isReserve", "reserve"); 41 mKeys.put("fixed", "fixed_price"); 42 mKeys.put("fixedPrice", "fixed_price"); 43 mKeys.put("isDutch", "dutch"); 44 mKeys.put("currently", "current_bid"); 45 mKeys.put("curBid", "current_bid"); 46 mKeys.put("minimum", "minimum_bid"); 47 mKeys.put("minBid", "minimum_bid"); 48 mKeys.put("usprice", "usd_current"); 49 mKeys.put("us_cur", "usd_current"); 50 mKeys.put("buy_now_us", "usd_buy_now"); 51 mKeys.put("buynow", "buy_now"); 52 } 53 54 static { setupKeys()55 setupKeys(); 56 } 57 AuctionCore()58 public AuctionCore() { 59 setTranslationTable(mKeys); 60 } 61 getIdentifier()62 public String getIdentifier() { return getString("identifier"); } 63 getTitle()64 public String getTitle() { return getString("title"); } 65 getHighBidder()66 public String getHighBidder() { return getString("highBidder"); } 67 68 // public String getHighBidderEmail() { return getString("highBidderEmail"); } getItemLocation()69 public String getItemLocation() { return getString("itemLocation", ""); } 70 isComplete()71 public boolean isComplete() { return getBoolean("ended"); } 72 getBestPrice()73 public Currency getBestPrice() { 74 Currency currentPrice = getCurBid(); 75 if (currentPrice == null || currentPrice.isNull()) { 76 currentPrice = getBuyNow(); 77 } 78 return currentPrice; 79 } 80 getCurBid()81 public Currency getCurBid() { return getMonetary("curBid"); } 82 getUSCurBid()83 public Currency getUSCurBid() { 84 if (getCurBid().getCurrencyType() == Currency.US_DOLLAR) { 85 return getCurBid(); 86 } 87 return getMonetary("us_cur", Currency.US_DOLLAR); 88 } 89 getMinBid()90 public Currency getMinBid() { return getMonetary("minBid", getCurBid()); } 91 getShipping()92 public Currency getShipping() { return getMonetary("shipping"); } 93 getInsurance()94 public Currency getInsurance() { return getMonetary("insurance"); } 95 getBuyNow()96 public Currency getBuyNow() { return getMonetary("buy_now"); } 97 getQuantity()98 public int getQuantity() { return getInteger("quantity", 1); } 99 getNumBidders()100 public int getNumBidders() { return getInteger("numBids", 0); } 101 getNumBids()102 public int getNumBids() { return getNumBidders(); } 103 getStartDate()104 public Date getStartDate() { return getDate("start"); } 105 getEndDate()106 public Date getEndDate() { 107 Date end = getEnd(); 108 if(end == null) end = Constants.FAR_FUTURE; 109 return end; 110 } 111 isReserve()112 public boolean isReserve() { return getBoolean("isReserve"); } 113 isPrivate()114 public boolean isPrivate() { return getBoolean("isPrivate"); } 115 isFixed()116 public boolean isFixed() { return getBoolean("fixed_price"); } 117 isReserveMet()118 public boolean isReserveMet() { return getBoolean("reserve_met"); } 119 hasPaypal()120 public boolean hasPaypal() { return getBoolean("paypal"); } 121 isInsuranceOptional()122 boolean isInsuranceOptional() { return getBoolean("insurance_optional", true); } 123 hasNoThumbnail()124 protected boolean hasNoThumbnail() { return getBoolean("noThumbnail"); } 125 getUSCur()126 public Currency getUSCur() { return getMonetary("us_cur", Currency.US_DOLLAR); } 127 getBuyNowUS()128 public Currency getBuyNowUS() { return getMonetary("buy_now_us", Currency.US_DOLLAR); } 129 getStart()130 public Date getStart() { return getDate("start"); } 131 getEnd()132 public Date getEnd() { return getDate("end"); } 133 getSellerId()134 public String getSellerId() { return get("seller_id"); } 135 hasThumb()136 private boolean hasThumb() { return getBoolean("has_thumbnail"); } 137 setHasThumb(boolean hasThumb)138 private void setHasThumb(boolean hasThumb) { setBoolean("has_thumbnail", hasThumb); } 139 hasThumbnail()140 protected boolean hasThumbnail() { 141 String imgPath = mThumbnailPath; 142 143 if(imgPath == null) { 144 imgPath = Thumbnail.getValidImagePath(getIdentifier()); 145 if(imgPath == null) return false; 146 } 147 148 File tester = new File(imgPath); 149 boolean rval= tester.exists(); 150 151 if(rval && mThumbnailPath == null) mThumbnailPath = imgPath; 152 153 return rval; 154 } 155 getThumbnail()156 public String getThumbnail() { 157 // Bad optimization -- BUGBUG -- mrs: 21-March-2004 18:28 158 // If it doesn't have a thumbnail, we check. 159 if(!hasThumb() || mThumbnailPath == null) { 160 if(!hasThumbnail()) return null; 161 } 162 163 setHasThumb(true); 164 165 return "file:" + mThumbnailPath; 166 } 167 } 168