From 3852b601e7c5d71282cb5e37e9c6ce6e648503a2 Mon Sep 17 00:00:00 2001 From: slaws Date: Sun, 25 Jan 2009 18:00:45 +0000 Subject: 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 --- .../car-contribution/src/scatours/car/CarImpl.java | 23 +- .../src/scatours/common/Book.java | 31 ++ .../src/scatours/common/TripItem.java | 55 ++++ .../src/scatours/flight/FlightImpl.java | 37 ++- .../src/scatours/hotel/HotelImpl.java | 35 +- sandbox/travelsample/node/build.xml | 3 +- .../travelsample/node/src/scatours/LaunchNode.java | 1 + sandbox/travelsample/pom.xml | 1 + .../META-INF/sca-contribution.xml | 2 - .../src/scatours/SCAToursBooking.java | 9 +- .../src/scatours/SCAToursCart.java | 34 ++ .../src/scatours/SCAToursImpl.java | 42 ++- .../src/scatours/SCAToursSearch.java | 32 ++ .../META-INF/sca-contribution.xml | 2 + .../src/scatours/shoppingcart/ShoppingCart.java | 12 +- .../scatours/shoppingcart/ShoppingCartImpl.java | 42 ++- .../scatours/travelcatalog/TravelCatalogImpl.java | 12 +- .../src/scatours/trip/TripImpl.java | 27 +- .../META-INF/sca-contribution.xml | 1 + .../travelsample/tripbooking-contribution/pom.xml | 6 + .../src/scatours/tripbooking/TripBooking.java | 12 +- .../src/scatours/tripbooking/TripBookingImpl.java | 64 +++- .../ui-contribution/META-INF/sca-contribution.xml | 1 + sandbox/travelsample/ui-contribution/build.xml | 3 +- .../ui-contribution/scatours.composite | 46 ++- sandbox/travelsample/ui-contribution/scatours.html | 361 ++++++++++++++------- 26 files changed, 654 insertions(+), 240 deletions(-) create mode 100644 sandbox/travelsample/common-contribution/src/scatours/common/Book.java create mode 100644 sandbox/travelsample/scatours-contribution/src/scatours/SCAToursCart.java create mode 100644 sandbox/travelsample/scatours-contribution/src/scatours/SCAToursSearch.java (limited to 'sandbox/travelsample') diff --git a/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java b/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java index dd28dc7498..059365a9ab 100644 --- a/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java +++ b/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java @@ -26,6 +26,7 @@ import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; +import scatours.common.Book; import scatours.common.Search; import scatours.common.SearchCallback; import scatours.common.TripItem; @@ -35,8 +36,8 @@ import scatours.common.TripLeg; * An implementation of the Hotel service */ @Scope("STATELESS") -@Service(interfaces={Search.class}) -public class CarImpl implements Search { +@Service(interfaces={Search.class, Book.class}) +public class CarImpl implements Search, Book { private List cars = new ArrayList(); @@ -47,19 +48,19 @@ public class CarImpl implements Search { public void init() { cars.add(new CarInfo("Premier Cars", "BMW 5 Series", - "ANU", - "06/12/08", + "FLR", + "06/12/09", "5", 100.00, - "USD", + "EUR", "http://localhost:8085/tbd" )); cars.add(new CarInfo("Premier Cars", "Ford Focus", - "ANU", - "06/12/08", + "FLR", + "06/12/09", "4", 60.00, - "USD", + "EUR", "http://localhost:8085/tbd" )); } @@ -71,7 +72,7 @@ public class CarImpl implements Search { if (car.getLocation().equals(tripLeg.getToLocation())){ TripItem item = new TripItem("", "", - "Car", + TripItem.CAR, car.getName(), car.getDescription(), car.getLocation(), @@ -92,4 +93,8 @@ public class CarImpl implements Search { // return available hotels searchCallback.searchResults(searchSynch(tripLeg)); } + + public String book(TripItem tripItem) { + return "car1"; + } } diff --git a/sandbox/travelsample/common-contribution/src/scatours/common/Book.java b/sandbox/travelsample/common-contribution/src/scatours/common/Book.java new file mode 100644 index 0000000000..f42db4341b --- /dev/null +++ b/sandbox/travelsample/common-contribution/src/scatours/common/Book.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package scatours.common; + +import java.util.List; + +import org.osoa.sca.annotations.Callback; +import org.osoa.sca.annotations.OneWay; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Book { + String book(TripItem tripItem); +} diff --git a/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java b/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java index f1e3581d86..e991668cbc 100644 --- a/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java +++ b/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java @@ -19,9 +19,16 @@ package scatours.common; +import java.util.List; + public class TripItem { + public static String FLIGHT = "Flight"; + public static String HOTEL = "Hotel"; + public static String CAR = "Car"; + public static String TRIP = "Trip"; + private String id; private String tripId; private String type; @@ -33,6 +40,10 @@ public class TripItem { private double price; private String currency; private String link; + private TripItem[] tripItems; // used for a trip made up of trip items + private String customerDetails; + private String agentDetails; + private String bookingCode; public TripItem() { } @@ -162,4 +173,48 @@ public class TripItem { public void setLink(String link) { this.link = link; } + + public TripItem[] getTripItems() { + return tripItems; + } + + public void setTripItems(TripItem[] tripItems) { + this.tripItems = tripItems; + } + + public String getCustomerDetails() { + return customerDetails; + } + + public void setCustomerDetails(String customerDetails) { + this.customerDetails = customerDetails; + } + + public String getAgentDetails() { + return agentDetails; + } + + public void setAgentDetails(String agentDetails) { + this.agentDetails = agentDetails; + } + + public String getBookingCode() { + return bookingCode; + } + + public void setBookingCode(String bookingCode) { + this.bookingCode = bookingCode; + } + + @Override + public boolean equals(Object obj) { + + if (obj instanceof TripItem){ + if (((TripItem)obj).getId().equals(getId())){ + return true; + } + } + + return super.equals(obj); + } } diff --git a/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java b/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java index 106144aebd..72c1c7201c 100644 --- a/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java +++ b/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java @@ -26,6 +26,7 @@ import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; +import scatours.common.Book; import scatours.common.Search; import scatours.common.SearchCallback; import scatours.common.TripItem; @@ -35,8 +36,8 @@ import scatours.common.TripLeg; * An implementation of the Hotel service */ @Scope("STATELESS") -@Service(interfaces={Search.class}) -public class FlightImpl implements Search { +@Service(interfaces={Search.class, Book.class}) +public class FlightImpl implements Search, Book { private List flights = new ArrayList(); @@ -45,25 +46,25 @@ public class FlightImpl implements Search { @Init public void init() { - flights.add(new FlightInfo("IA26", - "Island Airlines Boeing 747", + flights.add(new FlightInfo("EA26", + "Europe Airlines Airbus A300", "LGW", - "ANU", - "06/12/08", - "06/12/08", + "FLR", + "06/12/09", + "06/12/09", "350", 250, - "USD", + "EUR", "http://localhost:8085/tbd" )); - flights.add(new FlightInfo("IA27", - "Island Airlines Boeing 747", - "ANU", + flights.add(new FlightInfo("EA27", + "Europe Airlines Airbus A300", + "FLR", "LGW", - "13/12/08", - "13/12/08", + "13/12/09", + "13/12/09", "350", 250, - "USD", + "EUR", "http://localhost:8085/tbd" )); } @@ -78,7 +79,7 @@ public class FlightImpl implements Search { (flight.getFromDate().equals(tripLeg.getFromDate()))){ TripItem item = new TripItem("", "", - "Flight", + TripItem.FLIGHT, flight.getName(), flight.getDescription(), flight.getFromLocation() + " - " + flight.getToLocation(), @@ -98,7 +99,7 @@ public class FlightImpl implements Search { (flight.getFromDate().equals(tripLeg.getToDate()))){ TripItem item = new TripItem("", "", - "Flight", + TripItem.FLIGHT, flight.getName(), flight.getDescription(), flight.getFromLocation() + " - " + flight.getToLocation(), @@ -119,4 +120,8 @@ public class FlightImpl implements Search { // return available hotels searchCallback.searchResults(searchSynch(tripLeg)); } + + public String book(TripItem tripItem) { + return "flight1"; + } } diff --git a/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java b/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java index 81012ea08b..a9a6d1bbde 100644 --- a/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java +++ b/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java @@ -26,6 +26,7 @@ import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; +import scatours.common.Book; import scatours.common.Search; import scatours.common.SearchCallback; import scatours.common.TripItem; @@ -35,8 +36,8 @@ import scatours.common.TripLeg; * An implementation of the Hotel service */ @Scope("STATELESS") -@Service(interfaces={Search.class}) -public class HotelImpl implements Search { +@Service(interfaces={Search.class, Book.class}) +public class HotelImpl implements Search, Book { private List hotels = new ArrayList(); @@ -47,35 +48,35 @@ public class HotelImpl implements Search { public void init() { hotels.add(new HotelInfo("Deep Bay Hotel", "Wonderful sea views and a relaxed atmosphere", - "ANU", - "06/12/08", + "FLR", + "06/12/09", "200", 100, - "USD", + "EUR", "http://localhost:8085/tbd" )); hotels.add(new HotelInfo("Long Bay Hotel", "Friendly staff and an ocean breeze", - "ANU", - "06/12/08", + "FLR", + "06/12/09", "200", 100, - "USD", + "EUR", "http://localhost:8085/tbd" )); hotels.add(new HotelInfo("City Hotel", "Smart rooms and early breakfasts", - "NY", - "06/12/08", + "FLR", + "06/12/09", "200", 100, - "USD", + "EUR", "http://localhost:8085/tbd" )); hotels.add(new HotelInfo("County Hotel", "The smell of the open country", - "SOU", - "06/12/08", + "FLR", + "06/12/09", "200", 100, - "USD", + "EUR", "http://localhost:8085/tbd" )); } @@ -87,7 +88,7 @@ public class HotelImpl implements Search { if (hotel.getLocation().equals(tripLeg.getToLocation())){ TripItem item = new TripItem("", "", - "Hotel", + TripItem.HOTEL, hotel.getName(), hotel.getDescription(), hotel.getLocation(), @@ -108,4 +109,8 @@ public class HotelImpl implements Search { // return available hotels searchCallback.searchResults(searchSynch(tripLeg)); } + + public String book(TripItem tripItem) { + return "hotel1"; + } } diff --git a/sandbox/travelsample/node/build.xml b/sandbox/travelsample/node/build.xml index 0f0faf956c..ff93d7a224 100644 --- a/sandbox/travelsample/node/build.xml +++ b/sandbox/travelsample/node/build.xml @@ -161,7 +161,7 @@ - + @@ -180,7 +180,6 @@ - diff --git a/sandbox/travelsample/node/src/scatours/LaunchNode.java b/sandbox/travelsample/node/src/scatours/LaunchNode.java index 892f2b8dfd..007406061e 100644 --- a/sandbox/travelsample/node/src/scatours/LaunchNode.java +++ b/sandbox/travelsample/node/src/scatours/LaunchNode.java @@ -72,6 +72,7 @@ public class LaunchNode { new SCAContribution("hotel", "../hotel-contribution/target/classes"), new SCAContribution("flight", "../flight-contribution/target/classes"), new SCAContribution("car", "../car-contribution/target/classes"), + new SCAContribution("trip", "../trip-contribution/target/classes"), new SCAContribution("tripbooking", "../tripbooking-contribution/target/classes"), new SCAContribution("travelcatalog", "../travelcatalog-contribution/target/classes"), new SCAContribution("payment", "../payment-contribution/target/classes"), diff --git a/sandbox/travelsample/pom.xml b/sandbox/travelsample/pom.xml index 6d687c60e4..29576a5214 100644 --- a/sandbox/travelsample/pom.xml +++ b/sandbox/travelsample/pom.xml @@ -42,6 +42,7 @@ hotel-contribution flight-contribution car-contribution + trip-contribution payment-contribution paymentprocess-contribution emailgateway-contribution diff --git a/sandbox/travelsample/scatours-contribution/META-INF/sca-contribution.xml b/sandbox/travelsample/scatours-contribution/META-INF/sca-contribution.xml index 6d6a563b74..368e95ebd0 100644 --- a/sandbox/travelsample/scatours-contribution/META-INF/sca-contribution.xml +++ b/sandbox/travelsample/scatours-contribution/META-INF/sca-contribution.xml @@ -19,10 +19,8 @@ --> - - \ No newline at end of file diff --git a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursBooking.java b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursBooking.java index 611b4d8945..ac39443e9c 100644 --- a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursBooking.java +++ b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursBooking.java @@ -28,12 +28,5 @@ import scatours.common.TripItem; */ @Remotable public interface SCAToursBooking { - String addCart(); - String addTrip(String cartId); - void removeTrip(String cartId, String tripId); - void addTripItem(String cartId, String tripId, String tripItemId); - void removeTripItem(String cartId, String tripId, String tripItemId); - TripItem[] getTripItems(String cartId); - double getTotalPrice(String cartId); - void checkout(String name); + String bookTrip(String cartId, TripItem tripId); } diff --git a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursCart.java b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursCart.java new file mode 100644 index 0000000000..61e32ec4a2 --- /dev/null +++ b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursCart.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package scatours; + +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.Remotable; + +import scatours.common.TripItem; + +/** + * The ShoppingCart service interface + */ +@Remotable +public interface SCAToursCart{ + String newCart(); + TripItem[] getTrips(String cartId); + void checkout(String cartId); +} diff --git a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursImpl.java b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursImpl.java index d36a6604ce..c0f7bec6ea 100644 --- a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursImpl.java +++ b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursImpl.java @@ -43,8 +43,8 @@ import scatours.tripbooking.TripBooking; * An implementation of the Trip service */ @Scope("COMPOSITE") -@Service(interfaces={TravelCatalogSearch.class, SCAToursBooking.class}) -public class SCAToursImpl implements TravelCatalogSearch, SCAToursBooking{ +@Service(interfaces={SCAToursSearch.class, SCAToursBooking.class, SCAToursCart.class}) +public class SCAToursImpl implements SCAToursSearch, SCAToursBooking, SCAToursCart{ @Reference protected TravelCatalogSearch travelCatalogSearch; @@ -53,33 +53,38 @@ public class SCAToursImpl implements TravelCatalogSearch, SCAToursBooking{ protected TripBooking tripBooking; @Reference - protected ShoppingCart shoppingCart; - - @Reference - protected PaymentProcess paymentProcess; + protected ShoppingCart shoppingCart; @Context protected ComponentContext componentContext; private Map carts = new HashMap(); private Map trips = new HashMap(); - private Map searchItemsCache = new HashMap(); + //private Map searchItemsCache = new HashMap(); - // TravelCatalogSearch methods + // SCAToursSearch methods public TripItem[] search(TripLeg tripLeg) { TripItem[] searchItems = travelCatalogSearch.search(tripLeg); - for (int i =0; i< searchItems.length; i++){ - searchItemsCache.put(searchItems[i].getId(), searchItems[i]); - } + //for (int i =0; i< searchItems.length; i++){ + // searchItemsCache.put(searchItems[i].getId(), searchItems[i]); + //} return searchItems; } // SCAToursBooking methods - public String addCart(){ + public String bookTrip(String cartId, TripItem trip){ + TripItem bookedTrip = tripBooking.bookTrip(cartId, trip); + carts.get(cartId).addTrip(bookedTrip); + return bookedTrip.getBookingCode(); + } + + // SCAToursCart methods + + public String newCart(){ String cartId = UUID.randomUUID().toString(); ServiceReference shoppingCart = componentContext.getServiceReference(ShoppingCart.class, "shoppingCart"); @@ -87,8 +92,17 @@ public class SCAToursImpl implements TravelCatalogSearch, SCAToursBooking{ carts.put(cartId, shoppingCart.getService()); return cartId; - } + } + public TripItem[] getTrips(String cartId){ + return carts.get(cartId).getTrips(); + } + + public void checkout(String cartId){ + shoppingCart.checkout("Fred"); + } + +/* public String addTrip(String cartId){ String tripId = UUID.randomUUID().toString(); ServiceReference tripReference = componentContext.getServiceReference(TripBooking.class, @@ -143,4 +157,6 @@ public class SCAToursImpl implements TravelCatalogSearch, SCAToursBooking{ paymentProcess.makePayment(customerId, amount); } + +*/ } diff --git a/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursSearch.java b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursSearch.java new file mode 100644 index 0000000000..f0f435fc06 --- /dev/null +++ b/sandbox/travelsample/scatours-contribution/src/scatours/SCAToursSearch.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package scatours; + +import org.osoa.sca.annotations.Remotable; + +import scatours.common.TripItem; +import scatours.common.TripLeg; + +/** + * The Trip service interface + */ +@Remotable +public interface SCAToursSearch { + TripItem[] search(TripLeg tripLeg); +} diff --git a/sandbox/travelsample/shoppingcart-contribution/META-INF/sca-contribution.xml b/sandbox/travelsample/shoppingcart-contribution/META-INF/sca-contribution.xml index f90d041864..f4010d04b1 100644 --- a/sandbox/travelsample/shoppingcart-contribution/META-INF/sca-contribution.xml +++ b/sandbox/travelsample/shoppingcart-contribution/META-INF/sca-contribution.xml @@ -18,5 +18,7 @@ * under the License. --> + + \ No newline at end of file diff --git a/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCart.java b/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCart.java index a7ad6e0a18..f7595c71fe 100644 --- a/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCart.java +++ b/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCart.java @@ -19,15 +19,21 @@ package scatours.shoppingcart; import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; import org.osoa.sca.annotations.Remotable; +import scatours.common.TripItem; + /** * The ShoppingCart service interface */ @Remotable @Conversational public interface ShoppingCart{ - void addItem(String itemId); - void removeItem(String itemId); - String[] getItems(); + void addTrip(TripItem trip); + void removeTrip(TripItem trip); + TripItem[] getTrips(); + + @EndsConversation + void checkout(String name); } diff --git a/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCartImpl.java b/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCartImpl.java index 2278a85b0d..4fc9306785 100644 --- a/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCartImpl.java +++ b/sandbox/travelsample/shoppingcart-contribution/src/scatours/shoppingcart/ShoppingCartImpl.java @@ -27,12 +27,14 @@ import java.util.Map; 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.TripItem; +import scatours.paymentprocess.PaymentProcess; /** * An implementation of the Trip service @@ -40,34 +42,48 @@ import scatours.common.TripItem; @Scope("CONVERSATION") @Service(interfaces={ShoppingCart.class}) public class ShoppingCartImpl implements ShoppingCart{ + + @Reference + protected PaymentProcess paymentProcess; @ConversationID - protected String conversationId; + protected String cartId; - private List itemIds = new ArrayList(); + private List trips = new ArrayList(); // Trip methods @Init - public void initTrip() { - System.out.println("Cart init for id: " + conversationId); + public void initCart() { + System.out.println("Cart init for id: " + cartId); } @Destroy - public void destroyTrip() { - System.out.println("Cart destroy for id: " + conversationId); + public void destroyCart() { + System.out.println("Cart destroy for id: " + cartId); } + public void addTrip(TripItem trip) { + trips.add(trip); + } - public void addItem(String itemId){ - itemIds.add(itemId); + public void removeTrip(TripItem trip) { + trips.remove(trip); } - public void removeItem(String itemId){ - itemIds.remove(itemId); + public TripItem[] getTrips(){ + return trips.toArray(new TripItem[trips.size()]); + } + + public void checkout(String customerName){ + // get users credentials. Hard coded for now but should + // come from the security context + String customerId = customerName; + + // get the total for all the trips + float amount = (float)0.0; + + paymentProcess.makePayment(customerId, amount); } - public String[] getItems() { - return itemIds.toArray(new String[itemIds.size()]); - } } diff --git a/sandbox/travelsample/travelcatalog-contribution/src/scatours/travelcatalog/TravelCatalogImpl.java b/sandbox/travelsample/travelcatalog-contribution/src/scatours/travelcatalog/TravelCatalogImpl.java index 524507589d..2369baaff1 100644 --- a/sandbox/travelsample/travelcatalog-contribution/src/scatours/travelcatalog/TravelCatalogImpl.java +++ b/sandbox/travelsample/travelcatalog-contribution/src/scatours/travelcatalog/TravelCatalogImpl.java @@ -57,6 +57,9 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ @Reference protected Search carSearch; + + @Reference + protected Search tripSearch; @Property public String quoteCurrencyCode = "USD"; @@ -86,8 +89,9 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ flightSearch.searchAsynch(tripLeg); carSearch.searchAsynch(tripLeg); + tripSearch.searchAsynch(tripLeg); - while (responsesReceived < 3){ + while (responsesReceived < 4){ try { synchronized (this) { this.wait(); @@ -116,8 +120,10 @@ public class TravelCatalogImpl implements TravelCatalogSearch, SearchCallback{ Object callbackID = requestContext.getServiceReference().getCallbackID(); System.out.println(callbackID); - for(int i = 0; i < items.length; i++ ){ - searchResults.add(items[i]); + if (items != null) { + for(int i = 0; i < items.length; i++ ){ + searchResults.add(items[i]); + } } responsesReceived++; diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java index 5aa0cb4438..9d51c8078b 100644 --- a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java +++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java @@ -26,6 +26,7 @@ import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; +import scatours.common.Book; import scatours.common.Search; import scatours.common.SearchCallback; import scatours.common.TripItem; @@ -35,8 +36,8 @@ import scatours.common.TripLeg; * An implementation of the Hotel service */ @Scope("STATELESS") -@Service(interfaces={Search.class}) -public class TripImpl implements Search { +@Service(interfaces={Search.class, Book.class}) +public class TripImpl implements Search, Book { private List trips = new ArrayList(); @@ -45,16 +46,26 @@ public class TripImpl implements Search { @Init public void init() { - trips.add(new TripInfo("FS1APR4", + trips.add(new TripInfo("FS1DEC06", "Florence and Siena pre-packaged tour", "LGW", "FLR", - "04/04/09", - "11/04/09", + "06/12/09", + "13/12/09", "27", 450, "EUR", "http://localhost:8085/tbd" )); + trips.add(new TripInfo("FS1DEC13", + "Florence and Siena pre-packaged tour 2", + "LGW", + "FLR", + "13/12/09", + "20/12/09", + "27", + 550, + "EUR", + "http://localhost:8085/tbd" )); } public TripItem[] searchSynch(TripLeg tripLeg) { @@ -67,7 +78,7 @@ public class TripImpl implements Search { (trip.getFromDate().equals(tripLeg.getFromDate()))){ TripItem item = new TripItem("", "", - "Trip", + TripItem.TRIP, trip.getName(), trip.getDescription(), trip.getFromLocation() + " - " + trip.getToLocation(), @@ -88,4 +99,8 @@ public class TripImpl implements Search { // return available hotels searchCallback.searchResults(searchSynch(tripLeg)); } + + public String book(TripItem tripItem) { + return "trip1"; + } } 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 @@ + \ 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 @@ scatours-currency-contribution 1.5-SNAPSHOT + + + org.apache.tuscany.sca + scatours-shoppingcart-contribution + 1.5-SNAPSHOT + junit 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 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 } + */ } diff --git a/sandbox/travelsample/ui-contribution/META-INF/sca-contribution.xml b/sandbox/travelsample/ui-contribution/META-INF/sca-contribution.xml index c244245722..764030c28e 100644 --- a/sandbox/travelsample/ui-contribution/META-INF/sca-contribution.xml +++ b/sandbox/travelsample/ui-contribution/META-INF/sca-contribution.xml @@ -25,6 +25,7 @@ + diff --git a/sandbox/travelsample/ui-contribution/build.xml b/sandbox/travelsample/ui-contribution/build.xml index 53e3cc78e9..981e37ca97 100644 --- a/sandbox/travelsample/ui-contribution/build.xml +++ b/sandbox/travelsample/ui-contribution/build.xml @@ -95,8 +95,7 @@ - - + diff --git a/sandbox/travelsample/ui-contribution/scatours.composite b/sandbox/travelsample/ui-contribution/scatours.composite index 5dc1cb8453..1bd437a92e 100644 --- a/sandbox/travelsample/ui-contribution/scatours.composite +++ b/sandbox/travelsample/ui-contribution/scatours.composite @@ -29,34 +29,37 @@ - + + + + - + + + + - - - - + - + @@ -67,9 +70,12 @@ - + - + + + + GBP @@ -78,6 +84,11 @@ + + + + + @@ -86,6 +97,7 @@ + @@ -99,6 +111,7 @@ + @@ -107,7 +120,17 @@ - + + + + + + + + + + + @@ -119,6 +142,9 @@ + + +