diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-25 18:00:45 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-01-25 18:00:45 +0000 |
commit | 3852b601e7c5d71282cb5e37e9c6ce6e648503a2 (patch) | |
tree | 65e9367a1a4e6b3386f3b745f0611fb13ac67396 /sandbox/travelsample/tripbooking-contribution | |
parent | fcc6917ad657da26eedccadf3e7b8d81d410b6a7 (diff) |
switch components so that the booking component talks directly to the trip suppliers.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@737553 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/tripbooking-contribution')
4 files changed, 71 insertions, 12 deletions
diff --git a/sandbox/travelsample/tripbooking-contribution/META-INF/sca-contribution.xml b/sandbox/travelsample/tripbooking-contribution/META-INF/sca-contribution.xml index 5922c86cac..2accecffaa 100644 --- a/sandbox/travelsample/tripbooking-contribution/META-INF/sca-contribution.xml +++ b/sandbox/travelsample/tripbooking-contribution/META-INF/sca-contribution.xml @@ -20,5 +20,6 @@ <contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"> <import.java package="scatours.common"/> <import.java package="scatours.currencyconverter"/> + <import.java package="scatours.shoppingcart"/> <export.java package="scatours.tripbooking"/> </contribution>
\ No newline at end of file diff --git a/sandbox/travelsample/tripbooking-contribution/pom.xml b/sandbox/travelsample/tripbooking-contribution/pom.xml index e7061a0d79..b0e7b2fef7 100644 --- a/sandbox/travelsample/tripbooking-contribution/pom.xml +++ b/sandbox/travelsample/tripbooking-contribution/pom.xml @@ -52,6 +52,12 @@ <artifactId>scatours-currency-contribution</artifactId> <version>1.5-SNAPSHOT</version> </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>scatours-shoppingcart-contribution</artifactId> + <version>1.5-SNAPSHOT</version> + </dependency> <dependency> <groupId>junit</groupId> diff --git a/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBooking.java b/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBooking.java index ae9ea00e61..2255b29d35 100644 --- a/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBooking.java +++ b/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBooking.java @@ -30,17 +30,7 @@ import scatours.common.TripItem; * The Trip service interface */ @Remotable -@Conversational public interface TripBooking { - void addTripItem(TripItem tripItem); - - void removeTripItem(String tripItemId); - - TripItem[] getTripItems(); - - double getTripPrice(); - - @EndsConversation - void bookTrip(); + TripItem bookTrip(String cartId, TripItem trip); } diff --git a/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBookingImpl.java b/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBookingImpl.java index 5133844fe1..fd199fd19f 100644 --- a/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBookingImpl.java +++ b/sandbox/travelsample/tripbooking-contribution/src/scatours/tripbooking/TripBookingImpl.java @@ -22,23 +22,84 @@ import java.util.HashMap; import java.util.Map; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.annotations.Context; import org.osoa.sca.annotations.ConversationID; import org.osoa.sca.annotations.Destroy; import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; +import scatours.common.Book; +import scatours.common.Search; import scatours.common.TripItem; +import scatours.shoppingcart.ShoppingCart; /** * An implementation of the Trip service */ -@Scope("CONVERSATION") @Service(interfaces={TripBooking.class}) public class TripBookingImpl implements TripBooking{ + @Reference + protected Book hotelBook; + + @Reference + protected Book flightBook; + + @Reference + protected Book carBook; + + @Reference + protected Book tripBook; + + @Reference + protected ShoppingCart shoppingCart; + + @Context + protected ComponentContext componentContext; + + public TripItem bookTrip(String cartId, TripItem trip) { + + String bookingCode = ""; + + // book any nested items + TripItem[] nestedItems = trip.getTripItems(); + if (nestedItems != null){ + for(int i = 0; i < nestedItems.length; i++ ){ + TripItem tripItem = nestedItems[i]; + if (tripItem.getType().equals(TripItem.CAR)){ + tripItem.setBookingCode(carBook.book(tripItem)); + } else if (tripItem.getType().equals(TripItem.FLIGHT)){ + tripItem.setBookingCode(flightBook.book(tripItem)); + } else if (tripItem.getType().equals(TripItem.HOTEL)){ + tripItem.setBookingCode(hotelBook.book(tripItem)); + } else { + tripItem.setBookingCode(tripItem.getType() + " is invalid"); + } + } + } + + // book the top level item if it's a packaged trip + if (trip.getType().equals(TripItem.TRIP)){ + bookingCode = tripBook.book(trip); + trip.setBookingCode(bookingCode); + } + + // add trip to the shopping cart + //ServiceReference<ShoppingCart> cart = componentContext.getServiceReference(ShoppingCart.class, + // "shoppingCart"); + //cart.setConversationID(cartId); + //cart.getService().addTrip(trip); + + return trip; + } + + /* @ConversationID protected String conversationId; @@ -82,4 +143,5 @@ public class TripBookingImpl implements TripBooking{ public void bookTrip() { // TODO } + */ } |