summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-08-10 16:14:48 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-08-10 16:14:48 +0000
commit2a25d97953be52451c073f8abc22034283c6d8c9 (patch)
tree77132b7af9d104a019f38866a43594ad11a0266a /sandbox/travelsample
parent569c99b45bb0b3e6408c3af066110f4212da0688 (diff)
Start looking at a conversational interface on the Trip component
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@684543 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java3
-rw-r--r--sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java13
-rw-r--r--sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java6
-rw-r--r--sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java3
-rw-r--r--sandbox/travelsample/travel-contribution/src/scatours/travel/TravelBooking.java10
-rw-r--r--sandbox/travelsample/travel-contribution/src/scatours/travel/TravelImpl.java29
-rw-r--r--sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java2
-rw-r--r--sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java6
-rw-r--r--sandbox/travelsample/ui-contribution/scatours.html79
9 files changed, 110 insertions, 41 deletions
diff --git a/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java b/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java
index 120846c0ad..dd28dc7498 100644
--- a/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java
+++ b/sandbox/travelsample/car-contribution/src/scatours/car/CarImpl.java
@@ -69,7 +69,8 @@ public class CarImpl implements Search {
// find available hotels
for(CarInfo car : cars){
if (car.getLocation().equals(tripLeg.getToLocation())){
- TripItem item = new TripItem("1",
+ TripItem item = new TripItem("",
+ "",
"Car",
car.getName(),
car.getDescription(),
diff --git a/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java b/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java
index aac90c7bd5..311bb63b18 100644
--- a/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java
+++ b/sandbox/travelsample/common-contribution/src/scatours/common/TripItem.java
@@ -22,7 +22,8 @@ package scatours.common;
public class TripItem {
- private String id;
+ private String id;
+ private String tripId;
private String type;
private String name;
private String description;
@@ -37,6 +38,7 @@ public class TripItem {
}
public TripItem(String id,
+ String tripId,
String type,
String name,
String description,
@@ -47,6 +49,7 @@ public class TripItem {
String currency,
String link) {
this.id = id;
+ this.tripId = tripId;
this.type = type;
this.name = name;
this.description = description;
@@ -66,6 +69,14 @@ public class TripItem {
this.id = id;
}
+ public String getTripId() {
+ return tripId;
+ }
+
+ public void setTripId(String tripId) {
+ this.tripId = tripId;
+ }
+
public String getType() {
return type;
}
diff --git a/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java b/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java
index ec010342f3..106144aebd 100644
--- a/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java
+++ b/sandbox/travelsample/flight-contribution/src/scatours/flight/FlightImpl.java
@@ -76,7 +76,8 @@ public class FlightImpl implements Search {
if ((flight.getFromLocation().equals(tripLeg.getFromLocation())) &&
(flight.getToLocation().equals(tripLeg.getToLocation())) &&
(flight.getFromDate().equals(tripLeg.getFromDate()))){
- TripItem item = new TripItem("1",
+ TripItem item = new TripItem("",
+ "",
"Flight",
flight.getName(),
flight.getDescription(),
@@ -95,7 +96,8 @@ public class FlightImpl implements Search {
if ((flight.getFromLocation().equals(tripLeg.getToLocation())) &&
(flight.getToLocation().equals(tripLeg.getFromLocation())) &&
(flight.getFromDate().equals(tripLeg.getToDate()))){
- TripItem item = new TripItem("1",
+ TripItem item = new TripItem("",
+ "",
"Flight",
flight.getName(),
flight.getDescription(),
diff --git a/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java b/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java
index ac02c31e59..81012ea08b 100644
--- a/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java
+++ b/sandbox/travelsample/hotel-contribution/src/scatours/hotel/HotelImpl.java
@@ -85,7 +85,8 @@ public class HotelImpl implements Search {
// find available hotels
for(HotelInfo hotel : hotels){
if (hotel.getLocation().equals(tripLeg.getToLocation())){
- TripItem item = new TripItem("1",
+ TripItem item = new TripItem("",
+ "",
"Hotel",
hotel.getName(),
hotel.getDescription(),
diff --git a/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelBooking.java b/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelBooking.java
index 5aa3ef94f5..fec3ceb366 100644
--- a/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelBooking.java
+++ b/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelBooking.java
@@ -29,8 +29,10 @@ import scatours.common.TripItem;
@Remotable
public interface TravelBooking {
- void addTripItem(String id);
- void removeTripItem(String id);
- double getTotalPrice();
- void purchaseTrip();
+ String newTrip();
+ void addTripItem(String tripId, String id);
+ void removeTripItem(String tripId, String id);
+ TripItem[] getTripItems(String tripId);
+ double getTotalPrice(String tripId);
+ void purchaseTrip(String tripId);
}
diff --git a/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelImpl.java b/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelImpl.java
index 9d3b9b94e9..e4a641e1e5 100644
--- a/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelImpl.java
+++ b/sandbox/travelsample/travel-contribution/src/scatours/travel/TravelImpl.java
@@ -72,7 +72,7 @@ public class TravelImpl implements TravelSearch, SearchCallback, TravelBooking{
private int responsesReceived = 0;
private List<TripItem> searchResults = new ArrayList<TripItem>();
- private Map<String,ServiceReference<Trip>> trips = new HashMap<String,ServiceReference<Trip>>();
+ private Map<String,Trip> trips = new HashMap<String,Trip>();
// TravelSearch methods
@@ -95,6 +95,7 @@ public class TravelImpl implements TravelSearch, SearchCallback, TravelBooking{
for (TripItem tripItem : searchResults){
tripItem.setId(UUID.randomUUID().toString());
+ tripItem.setTripId(tripLeg.getId());
tripItem.setPrice(currencyConverter.convert(tripItem.getCurrency(),
quoteCurrencyCode,
tripItem.getPrice()));
@@ -124,28 +125,32 @@ public class TravelImpl implements TravelSearch, SearchCallback, TravelBooking{
String tripId = UUID.randomUUID().toString();
ServiceReference<Trip> tripReference = componentContext.getServiceReference(Trip.class,
"trip");
- //tripReference.setConversationID(tripId);
- trips.put(tripId, tripReference);
+ tripReference.setConversationID(tripId);
+ trips.put(tripId, tripReference.getService());
return tripId;
}
- public void addTripItem(String id){
+ public void addTripItem(String tripId, String id){
for (TripItem tripItem : searchResults) {
if (tripItem.getId().equals(id)){
- trip.addTripItem(tripItem);
+ trips.get(tripId).addTripItem(tripItem);
}
}
}
- public void removeTripItem(String id){
- trip.removeTripItem(id);
- }
+ public void removeTripItem(String tripId, String id){
+ trips.get(tripId).removeTripItem(id);
+ }
- public double getTotalPrice(){
- return trip.getTripPrice();
+ public TripItem[] getTripItems(String tripId) {
+ return trips.get(tripId).getTripItems();
}
- public void purchaseTrip() {
- trip.purchaseTrip();
+ public double getTotalPrice(String tripId){
+ return trips.get(tripId).getTripPrice();
+ }
+
+ public void purchaseTrip(String tripId) {
+ trips.get(tripId).purchaseTrip();
}
}
diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java
index 17f36c33f7..3555def0be 100644
--- a/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java
+++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java
@@ -39,6 +39,8 @@ public interface Trip {
void removeTripItem(String id);
+ TripItem[] getTripItems();
+
double getTripPrice();
@EndsConversation
diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
index 3f42edd587..9e536acbdd 100644
--- a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
+++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
@@ -68,7 +68,11 @@ public class TripImpl implements Trip{
public void removeTripItem(String id){
tripItems.remove(id);
- }
+ }
+
+ public TripItem[] getTripItems() {
+ return tripItems.values().toArray(new TripItem[tripItems.size()]);
+ }
public double getTripPrice(){
double totalPrice = 0.0;
diff --git a/sandbox/travelsample/ui-contribution/scatours.html b/sandbox/travelsample/ui-contribution/scatours.html
index 7b1a0b60d8..3ac053f059 100644
--- a/sandbox/travelsample/ui-contribution/scatours.html
+++ b/sandbox/travelsample/ui-contribution/scatours.html
@@ -42,9 +42,9 @@
var travelBooking = new Reference("travelBooking");
//local state
+ var currentTripId;
var searchResponseItems;
- var tripItems;
-
+
//the constructor for trip leg beans
function TripLegType(id,
fromLocation,
@@ -61,7 +61,7 @@
}
function getTripLeg(){
- return new TripLegType("X",
+ return new TripLegType(currentTripId,
document.travelForm.fromLocation.value,
document.travelForm.toLocation.value,
document.travelForm.fromDate.value,
@@ -71,7 +71,7 @@
function init() {
try {
-
+ newTrip();
}
catch(e) {
alert(e);
@@ -127,16 +127,43 @@
var j = 0;
for (var i=0; i<items.length; i++) {
if (items[i].checked == true) {
- travelBooking.addTripItem(items[i].value);
+ travelBooking.addTripItem(currentTripId, items[i].value);
} else {
- travelBooking.removeTripItem(items[i].value);
+ travelBooking.removeTripItem(currentTripId, items[i].value);
}
}
- travelBooking.getTotalPrice(totalPrice_response);
+ travelBooking.getTripItems(currentTripId,getTripItems_response);
+ }
+
+ function getTripItems_response(items, exception) {
+ if(exception){
+ alert(exception.javaStack);
+ return;
+ }
+ var itemsHTML = '<table border="0">';
+ itemsHTML += '<tr>';
+ itemsHTML += '<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++) {
+ 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 += '</tr>';
+ }
+
+ itemsHTML += '</table>';
+
+ document.getElementById('tripItems').innerHTML = itemsHTML;
+
+ travelBooking.getTotalPrice(currentTripId, getTotalPrice_response);
}
- function totalPrice_response(totalPrice, exception) {
+ function getTotalPrice_response(totalPrice, exception) {
if(exception){
alert(exception.javaStack);
return;
@@ -145,12 +172,26 @@
}
function newTrip() {
-
+ travelBooking.newTrip(newTrip_response);
+
+ document.getElementById('searchResponse').innerHTML = "";
+ document.getElementById('tripItems').innerHTML = "";
+ document.getElementById('totalPrice').innerHTML = "";
}
+ function newTrip_response(tripId, exception) {
+ if(exception){
+ alert(exception.javaStack);
+ return;
+ }
+ currentTripId = tripId
+ document.getElementById('tripId').innerHTML = "Trip: " + tripId;
+ }
+
function purchaseTrip() {
- travelBooking.purchaseTrip();
+ travelBooking.purchaseTrip(currentTripId);
+ document.getElementById('searchResponse').innerHTML = "";
document.getElementById('tripItems').innerHTML = "Thank you for shopping with SCA Tours";
document.getElementById('totalPrice').innerHTML = "";
searchResponseItems = null;
@@ -164,8 +205,9 @@
<body onload="init()" background="">
<img src="scatours.png" border="0" />
<div id="scatours">
- <br>
- <form name="travelForm">
+ <form name="travelForm">
+ <h3><div id="tripId"></h3>
+ <br/>
<table border="0">
<tr>
<td>From Location:</td>
@@ -196,19 +238,18 @@
<input type="button" onClick="searchFlights()" value="Search Flights">
<input type="button" onClick="searchHotels()" value="Search Cars">
</form>
- <form name="tripForm">
+ <form name="tripForm">
+ <h3>Search Results</h3>
<div id="searchResponse"></div>
<br>
- <input type="button" onClick="newTrip()" value="Create New Trip">
- <br>
- <div id="totalPrice"></div>
- <br>
+ <h3>You Trip</h3>
<div id="tripItems"></div>
+ <br>
+ <div id="totalPrice"></div>
<br>
+ <input type="button" onClick="newTrip()" value="Create New Trip">
<input type="button" onClick="purchaseTrip()" value="Purchase Trip">
</form>
-
-
</div>
</body>