You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/07/18 22:41:03 UTC

svn commit: r557392 [1/2] - in /ofbiz/trunk: applications/accounting/config/ applications/accounting/data/ applications/order/config/ applications/order/data/ applications/order/servicedef/ applications/order/src/org/ofbiz/order/order/ applications/ord...

Author: jacopoc
Date: Wed Jul 18 13:41:01 2007
New Revision: 557392

URL: http://svn.apache.org/viewvc?view=rev&rev=557392
Log:
This is the first version (still not completed) of the eBay integration (import of orders from eBay to OFBiz and export of products from OFBiz to eBay). Thanks to Marco Risaliti for the patch.

Added:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java   (with props)
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java   (with props)
Modified:
    ofbiz/trunk/applications/accounting/config/AccountingEntityLabels.properties
    ofbiz/trunk/applications/accounting/config/AccountingEntityLabels_it.properties
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    ofbiz/trunk/applications/order/config/OrderUiLabels.properties
    ofbiz/trunk/applications/order/config/OrderUiLabels_it.properties
    ofbiz/trunk/applications/order/data/OrderTypeData.xml
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
    ofbiz/trunk/applications/order/webapp/ordermgr/order/OrderForms.xml
    ofbiz/trunk/applications/order/widget/ordermgr/OrderViewScreens.xml
    ofbiz/trunk/applications/product/config/ProductUiLabels.properties
    ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties
    ofbiz/trunk/applications/product/servicedef/services.xml
    ofbiz/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
    ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml
    ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl
    ofbiz/trunk/applications/product/widget/catalog/FindScreens.xml
    ofbiz/trunk/framework/common/config/CommonEntityLabels.properties
    ofbiz/trunk/framework/common/config/CommonEntityLabels_it.properties

Modified: ofbiz/trunk/applications/accounting/config/AccountingEntityLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingEntityLabels.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/accounting/config/AccountingEntityLabels.properties (original)
+++ ofbiz/trunk/applications/accounting/config/AccountingEntityLabels.properties Wed Jul 18 13:41:01 2007
@@ -25,6 +25,7 @@
 PaymentMethodType.description.EFT_ACCOUNT=Electronic Funds Transfer
 PaymentMethodType.description.EXT_BILLACT=Billing Account
 PaymentMethodType.description.EXT_COD=Cash On Delivery
+PaymentMethodType.description.EXT_EBAY=eBay
 PaymentMethodType.description.EXT_OFFLINE=Offline Payment
 PaymentMethodType.description.EXT_PAYPAL=Paypal
 PaymentMethodType.description.EXT_WORLDPAY=WorldPay

Modified: ofbiz/trunk/applications/accounting/config/AccountingEntityLabels_it.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/config/AccountingEntityLabels_it.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/accounting/config/AccountingEntityLabels_it.properties (original)
+++ ofbiz/trunk/applications/accounting/config/AccountingEntityLabels_it.properties Wed Jul 18 13:41:01 2007
@@ -25,6 +25,7 @@
 PaymentMethodType.description.EFT_ACCOUNT=Trasferimento Elettronico Fondi(EFT)
 PaymentMethodType.description.EXT_BILLACT=Conto Fatturazione
 PaymentMethodType.description.EXT_COD=Contrassegno
+PaymentMethodType.description.EXT_EBAY=eBay
 PaymentMethodType.description.EXT_OFFLINE=Pagamento Offline
 PaymentMethodType.description.EXT_PAYPAL=Paypal
 PaymentMethodType.description.EXT_WORLDPAY=WorldPay

Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Wed Jul 18 13:41:01 2007
@@ -429,6 +429,7 @@
     <PaymentMethodType description="Company Account" paymentMethodTypeId="COMPANY_ACCOUNT"/>
     <PaymentMethodType description="Billing Account" paymentMethodTypeId="EXT_BILLACT"/>
     <PaymentMethodType description="Cash On Delivery" paymentMethodTypeId="EXT_COD"/>
+    <PaymentMethodType description="eBay" paymentMethodTypeId="EXT_EBAY"/>
     <PaymentMethodType description="Offline Payment" paymentMethodTypeId="EXT_OFFLINE"/>
     <PaymentMethodType description="PayPal" paymentMethodTypeId="EXT_PAYPAL"/>
     <PaymentMethodType description="WorldPay" paymentMethodTypeId="EXT_WORLDPAY"/>

Modified: ofbiz/trunk/applications/order/config/OrderUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderUiLabels.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/config/OrderUiLabels.properties (original)
+++ ofbiz/trunk/applications/order/config/OrderUiLabels.properties Wed Jul 18 13:41:01 2007
@@ -488,6 +488,8 @@
 OrderGrossItemsSoldIncludesPromotionsAndPendingOrders=Gross Items Sold (includes promotions and pending orders)
 OrderHold=Hold Order
 OrderImage=Image
+OrderImportOrdersFromEbay=Import Orders From eBay
+OrderImportEbayItem=Item Id
 OrderInProduction=In Production
 OrderInProgress=In Progress
 OrderInputQuickPurchaseOrder=Purchase Order Quick Entry
@@ -963,6 +965,14 @@
 # org.ofbiz.order.order messages
 # ========================================
 items.none=ERROR: There are no items to order
+
+ordersImportFromEbay.exceptionDuringBuildingGetEbayDetailsReques=Exception during building get eBay details request
+ordersImportFromEbay.exceptionDuringBuildingGetSellerTransactionRequest=Exception during building get seller transactions request
+ordersImportFromEbay.exceptionInImportFromEbay=Exception in importFromEbay
+ordersImportFromEbay.externalIdAlreadyExist=ExternalId Already Exists
+ordersImportFromEbay.externalIdNotAvailable=ExternalId Not Available
+ordersImportFromEbay.productIdNotAvailable=ProductId Not Available
+
 # 0=productName, 1=productId
 product.no_longer_for_sale=Tried to order the Product {0} (productId: {1}). This product is no longer available for sale. Please remove from your order.
 # 0=productId

Modified: ofbiz/trunk/applications/order/config/OrderUiLabels_it.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderUiLabels_it.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/config/OrderUiLabels_it.properties (original)
+++ ofbiz/trunk/applications/order/config/OrderUiLabels_it.properties Wed Jul 18 13:41:01 2007
@@ -372,6 +372,8 @@
 OrderGrossItemsSoldIncludesPromotionsAndPendingOrders=Righe Vendute Lorde (include promozioni e ordini sospesi)
 OrderHold=Congela Ordine
 OrderImage = Immagine
+OrderImportOrdersFromEbay=Importa Ordini Da eBay
+OrderImportEbayItem=Numero Oggetto
 OrderInProduction = In Produzione
 OrderInProgress = In Corso
 OrderInputQuickPurchaseOrder=Inserimento Veloce Ordine Acquisto
@@ -841,6 +843,13 @@
 # ========================================
 
 items.none=ERRORE: Non ci sono righe nell'ordine
+
+ordersImportFromEbay.exceptionDuringBuildingGetEbayDetailsReques=Eccezione durante la creazione della richiesta get eBay details
+ordersImportFromEbay.exceptionDuringBuildingGetSellerTransactionRequest=Eccezione durante la creazione della richiesta get seller transactions
+ordersImportFromEbay.exceptionInImportFromEbay=Eccezione in importFromEbay
+ordersImportFromEbay.externalIdAlreadyExist=Numero Ordine Esterno Gi\u00e0 Esistente
+ordersImportFromEbay.externalIdNotAvailable=Numero Ordine Esterno Non Disponibile
+ordersImportFromEbay.productIdNotAvailable=Codice Prodotto Non Disponibile
 
 # 0=productId
 product.not_found=Non \u00e8 possibile trovare il prodotto con codice [{0}], non possono essere acquisti.

Modified: ofbiz/trunk/applications/order/data/OrderTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/data/OrderTypeData.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/data/OrderTypeData.xml (original)
+++ ofbiz/trunk/applications/order/data/OrderTypeData.xml Wed Jul 18 13:41:01 2007
@@ -77,6 +77,7 @@
     <Enumeration description="E-Mail Channel" enumCode="EMAIL_CAHNNEL" enumId="EMAIL_SALES_CHANNEL" sequenceId="05" enumTypeId="ORDER_SALES_CHANNEL"/>
     <Enumeration description="Snail Mail Channel" enumCode="SNAIL_CAHNNEL" enumId="SNAIL_SALES_CHANNEL" sequenceId="06" enumTypeId="ORDER_SALES_CHANNEL"/>
     <Enumeration description="Affiliate Channel" enumCode="AFFIL_CHANNEL" enumId="AFFIL_SALES_CHANNEL" sequenceId="07" enumTypeId="ORDER_SALES_CHANNEL"/>
