diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-27 22:09:18 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-27 22:09:18 +0000 |
commit | f94a2904efd56b82c437c29eba14d09773b4d651 (patch) | |
tree | 5c1cd8e1a671ce9423fe7ecdb298f1cde748d61e /sandbox/sca-cloud-tutorial/store-appengine-webapp/src | |
parent | 57301b4c29de5847993f3f522a27adea5a9a8d1b (diff) |
Refactoring common artifacts to store-assets module
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@830361 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/sca-cloud-tutorial/store-appengine-webapp/src')
11 files changed, 3 insertions, 530 deletions
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Cart.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Cart.java deleted file mode 100644 index 3fb5439bc3..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Cart.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.apache.tuscany.sca.data.collection.Collection; -import org.oasisopen.sca.annotation.Remotable; - -@Remotable -public interface Cart extends Collection<String, Item> { - -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java deleted file mode 100644 index b8630370ad..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 Catalog { - Item[] get(); -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java deleted file mode 100644 index 09cae14100..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.Property; -import org.oasisopen.sca.annotation.Reference; -import org.oasisopen.sca.annotation.Scope; -import org.oasisopen.sca.annotation.Service; - -@Service(Catalog.class) -@Scope("COMPOSITE") -public class CatalogAggregatorImpl implements Catalog { - - @Property - public String currencyCode = "USD"; - - @Reference - public CurrencyConverter currencyConverter; - - @Reference - public Catalog fruitsCatalog; - - @Reference - public Catalog vegetablesCatalog; - - public Item[] get() { - String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); - - Item[] fruits = fruitsCatalog.get(); - Item[] vegetables = vegetablesCatalog.get(); - - Item[] catalog = new Item[fruits.length + vegetables.length]; - int i =0; - for (Item item: fruits) { - double price = Double.valueOf(item.getPrice().substring(1)); - price = currencyConverter.getConversion("USD", currencyCode, price); - catalog[i++] = new Item(item.getName(), currencySymbol + price); - } - - for (Item item: vegetables) { - double price = Double.valueOf(item.getPrice().substring(1)); - price = currencyConverter.getConversion("USD", currencyCode, price); - catalog[i++] = new Item(item.getName(), currencySymbol + price); - } - - return catalog; - } - -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java deleted file mode 100644 index 59435d9099..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 CurrencyConverter { - public double getConversion(String fromCurrenycCode, - String toCurrencyCode, - double amount); - - public String getCurrencySymbol(String currencyCode); -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java deleted file mode 100644 index d185a2fe83..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.Service; - -@Service(CurrencyConverter.class) -public class CurrencyConverterImpl implements CurrencyConverter { - public double getConversion(String fromCurrencyCode, - String toCurrencyCode, - double amount) { - if (toCurrencyCode.equals("USD")) - return amount; - else if (toCurrencyCode.equals("EUR")) - return ((double)Math.round(amount * 0.7256 * 100)) /100; - return 0; - } - - public String getCurrencySymbol(String currencyCode) { - if (currencyCode.equals("USD")) - return "$"; - else if (currencyCode.equals("EUR")) - return "E"; //"€"; - return "?"; - } -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java deleted file mode 100644 index 74e7239a20..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.io.Serializable; - -public class Item implements Serializable { - private static final long serialVersionUID = -5847326138627338217L; - - private String name; - private String price; - - public Item() { - } - - public Item(String name, String price) { - this.name = name; - this.price = price; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getPrice() { - return price; - } - - public void setPrice(String price) { - this.price = price; - } -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java deleted file mode 100644 index e4d590484c..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCart.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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{ - -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java deleted file mode 100644 index cfa9dd7435..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.tuscany.sca.data.collection.Entry; -import org.apache.tuscany.sca.data.collection.NotFoundException; -import org.oasisopen.sca.annotation.Scope; - -@Scope("COMPOSITE") -public class ShoppingCartImpl implements ShoppingCart { - - private Map<String, Item> cart = new HashMap<String, Item>(); - - public Entry<String, Item>[] getAll() { - Entry<String, Item>[] entries = new Entry[cart.size()]; - int i = 0; - for (Map.Entry<String, Item> e: cart.entrySet()) { - entries[i++] = new Entry<String, Item>(e.getKey(), e.getValue()); - } - return entries; - } - - public Item get(String key) throws NotFoundException { - Item item = cart.get(key); - if (item == null) { - throw new NotFoundException(key); - } else { - return item; - } - } - - public String post(String key, Item item) { - if (key == null || key.length() == 0) { - key ="cart-" + UUID.randomUUID().toString(); - } - cart.put(key, item); - return key; - } - - public void put(String key, Item item) throws NotFoundException { - if (!cart.containsKey(key)) { - throw new NotFoundException(key); - } - cart.put(key, item); - } - - public void delete(String key) throws NotFoundException { - if (key == null || key.equals("")) { - cart.clear(); - } else { - Item item = cart.remove(key); - if (item == null) - throw new NotFoundException(key); - } - } - - public Entry<String, Item>[] query(String queryString) { - List<Entry<String, Item>> entries = new ArrayList<Entry<String,Item>>(); - if (queryString.startsWith("name=")) { - String name = queryString.substring(5); - for (Map.Entry<String, Item> e: cart.entrySet()) { - Item item = e.getValue(); - if (item.getName().equals(name)) { - entries.add(new Entry<String, Item>(e.getKey(), e.getValue())); - } - } - } - return entries.toArray(new Entry[entries.size()]); - } - - public String getTotal() { - double total = 0; - String currencySymbol = ""; - if (!cart.isEmpty()) { - Item item = cart.values().iterator().next(); - currencySymbol = item.getPrice().substring(0, 1); - } - for (Item item : cart.values()) { - total += Double.valueOf(item.getPrice().substring(1)); - } - return currencySymbol + String.valueOf(total); - } -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java deleted file mode 100644 index 90f25d214c..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartManager.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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; - } -} diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java deleted file mode 100644 index b77cc1c7ac..0000000000 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 Total { - - String getTotal(); - -} 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 4fac764518..6b659f2876 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite @@ -32,7 +32,7 @@ </service> <reference name="fruitsCatalog"> <interface.java interface="services.Catalog"/> - <tuscany:binding.jsonrpc uri="http://tuscany-store-catalog.appspot.com/catalog"/> + <tuscany:binding.jsonrpc uri="http://tuscany-store-catalog.appspot.com/Catalog"/> </reference> <reference name="vegetablesCatalog"> <interface.java interface="services.Catalog"/> @@ -54,14 +54,14 @@ <tuscany:binding.jsonrpc uri="/ShoppingCart"/> </service> <reference name="userService" target="UserService"> - <binding.sca/> + <binding.sca name="local"/> </reference> </component> <component name="UserService"> <implementation.java class="org.apache.tuscany.sca.cloud.user.impl.GoogleUserService"/> <service name="UserService"> - <binding.sca/> + <binding.sca name="local"/> <tuscany:binding.jsonrpc uri="/User"/> </service> </component> |