You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/07/01 08:04:48 UTC
svn commit: r959523 - in /tuscany/sca-cpp/trunk: modules/wsgi/
samples/store-gae/ samples/store-gae/htdocs/
Author: jsdelfino
Date: Thu Jul 1 06:04:47 2010
New Revision: 959523
URL: http://svn.apache.org/viewvc?rev=959523&view=rev
Log:
Support user and email properties in WSGI integration.
Modified:
tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
tuscany/sca-cpp/trunk/samples/store-gae/Makefile.am
tuscany/sca-cpp/trunk/samples/store-gae/app.yaml
tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite
tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite
tuscany/sca-cpp/trunk/samples/store-gae/domain.composite
tuscany/sca-cpp/trunk/samples/store-gae/htdocs/store.html
tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py
Modified: tuscany/sca-cpp/trunk/modules/wsgi/scdl.py
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/wsgi/scdl.py?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/wsgi/scdl.py (original)
+++ tuscany/sca-cpp/trunk/modules/wsgi/scdl.py Thu Jul 1 06:04:47 2010
@@ -96,7 +96,7 @@ def properties(e):
return ()
if match(car(e), "start", "property") == False:
return properties(cdr(e))
- return cons(text(car(e)), properties(cdr(e)))
+ return cons((att(car(e))["name"], text(car(e))), properties(cdr(e)))
# Return the list of services under a SCDL component element
def services(e):
@@ -189,17 +189,26 @@ def evalReference(r, comps):
# value. The user and email properties are configured with the values
# from the HTTP request, if any
def evalProperty(p):
- if (isTaggedList(p, "user")):
+ if car(p) == "user":
return lambda: userProperty(cadr(p))
- if (isTaggedList(p, "email")):
+ if car(p) == "email":
return lambda: emailProperty(cadr(p))
- return lambda: p
+ return lambda: cadr(p)
+
+def currentUser():
+ try:
+ from google.appengine.api import users
+ return users.get_current_user()
+ except:
+ return None
def userProperty(v):
- return "nobody"
+ user = currentUser()
+ return user.user_id() if user else v
def emailProperty(v):
- return "nobody@nowhere.com"
+ user = currentUser()
+ return user.email() if user else v
# Evaluate a component, resolve its implementation, references and
# properties
Modified: tuscany/sca-cpp/trunk/samples/store-gae/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/Makefile.am?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/Makefile.am Thu Jul 1 06:04:47 2010
@@ -27,7 +27,7 @@ target.stamp: app.yaml *.py *.composite
cp app.yaml *.py *.composite `ls $(top_builddir)/modules/wsgi/*.py | grep -v "\-test"` target
mkdir -p target/htdocs
cp -R htdocs/* target/htdocs
- mkdir target/htdocs/js
+ mkdir -p target/htdocs/js
cp -R $(top_builddir)/modules/server/htdocs/js/* target/htdocs/js
touch target.stamp
Modified: tuscany/sca-cpp/trunk/samples/store-gae/app.yaml
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/app.yaml?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/app.yaml (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/app.yaml Thu Jul 1 06:04:47 2010
@@ -45,8 +45,10 @@ handlers:
static_files: htdocs/\1
upload: htdocs/(.*\.(html|png))
secure: always
+ login: required
- url: /.*
script: composite.py
secure: always
+ login: required
Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain-frontend.composite Thu Jul 1 06:04:47 2010
@@ -27,15 +27,9 @@
<service name="Widget">
<t:binding.http uri="store"/>
</service>
- <reference name="catalog">
- <t:binding.http uri="https://sca-store-backend.appspot.com/catalog"/>
- </reference>
- <reference name="shoppingCart">
- <t:binding.http uri="https://sca-store-backend.appspot.com/shoppingCart"/>
- </reference>
- <reference name="shoppingTotal">
- <t:binding.http uri="https://sca-store-backend.appspot.com/shoppingCart"/>
- </reference>
+ <reference name="catalog" target="Catalog"/>
+ <reference name="shoppingCart" target="ShoppingCart/Cart"/>
+ <reference name="shoppingTotal" target="ShoppingCart/Total"/>
</component>
<component name="Catalog">
@@ -49,7 +43,7 @@
<component name="ShoppingCart">
<t:implementation.python script="shopping-cart.py"/>
- <service name="ShoppingCart">
+ <service name="Cart">
<t:binding.atom uri="shoppingCart"/>
</service>
<service name="Total">
@@ -58,6 +52,7 @@
<reference name="cache">
<t:binding.http uri="https://sca-store-backend.appspot.com/cache"/>
</reference>
+ <property name="email">anonymous@example.com</property>
</component>
<component name="CurrencyConverter">
Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain-single.composite Thu Jul 1 06:04:47 2010
@@ -50,6 +50,7 @@
<t:binding.jsonrpc uri="total"/>
</service>
<reference name="cache" target="Cache"/>
+ <property name="email">anonymous@example.com</property>
</component>
<component name="CurrencyConverter">
Modified: tuscany/sca-cpp/trunk/samples/store-gae/domain.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/domain.composite?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/domain.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/domain.composite Thu Jul 1 06:04:47 2010
@@ -50,6 +50,7 @@
<t:binding.jsonrpc uri="total"/>
</service>
<reference name="cache" target="Cache"/>
+ <property name="email">anonymous@example.com</property>
</component>
<component name="CurrencyConverter">
Modified: tuscany/sca-cpp/trunk/samples/store-gae/htdocs/store.html
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/htdocs/store.html?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/htdocs/store.html (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/htdocs/store.html Thu Jul 1 06:04:47 2010
@@ -51,8 +51,14 @@
}
document.getElementById('catalog').innerHTML=catalog;
catalogItems = items;
-
- shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
+ }
+
+ function shoppingCart_getemailResponse(email, exception) {
+ if(exception) {
+ alert(exception.message);
+ return;
+ }
+ document.getElementById('email').innerHTML = email;
}
function shoppingCart_getResponse(feed) {
@@ -76,6 +82,8 @@
}
}
}
+
+ shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
}
function shoppingTotal_gettotalResponse(total,exception) {
@@ -132,6 +140,7 @@
try {
catalog.apply("getcatalog", catalog_getcatalogResponse);
+ shoppingCart.apply("getemail", shoppingCart_getemailResponse);
shoppingCart.get("", shoppingCart_getResponse);
}
catch(e){
@@ -145,6 +154,7 @@
<body onload="init()">
<h1>Store</h1>
+<p>You're signed in as: <span id="email"></span><br/><a href="/_ah/login?continue=/store.html&action=Logout">Sign out</a></p>
<div id="store">
<h2>Catalog</h2>
<form name="catalogForm">
@@ -155,7 +165,7 @@
<br>
- <h2>Your Shopping Cart</h2>
+ <h2>Your Shopping Cart</h2>
<form name="shoppingCartForm">
<div id="shoppingCart"></div>
<br>
Modified: tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py?rev=959523&r1=959522&r2=959523&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py (original)
+++ tuscany/sca-cpp/trunk/samples/store-gae/shopping-cart.py Thu Jul 1 06:04:47 2010
@@ -30,7 +30,7 @@ def getcart(id, cache):
return cart
# Post a new item to the cart, create a new cart if necessary
-def post(collection, item, cache):
+def post(collection, item, cache, email):
id = str(uuid.uuid1())
cart = ((item[0], id, item[2]),) + getcart(cartId, cache)
cache("put", (cartId,), cart)
@@ -46,13 +46,13 @@ def find(id, cart):
return find(id, cart[1:])
# Get items from the cart
-def get(id, cache):
+def get(id, cache, email):
if id == ():
return ("Your Cart", cartId) + getcart(cartId, cache)
return find(id[0], getcart(cartId, cache))
# Delete items from the cart
-def delete(id, cache):
+def delete(id, cache, email):
if id == ():
return cache("delete", (cartId,))
return True
@@ -68,7 +68,11 @@ def sum(items):
return price(items[0]) + sum(items[1:])
# Return the total price of the items in the cart
-def gettotal(cache):
+def gettotal(cache, email):
cart = getcart(cartId, cache)
return sum(cart)
+# Return the email of the cart owner
+def getemail(cache, email):
+ return email()
+