+    <Enumeration description="eBay Channel" enumCode="EBAY_CHANNEL" enumId="EBAY_SALES_CHANNEL" sequenceId="08" enumTypeId="ORDER_SALES_CHANNEL"/>
     <Enumeration description="Unknown Channel" enumCode="UNKOWN_CAHNNEL" enumId="UNKNWN_SALES_CHANNEL" sequenceId="99" enumTypeId="ORDER_SALES_CHANNEL"/>
 
     <QuoteType description="Other" hasTable="N" parentTypeId="" quoteTypeId="OTHER_QUOTE"/>

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Wed Jul 18 13:41:01 2007
@@ -760,4 +760,13 @@
         <attribute name="orderListSize" type="Integer" mode="OUT" optional="false"/>
     </service>
     
+    <!-- Import Orders Services -->    
+    <service name="importFromEbay" engine="java" transaction-timeout="300"
+             location="org.ofbiz.order.order.ImportOrdersFromEbay" invoke="importFromEbay" auth="true">
+        <description>Import Orders from eBay</description>
+        <attribute type="String" mode="IN" name="productStoreId" optional="false"/>
+        <attribute type="Timestamp" mode="IN" name="fromDate" optional="false"/>
+        <attribute type="Timestamp" mode="IN" name="thruDate" optional="false"/>
+        <attribute type="List" mode="OUT" name="orderList" optional="true"/>
+    </service>
 </services>

