Updating store with new vegetables catalog and adding basic support for shoppingCart services using JSON-RPC
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f60bcd37dc
commit
a6e0a1a959
18 changed files with 480 additions and 48 deletions
|
@ -1,9 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="war/WEB-INF/lib/tuscany-sca-api-2.0-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="output" path="war/WEB-INF/classes"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="war/WEB-INF/lib/tuscany-sca-api-2.0-SNAPSHOT.jar"/>
|
||||
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/tuscany-cloud-api"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/tuscany-cloud-google"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/tuscany-data-api"/>
|
||||
<classpathentry kind="output" path="war/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
||||
|
|
|
@ -21,19 +21,24 @@
|
|||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.appengine.eclipse.core.projectValidator</name>
|
||||
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
|
||||
<name>com.google.appengine.eclipse.core.enhancerbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.google.appengine.eclipse.core.projectValidator</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
|
||||
<nature>com.google.gdt.eclipse.core.webAppNature</nature>
|
||||
<nature>com.google.appengine.eclipse.core.gaeNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#Thu Oct 15 18:16:29 PDT 2009
|
||||
#Sun Oct 18 17:07:56 PDT 2009
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.2.6.jar|appengine-api-labs-1.2.6.jar|datanucleus-appengine-1.0.3.jar|datanucleus-core-1.1.5.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar
|
||||
ormEnhancementInclusions=
|
||||
|
|
|
@ -35,7 +35,19 @@
|
|||
<artifactId>tuscany-sca-api</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-cloud-api</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-cloud-google</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-implementation-java-runtime</artifactId>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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> {
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -1,7 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
|
||||
<application>tuscany-store</application>
|
||||
<version>1</version>
|
||||
<version>3</version>
|
||||
|
||||
<!-- Configure java.util.logging -->
|
||||
<system-properties>
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
#
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
# A default java.util.logging configuration.
|
||||
# (All App Engine logging is through java.util.logging by default).
|
||||
#
|
||||
|
@ -12,21 +32,6 @@
|
|||
# Set the default logging level for all loggers to WARNING
|
||||
.level = WARNING
|
||||
|
||||
# Set the default logging level for ORM, specifically, to WARNING
|
||||
DataNucleus.JDO.level=WARNING
|
||||
DataNucleus.Persistence.level=WARNING
|
||||
DataNucleus.Cache.level=WARNING
|
||||
DataNucleus.MetaData.level=WARNING
|
||||
DataNucleus.General.level=WARNING
|
||||
DataNucleus.Utility.level=WARNING
|
||||
DataNucleus.Transaction.level=WARNING
|
||||
DataNucleus.Datastore.level=WARNING
|
||||
DataNucleus.ClassLoading.level=WARNING
|
||||
DataNucleus.Plugin.level=WARNING
|
||||
DataNucleus.ValueGeneration.level=WARNING
|
||||
DataNucleus.Enhancer.level=WARNING
|
||||
DataNucleus.SchemaTool.level=WARNING
|
||||
|
||||
#tuscany debug messages
|
||||
org.apache.tuscany.level=WARNING
|
||||
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<!DOCTYPE web-app
|
||||
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Store</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<title>Online Store - Powered by Apache Tuscany</title>
|
||||
|
||||
<script type="text/javascript" src="dojo/dojo/dojo.js"></script>
|
||||
|
||||
|
@ -11,6 +30,10 @@
|
|||
<script language="JavaScript">
|
||||
|
||||
var catalog = new dojo.rpc.JsonService("/catalogAggregator?smd");
|
||||
|
||||
var shoppingCart = new dojo.rpc.JsonService("/shoppingCart/Cart?smd");
|
||||
|
||||
var shoppingTotal = new dojo.rpc.JsonService("/shoppingCart/Total?smd");
|
||||
|
||||
var catalogItems;
|
||||
|
||||
|
@ -25,9 +48,76 @@
|
|||
catalogItems = items;
|
||||
}
|
||||
|
||||
// This handles the response from shoppingCart.getAll
|
||||
// which is a collection of Entry<K,D>
|
||||
function shoppingCart_getResponse(items) {
|
||||
var list='';
|
||||
for (var i=0; i<items.length; i++) {
|
||||
//get the actual item, that is Entry.data
|
||||
var item = items[i].data;
|
||||
// process its attributes
|
||||
var name = item.name;
|
||||
var price = item.price
|
||||
list += name + ' - ' + price + ' <br>';
|
||||
}
|
||||
document.getElementById("shoppingCart").innerHTML = list;
|
||||
|
||||
if (items.length != 0) {
|
||||
try {
|
||||
shoppingTotal.getTotal().addCallback(shoppingTotal_getTotalResponse);
|
||||
}
|
||||
catch(e){
|
||||
alert(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function shoppingTotal_getTotalResponse(total,exception) {
|
||||
if(exception) {
|
||||
alert(exception.message);
|
||||
return;
|
||||
}
|
||||
document.getElementById('total').innerHTML = total;
|
||||
}
|
||||
|
||||
function shoppingCart_postResponse(entry) {
|
||||
shoppingCart.getAll().addCallback(shoppingCart_getResponse);
|
||||
}
|
||||
|
||||
function addToCart() {
|
||||
var items = document.catalogForm.items;
|
||||
var j = 0;
|
||||
for (var i=0; i<items.length; i++)
|
||||
if (items[i].checked) {
|
||||
shoppingCart.post("", catalogItems[i]).addCallback(shoppingCart_postResponse);
|
||||
items[i].checked = false;
|
||||
}
|
||||
}
|
||||
function checkoutCart() {
|
||||
document.getElementById('store').innerHTML='<h2>' +
|
||||
'Thanks for Shopping With Us!</h2>'+
|
||||
'<h2>Your Order</h2>'+
|
||||
'<form name="orderForm">'+
|
||||
document.getElementById('shoppingCart').innerHTML+
|
||||
'<br>'+
|
||||
document.getElementById('total').innerHTML+
|
||||
'<br>'+
|
||||
'<br>'+
|
||||
'<input type="submit" value="Continue Shopping">'+
|
||||
'</form>';
|
||||
shoppingCart.del("");
|
||||
}
|
||||
function deleteCart() {
|
||||
shoppingCart.del("");
|
||||
document.getElementById('shoppingCart').innerHTML = "";
|
||||
document.getElementById('total').innerHTML = "";
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
try {
|
||||
catalog.get().addCallback(catalog_getResponse);
|
||||
shoppingCart.get("").addCallback(shoppingCart_getResponse);
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
}
|
||||
|
@ -44,10 +134,22 @@
|
|||
<h2>Catalog</h2>
|
||||
<form name="catalogForm">
|
||||
<div id="catalog" ></div>
|
||||
<br>
|
||||
<br>
|
||||
<input type="button" onClick="addToCart()" value="Add to Cart">
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<br>
|
||||
|
||||
<h2>Your Shopping Cart</h2>
|
||||
<form name="shoppingCartForm">
|
||||
<div id="shoppingCart"></div>
|
||||
<br>
|
||||
<div id="total"></div>
|
||||
<br>
|
||||
<input type="button" onClick="checkoutCart()" value="Checkout">
|
||||
<input type="button" onClick="deleteCart()" value="Empty">
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue