diff options
Diffstat (limited to 'branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore')
5 files changed, 283 insertions, 0 deletions
diff --git a/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java new file mode 100644 index 0000000000..486946b2fc --- /dev/null +++ b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/server/ShoppingStoreServer.java @@ -0,0 +1,25 @@ +package shoppingstore.server; + +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class ShoppingStoreServer { + + public static void main(String[] args) { + + SCADomain scaDomain = SCADomain.newInstance("shoppingstore.composite"); + + try { + System.out.println("ToyApp server started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + System.out.println("ToyApp server stopped"); + } + + +} diff --git a/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java new file mode 100644 index 0000000000..e8f383c3e1 --- /dev/null +++ b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartService.java @@ -0,0 +1,35 @@ +package shoppingstore.services.cart; + +import org.osoa.sca.annotations.Remotable; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Remotable +public interface CartService { + + public CartCreateResponse CartCreate(CartCreate cartCreate); + + public CartAddResponse CartAdd(CartAdd cartAdd); + + public CartModifyResponse CartModify(CartModify cartModify); + + public CartClearResponse CartClear(CartClear cartClear); + + public CartGetResponse CartGet(CartGet cartGet); + + //@Init + //public void start(); + + //@Destroy + //public void stop(); + +} diff --git a/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java new file mode 100644 index 0000000000..1579dbd60d --- /dev/null +++ b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/cart/CartServiceImpl.java @@ -0,0 +1,144 @@ +package shoppingstore.services.cart; + +import java.util.HashMap; + +import org.osoa.sca.annotations.Scope; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.Cart; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddRequest; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartItem; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartItems; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Scope("COMPOSITE") +public class CartServiceImpl implements CartService { + + private static long ID = 0; + + private HashMap<String, Cart> cartsHash = new HashMap<String, Cart>(); + + public CartAddResponse CartAdd(CartAdd cartAdd) { + System.out.println("Entering cartAdd..."); + System.out.println("CartServiceID: " + this.toString()); + CartAddResponse cartAddResponse = new CartAddResponse(); + + CartAddRequest cartAddRequest = cartAdd.getRequest().get(0); + + //Cart cart = getCart(cartAddRequest.getCartId()); + Cart cart = getCart(cartAdd.getAWSAccessKeyId()); + if(cart == null){ + cartAddResponse.getCart().add(new Cart()); + return cartAddResponse; + } + + CartItem cartItem = new CartItem(); + cartItem.setASIN(cartAddRequest.getItems().getItem().get(0).getASIN()); + cartItem.setQuantity(cartAddRequest.getItems().getItem().get(0).getQuantity().toString()); + cart.getCartItems().getCartItem().add(cartItem); + cartAddResponse.getCart().add(cart); + System.out.println("Exiting cartAdd..."); + return cartAddResponse; + } + + public CartClearResponse CartClear(CartClear cartClear) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartClear..."); + CartClearResponse cartClearResponse = new CartClearResponse(); + + //CartClearRequest cartClearRequest = cartClear.getRequest().get(0); + + //Cart cart = getCart(cartClearRequest.getCartId()); + Cart cart = getCart(cartClear.getAWSAccessKeyId()); + if(cart == null) { + cartClearResponse.getCart().add(new Cart()); + return cartClearResponse; + } + + cart.getCartItems().getCartItem().clear(); + + cartClearResponse.getCart().add(cart); + System.out.println("Exiting cartClear..."); + return cartClearResponse; + } + + public CartCreateResponse CartCreate(CartCreate cartCreate) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartCreate..."); + CartCreateResponse cartCreateResponse = new CartCreateResponse(); + + Cart cart = getCart(cartCreate.getAWSAccessKeyId()); + if(cart != null){ + cartCreateResponse.getCart().add(cart); + System.out.println("User " + cartCreate.getAWSAccessKeyId() + " has already created a cart with ID: " + cart.getCartId()); + return cartCreateResponse; + } + + cart = new Cart(); + cart.setCartId(this.generateID()); + cart.setCartItems(new CartItems()); + addCart(cartCreate.getAWSAccessKeyId(), cart); + + cartCreateResponse.getCart().add(cart); + System.out.println("Exiting cartCreate..."); + return cartCreateResponse; + } + + public CartGetResponse CartGet(CartGet cartGet) { + System.out.println("CartServiceID: " + this.toString()); + System.out.println("Entering cartGet..."); + CartGetResponse cartGetResponse = new CartGetResponse(); + + //CartGetRequest cartGetRequest = cartGet.getRequest().get(0); + + //Cart cart = getCart(cartGetRequest.getCartId()); + Cart cart = getCart(cartGet.getAWSAccessKeyId()); + if(cart == null){ + cartGetResponse.getCart().add(new Cart()); + return cartGetResponse; + } + + cartGetResponse.getCart().add(cart); + System.out.println("Exiting cartGet..."); + return cartGetResponse; + } + + public CartModifyResponse CartModify(CartModify cartModify) { + // TODO Auto-generated method stub + return null; + } + + private synchronized String generateID(){ + ID++; + return String.valueOf(ID); + } + + + private Cart getCart(String cartId){ + Cart cart = null; + System.out.println(this.cartsHash.toString()); + cart = this.cartsHash.get(cartId); + return cart; + } + + private void addCart(String cartId, Cart cart){ + this.cartsHash.put(cartId, cart); + } +/* + public void start() { + System.out.println("Start CartService..."); + } + + public void stop() { + System.out.println("Stop CartService..."); + } +*/ +} diff --git a/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java new file mode 100644 index 0000000000..207125ac75 --- /dev/null +++ b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreService.java @@ -0,0 +1,30 @@ +package shoppingstore.services.proxy; + +import org.osoa.sca.annotations.Remotable; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + + +@Remotable +public interface ShoppingStoreService{ + + public CartCreateResponse CartCreate(CartCreate cartCreate); + + public CartAddResponse CartAdd(CartAdd cartAdd); + + public CartModifyResponse CartModify(CartModify cartModify); + + public CartClearResponse CartClear(CartClear cartClear); + + public CartGetResponse CartGet(CartGet cartGet); + +} diff --git a/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java new file mode 100644 index 0000000000..8a73631cbb --- /dev/null +++ b/branches/sca-android/tutorials/store/www-services/catalog-amazon/cart-amazon/src/main/java/shoppingstore/services/proxy/ShoppingStoreServiceImpl.java @@ -0,0 +1,49 @@ +package shoppingstore.services.proxy; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +import shoppingstore.services.cart.CartService; + +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartAddResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartClearResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreateResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartGetResponse; +import com.amazon.webservices.awsecommerceservice._2007_05_14.CartModifyResponse; + +@Scope("COMPOSITE") +public class ShoppingStoreServiceImpl implements ShoppingStoreService { + + private CartService cartService; + + @Reference + public void setCartService(CartService cartService) { + this.cartService = cartService; + } + + public CartAddResponse CartAdd( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartAdd cartAdd) { + return cartService.CartAdd(cartAdd); + } + + public CartClearResponse CartClear( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartClear cartClear) { + return cartService.CartClear(cartClear); + } + + public CartCreateResponse CartCreate( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartCreate cartCreate) { + return cartService.CartCreate(cartCreate); + } + + public CartGetResponse CartGet( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartGet cartGet) { + return cartService.CartGet(cartGet); + } + + public CartModifyResponse CartModify( + com.amazon.webservices.awsecommerceservice._2007_05_14.CartModify cartModify) { + return cartService.CartModify(cartModify); + } + +} |