[jboss-cvs] jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay ...
Shane Bryzak
sbryzak at redhat.com
Mon Apr 9 21:42:38 EDT 2007
User: sbryzak2
Date: 07/04/09 21:42:38
Modified: examples/seambay/src/org/jboss/seam/example/seambay
Auction.java AuctionService.java
AuctionServiceRemote.java
Added: examples/seambay/src/org/jboss/seam/example/seambay
AuctionAction.java Authenticator.java
Log:
improvements to web services test page
Revision Changes Path
1.4 +16 -0 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.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- Auction.java 29 Mar 2007 13:54:59 -0000 1.3
+++ Auction.java 10 Apr 2007 01:42:38 -0000 1.4
@@ -14,6 +14,10 @@
@Entity
public class Auction implements Serializable
{
+ public static final int STATUS_UNLISTED = 0;
+ public static final int STATUS_LIVE = 1;
+ public static final int STATUS_COMPLETED = 2;
+
private static final long serialVersionUID = -8349473227099432431L;
private Integer auctionId;
@@ -26,6 +30,8 @@
private int bids;
private double price;
+ private int status;
+
@Id @GeneratedValue
public Integer getAuctionId()
{
@@ -128,4 +134,14 @@
{
this.price = price;
}
+
+ public int getStatus()
+ {
+ return status;
+ }
+
+ public void setStatus(int status)
+ {
+ this.status = status;
+ }
}
1.5 +36 -14 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- AuctionService.java 30 Mar 2007 01:34:53 -0000 1.4
+++ AuctionService.java 10 Apr 2007 01:42:38 -0000 1.5
@@ -5,30 +5,26 @@
import javax.jws.WebService;
import org.jboss.seam.Component;
+import org.jboss.seam.security.Identity;
@Stateless
@WebService
public class AuctionService implements AuctionServiceRemote
{
@WebMethod
- public Auction[] findAuctions(String searchTerm)
+ public boolean login(String username, String password)
{
- AuctionSearchAction search = (AuctionSearchAction) Component.getInstance(
- AuctionSearchAction.class, true);
-
- search.setSearchTerm(searchTerm);
- search.queryAuctions();
-
- // TODO - trim the result somehow, or use DTOs. We don't want to send user records
- // (including their passwords!!) here, nor do we want to send a huge object graph.
-
- return search.getResults().toArray(new Auction[search.getResults().size()]);
+ Identity.instance().setUsername(username);
+ Identity.instance().setPassword(password);
+ Identity.instance().login();
+ return Identity.instance().isLoggedIn();
}
@WebMethod
- public Auction getAuctionDetails(Integer auctionId)
+ public boolean logout()
{
- return null;
+ Identity.instance().logout();
+ return !Identity.instance().isLoggedIn();
}
@WebMethod
@@ -41,4 +37,30 @@
return catAction.getCategories().toArray(new Category[catAction.getCategories().size()]);
}
+
+ @WebMethod
+ public Integer createAuction(String title, String description, int categoryId)
+ {
+ AuctionAction action = (AuctionAction) Component.getInstance(AuctionAction.class, true);
+
+ action.createAuction();
+ action.setDetails(title, description, categoryId);
+
+ return action.getAuction().getAuctionId();
+ }
+
+ @WebMethod
+ public Auction[] findAuctions(String searchTerm)
+ {
+ AuctionSearchAction search = (AuctionSearchAction) Component.getInstance(
+ AuctionSearchAction.class, true);
+
+ search.setSearchTerm(searchTerm);
+ search.queryAuctions();
+
+ // TODO - trim the result somehow, or use DTOs. We don't want to send user records
+ // (including their passwords!!) here, nor do we want to send a huge object graph.
+
+ return search.getResults().toArray(new Auction[search.getResults().size()]);
+ }
}
1.3 +8 -2 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AuctionServiceRemote.java 24 Mar 2007 05:38:19 -0000 1.2
+++ AuctionServiceRemote.java 10 Apr 2007 01:42:38 -0000 1.3
@@ -5,7 +5,13 @@
@Remote
public interface AuctionServiceRemote
{
- Auction[] findAuctions(String searchTerm);
- Auction getAuctionDetails(Integer auctionId);
+ boolean login(String username, String password);
+ boolean logout();
+
Category[] listCategories();
+ Integer createAuction(String title, String description, int categoryId);
+
+
+ Auction[] findAuctions(String searchTerm);
+
}
1.1 date: 2007/04/10 01:42:38; author: sbryzak2; state: Exp;jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionAction.java
Index: AuctionAction.java
===================================================================
package org.jboss.seam.example.seambay;
import static org.jboss.seam.ScopeType.CONVERSATION;
import java.io.Serializable;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.persistence.EntityManager;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.security.Restrict;
@Scope(CONVERSATION)
@Name("auctionAction")
@Restrict("#{identity.loggedIn}")
public class AuctionAction implements Serializable
{
private static final long serialVersionUID = -6738397725125671313L;
@In EntityManager entityManager;
@In User authenticatedUser;
private Auction auction;
private int durationDays;
@Begin
public void createAuction()
{
auction = new Auction();
auction.setUser(authenticatedUser);
entityManager.persist(auction);
}
@Begin
public void editAuction(Integer auctionId)
{
auction = entityManager.find(Auction.class, auctionId);
}
public void setDetails(String title, String description, int categoryId)
{
auction.setTitle(title);
auction.setDescription(description);
auction.setCategory(entityManager.find(Category.class, categoryId));
}
public void setDuration(int days)
{
this.durationDays = days;
}
@End
public void confirm()
{
Calendar cal = new GregorianCalendar();
cal.add(Calendar.DAY_OF_MONTH, durationDays);
auction.setEndDate(cal.getTime());
auction.setStatus(Auction.STATUS_LIVE);
auction = entityManager.merge(auction);
}
public Auction getAuction()
{
return auction;
}
}
1.1 date: 2007/04/10 01:42:38; author: sbryzak2; state: Exp;jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Authenticator.java
Index: Authenticator.java
===================================================================
package org.jboss.seam.example.seambay;
import static org.jboss.seam.ScopeType.SESSION;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.security.Identity;
@Name("authenticator")
public class Authenticator
{
@In
private EntityManager entityManager;
@Out(required = false, scope = SESSION)
private User authenticatedUser;
@In
private Identity identity;
public boolean authenticate()
{
try
{
User user = (User) entityManager.createQuery(
"from User where username = :username and password = :password")
.setParameter("username", identity.getUsername())
.setParameter("password", identity.getPassword())
.getSingleResult();
authenticatedUser = user;
return true;
}
catch (NoResultException ex)
{
return false;
}
}
}
More information about the jboss-cvs-commits
mailing list