You are viewing a plain text version of this content. The canonical link for it is here.
Posted to nuvem-commits@incubator.apache.org by js...@apache.org on 2010/12/27 06:23:29 UTC
svn commit: r1053005 - in /incubator/nuvem/trunk:
nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/
store-appengine-webapp/src/services/ store-appengine-webapp/war/
store-assets/ store-assets/src/main/java/services/
Author: jsdelfino
Date: Mon Dec 27 06:23:28 2010
New Revision: 1053005
URL: http://svn.apache.org/viewvc?rev=1053005&view=rev
Log:
Apply John's patch from JIRA issue NUVEM-7. Modifications to the XMPP API and store sample.
Added:
incubator/nuvem/trunk/store-assets/src/main/java/services/Address.java
incubator/nuvem/trunk/store-assets/src/main/java/services/Event.java
incubator/nuvem/trunk/store-assets/src/main/java/services/Location.java
incubator/nuvem/trunk/store-assets/src/main/java/services/LocationCode.java
incubator/nuvem/trunk/store-assets/src/main/java/services/Shipment.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentException.java
- copied, changed from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentObserver.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentRegistry.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentService.java
- copied, changed from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentServiceImpl.java
incubator/nuvem/trunk/store-assets/src/main/java/services/TrackingCode.java
- copied, changed from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
incubator/nuvem/trunk/store-assets/src/main/java/services/XMPPShipmentObserver.java
Modified:
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java
incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java
incubator/nuvem/trunk/store-appengine-webapp/src/services/CachedShoppingCartManager.java
incubator/nuvem/trunk/store-appengine-webapp/war/store.composite
incubator/nuvem/trunk/store-appengine-webapp/war/store.html
incubator/nuvem/trunk/store-assets/pom.xml
incubator/nuvem/trunk/store-assets/src/main/java/services/Cart.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartImpl.java
incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartManager.java
Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java Mon Dec 27 06:23:28 2010
@@ -20,12 +20,19 @@
package org.apache.nuvem.cloud.xmpp.api;
+import java.io.Serializable;
+
/**
* Contains the error details used.
*/
-public final class Error {
+public final class Error implements Serializable {
/**
+ * serial id.
+ */
+ private static final long serialVersionUID = 234776753829641455L;
+
+ /**
* Description of the error.
*/
private String description;
Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/JID.java Mon Dec 27 06:23:28 2010
@@ -20,6 +20,7 @@
package org.apache.nuvem.cloud.xmpp.api;
+import java.io.Serializable;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
@@ -27,98 +28,124 @@ import org.apache.commons.lang.StringUti
/**
* Represents the XMPP ID.
*/
-public final class JID {
+public final class JID implements Serializable{
- /**
- * The validation pattern for an JID id.
- */
- private static final Pattern VALID_PATTERN = Pattern.compile("^(?:([^@/<>'\"]+)@)?([^@/<>'\"]+)(?:/([^<>'\"]*))?$");
-
- /**
- * To be used instead of null.
- */
- public static final JID UNKNOWN = new JID("unknown@unknown.com");
-
- /**
- * The string form of the JID.
- */
- private String id;
-
- /**
- * Constructor. Validates the id passed as paramter befor initialising.
- *
- * @param id
- */
- public JID(String id) {
- if (id == null || !VALID_PATTERN.matcher(id).matches())
- throw new IllegalArgumentException("invalid JID! please check the format.. ");
- this.id = id;
- }
-
- /**
- * Returns the string representation of the JID.
- *
- * @return
- */
- public String asString() {
- return id;
- }
-
- /**
- * Returns only the domain identifier of the JID.
- *
- * @return
- */
- public String domainIdentifier() {
- return StringUtils.substringBefore(this.id, "@");
- }
-
- /**
- * Returns only the node identifier of this JID.
- *
- * @return the node identifier.
- */
- public String nodeIdentifier() {
- return StringUtils.substringBetween(id, "@", "/");
- }
-
- /**
- * Returns only the resource identifier of the JID.
- *
- * @return the resource identifier.
- */
- public String resourceIdentifier() {
- return StringUtils.substringAfter(id, "/");
- }
-
- /**
- * Just to make the equality check more descriptive and meaningful.
- *
- * @param jid the jid to which this jid is compared with.
- * @return true if both the jid are same, false otherwise.
- */
- public boolean isSameAs(JID jid) {
- return this.equals(jid);
- }
-
- /**
- * .
- */
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (!(o instanceof JID))
- return false;
-
- final JID jid = (JID)o;
-
- return id.equals(jid.id);
- }
-
- /**
- */
- public int hashCode() {
- return id.hashCode();
- }
+ /**
+ * serial id.
+ */
+ private static final long serialVersionUID = -5954050237038799970L;
+
+ /**
+ * The validation pattern for an JID id.
+ */
+ private static final Pattern VALID_PATTERN = Pattern
+ .compile("^(?:([^@/<>'\"]+)@)?([^@/<>'\"]+)(?:/([^<>'\"]*))?$");
+
+ /**
+ * To be used instead of null.
+ */
+ public static final JID UNKNOWN = new JID("unknown@unknown.com");
+
+ /**
+ * The string form of the JID.
+ */
+ private String id;
+
+ /**
+ * No argument constructor for supporting frameworks like tuscany.
+ */
+ public JID() {
+
+ }
+
+ /**
+ * A setter method for usage if default constructor is prefered.
+ * @param id the jid string.
+ */
+ public void setId(String id) {
+ if (id == null || !VALID_PATTERN.matcher(id).matches())
+ throw new IllegalArgumentException(
+ "invalid JID! please check the format.. ");
+ this.id = id;
+ }
+
+ /**
+ * Constructor. Validates the id passed as paramter befor initialising.
+ *
+ * @param id
+ */
+ public JID(String id) {
+ if (id == null || !VALID_PATTERN.matcher(id).matches())
+ throw new IllegalArgumentException(
+ "invalid JID! please check the format.. ");
+ this.id = id;
+ }
+
+ /**
+ * Returns the string representation of the JID.
+ *
+ * @return
+ */
+ public String asString() {
+ return id;
+ }
+
+ /**
+ * Returns only the domain identifier of the JID.
+ *
+ * @return
+ */
+ public String domainIdentifier() {
+ return StringUtils.substringBefore(this.id, "@");
+ }
+
+ /**
+ * Returns only the node identifier of this JID.
+ *
+ * @return the node identifier.
+ */
+ public String nodeIdentifier() {
+ return StringUtils.substringBetween(id, "@", "/");
+ }
+
+ /**
+ * Returns only the resource identifier of the JID.
+ *
+ * @return the resource identifier.
+ */
+ public String resourceIdentifier() {
+ return StringUtils.substringAfter(id, "/");
+ }
+
+ /**
+ * Just to make the equality check more descriptive and meaningful.
+ *
+ * @param jid
+ * the jid to which this jid is compared with.
+ * @return true if both the jid are same, false otherwise.
+ */
+ public boolean isSameAs(JID jid) {
+ return this.equals(jid);
+ }
+
+ /**
+ * .
+ */
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof JID))
+ return false;
+
+ final JID jid = (JID) o;
+
+ return id.equals(jid.id);
+ }
+
+ /**
+ */
+ public int hashCode() {
+ return id.hashCode();
+ }
}
Modified: incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java (original)
+++ incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Message.java Mon Dec 27 06:23:28 2010
@@ -20,6 +20,7 @@
package org.apache.nuvem.cloud.xmpp.api;
+import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -31,9 +32,14 @@ import org.apache.commons.lang.builder.H
* Encapsulates the complete message that needs to be delivered through the XMPP
* channel.
*/
-public final class Message {
+public final class Message implements Serializable {
/**
+ * serial id.
+ */
+ private static final long serialVersionUID = -4166419962507943317L;
+
+ /**
* to be used instead of null.
*/
public static final Message EMPTY_MESSAGE = new Message(PayLoad.EMPTY, JID.UNKNOWN, JID.UNKNOWN);
Modified: incubator/nuvem/trunk/store-appengine-webapp/src/services/CachedShoppingCartManager.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-appengine-webapp/src/services/CachedShoppingCartManager.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-appengine-webapp/src/services/CachedShoppingCartManager.java (original)
+++ incubator/nuvem/trunk/store-appengine-webapp/src/services/CachedShoppingCartManager.java Mon Dec 27 06:23:28 2010
@@ -19,18 +19,23 @@
package services;
+import java.util.ArrayList;
+
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
+
import net.sf.jsr107cache.Cache;
import net.sf.jsr107cache.CacheManager;
import org.apache.nuvem.cloud.user.User;
import org.apache.nuvem.cloud.user.UserService;
+import org.apache.nuvem.cloud.xmpp.api.JID;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.oasisopen.sca.annotation.Init;
@@ -46,6 +51,9 @@ public class CachedShoppingCartManager i
private Cache cache;
+ @Reference
+ private ShipmentService shipmentService;
+
@Init
public void init() {
try {
@@ -187,4 +195,16 @@ public class CachedShoppingCartManager i
return cartMap;
}
+
+ @Override
+ public String shipItems(String jid) {
+ List<Item> items = new ArrayList<Item>();
+ items.addAll(getUserItems().values());
+ try {
+ return shipmentService.shipItemsAndRegisterForUpdates(
+ Address.DUMMY_ADDRESS, new JID(jid), items);
+ } catch (ShipmentException e) {
+ return "shipment error";
+ }
+ }
}
Modified: incubator/nuvem/trunk/store-appengine-webapp/war/store.composite
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-appengine-webapp/war/store.composite?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-appengine-webapp/war/store.composite (original)
+++ incubator/nuvem/trunk/store-appengine-webapp/war/store.composite Mon Dec 27 06:23:28 2010
@@ -1,35 +1,28 @@
<?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.
--->
+ <!--
+ * 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.
+ -->
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
- xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:s="http://store"
- targetNamespace="http://store"
- name="store">
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:s="http://store" targetNamespace="http://store" name="store">
<component name="Catalog">
- <implementation.java class="services.FruitsCatalogImpl"/>
+ <implementation.java class="services.FruitsCatalogImpl" />
<property name="currencyCode">USD</property>
<service name="Catalog">
- <interface.java interface="services.Catalog"/>
- <tuscany:binding.jsonrpc uri="/Catalog"/>
+ <interface.java interface="services.Catalog" />
+ <tuscany:binding.jsonrpc uri="/Catalog" />
</service>
<reference name="currencyConverter" target="CurrencyConverter" />
</component>
@@ -37,31 +30,54 @@
<component name="CurrencyConverter">
<implementation.java class="services.CurrencyConverterImpl" />
<service name="CurrencyConverter">
- <interface.java interface="services.CurrencyConverter"/>
+ <interface.java interface="services.CurrencyConverter" />
</service>
</component>
<component name="ShoppingCartManager">
- <implementation.java class="services.ShoppingCartManager"/>
+ <implementation.java class="services.ShoppingCartManager" />
<service name="ShoppingCart">
- <tuscany:binding.jsonrpc uri="/ShoppingCart"/>
+ <tuscany:binding.jsonrpc uri="/ShoppingCart" />
</service>
<reference name="userService" target="UserService">
- <binding.sca name="local"/>
+ <binding.sca name="local" />
</reference>
+ <reference name="shipmentService" target="ShipmentService" />
<reference name="documentService" target="DocumentService" />
</component>
<component name="DocumentService">
- <implementation.java class="org.apache.nuvem.cloud.data.impl.MapDocumentServiceImpl" />
- <!-- implementation.java class="org.apache.nuvem.cloud.data.impl.MemcacheDocumentServiceImpl"/-->
+ <implementation.java
+ class="org.apache.nuvem.cloud.data.impl.MapDocumentServiceImpl" />
+ <!--
+ implementation.java
+ class="org.apache.nuvem.cloud.data.impl.MemcacheDocumentServiceImpl"/
+ -->
</component>
<component name="UserService">
- <implementation.java class="org.apache.nuvem.cloud.user.impl.GoogleUserService"/>
+ <implementation.java
+ class="org.apache.nuvem.cloud.user.impl.GoogleUserService" />
<service name="UserService">
- <binding.sca name="local"/>
- <tuscany:binding.jsonrpc uri="/User"/>
+ <binding.sca name="local" />
+ <tuscany:binding.jsonrpc uri="/User" />
</service>
</component>
+
+ <component name="XMPPEndpoint">
+ <implementation.java
+ class="org.apache.nuvem.cloud.xmpp.impl.GoogleXMPPEndPoint" />
+ </component>
+
+ <component name="ShipmentObserver">
+ <implementation.java class="services.XMPPShipmentObserver" />
+ <reference name="endpoint" target="XMPPEndpoint" />
+ </component>
+
+ <component name="ShipmentService">
+ <implementation.java class="services.ShipmentServiceImpl" />
+ <reference name="observer" target="ShipmentObserver" />
+ </component>
+
+
</composite>
Modified: incubator/nuvem/trunk/store-appengine-webapp/war/store.html
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-appengine-webapp/war/store.html?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-appengine-webapp/war/store.html (original)
+++ incubator/nuvem/trunk/store-appengine-webapp/war/store.html Mon Dec 27 06:23:28 2010
@@ -122,6 +122,8 @@
}
}
function checkoutCart() {
+ var jid = document.getElementById('jidToNotify').value;
+ alert(jid);
document.getElementById('store').innerHTML='<h2>' +
'Thanks for Shopping With Us!</h2>'+
'<h2>Your Order</h2>'+
@@ -133,7 +135,7 @@
'<br>'+
'<input type="submit" value="Continue Shopping">'+
'</form>';
- shoppingCart.delete("");
+ shoppingCart.shipItems(jid);
}
function deleteCart() {
shoppingCart.delete("");
@@ -161,34 +163,34 @@
</head>
<body onload="init()">
- <div id="appHeader" class="header">
- </div>
+<div id="appHeader" class="header"></div>
- <h1>Store</h1>
+<h1>Store</h1>
- <div id="store">
- <h2>Catalog</h2>
- <form name="catalogForm">
- <div id="catalog" ></div>
- <br>
- <input type="button" onClick="addToCart()" value="Add to Cart">
- </form>
-
-
- <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>
+<div id="store">
+<h2>Catalog</h2>
+<form name="catalogForm">
+<div id="catalog"></div>
+<br>
+<input type="button" onClick="addToCart()" value="Add to Cart">
+</form>
+
+
+<br>
+
+<h2>Your Shopping Cart</h2>
+<form name="shoppingCartForm">
+<div id="shoppingCart"></div>
+<br>
+<div id="total"></div>
+<br>
+Enter your JID to recieve instant updates : <input type="text"
+ id="jidToNotify"> <br> <input type="button" onClick="checkoutCart()"
+ value="Checkout"> <input type="button" onClick="deleteCart()"
+ value="Empty"></form>
+</div>
</body>
</html>
\ No newline at end of file
Modified: incubator/nuvem/trunk/store-assets/pom.xml
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/pom.xml?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-assets/pom.xml (original)
+++ incubator/nuvem/trunk/store-assets/pom.xml Mon Dec 27 06:23:28 2010
@@ -49,7 +49,13 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-sca-api</artifactId>
<version>${tuscany.version}</version>
- </dependency>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.2</version>
+ </dependency>
</dependencies>
</project>
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/Address.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/Address.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/Address.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/Address.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,104 @@
+/*
+ * 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.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+public class Address {
+
+ public static final Address DUMMY_ADDRESS = new Address("245",
+ Location.UNKNOWN, Location.UNKNOWN, Location.UNKNOWN);
+
+ private String door;
+
+ private Location street;
+
+ private Location city;
+
+ private Location country;
+
+ /**
+ * To support tuscany.
+ */
+ public Address() {
+
+ }
+
+ public Address(String door, Location street, Location city, Location country) {
+ this.door = door;
+ this.street = street;
+ this.city = city;
+ this.country = country;
+ }
+
+ public String getDoor() {
+ return door;
+ }
+
+ public void setDoor(String door) {
+ this.door = door;
+ }
+
+ public Location getStreet() {
+ return street;
+ }
+
+ public void setStreet(Location street) {
+ this.street = street;
+ }
+
+ public Location getCity() {
+ return city;
+ }
+
+ public void setCity(Location city) {
+ this.city = city;
+ }
+
+ public Location getCountry() {
+ return country;
+ }
+
+ public void setCountry(Location country) {
+ this.country = country;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final Address rhs = (Address) o;
+
+ return new EqualsBuilder().append(this.door, rhs.door).append(
+ this.city, rhs.city).append(this.country, rhs.country)
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(door).append(city).append(country)
+ .toHashCode();
+ }
+}
Modified: incubator/nuvem/trunk/store-assets/src/main/java/services/Cart.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/Cart.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/Cart.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/Cart.java Mon Dec 27 06:23:28 2010
@@ -74,4 +74,10 @@ public interface Cart {
* @param key
*/
void delete(String key) throws NotFoundException;
+
+ /**
+ * Ships the items selected in the shopping cart. this will be called in a
+ * secure manner after the payment process.
+ */
+ String shipItems(String jid);
}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/Event.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/Event.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/Event.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/Event.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,132 @@
+/*
+ * 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.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+public class Event {
+
+ private Location loacationBeforeEvent = Location.UNKNOWN;
+
+ private Location loacationAfterEvent = Location.UNKNOWN;
+
+ private Type type;
+
+ private Shipment eventFor;
+
+ private static void generateAndTriggerEvent(Shipment shipment,
+ Location currentLocation, Type type) {
+ Event event = new Event();
+ event.loacationBeforeEvent = shipment.getCurrentLocation();
+ event.loacationAfterEvent = currentLocation;
+ event.type = type;
+ event.eventFor = shipment;
+ shipment.updateStatus(event);
+ }
+
+ public Shipment eventFor() {
+ return eventFor;
+ }
+
+ public static void newShipment(Shipment shipment) {
+ generateAndTriggerEvent(shipment, shipment.getCurrentLocation(), Type.READY);
+ }
+
+ public static void updateShipment(Shipment shipment,
+ Location currentLocation) {
+ generateAndTriggerEvent(shipment, currentLocation, Type.INPROGRESS);
+ }
+
+ public static void triggerCancellation(Shipment shipment,
+ Location currentLocation) {
+ generateAndTriggerEvent(shipment, currentLocation, Type.CANCELED);
+ }
+
+ public static void triggerDeliverySuccessful(Shipment shipment,
+ Location currentLocation) {
+ generateAndTriggerEvent(shipment, currentLocation, Type.DELIVERED);
+ }
+
+ public Type type() {
+ return type;
+ }
+
+ public Location loacationAfterEvent() {
+ return loacationAfterEvent;
+ }
+
+ public Location loacationBeforeEvent() {
+ return loacationBeforeEvent;
+ }
+
+ public static enum Type {
+ READY, INPROGRESS, ONHOLD, CANCELED, DELIVERED;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final Event rhs = (Event) o;
+
+ return new EqualsBuilder().append(this.loacationBeforeEvent,
+ rhs.loacationBeforeEvent).append(this.loacationAfterEvent,
+ rhs.loacationAfterEvent).append(this.type, rhs.type).isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder().append(loacationBeforeEvent).append(
+ loacationBeforeEvent).append(type).toHashCode();
+ }
+
+ @Override
+ public String toString() {
+ String description = null;
+ switch (type) {
+ case READY:
+ description = "shipment ready for the voyage from : "
+ + this.loacationBeforeEvent;
+ break;
+ case INPROGRESS:
+ description = "shipmet moved from location: "
+ + this.loacationBeforeEvent + " to location: "
+ + this.loacationAfterEvent;
+ break;
+ case ONHOLD:
+ description = "shipment put on hold at location: "
+ + this.loacationBeforeEvent;
+ break;
+ case CANCELED:
+ description = "shipment canceled at: " + this.loacationAfterEvent;
+ break;
+ case DELIVERED:
+ description = "shipment delivered to the recipient";
+ }
+ return String.format(
+ "update for Shipment with tracking code: %s -> %s ",
+ this.eventFor.trackingCode(), description);
+ }
+}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/Location.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/Location.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/Location.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/Location.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+public class Location {
+
+ public static final Location UNKNOWN = new Location("unknown",
+ LocationCode.DUMMY);
+
+ private LocationCode code;
+
+ private String name;
+
+ /**
+ * To support tuscany.
+ */
+ public Location() {
+
+ }
+
+ public Location(String name, LocationCode code) {
+ if (code == null)
+ throw new IllegalArgumentException("location code cannot be null");
+ this.code = code;
+ this.name = name;
+ }
+
+ public LocationCode getCode() {
+ return code;
+ }
+
+ public void setCode(LocationCode code) {
+ this.code = code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final Location other = (Location) o;
+
+ return other.code != null && other.code.equals(this.code);
+ }
+
+ @Override
+ public int hashCode() {
+ return code.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return this.code.code();
+ }
+}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/LocationCode.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/LocationCode.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/LocationCode.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/LocationCode.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+/**
+ * Holds the unique location codes
+ *
+ */
+public class LocationCode {
+
+ public static final LocationCode DUMMY = new LocationCode("EX31617");
+ private String code;
+
+ /**
+ * To support tuscany.
+ */
+ public LocationCode() {
+
+ }
+
+ public LocationCode(String code) {
+ if (code == null)
+ throw new IllegalArgumentException(
+ "code cannot be null for constructing location code");
+ this.code = code;
+ }
+
+ public String code() {
+ return code;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ final LocationCode other = (LocationCode) o;
+
+ return other.code != null && other.code.equals(this.code);
+ }
+
+ @Override
+ public int hashCode() {
+ return code.hashCode();
+ }
+}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/Shipment.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/Shipment.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/Shipment.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/Shipment.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,101 @@
+/*
+ * 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.Collections;
+import java.util.List;
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+
+import services.Item;
+import services.ShipmentObserver;
+
+public class Shipment {
+
+ private TrackingCode code;
+
+ private List<Item> items;
+
+ private Address deliveryAddress;
+
+ private JID jidToUpdate;
+
+ private List<Event> history = new ArrayList<Event>();
+
+ private Location currentLocation;
+
+ private List<ShipmentObserver> observers = new ArrayList<ShipmentObserver>();
+
+ public Shipment(List<Item> items, Address address, JID jid) {
+ this.items = new ArrayList<Item>();
+ this.items.addAll(items);
+ this.deliveryAddress = address;
+ this.jidToUpdate = jid;
+ this.currentLocation = new Location("starting location",
+ new LocationCode("STR"));
+ }
+
+ public void startFrom(Location location) {
+ this.currentLocation = location;
+ }
+
+ public void setTrackingCode(TrackingCode code) {
+ this.code = code;
+ }
+
+ public TrackingCode trackingCode() {
+ return code;
+ }
+
+ public List<Item> getItems() {
+ return Collections.unmodifiableList(items);
+ }
+
+ public Address getDeliveryAddress() {
+ return deliveryAddress;
+ }
+
+ public JID getJidToUpdate() {
+ return jidToUpdate;
+ }
+
+ public void updateStatus(Event event) {
+ for (ShipmentObserver observer : observers) {
+ observer.onStatusUpdate(this, event);
+ }
+ this.currentLocation = event.loacationAfterEvent();
+ this.history.add(event);
+ }
+
+ public void addObserver(ShipmentObserver observer) {
+ observers.add(observer);
+ }
+
+ public List<Event> history() {
+ return history;
+ }
+
+ public Location getCurrentLocation() {
+ return currentLocation;
+ }
+
+}
Copied: incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentException.java (from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentException.java?p2=incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentException.java&p1=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java&r1=1044457&r2=1053005&rev=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentException.java Mon Dec 27 06:23:28 2010
@@ -7,49 +7,39 @@
* 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.
+ * under the License.
*/
-package org.apache.nuvem.cloud.xmpp.api;
+package services;
/**
- * Contains the error details used.
+ * Signals shipment errors.
+ *
*/
-public final class Error {
+public class ShipmentException extends Exception {
+
+ /**
+ * serial id.
+ */
+ private static final long serialVersionUID = -5237579957873565482L;
+
+ public ShipmentException() {
+
+ }
- /**
- * Description of the error.
- */
- private String description;
-
- /**
- * The actual error code.
- */
- private ErrorCode code;
-
- public Error(ErrorCode code) {
- this.code = code;
- }
-
- public Error(ErrorCode code, String description) {
- this.code = code;
- this.description = description;
- }
-
- public String description() {
- return description;
- }
-
- public ErrorCode code() {
- return code;
- }
+ public ShipmentException(Throwable e) {
+ super(e);
+ }
+ public ShipmentException(String message, Throwable e) {
+ super(message, e);
+ }
}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentObserver.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentObserver.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentObserver.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentObserver.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+public interface ShipmentObserver {
+
+ void onStatusUpdate(Shipment shipment, Event event);
+}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentRegistry.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentRegistry.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentRegistry.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,137 @@
+/*
+ * 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.Map;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+
+/**
+ * Registry/Container for all shipments.
+ *
+ * @author john
+ *
+ */
+public final class ShipmentRegistry {
+
+ private static final Logger log = Logger.getLogger(ShipmentRegistry.class
+ .getName());
+
+ private static final ShipmentRegistry INSTANCE = new ShipmentRegistry();
+
+ private Simulator simulator;
+
+ private Map<TrackingCode, Shipment> shipments = new ConcurrentHashMap<TrackingCode, Shipment>();
+
+ private BlockingQueue<TrackingCode> trackingCodes = new ArrayBlockingQueue<TrackingCode>(
+ 10);
+
+ private ShipmentRegistry() {
+ // simulator = new Simulator(trackingCodes);
+ // new Thread(simulator).start();
+ }
+
+ public static ShipmentRegistry getInstance() {
+ return INSTANCE;
+ }
+
+ public void shipmentHandled(TrackingCode code, Location newLocation) {
+ Shipment shipment = shipments.get(code);
+ Event.updateShipment(shipment, newLocation);
+ }
+
+ public void cancelShipment(TrackingCode trackingCode) {
+ Shipment shipment = shipments.get(trackingCode);
+ Event.triggerCancellation(shipment, shipment.getCurrentLocation());
+ }
+
+ public void markShipmentDelivered(TrackingCode trackingCode) {
+ Shipment shipment = shipments.get(trackingCode);
+ Event.triggerDeliverySuccessful(shipment, shipment.getDeliveryAddress()
+ .getStreet());
+ }
+
+ public String addNewShipment(Shipment shipment) throws ShipmentException {
+ TrackingCode code = TrackingCode.getNewTrackingCode();
+ shipment.setTrackingCode(code);
+ shipments.put(code, shipment);
+ Event.newShipment(shipment);
+ // trackingCodes.add(code);
+
+ // shipment simulation done in the same thread as GAE doesnt allow
+ // creation of threads.
+ shipmentHandled(code, new Location("inter1", new LocationCode("INT1")));
+ try {
+ Thread.sleep(5000);
+
+ shipmentHandled(code, new Location("inter2", new LocationCode(
+ "INT2")));
+ Thread.sleep(5000);
+ shipmentHandled(code, new Location("inter3", new LocationCode(
+ "INT3")));
+ Thread.sleep(5000);
+ shipmentHandled(code, new Location("inter4", new LocationCode(
+ "INT4")));
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ // TODO:fix me
+ log.severe("error during shipment");
+ throw new ShipmentException("shipment error", e);
+ }
+ markShipmentDelivered(code);
+ return code.toString();
+ }
+
+ public static class Simulator implements Runnable {
+
+ private BlockingQueue<TrackingCode> codes;
+
+ Simulator(BlockingQueue<TrackingCode> queue) {
+ codes = queue;
+ }
+
+ public void run() {
+ TrackingCode codeToProcess;
+ try {
+ while (true) {
+ codeToProcess = codes.take();
+ ShipmentRegistry registry = ShipmentRegistry.getInstance();
+ registry.shipmentHandled(codeToProcess, new Location(
+ "inter1", new LocationCode("INT1")));
+ Thread.sleep(5000);
+ registry.shipmentHandled(codeToProcess, new Location(
+ "inter2", new LocationCode("INT2")));
+ Thread.sleep(5000);
+ registry.shipmentHandled(codeToProcess, new Location(
+ "inter3", new LocationCode("INT3")));
+ Thread.sleep(5000);
+ registry.shipmentHandled(codeToProcess, new Location(
+ "inter4", new LocationCode("INT4")));
+ Thread.sleep(5000);
+ registry.markShipmentDelivered(codeToProcess);
+ }
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+}
Copied: incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentService.java (from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentService.java?p2=incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentService.java&p1=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java&r1=1044457&r2=1053005&rev=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentService.java Mon Dec 27 06:23:28 2010
@@ -7,49 +7,42 @@
* 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.
+ * under the License.
*/
-package org.apache.nuvem.cloud.xmpp.api;
+package services;
+
+import java.util.List;
+
+
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+import org.oasisopen.sca.annotation.Remotable;
/**
- * Contains the error details used.
+ * Business process service for shipment.
+ *
*/
-public final class Error {
-
- /**
- * Description of the error.
- */
- private String description;
-
- /**
- * The actual error code.
- */
- private ErrorCode code;
-
- public Error(ErrorCode code) {
- this.code = code;
- }
-
- public Error(ErrorCode code, String description) {
- this.code = code;
- this.description = description;
- }
-
- public String description() {
- return description;
- }
-
- public ErrorCode code() {
- return code;
- }
+@Remotable
+public interface ShipmentService {
+ /**
+ * Ships the items to the corresponding address
+ *
+ * @param to
+ * the address to which the item needs to be delivered.
+ * @param items
+ * the items to be shipped.
+ * @return a unique tracking id.
+ */
+ String shipItemsAndRegisterForUpdates(Address to, JID jid, List<Item> items)
+ throws ShipmentException;
}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentServiceImpl.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentServiceImpl.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShipmentServiceImpl.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,51 @@
+/*
+ * 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.List;
+import java.util.logging.Logger;
+
+import org.apache.nuvem.cloud.xmpp.api.JID;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class ShipmentServiceImpl implements ShipmentService {
+
+ private static final Logger log = Logger
+ .getLogger(ShipmentServiceImpl.class.getName());
+
+ private static final Location STARTING_LOCATION = new Location("starting1",
+ new LocationCode("START1"));
+
+ @Reference
+ private ShipmentObserver observer;
+
+ public String shipItemsAndRegisterForUpdates(Address to, JID jid,
+ List<Item> items) throws ShipmentException {
+ Shipment shipment = new Shipment(items, to, jid);
+ shipment.startFrom(STARTING_LOCATION);
+ shipment.addObserver(observer);
+ log.info("preparing shipment...");
+ return ShipmentRegistry.getInstance().addNewShipment(shipment);
+ }
+
+}
Modified: incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartImpl.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartImpl.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartImpl.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartImpl.java Mon Dec 27 06:23:28 2010
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
+import org.apache.commons.lang.StringUtils;
import org.apache.nuvem.cloud.data.DocumentService;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.NotFoundException;
@@ -110,4 +111,9 @@ public class ShoppingCartImpl implements
}
return currencySymbol + String.valueOf(total);
}
+
+ @Override
+ public String shipItems(String jid) {
+ return StringUtils.EMPTY;
+ }
}
Modified: incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartManager.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartManager.java?rev=1053005&r1=1053004&r2=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartManager.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/ShoppingCartManager.java Mon Dec 27 06:23:28 2010
@@ -19,14 +19,18 @@
package services;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
+import org.apache.commons.lang.StringUtils;
import org.apache.nuvem.cloud.data.DocumentService;
import org.apache.nuvem.cloud.user.User;
import org.apache.nuvem.cloud.user.UserService;
+import org.apache.nuvem.cloud.xmpp.api.JID;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.data.collection.NotFoundException;
import org.oasisopen.sca.annotation.Reference;
@@ -34,139 +38,164 @@ import org.oasisopen.sca.annotation.Scop
@Scope("COMPOSITE")
public class ShoppingCartManager implements ShoppingCart {
- private static final Logger log = Logger.getLogger(ShoppingCartManager.class.getName());
- private static String ANONYMOUS = "anonymous";
+ private static final Logger log = Logger
+ .getLogger(ShoppingCartManager.class.getName());
+ private static String ANONYMOUS = "anonymous";
+
+ @Reference
+ private DocumentService documentService;
+
+ @Reference
+ private UserService userService;
+
+ @Reference
+ private ShipmentService shipmentService;
+
+ public Entry<String, Item>[] getAll() {
+ Map<String, Item> cart = getUserShoppingCart();
+
+ 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 {
+ Map<String, Item> cart = getUserShoppingCart();
+
+ Item item = cart.get(key);
+ if (item == null) {
+ throw new NotFoundException(key);
+ } else {
+ return item;
+ }
+ }
+
+ public String post(String key, Item item) {
+ Map<String, Item> cart = getUserShoppingCart();
+
+ if (key == null || key.isEmpty()) {
+ key = this.generateItemKey();
+ }
+
+ // add to the cart map
+ cart.put(key, item);
+ // add back to the store
+ documentService.post(getCartKey(), cart);
+ return key;
+ }
+
+ public void put(String key, Item item) throws NotFoundException {
+ Map<String, Item> cart = getUserShoppingCart();
+
+ if (!cart.containsKey(key)) {
+ throw new NotFoundException(key);
+ }
+ // add to the cart map
+ cart.put(key, item);
+ // add back to the store
+ documentService.put(getCartKey(), cart);
+ }
+
+ public void delete(String key) throws NotFoundException {
+ if (key == null || key.isEmpty()) {
+ documentService.delete(getCartKey());
+ } else {
+ Map<String, Item> cart = getUserShoppingCart();
+
+ Item item = cart.remove(key);
+ if (item == null) {
+ throw new NotFoundException(key);
+ }
+ documentService.put(getCartKey(), cart);
+ }
+ }
+
+ public Entry<String, Item>[] query(String queryString) {
+ throw new UnsupportedOperationException("Operation not supported !");
+ }
+
+ public String getTotal() {
+ double total = 0;
+ String currencySymbol = "";
+
+ Map<String, Item> cart = getUserShoppingCart();
+ if (!cart.isEmpty()) {
+ Item item = cart.values().iterator().next();
+ currencySymbol = item.getCurrencySymbol();
+ }
+ for (Item item : cart.values()) {
+ total += item.getPrice();
+ }
+
+ return currencySymbol + String.valueOf(total);
+ }
+
+ /**
+ * Utility functions
+ */
+
+ private Map<String, Item> getUserShoppingCart() {
+ String userCartKey = getCartKey();
+ HashMap<String, Item> cart;
+
+ try {
+ cart = (HashMap<String, Item>) documentService.get(userCartKey);
+ } catch (NotFoundException e) {
+ cart = new HashMap<String, Item>();
+ documentService.post(userCartKey, cart);
+ }
+
+ return cart;
+ }
+
+ 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;
+ }
+ return userId;
+ }
+
+ private String getCartKey() {
+ String cartKey = "cart-" + this.getUserId();
+ return cartKey;
+ }
+
+ private String generateItemKey() {
+ String itemKey = getCartKey() + "-item-" + UUID.randomUUID().toString();
+ return itemKey;
+ }
+
+ @Override
+ public String shipItems(String jid) {
+ if (getUserShoppingCart() == null || getUserShoppingCart().isEmpty())
+ return StringUtils.EMPTY;
+ if (jid == null) {
+ log
+ .warning("using current user's email address for shipment updates");
+ jid = userService.getCurrentUser().getEmail();
+ }
+ List<Item> items = new ArrayList<Item>();
+ items.addAll(getUserShoppingCart().values());
+ try {
+ return shipmentService.shipItemsAndRegisterForUpdates(
+ Address.DUMMY_ADDRESS, new JID(jid), items);
+ } catch (ShipmentException e) {
+ log.severe("error occured during shipment");
+ return "shipment error";
+ }
- @Reference
- private DocumentService documentService;
-
- @Reference
- private UserService userService;
-
- public Entry<String, Item>[] getAll() {
- Map<String, Item> cart = getUserShoppingCart();
-
- 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 {
- Map<String, Item> cart = getUserShoppingCart();
-
- Item item = cart.get(key);
- if (item == null) {
- throw new NotFoundException(key);
- } else {
- return item;
- }
- }
-
- public String post(String key, Item item) {
- Map<String, Item> cart = getUserShoppingCart();
-
- if (key == null || key.isEmpty()) {
- key = this.generateItemKey();
- }
-
- // add to the cart map
- cart.put(key, item);
- // add back to the store
- documentService.post(getCartKey(), cart);
- return key;
- }
-
- public void put(String key, Item item) throws NotFoundException {
- Map<String, Item> cart = getUserShoppingCart();
-
- if (!cart.containsKey(key)) {
- throw new NotFoundException(key);
- }
- // add to the cart map
- cart.put(key, item);
- // add back to the store
- documentService.put(getCartKey(), cart);
- }
-
- public void delete(String key) throws NotFoundException {
- if (key == null || key.isEmpty()) {
- documentService.delete(getCartKey());
- } else {
- Map<String, Item> cart = getUserShoppingCart();
-
- Item item = cart.remove(key);
- if (item == null) {
- throw new NotFoundException(key);
- }
- documentService.put(getCartKey(), cart);
- }
- }
-
- public Entry<String, Item>[] query(String queryString) {
- throw new UnsupportedOperationException("Operation not supported !");
- }
-
- public String getTotal() {
- double total = 0;
- String currencySymbol = "";
-
- Map<String, Item> cart = getUserShoppingCart();
- if (!cart.isEmpty()) {
- Item item = cart.values().iterator().next();
- currencySymbol = item.getCurrencySymbol();
- }
- for (Item item : cart.values()) {
- total += item.getPrice();
- }
-
- return currencySymbol + String.valueOf(total);
- }
-
- /**
- * Utility functions
- */
-
- private Map<String, Item> getUserShoppingCart() {
- String userCartKey = getCartKey();
- HashMap<String, Item> cart;
-
- try {
- cart = (HashMap<String, Item>)documentService.get(userCartKey);
- } catch (NotFoundException e) {
- cart = new HashMap<String, Item>();
- documentService.post(userCartKey, cart);
- }
-
- return cart;
- }
-
- 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;
- }
- return userId;
- }
-
- private String getCartKey() {
- String cartKey = "cart-" + this.getUserId();
- return cartKey;
- }
-
- private String generateItemKey() {
- String itemKey = getCartKey() + "-item-" + UUID.randomUUID().toString();
- return itemKey;
- }
+ }
}
Copied: incubator/nuvem/trunk/store-assets/src/main/java/services/TrackingCode.java (from r1044457, incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java)
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/TrackingCode.java?p2=incubator/nuvem/trunk/store-assets/src/main/java/services/TrackingCode.java&p1=incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java&r1=1044457&r2=1053005&rev=1053005&view=diff
==============================================================================
--- incubator/nuvem/trunk/nuvem-api/src/main/java/org/apache/nuvem/cloud/xmpp/api/Error.java (original)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/TrackingCode.java Mon Dec 27 06:23:28 2010
@@ -7,49 +7,55 @@
* 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.
+ * under the License.
*/
-package org.apache.nuvem.cloud.xmpp.api;
+package services;
-/**
- * Contains the error details used.
- */
-public final class Error {
+import java.util.UUID;
+
+public class TrackingCode {
- /**
- * Description of the error.
- */
- private String description;
-
- /**
- * The actual error code.
- */
- private ErrorCode code;
-
- public Error(ErrorCode code) {
- this.code = code;
- }
-
- public Error(ErrorCode code, String description) {
- this.code = code;
- this.description = description;
- }
-
- public String description() {
- return description;
- }
-
- public ErrorCode code() {
- return code;
- }
+ private String code;
+ public static TrackingCode getNewTrackingCode() {
+ return new TrackingCode(UUID.randomUUID().toString());
+ }
+
+ private TrackingCode(String code) {
+ this.code = code;
+ }
+
+ /**
+ * .
+ */
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof TrackingCode))
+ return false;
+
+ final TrackingCode other = (TrackingCode) o;
+
+ return code.equals(other.code);
+ }
+
+ /**
+ */
+ public int hashCode() {
+ return code.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return code;
+ }
}
Added: incubator/nuvem/trunk/store-assets/src/main/java/services/XMPPShipmentObserver.java
URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/store-assets/src/main/java/services/XMPPShipmentObserver.java?rev=1053005&view=auto
==============================================================================
--- incubator/nuvem/trunk/store-assets/src/main/java/services/XMPPShipmentObserver.java (added)
+++ incubator/nuvem/trunk/store-assets/src/main/java/services/XMPPShipmentObserver.java Mon Dec 27 06:23:28 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.nuvem.cloud.xmpp.api.JID;
+import org.apache.nuvem.cloud.xmpp.api.MessageBuilder;
+import org.apache.nuvem.cloud.xmpp.api.Status;
+import org.apache.nuvem.cloud.xmpp.api.XMPPEndPoint;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+
+@Scope("COMPOSITE")
+public class XMPPShipmentObserver implements ShipmentObserver {
+
+ @Reference
+ private XMPPEndPoint endpoint;
+
+ public void onStatusUpdate(Shipment shipment, Event event) {
+ JID jid = shipment.getJidToUpdate();
+ System.out.println("inviting user of jid : " + jid.asString());
+ Status status = endpoint.invite(jid);
+ System.out.println("status of invite:" + status.hasErrors());
+ if (!status.hasErrors()) {
+ endpoint.sendMessage(new MessageBuilder().toRecipient(
+ shipment.getJidToUpdate().asString()).containing(
+ event.toString()).build());
+ }
+ }
+
+}