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
This commit is contained in:
slaws 2008-08-10 16:14:48 +00:00
parent 569c99b45b
commit 2a25d97953
9 changed files with 110 additions and 41 deletions

View file

@ -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(),

View file

@ -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;
}

View file

@ -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(),

View file

@ -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(),

View file

@ -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);
}

View file

@ -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();
}
}

View file

@ -39,6 +39,8 @@ public interface Trip {
void removeTripItem(String id);
TripItem[] getTripItems();
double getTripPrice();
@EndsConversation

View file

@ -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;

View file

@ -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>
<h3>You Trip</h3>
<div id="tripItems"></div>
<br>
<div id="totalPrice"></div>
<br>
<div id="tripItems"></div>
<br>
<input type="button" onClick="newTrip()" value="Create New Trip">
<input type="button" onClick="purchaseTrip()" value="Purchase Trip">
</form>
</div>
</body>