tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r829708 - in /tuscany/sandbox/sca-cloud-tutorial: cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/ cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/ cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/ st...
Date Mon, 26 Oct 2009 06:27:21 GMT
Author: lresende
Date: Mon Oct 26 06:27:21 2009
New Revision: 829708

URL: http://svn.apache.org/viewvc?rev=829708&view=rev
Log:
Adding user services and integrating with the store application

Added:
    tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
  (with props)
    tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/
    tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/
    tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
  (with props)
Modified:
    tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
    tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
    tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
    tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
    tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html

Modified: tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java?rev=829708&r1=829707&r2=829708&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
(original)
+++ tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
Mon Oct 26 06:27:21 2009
@@ -19,12 +19,30 @@
 
 package org.apache.tuscany.sca.cloud.user;
 
-public interface User {
+public class User {
     public static enum ROLES { UNDEFINED, USER, ADMIN};
     
-    String getUserId();
+    protected String userId;
+    protected String nickName;
+    protected String email;
     
-    String getEmail();
+    public User(String userId, String nickName, String email) {
+        this.userId = userId;
+        this.nickName = nickName;
+        this.email = email;
+    }
     
-    String getNickname();    
+    public String getUserId() {
+        return this.userId;
+    }
+    
+    public String getNickname() {
+        return this.nickName;
+    }
+    
+    public String getEmail() {
+        return this.email;
+    }
+    
+  
 }

Added: tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java?rev=829708&view=auto
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
(added)
+++ tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
Mon Oct 26 06:27:21 2009
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.tuscany.sca.cloud.user;
+
+public class UserContext extends User {
+    protected String loginUrl;
+    protected String logoutUrl;
+    protected boolean isUserLoggedIn;
+    
+    public UserContext(String userId, String nickName, String email, boolean isUserLoggedIn,
String loginUrl, String logoutUrl) {
+        super(userId, nickName, email);
+        this.isUserLoggedIn = isUserLoggedIn;
+        this.loginUrl = loginUrl;
+        this.logoutUrl = logoutUrl;
+    }
+    
+    public UserContext(User user, boolean isUserLoggedIn, String loginUrl, String logoutUrl)
{
+        super(user.getUserId(), user.getNickname(), user.getEmail());
+        this.isUserLoggedIn = isUserLoggedIn;
+        this.loginUrl = loginUrl;
+        this.logoutUrl = logoutUrl;
+    }
+    
+    public boolean isUserLoggedIn() {
+        return this.isUserLoggedIn;
+    }
+    
+    public String getLoginUrl() {
+        return this.loginUrl;
+    }
+    
+    public String getLogoutUrl() {
+        return this.logoutUrl;
+    }
+}

Propchange: tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java?rev=829708&r1=829707&r2=829708&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
(original)
+++ tuscany/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
Mon Oct 26 06:27:21 2009
@@ -19,20 +19,22 @@
 
 package org.apache.tuscany.sca.cloud.user;
 
+import org.oasisopen.sca.annotation.Remotable;
 
+@Remotable
 public interface UserService {
     
-    public String createLoginURL(String destinationURL, String authDomain);
+    public User getCurrentUser();
 
-    public String createLoginURL(String destinationURL);
+    public boolean isUserAdmin();
 
-    public String createLogoutURL(String destinationURL, String authDomain);
+    public boolean isUserLoggedIn();
 
-    public String createLogoutURL(String destinationURL);
+    public UserContext getUserContext(String destinationURL, String authDomain);
 
-    public User getCurrentUser();
+    public String createLoginURL(String destinationURL, String authDomain);
+
+    public String createLogoutURL(String destinationURL, String authDomain);
 
-    public boolean isUserAdmin();
 
-    public boolean isUserLoggedIn();
 }

Added: tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java?rev=829708&view=auto
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
(added)
+++ tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
Mon Oct 26 06:27:21 2009
@@ -0,0 +1,87 @@
+/*
+ * 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 org.apache.tuscany.sca.cloud.user.impl;
+
+import org.apache.tuscany.sca.cloud.user.User;
+import org.apache.tuscany.sca.cloud.user.UserContext;
+import org.apache.tuscany.sca.cloud.user.UserService;
+import org.oasisopen.sca.annotation.Init;
+import org.oasisopen.sca.annotation.Scope;
+import org.oasisopen.sca.annotation.Service;
+
+import com.google.appengine.api.users.UserServiceFactory;
+
+@Service(UserService.class)
+@Scope("COMPOSITE")
+public class GoogleUserService implements UserService {
+    private com.google.appengine.api.users.UserService googleUerService;
+
+    @Init
+    public void init() {
+        googleUerService = UserServiceFactory.getUserService();
+    }
+    
+
+    public User getCurrentUser() {
+        return fromGoogleUser(googleUerService.getCurrentUser());
+    }
+
+    public boolean isUserAdmin() {
+        //FIXME handle via roles from tuscany user api
+        throw new UnsupportedOperationException("Not supported yet");
+    }
+
+    public boolean isUserLoggedIn() {
+        return googleUerService.isUserLoggedIn();
+    }
+    
+    public UserContext getUserContext(String destinationURL, String authDomain) {
+        return new UserContext (getCurrentUser(),
+                                isUserLoggedIn(),
+                                createLoginURL(destinationURL, authDomain),
+                                createLogoutURL(destinationURL, authDomain));
+    }
+    
+    public String createLoginURL(String destinationURL, String authDomain) {
+        if(authDomain != null && authDomain.length() > 0) {
+            return googleUerService.createLoginURL(destinationURL, authDomain);
+        } else {
+            return googleUerService.createLoginURL(destinationURL);
+        }
+    }
+
+    public String createLogoutURL(String destinationURL, String authDomain) {
+        if(authDomain != null && authDomain.length() > 0) {
+            return googleUerService.createLogoutURL(destinationURL, authDomain);
+        } else {
+            return googleUerService.createLogoutURL(destinationURL);
+        }
+    }
+
+    private static User fromGoogleUser(com.google.appengine.api.users.User googleUser) {
+        if(googleUser != null) {
+            return new User(googleUser.getUserId(), googleUser.getNickname(), googleUser.getEmail());
+        } 
+        
+        return new User(null, null, null);
+    }
+
+    
+}

Propchange: tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.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=829708&r1=829707&r2=829708&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:21 2009
@@ -28,7 +28,7 @@
 		<property name="currencyCode">USD</property>
 		<service name="Catalog">
 		    <interface.java interface="services.Catalog"/>
-			<tuscany:binding.jsonrpc uri="/catalogAggregator"/>
+			<tuscany:binding.jsonrpc uri="/CatalogAggregator"/>
 		</service>
 		<reference name="fruitsCatalog">
 		    <interface.java interface="services.Catalog"/>
@@ -51,10 +51,17 @@
 	<component name="ShoppingCart">
 		<implementation.java class="services.ShoppingCartImpl"/>
 		<service name="Cart">
-			<tuscany:binding.jsonrpc uri="/shoppingCart/Cart"/>
+			<tuscany:binding.jsonrpc uri="/ShoppingCart/Cart"/>
 		</service>    	
 		<service name="Total">
-			<tuscany:binding.jsonrpc uri="/shoppingCart/Total"/>
+			<tuscany:binding.jsonrpc uri="/ShoppingCart/Total"/>
 		</service>    	
+	</component>
+	
+	<component name="UserService">
+		<implementation.java class="org.apache.tuscany.sca.cloud.user.impl.GoogleUserService"/>
+		<service name="UserService">
+			<tuscany:binding.jsonrpc uri="/User"/>
+		</service>
 	</component>	
 </composite>

Modified: tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml?rev=829708&r1=829707&r2=829708&view=diff
==============================================================================
--- tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
(original)
+++ tuscany/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
Mon Oct 26 06:27:21 2009
@@ -19,7 +19,7 @@
 -->
 <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
 	<application>tuscany-store</application>
-	<version>3</version>
+	<version>4</version>
 	
 	<!-- Configure java.util.logging -->
 	<system-properties>

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=829708&r1=829707&r2=829708&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:21
2009
@@ -21,6 +21,8 @@
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 <title>Online Store - Powered by Apache Tuscany</title>
 
+<link href="store.css" rel="stylesheet" type="text/css">
+
 <script type="text/javascript" src="dojo/dojo/dojo.js"></script>
 
 <script type="text/javascript">
@@ -29,25 +31,52 @@
 
 <script language="JavaScript">
 
-	var catalog = new dojo.rpc.JsonService("/catalogAggregator?smd");
+	var userServices = new dojo.rpc.JsonService("/User?smd");
+	
+	var catalog = new dojo.rpc.JsonService("/CatalogAggregator?smd");
+
+	var shoppingCart = new dojo.rpc.JsonService("/ShoppingCart/Cart?smd");
 
-	var shoppingCart = new dojo.rpc.JsonService("/shoppingCart/Cart?smd");
+	var shoppingTotal = new dojo.rpc.JsonService("/ShoppingCart/Total?smd");
 
-	var shoppingTotal = new dojo.rpc.JsonService("/shoppingCart/Total?smd");
+	var userContext;
 	
 	var catalogItems;
 
-	function catalog_getResponse(items) {
-		var catalog = "";
-		for (var i=0; i<items.length; i++) {
-			var item = items[i].name + ' - ' + items[i].price;
-			catalog += '<input name="items" type="checkbox" value="' + 
-						item + '">' + item + ' <br>';
+	function showHeader() {
+		var userContextCallback = function(context) {
+			userContext = context;
+			//alert(userContext.userId + " --> " + userContext.loginUrl);
+
+			var html='';
+			if(! userContext.userId) {
+				 html = "<a href='" + userContext.loginUrl +"'>Login</a>";
+			} else {
+				html = userContext.email + " | <a href='" + userContext.logoutUrl +"'> Logout</a>";
+			}
+
+			document.getElementById('appHeader').innerHTML = html;
+		}		
+			
+		userServices.getUserContext(document.URL, "").addCallback(userContextCallback);
+	}
+	
+	function showCatalogs() {
+		var catalogCallback = function(items) {
+			var catalog = "";
+			for (var i=0; i<items.length; i++) {
+				var item = items[i].name + ' - ' + items[i].price;
+				catalog += '<input name="items" type="checkbox" value="' + 
+							item + '">' + item + ' <br>';
+			}
+			document.getElementById('catalog').innerHTML=catalog;
+			catalogItems = items;
 		}
-		document.getElementById('catalog').innerHTML=catalog;
-		catalogItems = items;
+
+		catalog.get().addCallback(catalogCallback); 
 	}
 
+
 	// This handles the response from shoppingCart.getAll
 	// which is a collection of Entry<K,D>
 	function shoppingCart_getResponse(items) {
@@ -112,12 +141,16 @@
 		document.getElementById('shoppingCart').innerHTML = "";
 		document.getElementById('total').innerHTML = "";	
 	}	
+
 	
 
 	function init() {
 		try {
-		  catalog.get().addCallback(catalog_getResponse);
-		  shoppingCart.get("").addCallback(shoppingCart_getResponse);
+			showHeader();
+
+			showCatalogs();
+			
+			shoppingCart.getAll().addCallback(shoppingCart_getResponse);
 		} catch (e) {
 			alert(e);
 		}
@@ -129,7 +162,13 @@
 </head>
 
 <body onload="init()">
-<h1>Store</h1>
+   <div id="appHeader" class="header">
+   </div>
+
+   <h1>Store</h1>
+   
+   
+
   <div id="store">
    	<h2>Catalog</h2>
    	<form name="catalogForm">
@@ -152,4 +191,5 @@
 	</form>        
   </div>
 </body>
-</html>
+
+</html>
\ No newline at end of file



Mime
View raw message