From df0675b20c48b18b0fceef5883aff34fe711270a Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Tue, 21 Aug 2007 04:58:45 +0000 Subject: [PATCH] separated service-layer code from flow code for "Create booking" and "cancel" --- .../samples/booking/app/BookingService.java | 3 --- .../booking/app/JpaBookingService.java | 17 +--------------- ...BookingAction.java => BookingActions.java} | 20 +++++++++++++++---- .../booking/flow/main/MainActions.java | 6 +++++- .../webapp/flow/booking/booking-beans.xml | 2 +- .../src/main/webapp/flow/booking/booking.xml | 16 +++++---------- .../src/main/webapp/flow/main/main.xml | 8 ++------ 7 files changed, 30 insertions(+), 42 deletions(-) rename spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/{ValidateBookingAction.java => BookingActions.java} (59%) diff --git a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java index 2bf431c2..5789c6f5 100755 --- a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java +++ b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/BookingService.java @@ -10,7 +10,4 @@ public interface BookingService { public Hotel findHotelById(Long id); - public Booking bookHotel(Hotel hotel, User user); - - public void cancelBooking(Long id); } diff --git a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java index 8fe4c0c3..0ee6efa7 100755 --- a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java +++ b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/app/JpaBookingService.java @@ -41,19 +41,4 @@ public class JpaBookingService implements BookingService { public Hotel findHotelById(Long id) { return em.find(Hotel.class, id); } - - @Transactional(readOnly = true) - public Booking bookHotel(Hotel hotel, User user) { - Booking booking = new Booking(hotel, user); - em.persist(booking); - return booking; - } - - @Transactional - public void cancelBooking(Long id) { - Booking booking = em.find(Booking.class, id); - if (booking != null) { - em.remove(booking); - } - } -} +} \ No newline at end of file diff --git a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/ValidateBookingAction.java b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java similarity index 59% rename from spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/ValidateBookingAction.java rename to spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java index 011f9353..b1d67141 100644 --- a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/ValidateBookingAction.java +++ b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/booking/BookingActions.java @@ -4,16 +4,28 @@ import java.util.Calendar; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; +import javax.persistence.EntityManager; -import org.springframework.webflow.action.AbstractAction; +import org.springframework.webflow.action.MultiAction; import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.samples.booking.app.Booking; +import org.springframework.webflow.samples.booking.app.Hotel; +import org.springframework.webflow.samples.booking.app.User; -public class ValidateBookingAction extends AbstractAction { +public class BookingActions extends MultiAction { - @Override - protected Event doExecute(RequestContext context) throws Exception { + public Event createBooking(RequestContext context) { + Hotel hotel = (Hotel) context.getFlowScope().get("hotel"); + User user = (User) context.getFlowScope().get("user"); + Booking booking = new Booking(hotel, user); + EntityManager em = (EntityManager) context.getFlowScope().get("entityManager"); + em.persist(booking); + context.getFlowScope().put("booking", booking); + return success(); + } + + public Event validateBooking(RequestContext context) throws Exception { Booking booking = (Booking) context.getFlowScope().get("booking"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -1); diff --git a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java index f5fbe9ac..d5725033 100644 --- a/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java +++ b/spring-webflow-samples/booking-jsf/src/main/java/org/springframework/webflow/samples/booking/flow/main/MainActions.java @@ -27,7 +27,7 @@ public class MainActions extends MultiAction { public Event findCurrentUserBookings(RequestContext context) { User user = (User) context.getConversationScope().get("user"); - List bookings = bookingService.findBookings(user.getName()); + List bookings = bookingService.findBookings(user.getUsername()); context.getFlowScope().put("bookings", new SerializableListDataModel(bookings)); return success(); } @@ -40,4 +40,8 @@ public class MainActions extends MultiAction { return success(); } + public Event removeBooking(RequestContext context) { + return success(); + } + } diff --git a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking-beans.xml b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking-beans.xml index 8ea635ae..e06c069f 100755 --- a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking-beans.xml +++ b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking-beans.xml @@ -6,6 +6,6 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> - + \ No newline at end of file diff --git a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking.xml b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking.xml index e13cece6..644f27fe 100755 --- a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking.xml +++ b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/booking/booking.xml @@ -21,19 +21,13 @@ - + - - - - - - - - - + + + @@ -42,7 +36,7 @@ - + diff --git a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/main/main.xml b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/main/main.xml index d3cc60ee..f80a79ba 100755 --- a/spring-webflow-samples/booking-jsf/src/main/webapp/flow/main/main.xml +++ b/spring-webflow-samples/booking-jsf/src/main/webapp/flow/main/main.xml @@ -34,12 +34,8 @@ - - - - - - + +