[jboss-cvs] jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay ...
Shane Bryzak
sbryzak at redhat.com
Tue Jul 17 03:12:29 EDT 2007
User: sbryzak2
Date: 07/07/17 03:12:29
Modified: examples/seambay/src/org/jboss/seam/example/seambay
Auction.java BidAction.java
Log:
support for outbids/rebids
Revision Changes Path
1.15 +13 -6 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Auction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Auction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Auction.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- Auction.java 17 Jul 2007 03:37:14 -0000 1.14
+++ Auction.java 17 Jul 2007 07:12:29 -0000 1.15
@@ -32,7 +32,7 @@
private AuctionImage image;
private Bid highBid;
private int bids;
- private double price;
+ private double startingPrice;
private int status;
private int version;
@@ -119,6 +119,7 @@
this.image = image;
}
+ @OneToOne
public Bid getHighBid()
{
return highBid;
@@ -196,14 +197,14 @@
return sb.toString();
}
- public double getPrice()
+ public double getStartingPrice()
{
- return price;
+ return startingPrice;
}
- public void setPrice(double price)
+ public void setStartingPrice(double startingPrice)
{
- this.price = price;
+ this.startingPrice = startingPrice;
}
public int getStatus()
@@ -228,10 +229,16 @@
}
@Transient
+ public double getCurrentPrice()
+ {
+ return highBid != null ? highBid.getActualAmount() : getStartingPrice();
+ }
+
+ @Transient
public double getRequiredBid()
{
return highBid != null ? getRequiredBid(highBid.getActualAmount()) :
- getPrice();
+ getStartingPrice();
}
/**
1.5 +44 -19 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/BidAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BidAction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/BidAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- BidAction.java 17 Jul 2007 03:37:14 -0000 1.4
+++ BidAction.java 17 Jul 2007 07:12:29 -0000 1.5
@@ -29,14 +29,24 @@
@In(required = false)
private Account authenticatedAccount;
+ private String outcome;
+
@Begin(join = true)
public void placeBid()
{
+ if (auction.getStatus() != Auction.STATUS_LIVE ||
+ auction.getEndDate().getTime() < System.currentTimeMillis())
+ {
+ outcome = "ended";
+ }
+ else
+ {
bid = new Bid();
bid.setAuction(auction);
updateBid();
}
+ }
public void updateBid()
{
@@ -45,6 +55,11 @@
if (amount >= bid.getAuction().getRequiredBid())
{
bid.setMaxAmount(amount);
+ outcome = "confirm";
+ }
+ else
+ {
+ outcome = "invalid";
}
}
@@ -62,12 +77,14 @@
if (bid.getAuction().getStatus() != Auction.STATUS_LIVE)
{
- return "ended";
+ outcome = "ended";
+ return outcome;
}
else if (bid.getAuction().getEndDate().getTime() < bid.getBidDate().getTime())
{
bid.getAuction().setStatus(Auction.STATUS_COMPLETED);
- return "ended";
+ outcome = "ended";
+ return outcome;
}
List<Bid> bids = entityManager.createQuery(
@@ -103,6 +120,7 @@
// There are no bids so far...
bid.setActualAmount(bid.getAuction().getRequiredBid());
bid.getAuction().setHighBid(bid);
+ outcome = "success";
}
else if (bid.getMaxAmount() > highBid.getMaxAmount())
{
@@ -119,28 +137,35 @@
bid.setActualAmount(highBid.getActualAmount());
}
bid.getAuction().setHighBid(bid);
+ outcome = "success";
}
else
{
+ // Set this bid, and the highest bid's, actual bid amount to this
+ // bid's maximum amount
+ highBid.setActualAmount(bid.getMaxAmount());
bid.setActualAmount(bid.getMaxAmount());
+ outcome = "outbid";
}
+ if ("success".equals(outcome))
+ {
bid.getAuction().setBids(bid.getAuction().getBids() + 1);
-
entityManager.persist(bid);
entityManager.flush();
-
Conversation.instance().end();
- return "success";
}
- public Bid getBid()
+ return outcome;
+ }
+
+ public String getOutcome()
{
- return bid;
+ return outcome;
}
- public boolean isValidBid()
+ public Bid getBid()
{
- return bid != null && bid.getMaxAmount() >= bid.getAuction().getRequiredBid();
+ return bid;
}
}
More information about the jboss-cvs-commits
mailing list