svn commit: r813444 - in /ofbiz/trunk/specialpurpose/ebay: config/ servicedef/ src/org/ofbiz/ebay/ webapp/ebay/WEB-INF/ widget/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r813444 - in /ofbiz/trunk/specialpurpose/ebay: config/ servicedef/ src/org/ofbiz/ebay/ webapp/ebay/WEB-INF/ widget/

ashish-18
Author: ashish
Date: Thu Sep 10 13:58:33 2009
New Revision: 813444

URL: http://svn.apache.org/viewvc?rev=813444&view=rev
Log:
Initial pass on new call "GetOrders" (More to come in a day or so) - http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/GetOrders.html. OOTB we have "GetSellersTransactions" call implemented but we have observed something strange in its functionality.

Here are few reason for this implementation:
-- In "GetSellersTransactions" itemId(ProductId in ebay) is provided in the OrderHeader.externalId field which doesn't seems correct.
-- Suppose we have Single Order created in eBay if some one wins the auction and in that order we have 3 order items.
Then "GetSellersTransaction" call creates three orders in OFBiz for all those three items that are associated with Single Ebay order.
In short "GetSellersTransaction" request treat three item as three transactions.
-- "GetOrders" call will return the list of orders on the basis of search criteria and then we will create(Import) the Order in OFBiz from the resultant list of orders.
-- Current implementation for "GetSellersTransactions" will remain as it is in trunk - as we don't know if someone might be using it in their custom projects.

Also did miscellaneous cleanup.
Thanks Jacopo for providing your notes for this implementation & also discussing issues in b/w development - as always your notes were awesome.

Added:
    ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java   (with props)
Modified:
    ofbiz/trunk/specialpurpose/ebay/config/EbayUiLabels.xml
    ofbiz/trunk/specialpurpose/ebay/servicedef/services.xml
    ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java
    ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ImportOrdersFromEbay.java
    ofbiz/trunk/specialpurpose/ebay/webapp/ebay/WEB-INF/controller.xml
    ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml
    ofbiz/trunk/specialpurpose/ebay/widget/EbayMenus.xml
    ofbiz/trunk/specialpurpose/ebay/widget/EbayScreens.xml

Modified: ofbiz/trunk/specialpurpose/ebay/config/EbayUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/config/EbayUiLabels.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/config/EbayUiLabels.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/config/EbayUiLabels.xml Thu Sep 10 13:58:33 2009
@@ -32,6 +32,9 @@
         <value xml:lang="it">OFBiz</value>
         <value xml:lang="th">OFBiz</value>
     </property>
+    <property key="EbayEBayOrders">
+        <value xml:lang="en">eBay Orders</value>
+    </property>
     <property key="EbayExportToEbay">
         <value xml:lang="de">zu eBay exportieren</value>
         <value xml:lang="en">Export To eBay</value>
@@ -324,6 +327,12 @@
         <value xml:lang="th">ส่งออกสินค้าถึงอีเบย์</value>
         <value xml:lang="zh">把产品导出到eBay</value>
     </property>
+    <property key="buildEbayConfig.unableToFindEbayConfig">
+        <value xml:lang="en">Unable to find eBay configurations.</value>
+    </property>
+    <property key="buildEbayConfig.exceptionInGetOrdersFromEbay">
+        <value xml:lang="en">Exception in getting orders from Ebay.</value>
+    </property>
     <property key="ordersImportFromEbay.cannotConvertFromDate">
         <value xml:lang="en">Cannot convert from date, from yyyy-MM-dd HH:mm:ss.SSS date format to yyyy-MM-dd'T'HH:mm:ss.SSS'Z' date format</value>
         <value xml:lang="fr">Ne peut convertir la date de début, depuis le format yyyy-MM-dd HH:mm:ss.SSS vers yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</value>

Modified: ofbiz/trunk/specialpurpose/ebay/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/servicedef/services.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/servicedef/services.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/servicedef/services.xml Thu Sep 10 13:58:33 2009
@@ -108,4 +108,15 @@
         <attribute type="String" mode="IN" name="paid" optional="true"/>
         <attribute type="String" mode="IN" name="shipped" optional="true"/>
     </service>
