diff options
Diffstat (limited to '')
5 files changed, 37 insertions, 19 deletions
diff --git a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/CatalogAggregatorImpl.java b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/CatalogAggregatorImpl.java index 09cae14100..1d4b8fedfa 100644 --- a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/CatalogAggregatorImpl.java +++ b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/CatalogAggregatorImpl.java @@ -49,15 +49,15 @@ public class CatalogAggregatorImpl implements Catalog { Item[] catalog = new Item[fruits.length + vegetables.length]; int i =0; for (Item item: fruits) { - double price = Double.valueOf(item.getPrice().substring(1)); + double price = item.getPrice(); price = currencyConverter.getConversion("USD", currencyCode, price); - catalog[i++] = new Item(item.getName(), currencySymbol + price); + catalog[i++] = new Item(item.getName(), currencyCode, currencySymbol, price); } for (Item item: vegetables) { - double price = Double.valueOf(item.getPrice().substring(1)); + double price = item.getPrice(); price = currencyConverter.getConversion("USD", currencyCode, price); - catalog[i++] = new Item(item.getName(), currencySymbol + price); + catalog[i++] = new Item(item.getName(), currencyCode, currencySymbol, price); } return catalog; diff --git a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/FruitsCatalogImpl.java b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/FruitsCatalogImpl.java index 5290623487..c480991ef7 100644 --- a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/FruitsCatalogImpl.java +++ b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/FruitsCatalogImpl.java @@ -14,6 +14,7 @@ import org.oasisopen.sca.annotation.Service; public class FruitsCatalogImpl implements Catalog { @Property public String currencyCode = "USD"; + @Reference public CurrencyConverter currencyConverter; @@ -22,12 +23,9 @@ public class FruitsCatalogImpl implements Catalog { @Init public void init() { String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); - catalog.add(new Item("Apple", currencySymbol - + currencyConverter.getConversion("USD", currencyCode, 2.99))); - catalog.add(new Item("Orange", currencySymbol - + currencyConverter.getConversion("USD", currencyCode, 3.55))); - catalog.add(new Item("Pear", currencySymbol - + currencyConverter.getConversion("USD", currencyCode, 1.55))); + catalog.add(new Item("Apple", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 1.55))); } public Item[] get() { diff --git a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/Item.java b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/Item.java index 74e7239a20..c4397835ba 100644 --- a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/Item.java +++ b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/Item.java @@ -25,13 +25,17 @@ public class Item implements Serializable { private static final long serialVersionUID = -5847326138627338217L; private String name; - private String price; + private String currencyCode; + private String currencySymbol; + private double price; public Item() { } - public Item(String name, String price) { + public Item(String name, String currencyCode, String currencySymbol, double price) { this.name = name; + this.currencyCode = currencyCode; + this.currencySymbol = currencySymbol; this.price = price; } @@ -43,11 +47,27 @@ public class Item implements Serializable { this.name = name; } - public String getPrice() { + public String getCurrencyCode() { + return this.currencyCode; + } + + public void setCurrencyCode(String currencyCode) { + this.currencyCode = currencyCode; + } + + public String getCurrencySymbol() { + return this.currencySymbol; + } + + public void setCurrencySymbol(String currencySymbol) { + this.currencySymbol = currencySymbol; + } + + public double getPrice() { return price; } - public void setPrice(String price) { + public void setPrice(double price) { this.price = price; } } diff --git a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/ShoppingCartImpl.java b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/ShoppingCartImpl.java index 000e205948..febcc3a78f 100644 --- a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/ShoppingCartImpl.java +++ b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/ShoppingCartImpl.java @@ -99,10 +99,10 @@ public class ShoppingCartImpl implements ShoppingCart { String currencySymbol = ""; if (!cart.isEmpty()) { Item item = cart.values().iterator().next(); - currencySymbol = item.getPrice().substring(0, 1); + currencySymbol = item.getCurrencySymbol(); } for (Item item : cart.values()) { - total += Double.valueOf(item.getPrice().substring(1)); + total += item.getPrice(); } return currencySymbol + String.valueOf(total); } diff --git a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/VegetablesCatalogImpl.java b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/VegetablesCatalogImpl.java index 6ca311b42e..e7ae507dd4 100644 --- a/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/VegetablesCatalogImpl.java +++ b/sandbox/sca-cloud-tutorial/store-assets/src/main/java/services/VegetablesCatalogImpl.java @@ -39,9 +39,9 @@ public class VegetablesCatalogImpl implements Catalog { @Init public void init() { String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); - catalog.add(new Item("Broccoli", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99))); - catalog.add(new Item("Asparagus", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55))); - catalog.add(new Item("Cauliflower", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55))); + catalog.add(new Item("Broccoli", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Asparagus", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Cauliflower", currencyCode, currencySymbol, currencyConverter.getConversion("USD", currencyCode, 1.55))); } public Item[] get() { |