summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 06:27:21 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 06:27:21 +0000
commitaf2857365e659d99dda12bee356681ab7b789822 (patch)
tree8ae162fb541c1f5dabecf91f46bee0ba7d428f71 /sandbox
parent911069d0f429934349fa7b72160c864716fb011c (diff)
Adding user services and integrating with the store application
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829708 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java26
-rw-r--r--sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java52
-rw-r--r--sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java16
-rw-r--r--sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java87
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite13
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml2
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html70
7 files changed, 236 insertions, 30 deletions
diff --git a/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
index b218716330..1a5c21a760 100644
--- a/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
+++ b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/User.java
@@ -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;
+ }
+
+
}
diff --git a/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
new file mode 100644
index 0000000000..87d8e3c0a2
--- /dev/null
+++ b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserContext.java
@@ -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;
+ }
+}
diff --git a/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
index 7696f0d45b..2f37a8dc6e 100644
--- a/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
+++ b/sandbox/sca-cloud-tutorial/cloud-api/src/main/java/org/apache/tuscany/sca/cloud/user/UserService.java
@@ -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();
}
diff --git a/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java b/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
new file mode 100644
index 0000000000..bb449b22d3
--- /dev/null
+++ b/sandbox/sca-cloud-tutorial/cloud-google/src/main/java/org/apache/tuscany/sca/cloud/user/impl/GoogleUserService.java
@@ -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);
+ }
+
+
+}
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
index 17df51b252..255857ffd4 100644
--- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
+++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite
@@ -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>
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
index 6c83c9666b..85626f6b1c 100644
--- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
+++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/WEB-INF/appengine-web.xml
@@ -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>
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
index 2fc5fcc434..c28e417913 100644
--- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
+++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/war/store.html
@@ -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