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

Shane Bryzak sbryzak at redhat.com
Sun Apr 15 21:40:08 EDT 2007


  User: sbryzak2
  Date: 07/04/15 21:40:08

  Modified:    examples/seambay/src/org/jboss/seam/example/seambay     
                        Auction.java AuctionSearchAction.java
                        AuctionService.java AuctionServiceRemote.java
  Added:       examples/seambay/src/org/jboss/seam/example/seambay     
                        Aargh.java
  Log:
  prettified the search screen
  
  Revision  Changes    Path
  1.6       +34 -4     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.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- Auction.java	11 Apr 2007 07:16:04 -0000	1.5
  +++ Auction.java	16 Apr 2007 01:40:08 -0000	1.6
  @@ -11,6 +11,8 @@
   import javax.persistence.OneToOne;
   import javax.persistence.Transient;
   
  +import org.hibernate.validator.NotNull;
  +
   @Entity
   public class Auction implements Serializable
   {
  @@ -87,6 +89,7 @@
         this.description = description;
      }
      
  +   @NotNull
      public Date getEndDate()
      {
         return endDate;
  @@ -120,12 +123,39 @@
      }
      
      @Transient
  -   public String getTimeLeft()
  +   public long getTimeLeft()
      {
  -      if (endDate == null) 
  -         return null;
  +      return (endDate.getTime() - System.currentTimeMillis()); 
  +   }   
  +   
  +   @Transient
  +   public String getPrettyTimeLeft()
  +   {
  +      long timeLeft = getTimeLeft() / 1000;
  +      
  +      int days = (int) Math.floor(timeLeft / (60 * 60 * 24));
  +      
  +      timeLeft -= days * 24 * 60 * 60;
  +      int hours = (int) Math.floor(timeLeft / (60 * 60));
  +      
  +      timeLeft -= hours * 60 * 60;
  +      int minutes = (int) Math.floor(timeLeft / 60);
  +      
  +      timeLeft -= minutes * 60;
  +      int seconds = (int) timeLeft;
  +
  +      StringBuilder sb = new StringBuilder();
  +      
  +      if (days > 0)
  +         sb.append(String.format("%dd ", days));
  +      
  +      if (hours > 0)
  +         sb.append(String.format("%dh ", hours));
  +
  +      if (minutes > 0)
  +         sb.append(String.format("%dm ", minutes));     
         
  -      return (endDate.getTime() - System.currentTimeMillis()) + "ms"; 
  +      return sb.toString();
      }
      
      public double getPrice()
  
  
  
  1.6       +2 -2      jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionSearchAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- AuctionSearchAction.java	11 Apr 2007 07:16:04 -0000	1.5
  +++ AuctionSearchAction.java	16 Apr 2007 01:40:08 -0000	1.6
  @@ -50,7 +50,7 @@
         {
            qry = "from Auction a where lower(title) like #{searchPattern} " +
                  "and a.category = #{searchCategory} and a.status = 1 " +
  -               "and a.endDate >= #{currentDateTime}";
  +               "and a.endDate >= #{currentDatetime}";
         }
         
         auctions = entityManager.createQuery(qry)
  @@ -63,7 +63,7 @@
         for (Object[] result : (List<Object[]>) entityManager.createQuery(
               "select a.category.categoryId, count(a) from Auction a " +
               "where lower(a.title) like #{searchPattern} " +
  -            "and a.endDate >= #{currentDateTime} and a.status = 1 " +
  +            "and a.endDate >= #{currentDatetime} and a.status = 1 " +
               "group by a.category.categoryId")
               .getResultList())
         {
  
  
  
  1.7       +18 -0     jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- AuctionService.java	11 Apr 2007 15:41:04 -0000	1.6
  +++ AuctionService.java	16 Apr 2007 01:40:08 -0000	1.7
  @@ -5,6 +5,7 @@
   import javax.jws.WebService;
   
   import org.jboss.seam.Component;
  +import org.jboss.seam.core.Manager;
   import org.jboss.seam.security.Identity;
   
   @Stateless
  @@ -59,6 +60,23 @@
      }
      
      @WebMethod
  +   public void setAuctionDuration(int auctionId, int days)
  +   {
  +      Manager.instance().restoreConversation("" + auctionId);
  +      AuctionAction action = (AuctionAction) Component.getInstance(AuctionAction.class, true);
  +      
  +      action.setDuration(days);
  +   }
  +   
  +   @WebMethod
  +   public void confirmAuction(int auctionId)
  +   {
  +      AuctionAction action = (AuctionAction) Component.getInstance(AuctionAction.class, true);
  +      
  +      action.confirm();
  +   }
  +   
  +   @WebMethod
      public Auction[] findAuctions(String searchTerm)
      {
         AuctionSearchAction search = (AuctionSearchAction) Component.getInstance(
  
  
  
  1.5       +2 -1      jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionServiceRemote.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionServiceRemote.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionServiceRemote.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- AuctionServiceRemote.java	11 Apr 2007 15:41:04 -0000	1.4
  +++ AuctionServiceRemote.java	16 Apr 2007 01:40:08 -0000	1.5
  @@ -12,7 +12,8 @@
      
      Integer createAuction(String title, String description, int categoryId);   
      void updateAuction(int auctionId, String title, String description, int categoryId);
  +   void setAuctionDuration(int auctionId, int days);
  +   void confirmAuction(int auctionId);
      
      Auction[] findAuctions(String searchTerm);
  -
   }
  
  
  
  1.1      date: 2007/04/16 01:40:08;  author: sbryzak2;  state: Exp;jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Aargh.java
  
  Index: Aargh.java
  ===================================================================
  package org.jboss.seam.example.seambay;
  
  import static org.jboss.seam.InterceptionType.NEVER;
  import static org.jboss.seam.ScopeType.APPLICATION;
  
  import java.util.Calendar;
  import java.util.GregorianCalendar;
  import java.util.List;
  import java.util.Random;
  
  import javax.naming.InitialContext;
  import javax.persistence.EntityManager;
  import javax.transaction.SystemException;
  import javax.transaction.UserTransaction;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.annotations.Create;
  import org.jboss.seam.annotations.Intercept;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.Startup;
  
  /**
   * Nasty nasty hack because hsqldb doesn't support date arithmetic and we actually
   * want to deploy with usable test data.
   * 
   * @author shane
   *
   */
  @Startup
  @Name("aargh")
  @Scope(APPLICATION)
  @Intercept(NEVER)
  public class Aargh
  {
     @Create
     public void create()
     {
        UserTransaction t = null;
        try
        {
           InitialContext ctx = new InitialContext();
           
           t = (UserTransaction) ctx.lookup("UserTransaction");
           t.begin();
        
           EntityManager em = (EntityManager) Component.getInstance("entityManager", true);
           
           List<Auction> auctions = em.createQuery("from Auction").getResultList();
           
           Calendar cal = new GregorianCalendar();
           
           Random r = new Random();
           
           for (Auction auction : auctions)
           {
              cal.setTime(auction.getEndDate());
              cal.add(Calendar.DATE, r.nextInt(7));
              cal.add(Calendar.MINUTE, 30 + r.nextInt(1410));
              auction.setEndDate(cal.getTime());
              em.merge(auction);
           }
           
           t.commit();
        } 
        catch (Exception e)
        {
           try
           {
              if (t != null)
                 t.rollback();
           } 
           catch (SystemException e1) {}
           
           throw new RuntimeException("Error starting transaction", e);
        }      
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list