+    
+    <!-- Import Orders Services -->
+    <service name="getEbayOrders" engine="java" transaction-timeout="300"
+             location="org.ofbiz.ebay.EbayOrderServices" invoke="getEbayOrders" auth="true">
+        <description>Get Orders from eBay</description>
+        <attribute type="String" mode="IN" name="productStoreId" optional="false"/>
+        <attribute type="String" mode="IN" name="fromDate" optional="false"/>
+        <attribute type="String" mode="IN" name="thruDate" optional="false"/>
+        <attribute type="List" mode="OUT" name="orderList" optional="true"/>
+    </service>
+    
 </services>
\ No newline at end of file

Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java (original)
+++ ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java Thu Sep 10 13:58:33 2009
@@ -19,6 +19,17 @@
 
 package org.ofbiz.ebay;
 
+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.text.ParsePosition;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
 import java.util.Map;
 
 import javolution.util.FastMap;
@@ -27,24 +38,30 @@
 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.service.ServiceUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 
 public class EbayHelper {
     private static final String configFileName = "ebayExport.properties";
     private static final String module = EbayHelper.class.getName();
+    public static final String resource = "EbayUiLabels";
 
     public static Map<String, Object> buildEbayConfig(Map<String, Object> context, GenericDelegator delegator) {
         Map<String, Object> buildEbayConfigContext = FastMap.newInstance();
+        Locale locale = (Locale) context.get("locale");
         String productStoreId = (String) context.get("productStoreId");
         if (UtilValidate.isNotEmpty(productStoreId)) {
             GenericValue eBayConfig = null;
             try {
                 eBayConfig = delegator.findOne("EbayConfig", false, UtilMisc.toMap("productStoreId", productStoreId));
             } catch (GenericEntityException e) {
-                Debug.logError("Unable to find value for EbayConfig", module);
-                e.printStackTrace();
+                String errMsg = UtilProperties.getMessage(resource, "buildEbayConfig.unableToFindEbayConfig" + e.getMessage(), locale);
+                return ServiceUtil.returnError(errMsg);
             }
             if (UtilValidate.isNotEmpty(eBayConfig)) {
                 buildEbayConfigContext.put("devID", eBayConfig.getString("devId"));
@@ -66,4 +83,74 @@
         }    
         return buildEbayConfigContext;
     }    
+
+    public static void appendRequesterCredentials(Element elem, Document doc, String token) {
+        Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
+        UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
+    }
+    
+    public static String convertDate(String dateIn, String fromDateFormat, String toDateFormat) {
+        String dateOut;
+        try {
+            SimpleDateFormat formatIn = new SimpleDateFormat(fromDateFormat);
+            SimpleDateFormat formatOut= new SimpleDateFormat(toDateFormat);
+            Date data = formatIn.parse(dateIn, new ParsePosition(0));
+            dateOut = formatOut.format(data);
+        } catch (Exception e) {
+            dateOut = null;
+        }
+        return dateOut;
+    }
+
+    public 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();
+    }
+
+    public static Map<String, Object> postItem(String postItemsUrl, StringBuffer generatedXmlData, String devID, String appID, String certID,
+            String callName, String compatibilityLevel, String siteID) throws IOException {
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Request of " + callName + " To eBay:\n" + generatedXmlData.toString(), module);
+        }
+        HttpURLConnection connection = (HttpURLConnection) (new URL(postItemsUrl)).openConnection();
+        connection.setDoInput(true);
+        connection.setDoOutput(true);
+        connection.setRequestMethod("POST");
+        connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
+        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", siteID);
+        connection.setRequestProperty("Content-Type", "text/xml");
+
+        OutputStream outputStream = connection.getOutputStream();
+        outputStream.write(generatedXmlData.toString().getBytes());
+        outputStream.close();
+
+        int responseCode = connection.getResponseCode();
+        InputStream inputStream = null;
+        Map<String, Object> result = FastMap.newInstance();
+        String response = null;
+
+        if (responseCode == HttpURLConnection.HTTP_CREATED || responseCode == HttpURLConnection.HTTP_OK) {
+            inputStream = connection.getInputStream();
+            response = EbayHelper.toString(inputStream);
+            result = ServiceUtil.returnSuccess(response);
+        } else {
+            inputStream = connection.getErrorStream();
+            result = ServiceUtil.returnFailure(EbayHelper.toString(inputStream));
+        }
+        if (Debug.verboseOn()) {
+            Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
+        }
+        return result;
+    }
 }
\ No newline at end of file

