You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2009/10/26 07:27:27 UTC
svn commit: r829709 - in
/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp:
src/services/ShoppingCart.java src/services/ShoppingCartImpl.java
src/services/ShoppingCartManager.java src/store.composite war/store.css
war/store.html
Author: lresende
Date: Mon Oct 26 06:27:26 2009
New Revision: 829709
URL: http://svn.apache.org/viewvc?rev=829709&view=rev
Log:
Adding support for multi-user shoppingCart
Added:
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java (with props)
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java (with props)
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css (with props)
Modified:
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
Added: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java?rev=829709&view=auto
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java (added)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java Mon Oct 26 06:27:26 2009
@@ -0,0 +1,27 @@
+/*
+ * 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 services;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface ShoppingCart extends Cart, Total{
+
+}
Propchange: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java?rev=829709&r1=829708&r2=829709&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java (original)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java Mon Oct 26 06:27:26 2009
@@ -27,18 +27,12 @@
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.NotFoundException;
-import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Scope;
@Scope("COMPOSITE")
-public class ShoppingCartImpl implements Cart, Total {
+public class ShoppingCartImpl implements ShoppingCart {
- private Map<String, Item> cart;
-
- @Init
- public void init() {
- cart = new HashMap<String, Item>();
- }
+ private Map<String, Item> cart = new HashMap<String, Item>();
public Entry<String, Item>[] getAll() {
Entry<String, Item>[] entries = new Entry[cart.size()];
Added: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java?rev=829709&view=auto
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java (added)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java Mon Oct 26 06:27:26 2009
@@ -0,0 +1,117 @@
+/*
+ * 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 services;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.cloud.user.User;
+import org.apache.tuscany.sca.cloud.user.UserService;
+import org.apache.tuscany.sca.data.collection.Entry;
+import org.apache.tuscany.sca.data.collection.NotFoundException;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class ShoppingCartManager implements ShoppingCart {
+ private static final Logger log = Logger.getLogger(ShoppingCartManager.class.getName());
+ private static String ANONYMOUS = "anonymous";
+
+ private Map<String, ShoppingCart> carts = new HashMap<String, ShoppingCart>();
+
+ @Reference
+ private UserService userService;
+
+ public Entry<String, Item>[] getAll() {
+ return getUserShoppingCart().getAll();
+ }
+
+ public Item get(String key) throws NotFoundException {
+ return getUserShoppingCart().get(key);
+ }
+
+ public String post(String key, Item item) {
+ if (key == null || key.length() == 0) {
+ key = this.generateItemKey();
+ }
+ return getUserShoppingCart().post(key, item);
+ }
+
+ public void put(String key, Item item) throws NotFoundException {
+ getUserShoppingCart().put(key,item);
+ }
+
+ public Entry<String, Item>[] query(String queryString) {
+ return getUserShoppingCart().query(queryString);
+ }
+
+ public void delete(String key) throws NotFoundException {
+ this.getUserShoppingCart().delete(key);
+ }
+
+ public String getTotal() {
+ return this.getUserShoppingCart().getTotal();
+ }
+
+ /**
+ * Utility functions
+ */
+
+
+ private ShoppingCart getUserShoppingCart() {
+ String key = getCartKey();
+ ShoppingCart userCart = carts.get(key);
+ if(userCart == null) {
+ userCart = new ShoppingCartImpl();
+ carts.put(key, userCart);
+ }
+ return userCart;
+ }
+
+ private String getUserId() {
+ String userId = null;
+ if(userService != null) {
+ try {
+ User user = userService.getCurrentUser();
+ userId = user.getUserId();
+ } catch(Exception e) {
+ //ignore
+ e.printStackTrace();
+ }
+ }
+ if(userId == null || userId.length() == 0) {
+ userId = ANONYMOUS;
+ }
+ log.warning("Using userId:" + userId);
+ return userId;
+ }
+ private String getCartKey() {
+ String cartKey = "cart-" + this.getUserId();
+ log.warning("Using cartKey:" + cartKey);
+ return cartKey;
+ }
+ private String generateItemKey() {
+ String itemKey = getCartKey() + "-item-" + UUID.randomUUID().toString();
+ log.warning("Using itemKey:" + itemKey);
+ return itemKey;
+ }
+}
Propchange: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite?rev=829709&r1=829708&r2=829709&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite (original)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite Mon Oct 26 06:27:26 2009
@@ -48,19 +48,20 @@
</service>
</component>
- <component name="ShoppingCart">
- <implementation.java class="services.ShoppingCartImpl"/>
- <service name="Cart">
- <tuscany:binding.jsonrpc uri="/ShoppingCart/Cart"/>
- </service>
- <service name="Total">
- <tuscany:binding.jsonrpc uri="/ShoppingCart/Total"/>
- </service>
+ <component name="ShoppingCartManager">
+ <implementation.java class="services.ShoppingCartManager"/>
+ <service name="ShoppingCart">
+ <tuscany:binding.jsonrpc uri="/ShoppingCart"/>
+ </service>
+ <reference name="userService" target="UserService">
+ <binding.sca/>
+ </reference>
</component>
<component name="UserService">
<implementation.java class="org.apache.tuscany.sca.cloud.user.impl.GoogleUserService"/>
<service name="UserService">
+ <binding.sca/>
<tuscany:binding.jsonrpc uri="/User"/>
</service>
</component>
Added: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css?rev=829709&view=auto
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css (added)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css Mon Oct 26 06:27:26 2009
@@ -0,0 +1,22 @@
+<style type="text/css">
+
+html, body {
+ height:100%;
+ margin:0;
+ overflow:hidden;
+ width:100%;
+}
+
+.header {
+ font-size:13px;
+ text-align:right;
+ color:#CCCCCC;
+
+
+ padding:5px 5px 0;
+ padding-right:8px;
+ padding-top:0px !important;
+ padding-bottom: 0px;
+ border-bottom: 1px solid black;
+}
+</style>
\ No newline at end of file
Propchange: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.css
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html?rev=829709&r1=829708&r2=829709&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html (original)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html Mon Oct 26 06:27:26 2009
@@ -35,9 +35,7 @@
var catalog = new dojo.rpc.JsonService("/CatalogAggregator?smd");
- var shoppingCart = new dojo.rpc.JsonService("/ShoppingCart/Cart?smd");
-
- var shoppingTotal = new dojo.rpc.JsonService("/ShoppingCart/Total?smd");
+ var shoppingCart = new dojo.rpc.JsonService("/ShoppingCart?smd");
var userContext;
@@ -93,7 +91,7 @@
if (items.length != 0) {
try {
- shoppingTotal.getTotal().addCallback(shoppingTotal_getTotalResponse);
+ shoppingCart.getTotal().addCallback(shoppingCart_getTotalResponse);
}
catch(e){
alert(e);
@@ -101,7 +99,7 @@
}
}
- function shoppingTotal_getTotalResponse(total,exception) {
+ function shoppingCart_getTotalResponse(total,exception) {
if(exception) {
alert(exception.message);
return;