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 | |
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')
26 files changed, 654 insertions, 240 deletions
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<CarInfo> cars = new ArrayList<CarInfo>(); @@ -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<FlightInfo> flights = new ArrayList<FlightInfo>(); @@ -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<HotelInfo> hotels = new ArrayList<HotelInfo>(); @@ -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 @@ <include name="axis2-mtompolicy-1.4.1.jar"/> <include name="backport-util-concurrent-3.1.jar"/> <include name="bcprov-jdk13-132.jar"/> - <include name="cglib-nodep-2.1_3.jar"/> + <include name="cglib-nodep-2.2.jar"/> <include name="common-2.2.3.jar"/> <include name="commons-codec-1.3.jar"/> <include name="commons-collections-3.1.jar"/> @@ -180,7 +180,6 @@ <include name="ecore-xmi-2.2.3.jar"/> <include name="geronimo-activation_1.1_spec-1.0.1.jar"/> <include name="geronimo-common-1.2-beta.jar"/> - <include name="geronimo-commonj_1.1_spec-1.0.jar"/> <include name="geronimo-connector-1.2-beta.jar"/> <include name="geronimo-core-1.2-beta.jar"/> <include name="geronimo-deployment-1.2-beta.jar"/> 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 @@ <module>hotel-contribution</module> <module>flight-contribution</module> <module>car-contribution</module> + <module>trip-contribution</module> <module>payment-contribution</module> <module>paymentprocess-contribution</module> <module>emailgateway-contribution</module> 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 @@ --> <contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"> <import.java package="scatours.common"/> - <import.java package="scatours.currencyconverter"/> <import.java package="scatours.travelcatalog"/> <import.java package="scatours.tripbooking"/> - <import.java package="scatours.paymentprocess"/> <import.java package="scatours.shoppingcart"/> <export.java package="scatours"/> </contribution>
\ 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<String,ShoppingCart> carts = new HashMap<String,ShoppingCart>(); private Map<String,TripBooking> trips = new HashMap<String,TripBooking>(); - private Map<String, TripItem> searchItemsCache = new HashMap<String, TripItem>(); + //private Map<String, TripItem> searchItemsCache = new HashMap<String, TripItem>(); - // 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> 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<TripBooking> 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. --> <contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"> + <import.java package="scatours.common"/> + <import.java package="scatours.paymentprocess"/> <export.java package="scatours.shoppingcart"/> </contribution>
\ 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<String> itemIds = new ArrayList<String>(); + private List<TripItem> trips = new ArrayList<TripItem>(); // 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<TripInfo> trips = new ArrayList<TripInfo>(); @@ -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 @@ <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 } + */ } 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 @@ <import.java package="scatours.hotel"/> <import.java package="scatours.flight"/> <import.java package="scatours.car"/> + <import.java package="scatours.trip"/> <import.java package="scatours.tripbooking"/> <import.java package="scatours.travelcatalog"/> <import.java package="payment.creditcard.ws.impl"/> 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 @@ <include name="XmlSchema-1.4.2.jar"/> <include name="activation-1.1.jar"/> <include name="asm-all-3.1.jar"/> - <include name="cglib-nodep-2.1_3.jar"/> - <include name="geronimo-commonj_1.1_spec-1.0.jar"/> + <include name="cglib-nodep-2.2.jar"/> <include name="jaxb-api-2.1.jar"/> <include name="jaxb-impl-2.1.7.jar"/> <include name="jaxws-api-2.1.jar"/> 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 @@ <service name="Widget"> <tuscany:binding.http uri="/scatours"/> </service> - <reference name="scaToursSearch" target="SCAToursComponent/TravelCatalogSearch"> + <reference name="scaToursCatalog" target="SCAToursComponent/SCAToursSearch"> <tuscany:binding.jsonrpc/> </reference> <reference name="scaToursBooking" target="SCAToursComponent/SCAToursBooking"> <tuscany:binding.jsonrpc/> </reference> + <reference name="scaToursCart" target="SCAToursComponent/SCAToursCart"> + <tuscany:binding.jsonrpc/> + </reference> </component> <component name="SCAToursComponent"> <implementation.java class="scatours.SCAToursImpl"/> - <service name="TravelCatalogSearch"> + <service name="SCAToursSearch"> <tuscany:binding.jsonrpc/> </service> <service name="SCAToursBooking"> <tuscany:binding.jsonrpc/> </service> + <service name="SCAToursCart"> + <tuscany:binding.jsonrpc/> + </service> <reference name="travelCatalogSearch" target="TravelCatalogComponent/TravelCatalogSearch"/> <reference name="tripBooking" target="TripBookingComponent/TripBooking"/> - <reference name="shoppingCart" target="ShoppingCartComponent/ShoppingCart"/> - <reference name="paymentProcess"> - <binding.ws uri="http://localhost:8083/PaymentProcess" /> - </reference> + <reference name="shoppingCart" target="ShoppingCartComponent/ShoppingCart"/> </component> <component name="TravelCatalogComponent"> <implementation.java class="scatours.travelcatalog.TravelCatalogImpl"/> <service name="TravelCatalogSearch"/> - <reference name="hotelSearch" target="HotelComponent"> + <reference name="hotelSearch" target="HotelComponent/Search"> <binding.sca/> </reference> <reference name="flightSearch"> @@ -67,9 +70,12 @@ <binding.ws uri="http://localhost:8080/Flight/SearchCallback"/> </callback> </reference> - <reference name="carSearch" target="CarComponent"> + <reference name="carSearch" target="CarComponent/Search"> <binding.sca/> - </reference> + </reference> + <reference name="tripSearch" target="TripComponent/Search"> + <binding.sca/> + </reference> <reference name="currencyConverter" target="CurrencyConverterComponent"> </reference> <property name="quoteCurrencyCode">GBP</property> @@ -78,6 +84,11 @@ <component name="TripBookingComponent"> <implementation.java class="scatours.tripbooking.TripBookingImpl"/> <service name="TripBooking"/> + <reference name="hotelBook" target="HotelComponent/Book"/> + <reference name="flightBook" target="TripComponent/Book"/> + <reference name="carBook" target="CarComponent/Book"/> + <reference name="tripBook" target="TripComponent/Book"/> + <reference name="shoppingCart" target="ShoppingCartComponent/ShoppingCart"/> </component> <component name="HotelComponent"> @@ -86,6 +97,7 @@ <binding.sca/> <tuscany:binding.jsonrpc/> </service> + <service name="Book"/> </component> <component name="FlightComponent"> @@ -99,6 +111,7 @@ <binding.ws uri="http://localhost:8080/Flight/SearchCallback"/> </callback> </service> + <service name="Book"/> </component> <component name="CarComponent"> @@ -107,7 +120,17 @@ <binding.sca/> <tuscany:binding.jsonrpc/> </service> - </component> + <service name="Book"/> + </component> + + <component name="TripComponent"> + <implementation.java class="scatours.trip.TripImpl"/> + <service name="Search"> + <binding.sca/> + <tuscany:binding.jsonrpc/> + </service> + <service name="Book"/> + </component> <component name="CurrencyConverterComponent"> <implementation.java class="scatours.currencyconverter.CurrencyConverterImpl"/> @@ -119,6 +142,9 @@ <implementation.java class="scatours.shoppingcart.ShoppingCartImpl"/> <service name="ShoppingCart"> </service> + <reference name="paymentProcess"> + <binding.ws uri="http://localhost:8083/PaymentProcess" /> + </reference> </component> <!--component name="PaymentProcessComponent"> diff --git a/sandbox/travelsample/ui-contribution/scatours.html b/sandbox/travelsample/ui-contribution/scatours.html index 294c350ae1..f4206548c0 100644 --- a/sandbox/travelsample/ui-contribution/scatours.html +++ b/sandbox/travelsample/ui-contribution/scatours.html @@ -27,17 +27,18 @@ <script language="JavaScript"> //@Reference - var scaToursSearch = new Reference("scaToursSearch"); + var scaToursCatalog = new Reference("scaToursCatalog"); //@Reference var scaToursBooking = new Reference("scaToursBooking"); + + //@Reference + var scaToursCart = new Reference("scaToursCart"); //local state - var currentCartId; - var tripIds = []; - var currentTripIdIndex = -1; - var searchItems; - var cartItems; + var packagedItems; + var bespokeItems; + var cartId; //the constructor for trip leg beans function TripLegType(id, @@ -55,25 +56,83 @@ } function getTripLeg(){ - return new TripLegType(tripIds[currentTripIdIndex], - document.travelForm.fromLocation.value, - document.travelForm.toLocation.value, - document.travelForm.fromDate.value, - document.travelForm.toDate.value, - document.travelForm.noOfPeople.value); + return new TripLegType(cartId, + document.searchForm.fromLocation.value, + document.searchForm.toLocation.value, + document.searchForm.fromDate.value, + document.searchForm.toDate.value, + document.searchForm.noOfPeople.value); + } + + //the constructor for bespoke trip beans + function TripType() { + this.id = cartId; + this.type = "Bespoke"; + this.tripItems = new Array(); + // json databinding can't tolerate having a class hint set as the + // databinding transformer is not in the right classloader to load + // the class pointed to by the hint + //this.javaClass = "scatours.common.TripItem"; } + + function getTrip(){ + return new TripType(); + } + + // remove class hint from the trip object + // can also be used to limit the amount of + // data returned to the server + function copyTrip(trip){ + var tripCopy = new TripType(); + + tripCopy.id = trip.id; + tripCopy.tripId = trip.tripId; + tripCopy.type = trip.type; + tripCopy.name = trip.name; + tripCopy.description = trip.description; + tripCopy.location = trip.location; + tripCopy.fromDate = trip.fromDate; + tripCopy.toDate = trip.toDate; + tripCopy.price = trip.price; + tripCopy.currency = trip.currency; + tripCopy.link = trip.link; + + return tripCopy; + } function init() { try { - addCart(); + newCart(); } catch(e) { alert(e); } } + + function reset() { + document.getElementById('packagedTripItems').innerHTML = ""; + document.getElementById('bespokeTripItems').innerHTML = ""; + document.getElementById('cartItems').innerHTML = ""; + document.getElementById('cartPrice').innerHTML = ""; + packagedItems = new Array(); + bespokeItems = new Array(); + } + + function newCart() { + scaToursCart.newCart(newCart_response); + reset(); + } + + function newCart_response(newCartId, exception) { + if(exception){ + alert(exception.javaStack); + return; + } + cartId = newCartId + } function searchTravelCatalog() { - scaToursSearch.search(getTripLeg(), search_response); + scaToursCatalog.search(getTripLeg(), search_response); } function search_response(items, exception) { @@ -81,138 +140,191 @@ alert(exception.javaStack); return; } - var responseHTML = '<table border="0">'; - responseHTML += '<tr>'; - responseHTML += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>'; - responseHTML += '</tr>'; + + var packagedHTML = '<h3>Packaged Trip Items</h3>'; + packagedHTML += '<table border="0">'; + packagedHTML += '<tr>'; + packagedHTML += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>'; + packagedHTML += '</tr>'; + + var bespokeHTML = '<h3>Bespoke Trip Items</h3>'; + bespokeHTML += '<table border="0">'; + bespokeHTML += '<tr>'; + bespokeHTML += '<td>Select</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>'; + bespokeHTML += '</tr>'; for (var i=0; i<items.length; i++) { - responseHTML += '<tr>'; - responseHTML += '<td><input onClick="processSelection()" name="items" type="checkbox" value="' + items[i].id + '"></td>' - responseHTML += '<td>' + items[i].name + '</td>'; - responseHTML += '<td>' + items[i].description + '</td>'; - responseHTML += '<td>' + items[i].location + '</td>'; - responseHTML += '<td>' + items[i].fromDate + ' - ' + items[i].toDate +'</td>'; - responseHTML += '<td>' + items[i].price + ' ' + items[i].currency + '</td>'; - responseHTML += '</tr>'; + if (items[i].type == "Trip") { + packagedHTML += '<tr>'; + packagedHTML += '<td><input onClick="processPackagedSelection()" name="packagedTripItemSelection" type="checkbox" value="' + items[i].id + '"></td>' + packagedHTML += '<td>' + items[i].name + '</td>'; + packagedHTML += '<td>' + items[i].description + '</td>'; + packagedHTML += '<td>' + items[i].location + '</td>'; + packagedHTML += '<td>' + items[i].fromDate + ' - ' + items[i].toDate +'</td>'; + packagedHTML += '<td>' + items[i].price + ' ' + items[i].currency + '</td>'; + packagedHTML += '</tr>'; + packagedItems.push(items[i]); + } else { + bespokeHTML += '<tr>'; + bespokeHTML += '<td><input onClick="processBespokeSelection()" name="bespokeTripItemSelection" type="checkbox" value="' + items[i].id + '"></td>' + bespokeHTML += '<td>' + items[i].name + '</td>'; + bespokeHTML += '<td>' + items[i].description + '</td>'; + bespokeHTML += '<td>' + items[i].location + '</td>'; + bespokeHTML += '<td>' + items[i].fromDate + ' - ' + items[i].toDate +'</td>'; + bespokeHTML += '<td>' + items[i].price + ' ' + items[i].currency + '</td>'; + bespokeHTML += '</tr>'; + bespokeItems.push(items[i]); + } } - responseHTML += '</table>'; + packagedHTML += '</table>'; + packagedHTML += '<input type="button" onClick="bookPackagedTrip()" value="Book Packaged Trip">'; - document.getElementById('searchResponse').innerHTML = responseHTML; + bespokeHTML += '<tr><td/><td/><td>Total Price</td><td/><td/><td><div id="bespokeTripPrice"></div> </td></tr>'; + bespokeHTML += '</table>'; + bespokeHTML += '<input type="button" onClick="bookBespokeTrip()" value="Book Bespoke Trip">'; - searchItems = items; + if (packagedItems.length > 0){ + document.getElementById('packagedTripItems').innerHTML = packagedHTML; + } + + if (bespokeItems.length > 0){ + document.getElementById('bespokeTripItems').innerHTML = bespokeHTML; + } } - function processSelection() { + function processPackagedSelection() { // do nothing at the moment } - - function addItemsToCart() { - var items = document.tripForm.items; - + + function processBespokeSelection() { + // calculate total price + var items = document.getElementsByName("bespokeTripItemSelection"); + var totalPrice = 0.0; for (var i=0; i<items.length; i++) { - // notify the server of the change + // find the items that are checked if (items[i].checked == true) { - scaToursBooking.addTripItem(currentCartId, tripIds[currentTripIdIndex], items[i].value); - } else { - scaToursBooking.removeTripItem(currentCartId, tripIds[currentTripIdIndex], items[i].value); - } + totalPrice = totalPrice + bespokeItems[i].price; + } } + document.getElementById('bespokeTripPrice').innerHTML = totalPrice + ' ' + bespokeItems[0]. currency; + } + + function bookPackagedTrip() { + // find first selected trip item + var trip = null; + var items = document.getElementsByName("packagedTripItemSelection"); + for (var i=0; i<items.length; i++) { + + // find the items that are checked + if (items[i].checked == true) { + trip = copyTrip(packagedItems[i]); + break; + } + } + + if (trip != null) { + // book trip + scaToursBooking.bookTrip(cartId, trip); + + // reset the display + reset(); + + // re-populate the cart with all entries + getCartTrips(); + } else { + alert ("Please select a trip") + } + } + + function bookBespokeTrip() { + // create a trip object + var trip = getTrip(); - scaToursBooking.getTripItems(currentCartId, getTripItems_response); - } + // add selected trip items to trip + var items = document.getElementsByName("bespokeTripItemSelection"); + for (var i=0; i<items.length; i++) { + + // find the items that are checked + if (items[i].checked == true) { + trip.tripItems.push(copyTrip(bespokeItems[i])); + } + } + + if (trip.tripItems.length > 0) { + // book trip + scaToursBooking.bookTrip(cartId, trip); + + // reset the display + reset(); + + // re-populate the cart with all entries + getCartTrips(); + } else { + alert ("Please select some trip items!") + } + } - function getTripItems() { - scaToursBooking.getTripItems(currentCartId, getTripItems_response); + function getCartTrips() { + scaToursCart.getTrips(cartId, getCartTrips_response); } - function getTripItems_response(items, exception) { + function getCartTrips_response(trips, exception) { if(exception){ alert(exception.javaStack); return; } var itemsHTML = ''; + var totalPrice = 0.0; - for (var x=0; x<=currentTripIdIndex; x++){ - var tripId = tripIds[x] - itemsHTML += '<h3>Trip - ' + tripId + '</h3>'; + for (var x=0; x<trips.length; x++){ + itemsHTML += '<h3>Trip - ' + trips[x].id + '</h3>'; itemsHTML += '<table border="0">'; itemsHTML += '<tr>'; - itemsHTML += '<td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>'; + itemsHTML += '<td>Booking Ref</td><td>Name</td><td>Description</td><td>Location</td><td>From - To</td><td>Price</td>'; itemsHTML += '</tr>'; - for (var i=0; i<items.length; i++) { - if (items[i].tripId == tripId) { + if (trips[x].type == "Trip") { + itemsHTML += '<tr>'; + itemsHTML += '<td>' + trips[x].bookingCode + '</td>'; + itemsHTML += '<td>' + trips[x].name + '</td>'; + itemsHTML += '<td>' + trips[x].description + '</td>'; + itemsHTML += '<td>' + trips[x].location + '</td>'; + itemsHTML += '<td>' + trips[x].fromDate + ' - ' + trips[x].toDate +'</td>'; + itemsHTML += '<td>' + trips[x].price + ' ' + trips[x].currency + '</td>'; + itemsHTML += '</tr>'; + totalPrice = totalPrice + trips[x].price; + + } else { + var tripItems = trips[x].tripItems; + + for (var i=0; i<tripItems.length; i++) { itemsHTML += '<tr>'; - itemsHTML += '<td>' + items[i].name + '</td>'; - itemsHTML += '<td>' + items[i].description + '</td>'; - itemsHTML += '<td>' + items[i].location + '</td>'; - itemsHTML += '<td>' + items[i].fromDate + ' - ' + items[i].toDate +'</td>'; - itemsHTML += '<td>' + items[i].price + ' ' + items[i].currency + '</td>'; + itemsHTML += '<td>' + tripItems[i].bookingCode + '</td>'; + itemsHTML += '<td>' + tripItems[i].name + '</td>'; + itemsHTML += '<td>' + tripItems[i].description + '</td>'; + itemsHTML += '<td>' + tripItems[i].location + '</td>'; + itemsHTML += '<td>' + tripItems[i].fromDate + ' - ' + tripItems[i].toDate +'</td>'; + itemsHTML += '<td>' + tripItems[i].price + ' ' + tripItems[i].currency + '</td>'; itemsHTML += '</tr>'; + totalPrice = totalPrice + tripItems[i].price; } } itemsHTML += '</table>'; } - document.getElementById('tripItems').innerHTML = itemsHTML; - - scaToursBooking.getTotalPrice(currentCartId, getTotalPrice_response); - } - - function getTotalPrice_response(totalPrice, exception) { - if(exception){ - alert(exception.javaStack); - return; - } - document.getElementById('totalPrice').innerHTML = totalPrice; - } - - function addCart() { - scaToursBooking.addCart(addCart_response); - - document.getElementById('searchResponse').innerHTML = ""; - document.getElementById('tripItems').innerHTML = ""; - document.getElementById('totalPrice').innerHTML = ""; - currentTripIdIndex = -1; - tripIds = []; - } - - function addCart_response(cartId, exception) { - if(exception){ - alert(exception.javaStack); - return; - } - currentCartId = cartId - - if (currentTripIdIndex == -1){ - addTrip(); - } - } - - function addTrip() { - scaToursBooking.addTrip(currentCartId, addTrip_response); - } - - function addTrip_response(tripId, exception) { - if(exception){ - alert(exception.javaStack); - return; - } - currentTripIdIndex++; - tripIds[currentTripIdIndex] = tripId; - getTripItems(); - } + document.getElementById('cartItems').innerHTML = itemsHTML; + document.getElementById('cartPrice').innerHTML = totalPrice + ' ' + trips[0].currency; + } function checkout() { - scaToursBooking.checkout(currentCartId); + scaToursCart.checkout(cartId); document.getElementById('searchResponse').innerHTML = ""; - document.getElementById('tripItems').innerHTML = "Thank you for shopping with SCA Tours"; - document.getElementById('totalPrice').innerHTML = ""; + document.getElementById('cartItems').innerHTML = "Thank you for shopping with SCA Tours"; + document.getElementById('cartPrice').innerHTML = ""; searchResponseItems = null; tripItems = null; } @@ -227,21 +339,21 @@ <body onload="init()" background=""> <img src="scatours.png" border="0" /> <div id="scatours"> - <form name="travelForm"> - <h3>Search for hotels, flights and cars</h3> + <form name="searchForm"> + <h3>Search for trips, hotels, flights and cars</h3> <br/> <table border="0"> <tr> <td>From Location:</td> <td><input type="text" name="fromLocation" value="LGW"></td> <td>To Location:</td> - <td><input type="text" name="toLocation" value="ANU"></td> + <td><input type="text" name="toLocation" value="FLR"></td> </tr> <tr> <td>Start Date:</td> - <td><input type="text" name="fromDate" value="06/12/08"></td> + <td><input type="text" name="fromDate" value="06/12/09"></td> <td>End Date:</td> - <td><input type="text" name="toDate" value="13/12/08"></td> + <td><input type="text" name="toDate" value="13/12/09"></td> </tr> <tr> <td>Number of people:</td> @@ -258,23 +370,20 @@ <br/> <input type="button" onClick="searchTravelCatalog()" value="Search"> </form> - <form name="tripForm"> - <h3>Search Results</h3> - <div id="searchResponse"></div> - <br/> - <input type="button" onClick="addItemsToCart()" value="Add Items"> - <br/> + <form name="packagedTripForm"> + <div id="packagedTripItems"></div> + </form> + <form name="bespokeTripForm"> + <div id="bespokeTripItems"></div> + </form> + <form name="cartForm"> <h3>Shopping Cart</h3> - <h3><div id="cartId"></h3> - <div id="tripItems"></div> - <br/> - <h3>Cart Totals</h3> - Total Price: <div id="totalPrice"></div> - <br/> - <input type="button" onClick="addCart()" value="Reset Cart"> - <input type="button" onClick="addTrip()" value="Create New Trip"> + <div id="cartItems"></div> + <br/> + Total Price: <div id="cartPrice"></div> + <br/> <input type="button" onClick="checkout()" value="Checkout"> - </form> + </form> </div> </body> |