Added: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java?rev=813444&view=auto
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java (added)
+++ ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java Thu Sep 10 13:58:33 2009
@@ -0,0 +1,113 @@
+/*
+ * 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.ebay;
+
+import java.util.Locale;
+import java.util.Map;
+
+import javolution.util.FastMap;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.service.DispatchContext;
+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 EbayOrderServices {
+    
+    private static final String resource = "EbayUiLabels";
+    private static final String module = EbayOrderServices.class.getName();
+    
+    public static Map<String, Object> getEbayOrders(DispatchContext dctx, Map<String, Object> context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Locale locale = (Locale) context.get("locale");
+        Map<String, Object> result = FastMap.newInstance();
+        try {
+            Map<String, Object> eBayConfigResult = EbayHelper.buildEbayConfig(context, delegator);
+            StringBuffer getOrdersXml = new StringBuffer();
+
+            if (!ServiceUtil.isFailure(buildGetOrdersRequest(context, getOrdersXml, eBayConfigResult.get("token").toString()))) {
+                result = EbayHelper.postItem(eBayConfigResult.get("xmlGatewayUri").toString(), getOrdersXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetOrders", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
+                String success = (String) result.get(ModelService.SUCCESS_MESSAGE);
+                if (success != null) {
+                    result = checkOrders(delegator, dispatcher, locale, context, success);
+                }
+            }
+        } catch (Exception e) {
+            String errMsg = UtilProperties.getMessage(resource, "buildEbayConfig.exceptionInGetOrdersFromEbay" + e.getMessage(), locale);
+            return ServiceUtil.returnError(errMsg);
+        }
+        return result;
+    }
+
+    private static Map<String, Object> buildGetOrdersRequest(Map<String, Object> context, StringBuffer dataItemsXml, String token) {
+        Locale locale = (Locale) context.get("locale");
+        String fromDate = (String) context.get("fromDate");
+        String thruDate = (String) context.get("thruDate");
+        try {
+             Document transDoc = UtilXml.makeEmptyXmlDocument("GetOrdersRequest");
+             Element transElem = transDoc.getDocumentElement();
+             transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
+
+             EbayHelper.appendRequesterCredentials(transElem, transDoc, token);
+             UtilXml.addChildElementValue(transElem, "DetailLevel", "ReturnAll", transDoc);
+             UtilXml.addChildElementValue(transElem, "OrderRole", "Seller", transDoc);
+             UtilXml.addChildElementValue(transElem, "OrderStatus", "Completed", transDoc);
+
+             String fromDateOut = EbayHelper.convertDate(fromDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+             if (fromDateOut != null) {
+                 UtilXml.addChildElementValue(transElem, "CreateTimeFrom", fromDateOut, transDoc);
+             } else {
+                 Debug.logError("Cannot convert from date from yyyy-MM-dd HH:mm:ss.SSS date format to yyyy-MM-dd'T'HH:mm:ss.SSS'Z' date format", module);
+                 return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.cannotConvertFromDate", locale));
+             }
+             fromDateOut = EbayHelper.convertDate(thruDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+             if (fromDateOut != null) {
+                 UtilXml.addChildElementValue(transElem, "CreateTimeTo", fromDateOut, transDoc);
+             } else {
+                 Debug.logError("Cannot convert thru date from yyyy-MM-dd HH:mm:ss.SSS date format to yyyy-MM-dd'T'HH:mm:ss.SSS'Z' date format", module);
+                 return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.cannotConvertThruDate", locale));
+             }
+             //Debug.logInfo("The value of generated string is ======= " + UtilXml.writeXmlDocument(transDoc), module);
+             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<String, Object> checkOrders(GenericDelegator delegator, LocalDispatcher dispatcher, Locale locale, Map<String, Object> context, String response) {
+        Document docResponse;
+        try {
+            docResponse = UtilXml.readXmlDocument(response, true);
+            //Debug.logInfo("The generated string is ======= " + UtilXml.writeXmlDocument(docResponse), module);            
+        } catch (Exception e) {
+            Debug.logError("Exception during read response from Ebay", module);
+        }
+        return ServiceUtil.returnSuccess();
+    }
+}

Propchange: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayOrderServices.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ImportOrdersFromEbay.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ImportOrdersFromEbay.java?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ImportOrdersFromEbay.java (original)
+++ ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/ImportOrdersFromEbay.java Thu Sep 10 13:58:33 2009
@@ -18,24 +18,16 @@
  *******************************************************************************/
 package org.ofbiz.ebay;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
 import java.math.BigDecimal;
-import java.net.HttpURLConnection;
-import java.net.URL;
 import java.sql.Timestamp;
-import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Collection;
 
 import javolution.util.FastMap;
 
@@ -52,12 +44,12 @@
 import org.ofbiz.order.order.OrderChangeHelper;
 import org.ofbiz.order.shoppingcart.CheckOutHelper;
 import org.ofbiz.order.shoppingcart.ShoppingCart;
+import org.ofbiz.party.contact.ContactHelper;
 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.ofbiz.party.contact.ContactHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -76,7 +68,7 @@
             StringBuffer sellerTransactionsItemsXml = new StringBuffer();
 
             if (!ServiceUtil.isFailure(buildGetSellerTransactionsRequest(context, sellerTransactionsItemsXml, eBayConfigResult.get("token").toString()))) {
-                result = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), sellerTransactionsItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetSellerTransactions", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
+                result = EbayHelper.postItem(eBayConfigResult.get("xmlGatewayUri").toString(), sellerTransactionsItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetSellerTransactions", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
                 String success = (String)result.get(ModelService.SUCCESS_MESSAGE);
                 if (success != null) {
                     result = checkOrders(delegator, dispatcher, locale, context, success);
@@ -171,7 +163,7 @@
             StringBuffer completeSaleXml = new StringBuffer();
 
             if (!ServiceUtil.isFailure(buildCompleteSaleRequest(delegator, locale, externalId, transactionId, context, completeSaleXml, eBayConfigResult.get("token").toString()))) {
-                result = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), completeSaleXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "CompleteSale", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
+                result = EbayHelper.postItem(eBayConfigResult.get("xmlGatewayUri").toString(), completeSaleXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "CompleteSale", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
                 String successMessage = (String)result.get("successMessage");
                 if (successMessage != null) {
                     return readCompleteSaleResponse(successMessage, locale);
@@ -186,62 +178,6 @@
         return ServiceUtil.returnSuccess();
     }
 
-    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, String compatibilityLevel, String siteID) throws IOException {
-        if (Debug.verboseOn()) {
-            Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), module);
-        }
-
-        HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
-        connection.setDoInput(true);
-        connection.setDoOutput(true);
-        connection.setRequestMethod("POST");
-        connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
-        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", siteID);
-        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();
-        String response = null;
-
-        if (responseCode == HttpURLConnection.HTTP_CREATED ||
-            responseCode == HttpURLConnection.HTTP_OK) {
-            inputStream = connection.getInputStream();
-            response = toString(inputStream);
-            result = ServiceUtil.returnSuccess(response);
-        } else {
-            inputStream = connection.getErrorStream();
-            result = ServiceUtil.returnFailure(toString(inputStream));
-        }
-
-        if (Debug.verboseOn()) {
-            Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
-        }
-
-        return result;
-    }
-
     private static Map checkOrders(GenericDelegator delegator, LocalDispatcher dispatcher, Locale locale, Map context, String response) {
         StringBuffer errorMessage = new StringBuffer();
         List orders = readResponseFromEbay(response, locale, (String)context.get("productStoreId"), delegator, errorMessage);
@@ -281,10 +217,11 @@
              Element transElem = transDoc.getDocumentElement();
              transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
 
-             appendRequesterCredentials(transElem, transDoc, token);
+             EbayHelper.appendRequesterCredentials(transElem, transDoc, token);
              UtilXml.addChildElementValue(transElem, "DetailLevel", "ReturnAll", transDoc);
+             UtilXml.addChildElementValue(transElem, "IncludeContainingOrder", "true", transDoc);
 
-             String fromDateOut = convertDate(fromDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+             String fromDateOut = EbayHelper.convertDate(fromDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
              if (fromDateOut != null) {
                  UtilXml.addChildElementValue(transElem, "ModTimeFrom", fromDateOut, transDoc);
              } else {
@@ -293,14 +230,14 @@
              }
 
 
-             fromDateOut = convertDate(thruDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+             fromDateOut = EbayHelper.convertDate(thruDate, "yyyy-MM-dd HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
              if (fromDateOut != null) {
                  UtilXml.addChildElementValue(transElem, "ModTimeTo", fromDateOut, transDoc);
              } else {
                  Debug.logError("Cannot convert thru date from yyyy-MM-dd HH:mm:ss.SSS date format to yyyy-MM-dd'T'HH:mm:ss.SSS'Z' date format", module);
                  return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.cannotConvertThruDate", locale));
              }
-
+             //Debug.logInfo("The value of generated string is ======= " + UtilXml.writeXmlDocument(transDoc), module);
              dataItemsXml.append(UtilXml.writeXmlDocument(transDoc));
          } catch (Exception e) {
              Debug.logError("Exception during building get seller transactions request", module);
@@ -316,7 +253,7 @@
              Element transElem = transDoc.getDocumentElement();
              transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
 
-             appendRequesterCredentials(transElem, transDoc, token);
+             EbayHelper.appendRequesterCredentials(transElem, transDoc, token);
              UtilXml.addChildElementValue(transElem, "DetailName", "ShippingServiceDetails", transDoc);
              UtilXml.addChildElementValue(transElem, "DetailName", "TaxJurisdiction", transDoc);
              dataItemsXml.append(UtilXml.writeXmlDocument(transDoc));
@@ -341,7 +278,7 @@
             Element transElem = transDoc.getDocumentElement();
             transElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
 
-            appendRequesterCredentials(transElem, transDoc, token);
+            EbayHelper.appendRequesterCredentials(transElem, transDoc, token);
 
             UtilXml.addChildElementValue(transElem, "ItemID", itemId, transDoc);
 
@@ -380,11 +317,6 @@
         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 Map readCompleteSaleResponse(String msg, Locale locale) {
         try {
             Document docResponse = UtilXml.readXmlDocument(msg, true);
@@ -410,6 +342,7 @@
         List orders = null;
         try {
             Document docResponse = UtilXml.readXmlDocument(msg, true);
+//            Debug.logInfo("The generated string is ======= " + UtilXml.writeXmlDocument(docResponse), module);
             Element elemResponse = docResponse.getDocumentElement();
             String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
             List paginationList = UtilXml.childElementList(elemResponse, "PaginationResult");
@@ -1177,19 +1110,6 @@
         return orderHeader;
     }
 
-    private static String convertDate(String dateIn, String fromDateFormat, String toDateFormat) {
-        String dateOut;
-        try {
-            SimpleDateFormat formatIn = new SimpleDateFormat(fromDateFormat);
-            SimpleDateFormat formatOut= new SimpleDateFormat(toDateFormat);
-            Date data = formatIn.parse(dateIn, new ParsePosition(0));
-            dateOut = formatOut.format(data);
-        } catch (Exception e) {
-            dateOut = null;
-        }
-        return dateOut;
-    }
-
     private static void setShipmentMethodType(ShoppingCart cart, String shippingService) {
         String partyId = "_NA_";
         String shipmentMethodTypeId = "NO_SHIPPING";

Modified: ofbiz/trunk/specialpurpose/ebay/webapp/ebay/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/webapp/ebay/WEB-INF/controller.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/webapp/ebay/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/webapp/ebay/WEB-INF/controller.xml Thu Sep 10 13:58:33 2009
@@ -68,6 +68,28 @@
         <response name="success" type="view" value="ManageOrdersFromEbay"/>
         <response name="failure" type="view" value="ManageOrdersFromEbay"/>
     </request-map>
+    
+    <!-- New Import Order entries -->
+    <request-map uri="eBayOrders">
+        <security https="true" auth="true"/>
+        <response name="success" type="view" value="EbayOrders"/>
+        <response name="failure" type="view" value="EbayOrders"/>
+    </request-map>
+
+    <request-map uri="GetEbayOrders">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="getEbayOrders"/>
+        <response name="success" type="view" value="EbayOrders"/>
+        <response name="failure" type="view" value="EbayOrders"/>
+    </request-map>
+
+    <request-map uri="ImportEbayOrders">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="ImportEbayOrders"/>
+        <response name="success" type="view" value="EbayOrders"/>
+        <response name="failure" type="view" value="EbayOrders"/>
+    </request-map>
+    
     <!-- end of request mappings -->
 
     <!-- View Mappings -->
@@ -76,5 +98,6 @@
     <view-map name="keywordsearch" type="screen" page="component://ebay/widget/EbayScreens.xml#keywordsearch"/>
     <view-map name="ProductsExportToEbay" type="screen" page="component://ebay/widget/EbayScreens.xml#ProductsExportToEbay"/>
     <view-map name="ManageOrdersFromEbay" type="screen" page="component://ebay/widget/EbayScreens.xml#ManageOrdersFromEbay"/>
+    <view-map name="EbayOrders" type="screen" page="component://ebay/widget/EbayScreens.xml#EbayOrders"/>
     <!-- end of view mappings -->
 </site-conf>

Modified: ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml Thu Sep 10 13:58:33 2009
@@ -87,4 +87,31 @@
         <field name="_rowSubmit" title="${uiLabelMap.CommonSelect}" use-when="!${canImportOrder}"><display/></field>
         <field name="submitButton" title="${uiLabelMap.EbayImportOrdersFromEbay}" widget-style="smallSubmit"><submit/></field>
     </form>
+    
+    <form name="FindEbayOrders" type="single" target="GetEbayOrders"
+        header-row-style="header-row" default-table-style="basic-table">
+        <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 default-value="${groovy: org.ofbiz.base.util.UtilDateTime.getDayStart(nowTimestamp)}"/></field>
+        <field name="thruDate" title="${uiLabelMap.CommonThruDateTime}"><date-time default-value="${groovy: org.ofbiz.base.util.UtilDateTime.getDayEnd(nowTimestamp)}"/></field>
+        <field name="submitButton" title="${uiLabelMap.CommonFind}"><submit button-type="button"/></field>
+    </form>
+
+    <form name="ListEbayOrders" type="multi" use-row-submit="true" list-name="orderList" target="ImportEbayOrders"
+        odd-row-style="alternate-row" default-table-style="basic-table hover-bar">
+        <field name="productStoreId"><hidden/></field>
+        <field name="eBayOrderId" title="${uiLabelMap.EbayEbayOrderId}"><display/></field>
+        <field name="orderId">
+            <hyperlink target="orderview" description="${orderId}">
+                <parameter param-name="orderId"/>
+            </hyperlink>
+        </field>
+        <field name="createdDate"><display/></field>
+        <field name="submitButton" title="${uiLabelMap.EbayImportOrdersFromEbay}" widget-style="smallSubmit"><submit/></field>
+    </form>
 </forms>
\ No newline at end of file

Modified: ofbiz/trunk/specialpurpose/ebay/widget/EbayMenus.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/widget/EbayMenus.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/widget/EbayMenus.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/widget/EbayMenus.xml Thu Sep 10 13:58:33 2009
@@ -21,5 +21,6 @@
     <menu name="EbayAppBar" title="${uiLabelMap.EbayApplication}" extends="CommonAppBarMenu" extends-resource="component://common/widget/CommonMenus.xml">
         <menu-item name="export" title="${uiLabelMap.EbayExportToEbay}"><link target="advancedsearch"/></menu-item>
         <menu-item name="importOrders" title="${uiLabelMap.EbayImportOrdersFromEbay}"><link target="ManageOrdersFromEbay"/></menu-item>
+        <menu-item name="eBayOrders" title="${uiLabelMap.EbayEBayOrders}"><link target="eBayOrders"/></menu-item>
     </menu>
 </menus>

Modified: ofbiz/trunk/specialpurpose/ebay/widget/EbayScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/widget/EbayScreens.xml?rev=813444&r1=813443&r2=813444&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ebay/widget/EbayScreens.xml (original)
+++ ofbiz/trunk/specialpurpose/ebay/widget/EbayScreens.xml Thu Sep 10 13:58:33 2009
@@ -195,4 +195,38 @@
             </widgets>
         </section>
     </screen>
+    
+    <screen name="EbayOrders">
+        <section>
+            <actions>
+                <set field="titleProperty" value="EbayEBayOrders"/>
+                <set field="headerItem" value="eBayOrders"/>
+                <set field="orderList" from-field="parameters.orderList"/>
+            </actions>
+            <widgets>
+                <decorator-screen name="permission-decorator" location="${parameters.mainDecoratorLocation}">
+                    <decorator-section name="body">
+                        <section>
+                            <condition>
+                                <if-has-permission permission="EBAY" action="_VIEW"/>
+                            </condition>
+                            <widgets>
+                                <decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
+                                    <decorator-section name="search-options">
+                                        <include-form name="FindEbayOrders" location="component://ebay/widget/EbayForms.xml"/>
+                                    </decorator-section>
+                                    <decorator-section name="search-results">
+                                        <include-form name="ListEbayOrders" location="component://ebay/widget/EbayForms.xml"/>
+                                    </decorator-section>
+                                </decorator-screen>
+                            </widgets>
+                            <fail-widgets>
+                                <label style="h3">${uiLabelMap.EbayViewPermissionError}</label>
+                            </fail-widgets>
+                        </section>
+                    </decorator-section>
+                </decorator-screen>
+            </widgets>
+        </section>
+    </screen>
 </screens>
\ No newline at end of file