summaryrefslogtreecommitdiffstats
path: root/sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services')
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Cart.java28
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Catalog.java19
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CatalogAggregatorImpl.java12
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverter.java19
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/CurrencyConverterImpl.java19
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Item.java19
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/ShoppingCartImpl.java112
-rw-r--r--sandbox/sca-cloud-tutorial/store-appengine-webapp/src/services/Total.java29
8 files changed, 256 insertions, 1 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
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();
+
+}