diff options
12 files changed, 193 insertions, 119 deletions
diff --git a/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/META-INF/sca-contribution.xml b/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/META-INF/sca-contribution.xml index 6aa3e9183c..c4a03c9f64 100644 --- a/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/META-INF/sca-contribution.xml +++ b/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/META-INF/sca-contribution.xml @@ -17,6 +17,7 @@ * specific language governing permissions and limitations
* under the License.
-->
-<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0">
- <export.java package="scatours.calendar"/>
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:scatours="http://scatours">
+ <export.java package="calendar"/>
</contribution>
\ No newline at end of file diff --git a/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/calendar.composite b/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/calendar.composite index b9736a527d..16d7e58448 100644 --- a/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/calendar.composite +++ b/sandbox/travelsample/contributions/calendar-contribution/src/main/resources/calendar.composite @@ -18,8 +18,8 @@ * under the License.
-->
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
- targetNamespace="http://travel"
- xmlns:sample="http://travel"
+ targetNamespace="http://scatours"
+ xmlns:scatours="http://scatours"
name="calendar">
<component name="CalendarComponent">
diff --git a/sandbox/travelsample/contributions/calendar-contribution/src/test/java/calendar/CalendarTestCase.java b/sandbox/travelsample/contributions/calendar-contribution/src/test/java/calendar/CalendarTestCase.java index 6509b74ffb..6772e7e961 100644 --- a/sandbox/travelsample/contributions/calendar-contribution/src/test/java/calendar/CalendarTestCase.java +++ b/sandbox/travelsample/contributions/calendar-contribution/src/test/java/calendar/CalendarTestCase.java @@ -41,7 +41,7 @@ public class CalendarTestCase extends TestCase { scaDomain.close();
}
- public void testCalculator() throws Exception {
+ public void testCalendar() throws Exception {
System.out.println(calendar.getEndDate("07/10/96 04:05", 3));
}
}
diff --git a/sandbox/travelsample/contributions/creditcard-payment-jaxb-contribution/src/main/resources/creditcard.composite b/sandbox/travelsample/contributions/creditcard-payment-jaxb-contribution/src/main/resources/creditcard.composite index df37a189db..e675da0372 100644 --- a/sandbox/travelsample/contributions/creditcard-payment-jaxb-contribution/src/main/resources/creditcard.composite +++ b/sandbox/travelsample/contributions/creditcard-payment-jaxb-contribution/src/main/resources/creditcard.composite @@ -26,6 +26,7 @@ <component name="CreditCardPaymentComponent"> <implementation.java class="payment.creditcard.CreditCardPaymentImpl" /> <service name="CreditCardPayment"> + <interface.wsdl interface="http://www.tuscanyscatours.com/CreditCardPayment/#wsdl.interface(CreditCardPayment)" /> <binding.ws uri="http://localhost:8082/CreditCardPayment" /> <binding.sca/> </service> diff --git a/sandbox/travelsample/contributions/fullapp-ui-contribution/src/main/resources/scatours.composite b/sandbox/travelsample/contributions/fullapp-ui-contribution/src/main/resources/scatours.composite index 2a877cff01..3e03a2deb4 100644 --- a/sandbox/travelsample/contributions/fullapp-ui-contribution/src/main/resources/scatours.composite +++ b/sandbox/travelsample/contributions/fullapp-ui-contribution/src/main/resources/scatours.composite @@ -37,7 +37,7 @@ </reference> <reference name="scaToursCart" target="SCAToursComponent/SCAToursCart"> <tuscany:binding.jsonrpc/> - </reference> + </reference> </component> <component name="SCAToursComponent"> @@ -81,6 +81,10 @@ <property name="quoteCurrencyCode">GBP</property> </component> + <component name="CurrencyConverterComponent"> + <implementation.java class="scatours.currencyconverter.CurrencyConverterImpl"/> + </component> + <component name="TripBookingComponent"> <implementation.java class="scatours.tripbooking.TripBookingImpl"/> <service name="TripBooking"/> @@ -132,19 +136,18 @@ <service name="Book"/> </component> - <component name="CurrencyConverterComponent"> - <implementation.java class="scatours.currencyconverter.CurrencyConverterImpl"/> - <service name="CurrencyConverter"> - </service> - </component> - <component name="ShoppingCartComponent"> <implementation.java class="scatours.shoppingcart.ShoppingCartImpl"/> - <service name="ShoppingCart"> - </service> + <service name="ShoppingCart"/> + <reference name="cartStore" target="CartStoreComponent/CartStore"/> <reference name="payment"> <binding.ws uri="http://localhost:8081/Payment" /> </reference> - </component> + </component> + + <component name="CartStoreComponent"> + <implementation.java class="scatours.shoppingcart.CartStoreImpl"/> + <service name="CartStore"/> + </component> </composite> diff --git a/sandbox/travelsample/contributions/hotel-contribution/src/main/java/scatours/hotel/HotelImpl.java b/sandbox/travelsample/contributions/hotel-contribution/src/main/java/scatours/hotel/HotelImpl.java index e4dcfbfe0a..85eb4a592b 100644 --- a/sandbox/travelsample/contributions/hotel-contribution/src/main/java/scatours/hotel/HotelImpl.java +++ b/sandbox/travelsample/contributions/hotel-contribution/src/main/java/scatours/hotel/HotelImpl.java @@ -36,8 +36,8 @@ import scatours.common.TripLeg; * An implementation of the Hotel service
*/
@Scope("STATELESS")
-@Service(interfaces={Search.class, Book.class})
-public class HotelImpl implements Search, Book {
+@Service(interfaces={Search.class, Book.class, HotelManagement.class})
+public class HotelImpl implements Search, Book, HotelManagement {
private List<HotelInfo> hotels = new ArrayList<HotelInfo>();
@@ -113,4 +113,9 @@ public class HotelImpl implements Search, Book { public String book(TripItem tripItem) {
return "hotel1";
}
+
+ public void addHotelInfo(HotelInfo hotelInfo){
+ hotels.add(hotelInfo);
+ System.out.println("Added hotel info - " + hotelInfo.getName());
+ }
}
diff --git a/sandbox/travelsample/contributions/scatours-contribution/src/main/java/scatours/SCAToursImpl.java b/sandbox/travelsample/contributions/scatours-contribution/src/main/java/scatours/SCAToursImpl.java index d81b950047..2ac1e00f5f 100644 --- a/sandbox/travelsample/contributions/scatours-contribution/src/main/java/scatours/SCAToursImpl.java +++ b/sandbox/travelsample/contributions/scatours-contribution/src/main/java/scatours/SCAToursImpl.java @@ -36,10 +36,8 @@ import scatours.travelcatalog.TravelCatalogSearch; import scatours.tripbooking.TripBooking;
/**
- * An implementation of the SCA tours component. This component currently provides
- * a front end to the components that the UI communicated with. It allows a conversation
- * to be held with the shopping cart as javascript doesn't support conversations.
- * Other than that it's just a pass through so we could look to remove it.
+ * An implementation of the SCA tours component. it's just a pass through and allows
+ * the outward facing bindings to be changed without changing the individual contributions
*/
@Scope("COMPOSITE")
@Service(interfaces={SCAToursSearch.class, SCAToursBooking.class, SCAToursCart.class})
@@ -53,47 +51,34 @@ public class SCAToursImpl implements SCAToursSearch, SCAToursBooking, SCAToursCa @Reference
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>();
-
+
// SCAToursSearch methods
public TripItem[] search(TripLeg tripLeg) {
-
return travelCatalogSearch.search(tripLeg);
-
}
// SCAToursBooking methods
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");
- shoppingCart.setConversationID(cartId);
- carts.put(cartId, shoppingCart.getService());
-
+ String cartId = shoppingCart.newCart();
return cartId;
}
public TripItem[] getTrips(String cartId){
- return carts.get(cartId).getTrips();
+ return shoppingCart.getTrips(cartId);
}
public void checkout(String cartId){
- // need to get the user id from the context here
- carts.get(cartId).checkout("c-0");
+ // need to get the user id from the context here but
+ // just make one up for the time being
+ shoppingCart.checkout(cartId, "c-0");
}
}
diff --git a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStore.java b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStore.java new file mode 100644 index 0000000000..949a602686 --- /dev/null +++ b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStore.java @@ -0,0 +1,41 @@ +/* + * 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.shoppingcart; + +import org.osoa.sca.annotations.Conversational; +import org.osoa.sca.annotations.EndsConversation; +import org.osoa.sca.annotations.Remotable; + +import scatours.common.TripItem; + +/** + * The CartStore service interface + */ +@Remotable +@Conversational +public interface CartStore{ + void addTrip(TripItem trip); + + void removeTrip(TripItem trip); + + TripItem[] getTrips(); + + @EndsConversation + void reset(); +} diff --git a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStoreImpl.java b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStoreImpl.java new file mode 100644 index 0000000000..64e9d83e86 --- /dev/null +++ b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/CartStoreImpl.java @@ -0,0 +1,72 @@ +/* + * 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.shoppingcart; + +import java.util.ArrayList; +import java.util.List; + +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 payment.Payment; +import scatours.common.TripItem; + +/** + * An implementation of the Trip service + */ +@Scope("CONVERSATION") +@Service(interfaces={CartStore.class}) +public class CartStoreImpl implements CartStore{ + + @ConversationID + protected String cartId; + + private List<TripItem> trips = new ArrayList<TripItem>(); + + @Init + public void initCart() { + System.out.println("CartStore init for id: " + cartId); + } + + @Destroy + public void destroyCart() { + System.out.println("CartStore destroy for id: " + cartId); + } + + public void addTrip(TripItem trip) { + trips.add(trip); + } + + public void removeTrip(TripItem trip) { + trips.remove(trip); + } + + public TripItem[] getTrips(){ + return trips.toArray(new TripItem[trips.size()]); + } + + public void reset(){ + trips.clear(); + } + +} diff --git a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCart.java b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCart.java index af86860f2f..e2773f6754 100644 --- a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCart.java +++ b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCart.java @@ -28,12 +28,10 @@ import scatours.common.TripItem; * The ShoppingCart service interface
*/
@Remotable
-@Conversational
public interface ShoppingCart{
- void addTrip(TripItem trip);
- void removeTrip(TripItem trip);
- TripItem[] getTrips();
-
- @EndsConversation
- void checkout(String name);
+ String newCart();
+ void addTrip(String cartId,TripItem trip);
+ void removeTrip(String cartId,TripItem trip);
+ TripItem[] getTrips(String cartId);
+ void checkout(String cartId,String name);
}
diff --git a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCartImpl.java b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCartImpl.java index 6967e00852..fa4ef02e55 100644 --- a/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCartImpl.java +++ b/sandbox/travelsample/contributions/shoppingcart-contribution/src/main/java/scatours/shoppingcart/ShoppingCartImpl.java @@ -19,8 +19,14 @@ package scatours.shoppingcart;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+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;
@@ -34,43 +40,43 @@ import scatours.common.TripItem; /**
* An implementation of the Trip service
*/
-@Scope("CONVERSATION")
@Service(interfaces={ShoppingCart.class})
public class ShoppingCartImpl implements ShoppingCart{
@Reference
- protected Payment payment;
-
- @ConversationID
- protected String cartId;
+ protected Payment payment;
- private List<TripItem> trips = new ArrayList<TripItem>();
-
- // Trip methods
+ @Reference
+ protected CartStore cartStore;
- @Init
- public void initCart() {
- System.out.println("Cart init for id: " + cartId);
- }
+ @Context
+ protected ComponentContext componentContext;
- @Destroy
- public void destroyCart() {
- System.out.println("Cart destroy for id: " + cartId);
- }
+ private static Map<String, CartStore> cartStores = new HashMap<String, CartStore>();
+
+ public String newCart(){
+ String cartId = UUID.randomUUID().toString();
+ ServiceReference<CartStore> cartStore = componentContext.getServiceReference(CartStore.class,
+ "cartStore");
+ cartStore.setConversationID(cartId);
+ cartStores.put(cartId, cartStore.getService());
+
+ return cartId;
+ }
- public void addTrip(TripItem trip) {
- trips.add(trip);
+ public void addTrip(String cartId, TripItem trip) {
+ cartStores.get(cartId).addTrip(trip);
}
- public void removeTrip(TripItem trip) {
- trips.remove(trip);
+ public void removeTrip(String cartId, TripItem trip) {
+ cartStores.get(cartId).addTrip(trip);
}
- public TripItem[] getTrips(){
- return trips.toArray(new TripItem[trips.size()]);
+ public TripItem[] getTrips(String cartId){
+ return cartStores.get(cartId).getTrips();
}
- public void checkout(String customerName){
+ public void checkout(String cartId, String customerName){
// get users credentials. Hard coded for now but should
// come from the security context
String customerId = customerName;
@@ -78,6 +84,8 @@ public class ShoppingCartImpl implements ShoppingCart{ // get the total for all the trips
float amount = (float)0.0;
+ TripItem[] trips = getTrips(cartId);
+
for (TripItem trip : trips){
if (trip.getType().equals(TripItem.TRIP)){
amount += trip.getPrice();
@@ -90,6 +98,10 @@ public class ShoppingCartImpl implements ShoppingCart{ // Take the payment from the customer
payment.makePaymentMember(customerId, amount);
+
+ // reset the cart store
+ cartStores.get(cartId).reset();
+ cartStores.remove(cartId);
}
}
diff --git a/sandbox/travelsample/contributions/tripbooking-contribution/src/main/java/scatours/tripbooking/TripBookingImpl.java b/sandbox/travelsample/contributions/tripbooking-contribution/src/main/java/scatours/tripbooking/TripBookingImpl.java index aea855cef6..debbafda64 100644 --- a/sandbox/travelsample/contributions/tripbooking-contribution/src/main/java/scatours/tripbooking/TripBookingImpl.java +++ b/sandbox/travelsample/contributions/tripbooking-contribution/src/main/java/scatours/tripbooking/TripBookingImpl.java @@ -19,6 +19,7 @@ package scatours.tripbooking;
import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
import org.osoa.sca.annotations.Context;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Service;
@@ -79,57 +80,12 @@ public class TripBookingImpl implements TripBooking{ }
// add trip to the shopping cart
- //ServiceReference<ShoppingCart> cart = componentContext.getServiceReference(ShoppingCart.class,
- // "shoppingCart");
- //cart.setConversationID(cartId);
- //cart.getService().addTrip(trip);
+ ServiceReference<ShoppingCart> cart = componentContext.getServiceReference(ShoppingCart.class,
+ "shoppingCart");
+ cart.setConversationID(cartId);
+ cart.getService().addTrip(cartId, trip);
return trip;
}
- /*
- @ConversationID
- protected String conversationId;
-
- private Map<String, TripItem> tripItems = new HashMap<String, TripItem>();
-
- // Trip methods
-
- @Init
- public void initTrip() {
- System.out.println("Trip init for id: " + conversationId);
- }
-
- @Destroy
- public void destroyTrip() {
- System.out.println("Trip destroy for id: " + conversationId);
- }
-
-
- public void addTripItem(TripItem tripItem){
- tripItems.put(tripItem.getId(), tripItem);
- }
-
- 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;
-
- for (TripItem tripItem : tripItems.values()){
- totalPrice += tripItem.getPrice();
- }
-
- return totalPrice;
- }
-
- public void bookTrip() {
- // TODO
- }
- */
}
|