[jboss-cvs] jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay ...

Norman Richards norman.richards at jboss.com
Sat Oct 21 18:23:45 EDT 2006


  User: nrichards
  Date: 06/10/21 18:23:45

  Modified:    examples/seampay/src/org/jboss/seam/example/seampay   
                        Payment.java PaymentController.java
                        PaymentProcessor.java
  Log:
  add recurring payments
  
  Revision  Changes    Path
  1.2       +65 -24    jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/Payment.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Payment.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/Payment.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Payment.java	20 Oct 2006 16:51:26 -0000	1.1
  +++ Payment.java	21 Oct 2006 22:23:45 -0000	1.2
  @@ -4,12 +4,15 @@
   import org.hibernate.validator.*;
   
   import java.io.Serializable;
  -import java.util.Date;
  +import java.util.*;
   
   @Entity
   public class Payment
       implements Serializable
   {
  +
  +
  +
       @Id @GeneratedValue 
       private Long id;
   
  @@ -25,21 +28,21 @@
       private Date paymentDate;
       @NotNull
       private Date createdDate;
  +    private Date lastPaid;
   
  -    private boolean paid = false;
  +    private boolean active = true;
   
  +    private Frequency paymentFrequency = Frequency.DAILY;
   
  -    public Long getId()
  -    {
  +
  +    public Long getId() {
           return id;
       }
       
  -    public float getAmount()
  -    {
  +    public float getAmount() {
           return amount;
       }
  -    public void setAmount(float amount)
  -    {
  +    public void setAmount(float amount) {
           this.amount = amount;
       }
       
  @@ -48,40 +51,78 @@
           return payee;
       }
   
  -    public void setPayee(String payee)
  -    {
  +    public void setPayee(String payee) {
           this.payee = payee;
       }
   
  -    public Account getAccount()
  -    {
  +    public Account getAccount() {
           return account;
       }
       
  -    public void setAccount(Account account)
  -    {
  +    public void setAccount(Account account) {
           this.account = account;
           account.getPayments().add(this);
       }
   
  -    public Date getPaymentDate()
  -    {
  +    public Date getPaymentDate() {
           return paymentDate;
       }
  -    public void setPaymentDate(Date paymentDate)
  -    {
  +    public void setPaymentDate(Date paymentDate) {
           this.paymentDate = paymentDate;
       }  
   
  -    public Date getCreatedDate()
  -    {
  +    public Date getCreatedDate() {
           return createdDate;
       }    
  -    public void setCreatedDate(Date createdDate)
  -    {
  +    public void setCreatedDate(Date createdDate) {
           this.createdDate = createdDate;
       }  
           
  -    public boolean getPaid() { return paid;} 
  -    public void setPaid(boolean paid) { this.paid = paid; }
  +
  +    public Date getLastPaid() {
  +        return lastPaid;
  +    }    
  +    public void setLastPaid(Date lastPaid) {
  +        this.lastPaid = lastPaid;
  +    }  
  +        
  +    public boolean getActive() {
  +        return active;
  +    }
  +    public void setActive(boolean active) {
  +        this.active = active;
  +    }
  +   
  +    public Frequency getPaymentFrequency() { 
  +        return paymentFrequency; 
  +    }
  +    public void setPaymentFrequency(Frequency paymentFrequency) {
  +        this.paymentFrequency = paymentFrequency;
  +    }
  +
  +    public Map<String,Frequency> getFrequencies() {
  +        Map<String,Frequency> result = new HashMap<String,Frequency>();
  +        for (Frequency frequency : Frequency.values()) {
  +            result.put(frequency.toString(), frequency);
  +        }
  +        return result;
  +    }
  +
  +    public enum Frequency {
  +        ONCE(0), 
  +        EVERY_MINUTE(60*1000),
  +        HOURLY(60*60*1000), 
  +        DAILY(24*60*60*1000), 
  +        WEEKLY(7*24*60*60*1000);
  +
  +        long interval; 
  +
  +        Frequency(long interval) {
  +            this.interval = interval;
  +        }
  +        
  +        public long getInterval() {
  +            return interval;
  +        }
  +    };
   }
  
  
  
  1.2       +6 -1      jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PaymentController.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/PaymentController.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- PaymentController.java	20 Oct 2006 16:51:26 -0000	1.1
  +++ PaymentController.java	21 Oct 2006 22:23:45 -0000	1.2
  @@ -26,8 +26,13 @@
           
           Payment payment = getInstance();
           log.info("scheduling instance #0", payment);
  -        processor.schedulePayment(payment.getPaymentDate(), payment);
  +
  +        processor.schedulePayment(payment.getPaymentDate(), 
  +                                  payment.getPaymentFrequency().getInterval(), 
  +                                  payment);
   
           return result;
       }
  +
  +    
   }
  
  
  
  1.2       +18 -7     jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/PaymentProcessor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PaymentProcessor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seampay/src/org/jboss/seam/example/seampay/PaymentProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- PaymentProcessor.java	20 Oct 2006 16:51:26 -0000	1.1
  +++ PaymentProcessor.java	21 Oct 2006 22:23:45 -0000	1.2
  @@ -2,26 +2,37 @@
   
   import org.jboss.seam.annotations.*;
   import org.jboss.seam.annotations.timer.*;
  +import org.jboss.seam.log.Log;
   
   import java.util.Date;
   import javax.persistence.*;
   import javax.ejb.Timer;
   
  +
   @Name("processor")
   public class PaymentProcessor {
       @In(create=true) EntityManager entityManager;
   
  +    @Logger Log log;
  +
       @Asynchronous
       @Transactional
  -    public Timer schedulePayment(@Expiration Date when, Payment payment) { 
  +    public Timer schedulePayment(@Expiration Date when, 
  +                                 @IntervalDuration long interval, 
  +                                 Payment payment) 
  +    { 
           payment = entityManager.merge(payment);
   
  -        System.out.println("[" + System.currentTimeMillis() + "] Processing  " + payment); 
  +        log.info("[#0] Processing payment #1", System.currentTimeMillis(), payment.getId());
   
  -        if (!payment.getPaid()) {
  +        if (payment.getActive()) {
               float balance = payment.getAccount().adjustBalance(-payment.getAmount());
  -            System.out.println(":: balance is now " + balance);
  -            payment.setPaid(true);
  +            log.info(":: balance is now #0", balance);
  +            payment.setLastPaid(new Date());
  +
  +            if (payment.getPaymentFrequency().equals(Payment.Frequency.ONCE)) {
  +                payment.setActive(false);
  +            }
           }
   
           return null;
  
  
  



More information about the jboss-cvs-commits mailing list