Added: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java?view=auto&rev=557392
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java (added)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java Wed Jul 18 13:41:01 2007
@@ -0,0 +1,785 @@
+/*******************************************************************************
+ * 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 org.ofbiz.order.order;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javolution.util.FastMap;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.order.shoppingcart.CheckOutHelper;
+import org.ofbiz.order.shoppingcart.ShoppingCart;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ImportOrdersFromEbay {
+    
+    private static final String resource = "OrderUiLabels";
+    private static final String module = ImportOrdersFromEbay.class.getName();
+    
+    public static Map importFromEbay(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Locale locale = (Locale) context.get("locale");
+        Map result = FastMap.newInstance();
+        try {
+            String configString = "productsExport.properties";
+                            
+            // get the Developer Key
+            String devID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.devID");
+            
+            // get the Application Key
+            String appID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.appID");
+            
+            // get the Certifcate Key
+            String certID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.certID");
+            
+            // get the Token
+            String token = UtilProperties.getPropertyValue(configString, "productsExport.eBay.token");
+            
+            // get the xmlGatewayUri
+            String xmlGatewayUri = UtilProperties.getPropertyValue(configString, "productsExport.eBay.xmlGatewayUri");
+            
+            StringBuffer ebayDetailsItemsXml = new StringBuffer();
+            StringBuffer sellerTransactionsItemsXml = new StringBuffer();
+            
+            if (!ServiceUtil.isFailure(buildGetEbayDetailsRequest(context, ebayDetailsItemsXml, token))) { 
+                postItem(xmlGatewayUri, ebayDetailsItemsXml, devID, appID, certID, "GeteBayDetails");
+                
+                if (!ServiceUtil.isFailure(buildGetSellerTransactionsRequest(context, sellerTransactionsItemsXml, token))) { 
+                    result = postItem(xmlGatewayUri, sellerTransactionsItemsXml, devID, appID, certID, "GetSellerTransactions");
+                    String success = (String)result.get("responseMessage");
+                    if (success != null && success.equals("success")) { 
+                        result = createOrders(delegator, dispatcher, locale, context, (String)result.get("successMessage"), true);
+                    }
+                }
+            }
+        } catch (Exception e) {        
+            Debug.logError("Exception in importFromEbay " + e, module);
+            return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.exceptionInImportFromEbay", locale));
+        }
+        
+        return result;
+    }
+   
+    private static String toString(InputStream inputStream) throws IOException {
+        String string;
+        StringBuilder outputBuilder = new StringBuilder();
+        if (inputStream != null) {
+            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+            while (null != (string = reader.readLine())) {
+                outputBuilder.append(string).append('\n');
+            }
+        }
+        return outputBuilder.toString();
+    }
+    
+    private static Map postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID, String callName) throws IOException {
+        HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
+      
+        connection.setDoInput(true);
+        connection.setDoOutput(true);
+        connection.setRequestMethod("POST");
+        connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", "517");
+        connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
+        connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
+        connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
+        connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
+        connection.setRequestProperty("X-EBAY-API-SITEID", "0");
+        connection.setRequestProperty("Content-Type", "text/xml");
+        
+        OutputStream outputStream = connection.getOutputStream();
+        outputStream.write(dataItems.toString().getBytes());
+        outputStream.close();
+    
+        int responseCode = connection.getResponseCode();
+        InputStream inputStream = null;
+        Map result = FastMap.newInstance();
+        if (responseCode == HttpURLConnection.HTTP_CREATED ||
+            responseCode == HttpURLConnection.HTTP_OK) {
+            inputStream = connection.getInputStream();
+            String response = toString(inputStream);
+            result = ServiceUtil.returnSuccess(response);
+        } else {
+            inputStream = connection.getErrorStream();
+            result = ServiceUtil.returnFailure(toString(inputStream));
+        }
+        return result;
+    }
+    
+    private static Map createOrders(GenericDelegator delegator, LocalDispatcher dispatcher, Locale locale, Map context, String response, boolean onlyCheck) {
+        if (response != null && response.length() > 0) {
+            List orders = readResponseFromEbay(response, locale);
+            if (orders != null && orders.size() > 0) {
+                if (!onlyCheck) {
+                    Iterator orderIter = orders.iterator();
+                    while (orderIter.hasNext()) {
+                        createShoppingCart(delegator, dispatcher, locale, context, (Map)orderIter.next());
+                    }
+                }
+                Map result = FastMap.newInstance();
+                result.put("responseMessage", "success");
+                result.put("orderList", orders);
+                return result;
+            } else {
+                //TODO create a new property in resource
+                return ServiceUtil.returnFailure("No orders found");
+            }
+        } else {
+            //TODO create a new property in resource
+            return ServiceUtil.returnFailure("No orders found"); 
+        }
+    }
+        
+    private static Map buildGetSellerTransactionsRequest(Map context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale)context.get("locale");
+        Timestamp fromDate = (Timestamp)context.get("fromDate");
+        Timestamp thruDate = (Timestamp)context.get("thruDate");
+        try {
+             Document transDoc = UtilXml.makeEmptyXmlDocument("GetSellerTransactionsRequest");
+             Element transElem = transDoc.getDocumentElement();
+             transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+              
+             appendRequesterCredentials(transElem, transDoc, token);
+             UtilXml.addChildElementValue(transElem, "DetailLevel", "ReturnAll", transDoc);
+             UtilXml.addChildElementValue(transElem, "ModTimeFrom", fromDate.toString(), transDoc);
+             UtilXml.addChildElementValue(transElem, "ModTimeTo", thruDate.toString(), transDoc);
+             
+             dataItemsXml.append(UtilXml.writeXmlDocument(transDoc));
+         } catch (Exception e) {
+             Debug.logError("Exception during building get seller transactions request", module);
+             return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.exceptionDuringBuildingGetSellerTransactionRequest", locale));
+         }
+         return ServiceUtil.returnSuccess();
+    }
+    
+    private static Map buildGetEbayDetailsRequest(Map context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale)context.get("locale");
+        try {
+             Document transDoc = UtilXml.makeEmptyXmlDocument("GeteBayDetailsRequest");
+             Element transElem = transDoc.getDocumentElement();
+             transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+             
+             appendRequesterCredentials(transElem, transDoc, token);
+             UtilXml.addChildElementValue(transElem, "DetailName", "ShippingServiceDetails", transDoc);
+             UtilXml.addChildElementValue(transElem, "DetailName", "TaxJurisdiction", transDoc);
+             dataItemsXml.append(UtilXml.writeXmlDocument(transDoc));
+         } catch (Exception e) {
+             Debug.logError("Exception during building get eBay details request", module);
+             return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.exceptionDuringBuildingGetEbayDetailsRequest", locale));
+         }
+         return ServiceUtil.returnSuccess();
+    }
+    
+    private static void appendRequesterCredentials(Element elem, Document doc, String token) {
+        Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
+        UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
+    }
+    
+    private static List readResponseFromEbay(String msg, Locale locale) {
+        List orders = null;
+        Debug.logInfo(msg, module);
+        try {
+            Document docResponse = UtilXml.readXmlDocument(msg, true);
+            Element elemResponse = docResponse.getDocumentElement();
+            String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
+            List paginationList = UtilXml.childElementList(elemResponse, "PaginationResult");
+            
+            int totalOrders = 0;
+            Iterator paginationElemIter = paginationList.iterator();
+            while (paginationElemIter.hasNext()) {
+                Element paginationElement = (Element) paginationElemIter.next();
+                String totalNumberOfEntries = UtilXml.childElementValue(paginationElement, "TotalNumberOfEntries", "0");
+                totalOrders = new Integer(totalNumberOfEntries).intValue();
+            }
+            
+            if (ack != null && ack.equals("Success") && totalOrders    > 0) {
+                orders = new ArrayList();
+                
+                // retrieve transaction array
+                List transactions = UtilXml.childElementList(elemResponse, "TransactionArray");
+                Iterator transactionsElemIter = transactions.iterator();
+                while (transactionsElemIter.hasNext()) {
+                    Element transactionsElement = (Element) transactionsElemIter.next();
+                    
+                    // retrieve transaction
+                    List transaction = UtilXml.childElementList(transactionsElement, "Transaction");
+                    Iterator transactionElemIter = transaction.iterator();
+                    while (transactionElemIter.hasNext()) {
+                        Map order = FastMap.newInstance();
+                        
+                        Element transactionElement = (Element) transactionElemIter.next();
+                        order.put("amountPaid", UtilXml.childElementValue(transactionElement, "AmountPaid", "0"));
+                        
+                        // retrieve buyer
+                        List buyer = UtilXml.childElementList(transactionElement, "Buyer");
+                        Iterator buyerElemIter = buyer.iterator();
+                        while (buyerElemIter.hasNext()) {
+                            Element buyerElement = (Element)buyerElemIter.next();
+                            order.put("emailBuyer", UtilXml.childElementValue(buyerElement, "Email", ""));
+                            
+                            // retrieve buyer information
+                            List buyerInfo = UtilXml.childElementList(buyerElement, "BuyerInfo");
+                            Iterator buyerInfoElemIter = buyerInfo.iterator();
+                            while (buyerInfoElemIter.hasNext()) {
+                                Element buyerInfoElement = (Element)buyerInfoElemIter.next();
+                                
+                                // retrieve shipping address
+                                List shippingAddressInfo = UtilXml.childElementList(buyerInfoElement, "ShippingAddress");
+                                Iterator shippingAddressElemIter = shippingAddressInfo.iterator();
+                                while (shippingAddressElemIter.hasNext()) {
+                                    Element shippingAddressElement = (Element)shippingAddressElemIter.next();
+                                    order.put("buyerName", UtilXml.childElementValue(shippingAddressElement, "Name", ""));
+                                    order.put("shippingAddressStreet1", UtilXml.childElementValue(shippingAddressElement, "Street1", ""));
+                                    order.put("shippingAddressCityName", UtilXml.childElementValue(shippingAddressElement, "CityName", ""));
+                                    order.put("shippingAddressStateOrProvince", UtilXml.childElementValue(shippingAddressElement, "StateOrProvince", ""));
+                                    order.put("shippingAddressCountry", UtilXml.childElementValue(shippingAddressElement, "Country", ""));
+                                    order.put("shippingAddressCountryName", UtilXml.childElementValue(shippingAddressElement, "CountryName", ""));
+                                    order.put("shippingAddressPhone", UtilXml.childElementValue(shippingAddressElement, "Phone", ""));
+                                    order.put("shippingAddressPostalCode", UtilXml.childElementValue(shippingAddressElement, "PostalCode", ""));
+                                }
+                            }
+                        }
+                        
+                        // retrieve shipping details
+                        List shippingDetails = UtilXml.childElementList(transactionElement, "ShippingDetails");
+                        Iterator shippingDetailsElemIter = shippingDetails.iterator();
+                        while (shippingDetailsElemIter.hasNext()) {
+                            Element shippingDetailsElement = (Element)shippingDetailsElemIter.next();
+                            order.put("insuranceFee", UtilXml.childElementValue(shippingDetailsElement, "InsuranceFee", "0"));
+                            order.put("insuranceOption", UtilXml.childElementValue(shippingDetailsElement, "InsuranceOption", ""));
+                            order.put("insuranceWanted", UtilXml.childElementValue(shippingDetailsElement, "InsuranceWanted", "false"));
+                            
+                            // retrieve sales Tax
+                            List salesTax = UtilXml.childElementList(shippingDetailsElement, "SalesTax");
+                            Iterator salesTaxElemIter = salesTax.iterator();
+                            while (salesTaxElemIter.hasNext()) {
+                                Element salesTaxElement = (Element)salesTaxElemIter.next();
+                                order.put("salesTaxAmount", UtilXml.childElementValue(salesTaxElement, "SalesTaxAmount", "0"));
+                                order.put("salesTaxPercent", UtilXml.childElementValue(salesTaxElement, "SalesTaxPercent", "0"));
+                                order.put("salesTaxState", UtilXml.childElementValue(salesTaxElement, "SalesTaxState", "0"));
+                                order.put("shippingIncludedInTax", UtilXml.childElementValue(salesTaxElement, "ShippingIncludedInTax", "false"));                                
+                            }
+                            
+                            // retrieve tax table
+                            List taxTable = UtilXml.childElementList(shippingDetailsElement, "TaxTable");
+                            Iterator taxTableElemIter = taxTable.iterator();
+                            while (taxTableElemIter.hasNext()) {
+                                Element taxTableElement = (Element)taxTableElemIter.next();
+                                
+                                List taxJurisdiction = UtilXml.childElementList(taxTableElement, "TaxJurisdiction");
+                                Iterator taxJurisdictionElemIter = taxJurisdiction.iterator();
+                                while (taxJurisdictionElemIter.hasNext()) {
+                                    Element taxJurisdictionElement = (Element)taxJurisdictionElemIter.next();
+                                    
+                                    order.put("jurisdictionID", UtilXml.childElementValue(taxJurisdictionElement, "JurisdictionID", ""));
+                                    order.put("jurisdictionSalesTaxPercent", UtilXml.childElementValue(taxJurisdictionElement, "SalesTaxPercent", "0"));
+                                    order.put("jurisdictionShippingIncludedInTax", UtilXml.childElementValue(taxJurisdictionElement, "ShippingIncludedInTax", "0"));
+                                }
+                            }
+                        }
+                            
+                        // retrieve created date
+                        order.put("createdDate", UtilXml.childElementValue(transactionElement, "CreatedDate", ""));
+                        
+                        // retrieve item
+                        List item = UtilXml.childElementList(transactionElement, "Item");
+                        Iterator itemElemIter = item.iterator();
+                        while (itemElemIter.hasNext()) {
+                            Element itemElement = (Element)itemElemIter.next();
+                            order.put("externalId", UtilXml.childElementValue(itemElement, "ItemID", ""));
+                            order.put("paymentMethods", UtilXml.childElementValue(itemElement, "PaymentMethods", ""));
+                            order.put("quantity", UtilXml.childElementValue(itemElement, "Quantity", "0"));
+                            order.put("productId", UtilXml.childElementValue(itemElement, "SKU", ""));
+                            order.put("startPrice", UtilXml.childElementValue(itemElement, "StartPrice", "0"));
+                            order.put("title", UtilXml.childElementValue(itemElement, "Title", ""));
+                            
+                            // retrieve selling status
+                            List sellingStatus = UtilXml.childElementList(itemElement, "SellingStatus");
+                            Iterator sellingStatusitemElemIter = sellingStatus.iterator();
+                            while (sellingStatusitemElemIter.hasNext()) {
+                                Element sellingStatusElement = (Element)sellingStatusitemElemIter.next();
+                                order.put("amount", UtilXml.childElementValue(sellingStatusElement, "CurrentPrice", "0"));
+                                order.put("quantitySold", UtilXml.childElementValue(sellingStatusElement, "QuantitySold", "0"));
+                                order.put("listingStatus", UtilXml.childElementValue(sellingStatusElement, "ListingStatus", ""));
+                            }
+                        }
+                        
+                        // retrieve status
+                        List status = UtilXml.childElementList(transactionElement, "Status");
+                        Iterator statusElemIter = status.iterator();
+                        while (statusElemIter.hasNext()) {
+                            Element statusElement = (Element)statusElemIter.next();
+                            order.put("eBayPaymentStatus", UtilXml.childElementValue(statusElement, "eBayPaymentStatus", ""));
+                            order.put("checkoutStatus", UtilXml.childElementValue(statusElement, "CheckoutStatus", ""));
+                            order.put("paymentMethodUsed", UtilXml.childElementValue(statusElement, "PaymentMethodUsed", ""));
+                            order.put("completeStatus", UtilXml.childElementValue(statusElement, "CompleteStatus", ""));
+                            order.put("buyerSelectedShipping", UtilXml.childElementValue(statusElement, "BuyerSelectedShipping", ""));
+                        }
+                        
+                        // retrieve external transaction
+                        List externalTransaction = UtilXml.childElementList(transactionElement, "ExternalTransaction");
+                        Iterator externalTransactionElemIter = externalTransaction.iterator();
+                        while (externalTransactionElemIter.hasNext()) {
+                            Element externalTransactionElement = (Element)externalTransactionElemIter.next();
+                            order.put("externalTransactionID", UtilXml.childElementValue(externalTransactionElement, "ExternalTransactionID", ""));
+                            order.put("externalTransactionTime", UtilXml.childElementValue(externalTransactionElement, "ExternalTransactionTime", ""));
+                            order.put("feeOrCreditAmount", UtilXml.childElementValue(externalTransactionElement, "FeeOrCreditAmount", "0"));
+                            order.put("paymentOrRefundAmount", UtilXml.childElementValue(externalTransactionElement, "PaymentOrRefundAmount", "0"));
+                        }
+                        
+                        // retrieve shipping service selected
+                        List shippingServiceSelected = UtilXml.childElementList(transactionElement, "ShippingServiceSelected");
+                        Iterator shippingServiceSelectedElemIter = shippingServiceSelected.iterator();
+                        while (shippingServiceSelectedElemIter.hasNext()) {
+                            Element shippingServiceSelectedElement = (Element)shippingServiceSelectedElemIter.next();
+                            order.put("shippingService", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingService", ""));
+                            order.put("shippingServiceCost", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingServiceCost", "0"));
+                        }
+                        
+                        // retrieve paid time
+                        order.put("paidTime", UtilXml.childElementValue(transactionElement, "PaidTime", ""));
+                        
+                        // retrieve shipped time
+                        order.put("shippedTime", UtilXml.childElementValue(transactionElement, "ShippedTime", ""));
+                                                
+                        orders.add(order);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            //TODO ServiceUtil.returnSuccess("Exception in readResponseFromEbay");
+            ;
+        }
+        return orders;
+    }
+    
+    private static Map createShoppingCart(GenericDelegator delegator, LocalDispatcher dispatcher, Locale locale, Map context, Map order) {
+        try {
+            String productStoreId = (String)context.get("productStoreId");
+            GenericValue userLogin = (GenericValue) context.get("userLogin");
+            String defaultCurrencyUomId = "";
+            String payToPartyId = "";
+            String facilityId = "";
+            
+            // Product Store is mandatory
+            if (productStoreId == null) {
+                ; //TODO error message has to be returned
+            } else {
+                GenericValue productStore = delegator.findByPrimaryKey("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));
+                if (productStore != null) {
+                    defaultCurrencyUomId = productStore.getString("defaultCurrencyUomId");
+                    payToPartyId = productStore.getString("payToPartyId");
+                    facilityId = productStore.getString("inventoryFacilityId");
+                } else {
+                    ; //TODO error message has to be returned 
+                }
+            }
+            
+            // create a new shopping cart
+            ShoppingCart cart = new ShoppingCart(delegator, productStoreId, locale, defaultCurrencyUomId);
+            
+            // set the external id with the eBay Item Id
+            String externalId = (String)order.get("externalId");
+            if (UtilValidate.isNotEmpty(externalId)) {
+                if (externalOrderExists(delegator, externalId)) {
+                    return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.externalIdAlreadyExist", locale));
+                }
+                cart.setExternalId(externalId);
+            } else {
+                return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.externalIdNotAvailable", locale));
+            }
+            
+            cart.setOrderType("SALES_ORDER");
+            cart.setChannelType("EBAY_SALES_CHANNEL");
+            cart.setUserLogin(userLogin, dispatcher);
+            cart.setProductStoreId(productStoreId);
+            
+            if (UtilValidate.isNotEmpty(facilityId)) {
+                cart.setFacilityId(facilityId);
+            }
+            
+            String amountStr = (String)order.get("amountPaid");
+            Double amountPaid = new Double(0);
+            
+            if (UtilValidate.isNotEmpty(amountStr)) {
+                amountPaid = new Double(amountStr);
+            } 
+            
+            // add the payment EXT_EBAY for the paid amount
+            cart.addPaymentAmount("EXT_EBAY", amountPaid, externalId, null, true, false, false);
+            
+            // set the order date with the eBay created date
+            Timestamp orderDate = UtilDateTime.nowTimestamp();
+            if (UtilValidate.isNotEmpty((String)order.get("createdDate"))) {
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+                Date createdDate = sdf.parse((String)order.get("createdDate"));
+                orderDate = new Timestamp(createdDate.getTime());
+            }
+            cart.setOrderDate(orderDate);
+            
+            // create the shipment group item
+            cart.addItemGroup("00001", null);
+            
+            // create the order item
+            String productId = (String)order.get("productId");
+            if (UtilValidate.isEmpty(productId)) {
+                return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.productIdNotAvailable", locale));
+            }                
+            
+            Double unitPrice = new Double((String)order.get("amount"));
+            double quantity = new Double((String)order.get("quantitySold")).doubleValue();
+            Double amount = new Double(quantity * unitPrice.doubleValue());
+            cart.addItemToEnd(productId, amount, quantity, unitPrice, null, null, null, "PRODUCT_ORDER_ITEM", dispatcher, Boolean.FALSE, Boolean.FALSE);
+           
+            // set partyId from
+            if (UtilValidate.isNotEmpty(payToPartyId)) {
+                cart.setBillFromVendorPartyId(payToPartyId);
+            }
+            
+            // set partyId to
+            String partyId = createCustomerParty(dispatcher, (String)order.get("buyerName"), userLogin);
+            String contactMechId = "";            
+            if (UtilValidate.isNotEmpty(partyId)) {
+                contactMechId = createAddress(dispatcher, partyId, userLogin, "SHIPPING_LOCATION", order);
+                createPartyPhone(dispatcher, partyId, (String)order.get("shippingAddressPhone"), userLogin);
+                String emailBuyer = (String)order.get("emailBuyer");
+                if (!(emailBuyer.equals("") || emailBuyer.equalsIgnoreCase("Invalid Request"))) {
+                    createPartyEmail(dispatcher, partyId, emailBuyer, userLogin);
+                }
+            } else {
+                partyId = "admin";
+            }
+            
+            cart.setBillToCustomerPartyId(partyId);
+            cart.setPlacingCustomerPartyId(partyId);
+            cart.setShipToCustomerPartyId(partyId);
+            cart.setEndUserCustomerPartyId(partyId);
+            
+            cart.setCarrierPartyId("_NA_");
+            cart.setShippingContactMechId(contactMechId);
+            
+            //TODO handle shipment method type
+            cart.setShipmentMethodTypeId("NO_SHIPPING");
+            cart.setMaySplit(Boolean.FALSE);
+            cart.makeAllShipGroupInfos();
+            
+            // Apply shipping costs 
+            String shippingCost = (String)order.get("shippingServiceCost");
+            if (UtilValidate.isNotEmpty(shippingCost)) {
+                double shippingAmount = new Double(shippingCost).doubleValue();
+                if (shippingAmount > 0) {
+                    GenericValue shippingAdjustment = madeOrderAdjustment(delegator, "SHIPPING_CHARGES", cart.getOrderId(), null, null, shippingAmount);       
+                    if (shippingAdjustment != null) {
+                        cart.addAdjustment(shippingAdjustment);
+                    }
+                }
+            }
+                
+            // create the order
+            CheckOutHelper checkout = new CheckOutHelper(dispatcher, delegator, cart);
+            Map orderCreate = checkout.createOrder(userLogin);
+            
+            String orderId = (String)orderCreate.get("orderId");
+            
+            // approve the order
+            if (UtilValidate.isNotEmpty(orderId)) {
+                boolean approved = OrderChangeHelper.approveOrder(dispatcher, userLogin, orderId);
+                
+                // create the payment from the preference
+                if (approved) {
+                    createPaymentFromPaymentPreferences(delegator, dispatcher, userLogin, orderId, externalId, cart.getOrderDate(), partyId);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            //TODO handle exception error message
+        }
+        return ServiceUtil.returnSuccess();
+    }
+    
+    private static boolean createPaymentFromPaymentPreferences(GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin, 
+                                                               String orderId, String externalId, Timestamp orderDate, String partyIdFrom) {
+        List paymentPreferences = null;
+        try {
+            Map paymentFields = UtilMisc.toMap("orderId", orderId, "statusId", "PAYMENT_RECEIVED", "paymentMethodTypeId", "EXT_EBAY");
+            paymentPreferences = delegator.findByAnd("OrderPaymentPreference", paymentFields);
+            
+            if (paymentPreferences != null && paymentPreferences.size() > 0) {
+                Iterator i = paymentPreferences.iterator();
+                while (i.hasNext()) {
+                    GenericValue pref = (GenericValue) i.next();
+                    boolean okay = createPayment(dispatcher, userLogin, pref, orderId, externalId, orderDate, partyIdFrom);
+                    if (!okay)
+                        return false;
+                }
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, "Cannot get payment preferences for order #" + orderId, module);
+            return false;
+        }
+        return true;
+    }  
+        
+    private static boolean createPayment(LocalDispatcher dispatcher, GenericValue userLogin, GenericValue paymentPreference, 
+                                         String orderId, String externalId, Timestamp orderDate, String partyIdFrom) {
+        try {
+            GenericDelegator delegator = paymentPreference.getDelegator();
+    
+            // create the PaymentGatewayResponse
+            String responseId = delegator.getNextSeqId("PaymentGatewayResponse");
+            GenericValue response = delegator.makeValue("PaymentGatewayResponse", null);
+            response.set("paymentGatewayResponseId", responseId);
+            response.set("paymentServiceTypeEnumId", "PRDS_PAY_EXTERNAL");
+            response.set("orderPaymentPreferenceId", paymentPreference.get("orderPaymentPreferenceId"));
+            response.set("paymentMethodTypeId", paymentPreference.get("paymentMethodTypeId"));
+            response.set("paymentMethodId", paymentPreference.get("paymentMethodId"));
+            response.set("amount", paymentPreference.get("maxAmount"));
+            response.set("referenceNum", externalId);
+            response.set("transactionDate", orderDate);
+            delegator.createOrStore(response);
+            
+            // create the payment
+            Map results = dispatcher.runSync("createPaymentFromPreference", UtilMisc.toMap("userLogin", userLogin, 
+                                             "orderPaymentPreferenceId", paymentPreference.get("orderPaymentPreferenceId"), 
+                                             "paymentFromId", partyIdFrom,
+                                             "paymentRefNum", externalId,
+                                             "comments", "Payment receive via eBay"));
+            
+            if ((results == null) || (results.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_ERROR))) {
+                Debug.logError((String) results.get(ModelService.ERROR_MESSAGE), module); 
+                return false;
+            }
+            return true;     
+        } catch (Exception e) {
+            Debug.logError(e, "Failed to create the payment for order " + orderId, module);
+            return false;
+        }
+    }
+    
+    public static GenericValue madeOrderAdjustment(GenericDelegator delegator, String orderAdjustmentTypeId, String orderId, String orderItemSeqId, String shipGroupSeqId, double amount) {
+        GenericValue orderAdjustment  = null;
+        
+        try {
+            if (UtilValidate.isNotEmpty(orderItemSeqId)) {
+                orderItemSeqId = "_NA_";
+            }
+            if (UtilValidate.isNotEmpty(shipGroupSeqId)) {
+                shipGroupSeqId = "_NA_";     
+            }
+      
+            Map inputMap = UtilMisc.toMap("orderAdjustmentTypeId", orderAdjustmentTypeId,  "orderId", orderId, "orderItemSeqId", orderItemSeqId, 
+                                          "shipGroupSeqId", shipGroupSeqId, "amount", new Double(amount));
+            orderAdjustment = delegator.makeValue("OrderAdjustment", inputMap);
+        } catch (Exception e) {
+            Debug.logError(e, "Failed to made order adjustment for order " + orderId, module);
+        }
+        return orderAdjustment;
+    }
+
+    public static String createCustomerParty(LocalDispatcher dispatcher, String name, GenericValue userLogin) {
+        String partyId = null;
+        
+        try {
+            if (UtilValidate.isNotEmpty(name) && UtilValidate.isNotEmpty(userLogin) ) {
+                Debug.logVerbose("Creating Customer Party: "+name, module);
+                
+                // Try to split the lastname from the firstname
+                String firstName = "";
+                String lastName = "";
+                int pos = name.indexOf(" ");
+                
+                if (pos >= 0) {
+                    firstName = name.substring(0, pos);
+                    lastName = name.substring(pos+1);
+                } else {
+                    lastName = name;    
+                }
+                    
+                Map summaryResult = dispatcher.runSync("createPerson", UtilMisc.toMap("description", name, "firstName", firstName, "lastName", lastName, 
+                                                                                      "userLogin", userLogin, "comments", "Created via eBay"));                                         
+                partyId = (String) summaryResult.get("partyId");   
+                Debug.logVerbose("Created Customer Party: "+partyId, module);
+            }
+        } catch (Exception e) {
+            //TODO error calling the service createPerson
+            e.printStackTrace();
+        }
+        return partyId;
+    }
+    
+    public static String createAddress(LocalDispatcher dispatcher, String partyId, GenericValue userLogin, 
+                                       String contactMechPurposeTypeId, Map address) {
+        String contactMechId = null;
+        try {
+            Map context = FastMap.newInstance();
+            context.put("partyId", partyId);
+            context.put("address1", (String)address.get("shippingAddressStreet1"));
+            context.put("postalCode", (String)address.get("shippingAddressPostalCode"));
+            context.put("userLogin", userLogin);
+            context.put("contactMechPurposeTypeId", contactMechPurposeTypeId);       
+            
+            String country = ((String)address.get("shippingAddressCountry")).toUpperCase();
+            String state = ((String)address.get("shippingAddressStateOrProvince")).toUpperCase();
+            String city = (String)address.get("shippingAddressCityName");
+            correctCityStateCountry(dispatcher, context, city, state, country);
+
+            Map summaryResult = dispatcher.runSync("createPartyPostalAddress",context);
+            contactMechId = (String)summaryResult.get("contactMechId");
+        } catch (GenericServiceException e) {
+            //TODO error calling the service createPartyPostalAddress
+            e.printStackTrace();
+        }
+        return contactMechId;
+    }
+    
+    private static void correctCityStateCountry(LocalDispatcher dispatcher, Map map, String city, String state, String country) {
+        try { 
+            Debug.logInfo("correctCityStateCountry params: " + city + ", " + state + ", " + country, module);
+            String geoId = "USA";
+            if (country.indexOf("UNITED STATES") > -1 || country.indexOf("USA") > -1)
+                country = "US";
+            Debug.logInfo("GeoCode: " + country, module);
+            Map outMap = getCountryGeoId(dispatcher.getDelegator(), country);
+            geoId = (String)outMap.get("geoId");
+            map.put("countryGeoId", geoId);
+            Debug.logInfo("Country geoid: " + geoId, module);
+            if (geoId.equals("USA") || geoId.equals("CAN")) {
+                if (state.length() > 0) {
+                    map.put("stateProvinceGeoId", state);
+                }   
+                map.put("city", city);
+            } else {
+                map.put("city", city + ", " + state);
+            }
+            Debug.logInfo("State geoid: " + state, module);
+        } catch (Exception e) {
+            Debug.logVerbose("Problem finding country bill code " + e.getMessage(),module);
+            //TODO handle error message
+        }
+    }
+        
+    public static String createPartyPhone(LocalDispatcher dispatcher, String partyId, String phoneNumber, GenericValue userLogin) {
+        Map summaryResult = FastMap.newInstance();
+        Map context = FastMap.newInstance();
+        String phoneContactMechId = null;
+        
+        try { 
+            context.put("contactNumber", phoneNumber);                   
+            context.put("partyId", partyId);
+            context.put("userLogin", userLogin);
+            summaryResult = dispatcher.runSync("createPartyTelecomNumber", context);
+            phoneContactMechId = (String)summaryResult.get("contactMechId");
+        } catch (Exception e) { 
+            Debug.logWarning("Phone number not found", module);
+            //TODO handle error message
+        }
+        return phoneContactMechId;
+    }
+    
+    public static String createPartyEmail(LocalDispatcher dispatcher, String partyId, String email, GenericValue userLogin) {
+        Map context = FastMap.newInstance();
+        Map summaryResult = FastMap.newInstance();
+        String emailContactMechId = null;
+        
+        try {
+            if (UtilValidate.isNotEmpty(email)) {
+                context.clear();
+                context.put("emailAddress", email);
+                context.put("userLogin", userLogin);
+                context.put("contactMechTypeId", "EMAIL_ADDRESS");                                      
+                summaryResult = dispatcher.runSync("createEmailAddress", context);
+                emailContactMechId = (String) summaryResult.get("contactMechId");
+                
+                context.clear();
+                context.put("partyId", partyId);
+                context.put("contactMechId", emailContactMechId);
+                context.put("userLogin", userLogin);                 
+                summaryResult = dispatcher.runSync("createPartyContactMech", context);
+            }
+        } catch (Exception e) { 
+            Debug.logWarning("Email not found", module);
+            //TODO handle error message
+        }
+        return emailContactMechId;
+    }
+    
+    public static Map getCountryGeoId(GenericDelegator delegator, String geoCode) {
+        GenericValue geo = null;
+        try {
+            Debug.logInfo("geocode: " + geoCode, module);
+            
+            List geoEntities = delegator.findByAnd("Geo", UtilMisc.toMap("geoCode", geoCode.toUpperCase(), "geoTypeId", "COUNTRY"));
+            if (geoEntities != null && geoEntities.size() > 0) {
+                geo = (GenericValue)geoEntities.get(0);
+                Debug.logInfo("Found a geo entity " + geo, module);
+            } else {
+                geo = delegator.makeValue("Geo", null);
+                geo.set("geoId", geoCode + "_IMPORTED");
+                geo.set("geoTypeId", "COUNTRY");
+                geo.set("geoName", geoCode + "_IMPORTED");
+                geo.set("geoCode", geoCode + "_IMPORTED");
+                geo.set("abbreviation", geoCode + "_IMPORTED");
+                delegator.create(geo);
+                Debug.logInfo("Creating new geo entity: " + geo, module);
+            }
+        } catch (Exception e) {
+            String errMsg = "Failed to find/setup geo id";
+            Debug.logError(e, errMsg, module);
+            return ServiceUtil.returnError(errMsg);
+        }
+        
+        Map result = ServiceUtil.returnSuccess();
+        result.put("geoId", (String)geo.get("geoId"));
+        return result;
+    }   
+    
+    public static boolean externalOrderExists(GenericDelegator delegator, String externalId) throws GenericEntityException {
+        Debug.logInfo("Checking for existing externalOrderId: " + externalId, module);
+        List entities = delegator.findByAnd("OrderHeader", UtilMisc.toMap("externalId", externalId));
+        return (entities != null && entities.size() > 0);
+    }
+}

Propchange: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/ImportOrdersFromEbay.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Wed Jul 18 13:41:01 2007
@@ -1487,6 +1487,23 @@
     <request-map uri="return.pdf"><security https="true" auth="true"/><response name="success" type="view" value="ReturnPDF"/></request-map>
     <request-map uri="shipGroups.pdf"><security https="true" auth="true"/><response name="success" type="view" value="ShipGroupsPDF"/></request-map>
 
+    <request-map uri="LookupProductCategory">
+        <security auth="true" https="true"/>
+        <response name="success" type="view" value="LookupProductCategory"/>
+    </request-map>
+    
+    <request-map uri="ManageOrdersFromEbay">
+        <response name="success" type="view" value="ManageOrdersFromEbay"/>
+        <response name="failure" type="view" value="ManageOrdersFromEbay"/>
+    </request-map>
+    
+    <request-map uri="ImportOrdersFromEbay">
+        <security https="true" auth="true"/>
+        <event type="service" path="" invoke="importFromEbay"/>
+        <response name="success" type="view" value="ManageOrdersFromEbay"/>
+        <response name="failure" type="view" value="ManageOrdersFromEbay"/>
+    </request-map>
+    
     <!--
         These are just examples of reports developed using JasperReport and not really
         useful reports. In order to run them you'll have to follow the notes in the 
@@ -1505,16 +1522,13 @@
         <security https="true" auth="true"/>
         <response name="success" type="view" value="orderreportlist"/>
     </request-map>
+    
+    
     <view-map name="orderreportlist" type="screen" page="component://order/widget/ordermgr/OrderReportScreens.xml#OrderReportList"/>
     <view-map name="orderreportjasper" type="jasperreportspdf" page="/reports/orderreport.xml" content-type="application/pdf" encoding="none"/>
     <view-map name="orderitemreportjasper" type="jasperreportspdf" page="/reports/orderitemreport.xml" content-type="application/pdf" encoding="none"/>
     -->
 
-    <request-map uri="LookupProductCategory">
-        <security auth="true" https="true"/>
-        <response name="success" type="view" value="LookupProductCategory"/>
-    </request-map>
-
     <!-- end of request mappings -->
 
     <!-- View Mappings -->
@@ -1670,5 +1684,7 @@
     <view-map name="ShipGroupsPDF" type="screenfop" page="component://order/widget/ordermgr/OrderPrintScreens.xml#ShipGroupsPDF" content-type="application/pdf" encoding="none"/>
 
     <view-map name="SendConfirmationMail" type="screen" page="component://order/widget/ordermgr/OrderViewScreens.xml#SendOrderConfirmation"/>
+    <view-map name="ManageOrdersFromEbay" type="screen" page="component://order/widget/ordermgr/OrderViewScreens.xml#ManageOrdersFromEbay"/>
+    <view-map name="ListOrdersFromEbay" type="screen" page="component://order/widget/ordermgr/OrderViewScreens.xml#ListOrdersFromEbay"/>
     <!-- end of view mappings -->
 </site-conf>

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/OrderForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/OrderForms.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/order/OrderForms.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/order/OrderForms.xml Wed Jul 18 13:41:01 2007
@@ -118,4 +118,36 @@
         </field>
         <field name="addButton" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
+    <form name="ManageOrdersFromEbay" type="single" target="ImportOrdersFromEbay">
+        <field name="productStoreId">
+            <drop-down>
+                <entity-options entity-name="ProductStore" description="${storeName}" key-field-name="productStoreId">
+                    <entity-order-by field-name="storeName"/>
+                </entity-options>
+            </drop-down>
+        </field>
+        <field name="fromDate" title="${uiLabelMap.CommonFromDateTime}"><date-time/></field>
+        <field name="thruDate" title="${uiLabelMap.CommonThruDateTime}"><date-time/></field>
+        <field name="submitButton" title="${uiLabelMap.OrderImportOrdersFromEbay}"><submit button-type="button"/></field>
+    </form>
+    <form name="ListOrdersFromEbay" type="list" list-name="orderList">
+        <field name="externalId" title="${uiLabelMap.OrderImportEbayItem}"><display/></field>
+        <field name="orderId"><display/></field>
+        <field name="createdDate"><display/></field>
+        <field name="productId"><display/></field>
+        <field name="title"><display/></field>
+        <field name="quantitySold"><display/></field>
+        <field name="amount"><display/></field>
+        <field name="shippingServiceCost"><display/></field>
+        <field name="amountPaid"><display/></field>
+        <field name="shippingService"><display/></field>
+        <field name="paymentMethodUsed"><display/></field>
+        <field name="eBayPaymentStatus"><display/></field>
+        <field name="checkoutStatus"><display/></field>
+        <field name="completeStatus"><display/></field>
+        <field name="paidTime"><display/></field>
+        <field name="shippedTime"><display/></field>
+        <field name="buyerName"><display/></field>
+        <field name="emailBuyer"><display/></field>
+    </form>
 </forms>

Modified: ofbiz/trunk/applications/order/widget/ordermgr/OrderViewScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/widget/ordermgr/OrderViewScreens.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/order/widget/ordermgr/OrderViewScreens.xml (original)
+++ ofbiz/trunk/applications/order/widget/ordermgr/OrderViewScreens.xml Wed Jul 18 13:41:01 2007
@@ -313,4 +313,23 @@
             </widgets>
         </section>
     </screen>
+    <screen name="ManageOrdersFromEbay">
+        <section>
+            <actions>
+                <set field="titleProperty" value="OrderImportOrdersFromEbay"/>
+                <set field="orderList" from-field="parameters.orderList"/>
+            </actions>
+            <widgets>
+                <decorator-screen name="CommonOrderViewDecorator">
+                    <decorator-section name="body">
+                        <container>
+                            <label style="head1">${uiLabelMap.OrderImportOrdersFromEbay}</label>
+                        </container>
+                        <include-form name="ManageOrdersFromEbay" location="component://order/webapp/ordermgr/order/OrderForms.xml"/>
+                        <include-form name="ListOrdersFromEbay" location="component://order/webapp/ordermgr/order/OrderForms.xml"/>
+                    </decorator-section>
+                </decorator-screen>
+            </widgets>
+        </section>
+    </screen>
 </screens>

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels.properties (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels.properties Wed Jul 18 13:41:01 2007
@@ -188,6 +188,7 @@
 PageTitlePickingMoveStock=Picking : Move Stock
 PageTitlePickingViewStartedPicks=Picking : View Started Picks
 PageTitleProductsExportToGoogle=Products Export on Google Base
+PageTitleProductsExportToEbay=Products Export on eBay
 PageTitleQuickAddProductVariants=Quick Add Product Variants
 PageTitleSearchInventoryItems=Search Inventory Items
 PageTitleSearchResults=Search Results
@@ -557,6 +558,7 @@
 ProductExpireDate=Expire Date
 ProductExpireResultsFrom=Expire Results From
 ProductExplodeOrderItems=Explode Order Items
+ProductExportToeBay=Export To eBay
 ProductExportDeactivated=Deactivated
 ProductExportPublish=Publish
 ProductExportPublishDraft=Publish Draft
@@ -1483,6 +1485,10 @@
 productevents.specified_update_mode_not_supported=Specified update mode: "${updateMode}" is not supported.
 productevents.thru_date_not_formatted_correctly=Thru Date not formatted correctly.
 productevents.updatemode_not_specified=Update Mode was not specified, but is required.
+productsExportToEbay.errorDuringAuthenticationToEbay=Error during authentication to eBay
+productsExportToEbay.exceptionDuringBuildingDataItemsToEbay=Exception occurred during building data items to eBay
+productsExportToEbay.exceptionInExportToEbay=Exception in exportToEbay
+productsExportToEbay.productItemsSentCorrecltyToEbay=Product items sent correclty to eBay
 productsExportToGoogle.errorDuringAuthenticationToGoogle=Error during authentication to Google Account
 productsExportToGoogle.errorInTheResponseFromGoogle=Error in the response from Google :
 productsExportToGoogle.exceptionDuringBuildingDataItemsToGoogle=Exception occurred during building data items to Google Base

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties Wed Jul 18 13:41:01 2007
@@ -186,6 +186,7 @@
 PageTitlePickingMoveStock=Prelievo : Muovi Giacenza
 PageTitlePickingViewStartedPicks=Prelievo : Mostra Inizio Prelievo
 PageTitleProductsExportToGoogle=Esportazioni Prodotti su Google Base
+PageTitleProductsExportToeBay=Esportazioni Prodotti su eBay
 PageTitleQuickAddProductVariants=Aggiunta Veloce Varianti Prodotto
 PageTitleSearchInventoryItems=Ricerca Righe Inventario
 PageTitleSearchResults=Risultati Ricerca
@@ -552,6 +553,7 @@
 ProductExpireDate=Data Scadenza
 ProductExpireResultsFrom=Risultati Scaduti Da
 ProductExplodeOrderItems=Esplodi Righe Ordine
+ProductExportToeBay=Esportazione Su eBay
 ProductExportDeactivated=Disattiva
 ProductExportPublish=Pubblica
 ProductExportPublishDraft=Pubblica come Bozza
@@ -1466,6 +1468,10 @@
 productevents.specified_update_mode_not_supported=Specificato modo di aggiornamento: "${updateMode}" non \u00e8 supportato.
 productevents.thru_date_not_formatted_correctly=Data A non formattata correttamente.
 productevents.updatemode_not_specified=Modo di Aggiornamento non \u00e8 stato specificato, ma \u00e8 richiesto.
+productsExportToEbay.errorDuringAuthenticationToEbay=Errore durante l\'autenticazione su eBay
+productsExportToEbay.exceptionDuringBuildingDataItemsToEbay=Eccezione accaduta durante la creazione dei dati prodotti per eBay
+productsExportToEbay.exceptionInExportToEbay=Eccezione in exportToEbay
+productsExportToEbay.productItemsSentCorrecltyToEbay=Prodotti inviati correttamente su eBay
 productsExportToGoogle.errorDuringAuthenticationToGoogle=Errore durante l\'autenticazione su Google Account
 productsExportToGoogle.errorInTheResponseFromGoogle=Errore nella risposta di Google :
 productsExportToGoogle.exceptionDuringBuildingDataItemsToGoogle=Eccezione accaduta durante la creazione dei dati prodotti per Google Base

Modified: ofbiz/trunk/applications/product/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?view=diff&rev=557392&r1=557391&r2=557392
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services.xml Wed Jul 18 13:41:01 2007
@@ -1126,4 +1126,12 @@
         <attribute type="String" mode="IN" name="statusId" optional="false"/>
         <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/>
     </service>
+    <service name="exportToEbay" engine="java"
+             location="org.ofbiz.product.product.ProductsExportToEbay" invoke="exportToEbay" auth="true">
+        <description>Export products to eBay</description>
+        <attribute type="List" mode="IN" name="selectResult" optional="false"/>
+        <attribute type="String" mode="IN" name="webSiteUrl" optional="false"/>
+        <attribute type="String" mode="IN" name="imageUrl" optional="false"/>
+        <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/>
+    </service>
 </services>

Added: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java?view=auto&rev=557392
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java (added)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java Wed Jul 18 13:41:01 2007
@@ -0,0 +1,324 @@
+/*******************************************************************************
+ * 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 org.ofbiz.product.product;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.sql.Timestamp;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javolution.util.FastMap;
+
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ProductsExportToEbay {
+    
+    private static final String resource = "ProductUiLabels";
+    private static final String module = ProductsExportToEbay.class.getName();
+    private static final String xmlHeader = "<?xml version=\'1.0\' encoding='UTF-8'?>\n";
+
+    public static Map exportToEbay(DispatchContext dctx, Map context) {
+        Locale locale = (Locale) context.get("locale");
+        try {
+            String configString = "productsExport.properties";
+                            
+            // get the Developer Key
+            String devID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.devID");
+            
+            // get the Application Key
+            String appID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.appID");
+            
+            // get the Certifcate Key
+            String certID = UtilProperties.getPropertyValue(configString, "productsExport.eBay.certID");
+            
+            // get the Token
+            String token = UtilProperties.getPropertyValue(configString, "productsExport.eBay.token");
+            
+            // get the Rest Token
+            String restToken = UtilProperties.getPropertyValue(configString, "productsExport.eBay.restToken");
+            
+            // get the xmlGatewayUri
+            String xmlGatewayUri = UtilProperties.getPropertyValue(configString, "productsExport.eBay.xmlGatewayUri");
+            
+            StringBuffer dataItemsXml = new StringBuffer();
+            
+            if (!ServiceUtil.isFailure(buildSellerTransactionsXml(context, dataItemsXml, token))) { 
+                Map result = postItem(xmlGatewayUri, dataItemsXml, devID, appID, certID, "GetSellerTransactions");
+                Debug.logInfo(result.toString(), module);
+                /*
+                if (ServiceUtil.isFailure(result)) { 
+                        return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(result));
+                } else {
+                    Debug.logError("Error during authentication to eBay Account", module);
+                    return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToeBay.errorDuringAuthenticationToeBay", locale));
+                } 
+                */   
+            }
+            
+            dataItemsXml.replace(0, dataItemsXml.length(), "");
+            if (!ServiceUtil.isFailure(buildDataItemsXml(dctx, context, dataItemsXml, token))) { 
+                Map result = postItem(xmlGatewayUri, dataItemsXml, devID, appID, certID, "AddItem");
+                if (ServiceUtil.isFailure(result)) { 
+                        return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(result));
+                } else {
+                    Debug.logError("Error during authentication to eBay Account", module);
+                    return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.errorDuringAuthenticationToEbay", locale));
+                }            
+            }
+        } catch (Exception e) {        
+            Debug.logError("Exception in exportToEbay " + e, module);
+            return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionInExportToEbay", locale));
+        }
+        return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "productsExportToEbay.productItemsSentCorrecltyToEbay", locale));
+    }
+   
+    private static String toString(InputStream inputStream) throws IOException {
+        String string;
+        StringBuilder outputBuilder = new StringBuilder();
+        if (inputStream != null) {
+            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
+            while (null != (string = reader.readLine())) {
+                outputBuilder.append(string).append('\n');
+            }
+        }
+        return outputBuilder.toString();
+    }
+    
+    private static Map postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID, String callName) throws IOException {
+        HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
+      
+        connection.setDoInput(true);
+        connection.setDoOutput(true);
+        connection.setRequestMethod("POST");
+        connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", "517");
+        connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
+        connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
+        connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
+        connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
+        connection.setRequestProperty("X-EBAY-API-SITEID", "0");
+        connection.setRequestProperty("Content-Type", "text/xml");
+        
+        OutputStream outputStream = connection.getOutputStream();
+        outputStream.write(dataItems.toString().getBytes());
+        outputStream.close();
+    
+        int responseCode = connection.getResponseCode();
+        InputStream inputStream;
+        Map result = FastMap.newInstance();
+        if (responseCode == HttpURLConnection.HTTP_CREATED) {
+            inputStream = connection.getInputStream();
+            result = ServiceUtil.returnSuccess(toString(inputStream));
+            Debug.logInfo(toString(inputStream), module);
+        } else if (responseCode == HttpURLConnection.HTTP_OK) {
+            inputStream = connection.getInputStream();
+            result = ServiceUtil.returnFailure(toString(inputStream));
+        } else {
+            inputStream = connection.getErrorStream();
+            result = ServiceUtil.returnFailure(toString(inputStream));
+        }
+        return result;
+    }
+    
+    private static Map buildDataItemsXml(DispatchContext dctx, Map context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale)context.get("locale");
+        try {
+             GenericDelegator delegator = dctx.getDelegator();
+             LocalDispatcher dispatcher = dctx.getDispatcher();
+             List selectResult = (List)context.get("selectResult");
+             String webSiteUrl = (String)context.get("webSiteUrl");
+             String imageUrl = (String)context.get("imageUrl");
+             String trackingCodeId = (String)context.get("trackingCodeId");
+             
+             // Get the list of products to be exported to eBay
+             List productsList  = delegator.findByCondition("Product", new EntityExpr("productId", EntityOperator.IN, selectResult), null, null);
+             
+             // Get the tracking code
+             if (UtilValidate.isEmpty(trackingCodeId) || "_NA_".equals(trackingCodeId)) {
+                 trackingCodeId = "";
+             } else {
+                 trackingCodeId = "?atc=" + trackingCodeId;
+             }
+             
+             try {
+                 Document itemDocument = UtilXml.makeEmptyXmlDocument("AddItemRequest");
+                 Element itemRequestElem = itemDocument.getDocumentElement();
+                 itemRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+                 
+                 dataItemsXml.append(xmlHeader);
+                 
+                 // Iterate the product list getting all the relevant data
+                 Iterator productsListItr = productsList.iterator();
+                 while(productsListItr.hasNext()) {
+                     GenericValue prod = (GenericValue)productsListItr.next();
+                     String link = webSiteUrl + "/control/product/~product_id=" + prod.getString("productId") + trackingCodeId;
+                     String title = parseText(prod.getString("productName"));
+                     String description = parseText(prod.getString("description"));
+                     String image_link = "";
+                     if (UtilValidate.isNotEmpty(prod.getString("largeImageUrl"))) {
+                         image_link = imageUrl + prod.getString("largeImageUrl");
+                     }
+                     
+                     Element requesterCredentialsElem = UtilXml.addChildElement(itemRequestElem, "RequesterCredentials", itemDocument);
+                     UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, itemDocument);
+                     
+                     Element itemElem = UtilXml.addChildElement(itemRequestElem, "Item", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "Country", "US", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "Location", "New York", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "Currency", "USD", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "SKU", prod.getString("productId"), itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "Title", title, itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "ListingDuration", "Days_1", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "Quantity", "3", itemDocument);
+                     UtilXml.addChildElementValue(itemElem, "PaymentMethods", "AmEx", itemDocument);
+                     
+                     Element primaryCatElem = UtilXml.addChildElement(itemElem, "PrimaryCategory", itemDocument);
+                     UtilXml.addChildElementValue(primaryCatElem, "CategoryID", "20118", itemDocument);
+                     
+                     Element startPriceElem = UtilXml.addChildElementValue(itemElem, "StartPrice", "1.00", itemDocument);
+                     startPriceElem.setAttribute("currencyID", "USD");
+                 }
+                 OutputStream os = new ByteArrayOutputStream();
+                 OutputFormat format = new OutputFormat();
+                 format.setOmitDocumentType(true);
+                 format.setOmitXMLDeclaration(true);
+                 format.setIndenting(false);
+                 XMLSerializer serializer = new XMLSerializer(os, format);
+                 serializer.asDOMSerializer();
+                 serializer.serialize(itemDocument.getDocumentElement());
+                 
+                 dataItemsXml.append(os.toString());
+             } catch (Exception e) {
+                 Debug.logError("Exception during building data items to eBay", module);
+                  return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
+             }
+         } catch (Exception e) {
+            Debug.logError("Exception during building data items to eBay", module);
+            return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
+         } 
+         return ServiceUtil.returnSuccess();
+    }
+    
+    private static Map buildCategoriesXml(Map context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale)context.get("locale");
+        try {
+             Document itemRequest = UtilXml.makeEmptyXmlDocument("GetCategoriesRequest");
+             Element itemRequestElem = itemRequest.getDocumentElement();
+             itemRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+             
+             dataItemsXml.append(xmlHeader);
+             Element requesterCredentialsElem = UtilXml.addChildElement(itemRequestElem, "RequesterCredentials", itemRequest);
+             UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, itemRequest);
+             
+             UtilXml.addChildElementValue(itemRequestElem, "DetailLevel", "ReturnAll", itemRequest);
+             UtilXml.addChildElementValue(itemRequestElem, "CategorySiteID", "0", itemRequest);
+             UtilXml.addChildElementValue(itemRequestElem, "LevelLimit", "2", itemRequest);
+             UtilXml.addChildElementValue(itemRequestElem, "ViewAllNodes", "false", itemRequest);
+             
+             OutputStream os = new ByteArrayOutputStream();
+             OutputFormat format = new OutputFormat();
+             format.setOmitDocumentType(true);
+             format.setOmitXMLDeclaration(true);
+             format.setIndenting(false);
+             XMLSerializer serializer = new XMLSerializer(os, format);
+             serializer.asDOMSerializer();
+             serializer.serialize(itemRequest.getDocumentElement());
+             
+             dataItemsXml.append(os.toString());
+         } catch (Exception e) {
+             Debug.logError("Exception during building data items to eBay", module);
+              return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
+         }
+         return ServiceUtil.returnSuccess();
+    }
+    
+    private static Map buildSellerTransactionsXml(Map context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale)context.get("locale");
+        try {
+             Document transDoc = UtilXml.makeEmptyXmlDocument("GetSellerTransactionsRequest");
+             Element transElem = transDoc.getDocumentElement();
+             transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+             
+             dataItemsXml.append(xmlHeader);
+             
+             Element requesterCredentialsElem = UtilXml.addChildElement(transElem, "RequesterCredentials", transDoc);
+             UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, transDoc);
+             Timestamp end = new Timestamp(System.currentTimeMillis());
+             Timestamp start = UtilDateTime.getDayEnd(end, -1);
+             
+             UtilXml.addChildElementValue(transElem, "DetailLevel", "ReturnAll", transDoc);
+             UtilXml.addChildElementValue(transElem, "ModTimeFrom", start.toString(), transDoc);
+             UtilXml.addChildElementValue(transElem, "ModTimeTo", end.toString(), transDoc);
+             
+             OutputStream os = new ByteArrayOutputStream();
+             OutputFormat format = new OutputFormat();
+             format.setOmitDocumentType(true);
+             format.setOmitXMLDeclaration(true);
+             format.setIndenting(false);
+             XMLSerializer serializer = new XMLSerializer(os, format);
+             serializer.asDOMSerializer();
+             serializer.serialize(transDoc.getDocumentElement());
+             
+             dataItemsXml.append(os.toString());
+         } catch (Exception e) {
+             Debug.logError("Exception during building data items to eBay", module);
+              return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
+         }
+         return ServiceUtil.returnSuccess();
+    }
+    
+    private static String parseText(String text) {
+        Pattern htmlPattern = Pattern.compile("[<](.+?)[>]");
+        Pattern tabPattern = Pattern.compile("\\s");
+        if (null != text && text.length() > 0){
+            Matcher matcher = htmlPattern.matcher(text);
+            text = matcher.replaceAll("");
+            matcher = tabPattern.matcher(text);
+            text = matcher.replaceAll(" ");
+        } else {
+            text = "";
+        }
+        return text;
+    }
+}
\ No newline at end of file

Propchange: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToEbay.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain