summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/trip-contribution
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-08-03 13:36:24 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-08-03 13:36:24 +0000
commitdecdb7869ac71c291b835db1b291172b73e3c280 (patch)
tree0eca72e470f26cb889fddf122a5bd9cdb7ea8352 /sandbox/travelsample/trip-contribution
parent2039d195339d7790cb584e19058deeaf7db95829 (diff)
Updates to add in cars and flights
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@682170 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/trip-contribution')
-rw-r--r--sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java34
-rw-r--r--sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java129
-rw-r--r--sandbox/travelsample/trip-contribution/src/scatours/trip/TripSearch.java (renamed from sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java)4
3 files changed, 147 insertions, 20 deletions
diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.java
new file mode 100644
index 0000000000..78eb8fdab4
--- /dev/null
+++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripContents.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.trip;
+
+import org.apache.tuscany.sca.data.collection.Collection;
+import org.osoa.sca.annotations.Remotable;
+
+import scatours.common.TripItem;
+
+/**
+ * The Trip service interface
+ */
+@Remotable
+public interface TripContents extends Collection<String, TripItem> {
+
+ void addTripItem(String id);
+ double getTotalPrice();
+}
diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
index 568b88c102..53e368f8e6 100644
--- a/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
+++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripImpl.java
@@ -19,8 +19,13 @@
package scatours.trip;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
@@ -36,46 +41,136 @@ import scatours.currencyconverter.CurrencyConverter;
* An implementation of the Trip service
*/
@Scope("COMPOSITE")
-@Service(interfaces={Trip.class})
-public class TripImpl implements Trip, SearchCallback {
+@Service(interfaces={TripSearch.class, TripContents.class})
+public class TripImpl implements TripSearch, SearchCallback, TripContents{
@Reference
protected CurrencyConverter currencyConverter;
@Reference
protected Search hotelSearch;
+
+ @Reference
+ protected Search flightSearch;
+
+ @Reference
+ protected Search carSearch;
@Property
public String quoteCurrencyCode = "USD";
private List<TripItem> searchResults = new ArrayList<TripItem>();
+ private Map<String, TripItem> tripItems = new HashMap<String, TripItem>();
+
+ // TripSearch methods
public TripItem[] search(TripLeg tripLeg) {
+ searchResults.clear();
+
hotelSearch.searchAsynch(tripLeg);
- //flightSearch.searchAsynch(tripLeg);
- //carSearch.searchAsynch(tripLeg);
+ flightSearch.searchAsynch(tripLeg);
+ carSearch.searchAsynch(tripLeg);
- // TODO - extend this to have the three searches run in parallel
+ // TODO - wait for searches to complete
- TripItem[] tripItemArray = searchResults.toArray(new TripItem[searchResults.size()]);
- searchResults.clear();
+ for (TripItem tripItem : searchResults){
+ tripItem.setId(String.valueOf(searchResults.indexOf(tripItem)));
+ tripItem.setPrice(currencyConverter.convert(tripItem.getCurrency(),
+ quoteCurrencyCode,
+ tripItem.getPrice()));
+ tripItem.setCurrency(quoteCurrencyCode);
+ }
- return tripItemArray;
- }
-
- public double getTotalPrice(){
- String supplierCurrencyCode = "USD";
- double price = 100.00;
-
- return currencyConverter.convert(supplierCurrencyCode,
- quoteCurrencyCode,
- price);
+ return searchResults.toArray(new TripItem[searchResults.size()]);
}
+ // SearchCallback methods
+
public void searchResults(TripItem[] items){
for(int i = 0; i < items.length; i++ ){
searchResults.add(items[i]);
}
+ }
+
+ // TripContents methods
+ public void addTripItem(String id){
+ for (TripItem tripItem : searchResults) {
+ if (tripItem.getId().equals(id)){
+ tripItems.put(id, tripItem);
+ }
+ }
+ }
+
+
+ // Not using the DataCollection iface yet as it seems like a
+ // likely attach vector to be passing complete tripItem records in
+ // really need to look up the cached item based on id
+ public Entry<String, TripItem>[] getAll() {
+ Entry<String, TripItem>[] entries = new Entry[tripItems.size()];
+ int i = 0;
+ for (Map.Entry<String, TripItem> e: tripItems.entrySet()) {
+ entries[i++] = new Entry<String, TripItem>(e.getKey(), e.getValue());
+ }
+ return entries;
+ }
+
+ public TripItem get(String key) throws NotFoundException {
+ TripItem item = tripItems.get(key);
+ if (item == null) {
+ throw new NotFoundException(key);
+ } else {
+ return item;
+ }
+ }
+
+ public String post(String key, TripItem item) {
+ tripItems.put(key, item);
+ return key;
+ }
+
+ public void put(String key, TripItem item) throws NotFoundException {
+ if (!tripItems.containsKey(key)) {
+ throw new NotFoundException(key);
+ }
+ tripItems.put(key, item);
}
+
+ public void delete(String key) throws NotFoundException {
+ if (key == null || key.equals("")) {
+ tripItems.clear();
+ } else {
+ TripItem item = tripItems.remove(key);
+ if (item == null)
+ throw new NotFoundException(key);
+ }
+ }
+
+ public Entry<String, TripItem>[] query(String queryString) {
+ List<Entry<String, TripItem>> entries = new ArrayList<Entry<String,TripItem>>();
+ if (queryString.startsWith("name=")) {
+ String name = queryString.substring(5);
+ for (Map.Entry<String, TripItem> e: tripItems.entrySet()) {
+ TripItem item = e.getValue();
+ if (item.getName().equals(name)) {
+ entries.add(new Entry<String, TripItem>(e.getKey(), e.getValue()));
+ }
+ }
+ }
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ // TripTotal methods
+
+ public double getTotalPrice(){
+ double totalPrice = 0.0;
+
+ for (TripItem tripItem : tripItems.values()){
+ totalPrice += tripItem.getPrice();
+ }
+
+ return totalPrice;
+ }
+
+
}
diff --git a/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripSearch.java
index 8ec0dbad67..2bdeb0ccb4 100644
--- a/sandbox/travelsample/trip-contribution/src/scatours/trip/Trip.java
+++ b/sandbox/travelsample/trip-contribution/src/scatours/trip/TripSearch.java
@@ -18,7 +18,6 @@
*/
package scatours.trip;
-import org.apache.tuscany.sca.data.collection.Item;
import org.osoa.sca.annotations.Remotable;
import scatours.common.TripItem;
@@ -28,7 +27,6 @@ import scatours.common.TripLeg;
* The Trip service interface
*/
@Remotable
-public interface Trip {
+public interface TripSearch {
TripItem[] search(TripLeg tripLeg);
- double getTotalPrice();
}