minor refinements. par-provided will return proper dependencies. removed reference to hotelSearchAgent from booking flow. removed WEB-INF/controllers

This commit is contained in:
Scott Andrews
2008-07-02 15:37:24 +00:00
parent df4db13b6c
commit 119384783b
14 changed files with 45 additions and 34 deletions

View File

@@ -19,8 +19,8 @@
<dependencies>
<dependency org="org.springframework.samples" name="org.springframework.samples.springtravel.resource" rev="latest.integration" conf="compile->runtime" />
<dependency org="org.hibernate" name="org.hibernate.ejb-library" rev="3.3.1.ga" conf="provided->runtime" />
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided->runtime" />
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="test->runtime" />
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided-platform->compile" />
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="provided->runtime" />
</dependencies>

View File

@@ -18,7 +18,7 @@
<dependencies>
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="provided->runtime"/>
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided->runtime" />
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided-platform->compile" />
</dependencies>
</ivy-module>

View File

@@ -21,15 +21,15 @@
<dependencies>
<dependency org="org.springframework.samples" name="org.springframework.samples.springtravel.resource" rev="latest.integration" conf="compile->runtime" />
<dependency org="org.springframework.samples" name="org.springframework.samples.springtravel.hotel.search" rev="latest.integration" conf="compile->runtime" />
<dependency org="org.springframework.webflow" name="org.springframework.webflow" rev="latest.integration" conf="provided->runtime" />
<dependency org="org.springframework.webflow" name="org.springframework.binding" rev="latest.integration" conf="provided->runtime" />
<dependency org="org.springframework.webflow" name="org.springframework.faces" rev="latest.integration" conf="provided->runtime" />
<dependency org="org.springframework.webflow" name="org.springframework.js" rev="latest.integration" conf="provided->runtime" />
<dependency org="org.springframework.webflow" name="org.springframework.webflow" rev="latest.integration" conf="provided->provided" />
<dependency org="org.springframework.webflow" name="org.springframework.binding" rev="latest.integration" conf="provided->provided" />
<dependency org="org.springframework.webflow" name="org.springframework.faces" rev="latest.integration" conf="provided->provided" />
<dependency org="org.springframework.webflow" name="org.springframework.js" rev="latest.integration" conf="provided->provided" />
<dependency org="org.hibernate" name="org.hibernate.ejb-library" rev="3.3.1.ga" conf="provided->runtime" />
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided->runtime" />
<dependency org="org.springframework" name="org.springframework.spring-library" rev="2.5.4.A" conf="provided-platform->compile" />
<dependency org="org.apache.myfaces" name="org.apache.myfaces-library" rev="1.2.2" conf="provided->runtime" />
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="test->runtime" />
<dependency org="org.springframework.security" name="org.springframework.security" rev="2.0.2.A" conf="provided->runtime" />
<dependency org="org.hsqldb" name="com.springsource.org.hsqldb" rev="1.8.0.9" conf="provided->runtime" />
<dependency org="org.springframework.security" name="org.springframework.security" rev="2.0.2.A" conf="provided->provided" />
<dependency org="com.sun.facelets" name="com.springsource.com.sun.facelets" rev="1.1.14" conf="provided->runtime" />
<dependency org="org.jboss.el" name="com.springsource.org.jboss.el" rev="2.0.0.GA" conf="provided->runtime" />
</dependencies>

View File

@@ -19,17 +19,6 @@ public interface HotelBookingAgent {
*/
public List<HotelBooking> findBookings(String username);
/**
* Create a new, transient hotel booking instance for the given user.
*
* @param hotel
* the hotel
* @param userName
* the user name
* @return the new transient booking instance
*/
public HotelBooking createBooking(Hotel hotel, String userName);
/**
* Cancel an existing booking.
*
@@ -38,4 +27,18 @@ public interface HotelBookingAgent {
*/
public void cancelBooking(Long id);
// flow helpers
/**
* Create a new, persistent, hotel booking instance for the given user. This method is a flow
* helper, it has no direct relationship to the booking process.
*
* @param hotelId
* the hotel id
* @param userName
* the user name
* @return the new transient booking instance
*/
public HotelBooking createBooking(Long hotelId, String userName);
}

View File

@@ -44,12 +44,6 @@ public class JpaHotelBookingAgent implements HotelBookingAgent {
}
}
@Transactional(readOnly = true)
public HotelBooking createBooking(Hotel hotel, String username) {
User user = findUser(username);
return new HotelBooking(hotel, user);
}
@Transactional
public void cancelBooking(Long id) {
HotelBooking booking = em.find(HotelBooking.class, id);
@@ -58,6 +52,17 @@ public class JpaHotelBookingAgent implements HotelBookingAgent {
}
}
// flow helper
@Transactional(readOnly = true)
public HotelBooking createBooking(Long hotelId, String username) {
User user = findUser(username);
Hotel hotel = findHotel(hotelId);
HotelBooking booking = new HotelBooking(hotel, user);
em.persist(booking);
return booking;
}
// helpers
private User findUser(String username) {
@@ -65,5 +70,11 @@ public class JpaHotelBookingAgent implements HotelBookingAgent {
"select u from User u where u.username = :username")
.setParameter("username", username).getSingleResult();
}
private Hotel findHotel(Long hotelId) {
return (Hotel) em.createQuery(
"select h from Hotel h where h.id = :hotelId")
.setParameter("hotelId", hotelId).getSingleResult();
}
}

View File

@@ -36,8 +36,8 @@
<!-- The registry of executable flow definitions in this module -->
<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
<webflow:flow-location path="WEB-INF/controllers/hotel/search/search.xml" />
<webflow:flow-location path="WEB-INF/controllers/hotel/booking/booking.xml" />
<webflow:flow-location path="WEB-INF/hotel/search/search.xml" />
<webflow:flow-location path="WEB-INF/hotel/booking/booking.xml" />
</webflow:flow-registry>
<!-- Enables the flow JSF integration -->

View File

@@ -10,8 +10,7 @@
<input name="hotelId" required="true"/>
<on-start>
<evaluate expression="hotelSearchAgent.findHotelById(hotelId)" result="flowScope.hotel" />
<evaluate expression="hotelBookingAgent.createBooking(hotel, currentUser.name)" result="flowScope.booking" />
<evaluate expression="hotelBookingAgent.createBooking(hotelId, currentUser.name)" result="flowScope.booking" />
</on-start>
<view-state id="enterBookingDetails" model="booking">
@@ -20,9 +19,7 @@
</view-state>
<view-state id="reviewBooking">
<transition on="confirm" to="bookingConfirmed">
<evaluate expression="persistenceContext.persist(booking)" />
</transition>
<transition on="confirm" to="bookingConfirmed" />
<transition on="revise" to="enterBookingDetails" />
<transition on="cancel" to="bookingCancelled" />
</view-state>