diff options
Diffstat (limited to '')
10 files changed, 289 insertions, 19 deletions
diff --git a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/log4j.properties b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/log4j.properties index f98cabf1b8..036b48afd7 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/log4j.properties +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/log4j.properties @@ -1,27 +1,28 @@ -# A default log4j configuration for log4j users. # -# To use this configuration, deploy it into your application's WEB-INF/classes -# directory. You are also encouraged to edit it as you like. +# +# 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. +# +# # Configure the console as our one appender log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n -# tighten logging on the DataNucleus Categories -log4j.category.DataNucleus.JDO=WARN, A1 -log4j.category.DataNucleus.Persistence=WARN, A1 -log4j.category.DataNucleus.Cache=WARN, A1 -log4j.category.DataNucleus.MetaData=WARN, A1 -log4j.category.DataNucleus.General=WARN, A1 -log4j.category.DataNucleus.Utility=WARN, A1 -log4j.category.DataNucleus.Transaction=WARN, A1 -log4j.category.DataNucleus.Datastore=WARN, A1 -log4j.category.DataNucleus.ClassLoading=WARN, A1 -log4j.category.DataNucleus.Plugin=WARN, A1 -log4j.category.DataNucleus.ValueGeneration=WARN, A1 -log4j.category.DataNucleus.Enhancer=WARN, A1 -log4j.category.DataNucleus.SchemaTool=WARN, A1 - #tuscany debug messages log4j.category.org.apache.tuscany=ALL,A1 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 new file mode 100644 index 0000000000..3fb5439bc3 --- /dev/null +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Cart.java @@ -0,0 +1,28 @@ +/* + * 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 index 2ecf9ae855..b8630370ad 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java @@ -1,3 +1,22 @@ +/* + * 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; 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 index 29c99bbcb5..09cae14100 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java @@ -36,19 +36,29 @@ public class CatalogAggregatorImpl implements Catalog { @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]; + 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 index 07a152a276..59435d9099 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java @@ -1,3 +1,22 @@ +/* + * 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; 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 index 7de3894e2e..d185a2fe83 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java @@ -1,3 +1,22 @@ +/* + * 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; 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 index 65aaa53224..74e7239a20 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java @@ -1,3 +1,22 @@ +/* + * 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; 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 new file mode 100644 index 0000000000..d06ee5b61b --- /dev/null +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java @@ -0,0 +1,112 @@ +/* + * 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.Init; +import org.oasisopen.sca.annotation.Scope; + +@Scope("COMPOSITE") +public class ShoppingCartImpl implements Cart, Total { + + private Map<String, Item> cart; + + @Init + public void init() { + 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/Total.java b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java new file mode 100644 index 0000000000..b77cc1c7ac --- /dev/null +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java @@ -0,0 +1,29 @@ +/* + * 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 9a5897e87b..17df51b252 100644 --- a/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite +++ b/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/store.composite @@ -34,6 +34,10 @@ <interface.java interface="services.Catalog"/> <tuscany:binding.jsonrpc uri="http://tuscany-store-catalog.appspot.com/catalog"/> </reference> + <reference name="vegetablesCatalog"> + <interface.java interface="services.Catalog"/> + <tuscany:binding.jsonrpc uri="http://tuscany.figueiredos.com/store-catalog-ibmcloud-2x-webapp/Catalog"/> + </reference> <reference name="currencyConverter" target="CurrencyConverter" /> </component> @@ -43,4 +47,14 @@ <interface.java interface="services.CurrencyConverter"/> </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> </composite> |