Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
Simple JavaDoc formatting in AbstractReportThread Fixes 3 REC_CATCH_EXCEPTION bugs in EbayOrderServices and 1 in ImportOrdersFromEbay, ie: <<This method uses a block try-catch that catches Exception objects, but Exception is never fired in this block, and RuntimeException is not explicitly intercepted. It is a common mistake to say that try / catch (Exception e) is the same as many try / catch, but this twist also intercepts RuntimeException, hiding potential bugs.>> Also some formatting and useless comments removed in both classes.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,7 @@
|
||||
*******************************************************************************/
|
||||
package org.apache.ofbiz.ebay;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -29,6 +30,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.UtilDateTime;
|
||||
import org.apache.ofbiz.base.util.UtilMisc;
|
||||
@@ -38,9 +41,9 @@ import org.apache.ofbiz.base.util.UtilXml;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.GenericEntityException;
|
||||
import org.apache.ofbiz.entity.GenericValue;
|
||||
import org.apache.ofbiz.entity.util.EntityQuery;
|
||||
import org.apache.ofbiz.entity.condition.EntityCondition;
|
||||
import org.apache.ofbiz.entity.condition.EntityComparisonOperator;
|
||||
import org.apache.ofbiz.entity.condition.EntityCondition;
|
||||
import org.apache.ofbiz.entity.util.EntityQuery;
|
||||
import org.apache.ofbiz.order.order.OrderChangeHelper;
|
||||
import org.apache.ofbiz.order.shoppingcart.CheckOutHelper;
|
||||
import org.apache.ofbiz.order.shoppingcart.ShoppingCart;
|
||||
@@ -50,6 +53,7 @@ import org.apache.ofbiz.service.ModelService;
|
||||
import org.apache.ofbiz.service.ServiceUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class ImportOrdersFromEbay {
|
||||
|
||||
@@ -68,8 +72,8 @@ public class ImportOrdersFromEbay {
|
||||
if (!ServiceUtil.isFailure(buildGetSellerTransactionsRequest(context, sellerTransactionsItemsXml,
|
||||
eBayConfigResult.get("token").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());
|
||||
"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);
|
||||
@@ -78,7 +82,7 @@ public class ImportOrdersFromEbay {
|
||||
} catch (Exception e) {
|
||||
Debug.logError("Exception in importOrdersSearchFromEbay " + e, MODULE);
|
||||
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "ordersImportFromEbay.exceptionInImportOrdersSearchFromEbay",
|
||||
locale));
|
||||
locale));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -148,7 +152,7 @@ public class ImportOrdersFromEbay {
|
||||
if (orderHeader == null) {
|
||||
Debug.logError("Cannot find order with orderId [" + orderId + "]", MODULE);
|
||||
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "ordersImportFromEbay.errorRetrievingOrderFromOrderId",
|
||||
locale));
|
||||
locale));
|
||||
}
|
||||
|
||||
if (!"EBAY_SALES_CHANNEL".equals(orderHeader.getString("salesChannelEnumId")) || orderHeader.getString("externalId") == null) {
|
||||
@@ -172,8 +176,8 @@ public class ImportOrdersFromEbay {
|
||||
if (!ServiceUtil.isFailure(buildCompleteSaleRequest(delegator, locale, externalId, transactionId, context, completeSaleXml,
|
||||
eBayConfigResult.get("token").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());
|
||||
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) {
|
||||
@@ -190,7 +194,7 @@ public class ImportOrdersFromEbay {
|
||||
}
|
||||
|
||||
private static Map<String, Object> checkOrders(Delegator delegator, LocalDispatcher dispatcher, Locale locale, Map<String, Object> context,
|
||||
String response) {
|
||||
String response) {
|
||||
StringBuffer errorMessage = new StringBuffer();
|
||||
List<Map<String, Object>> orders = readResponseFromEbay(response, locale, (String) context.get("productStoreId"), delegator, errorMessage);
|
||||
if (orders == null) {
|
||||
@@ -242,7 +246,6 @@ public class ImportOrdersFromEbay {
|
||||
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, "ModTimeTo", fromDateOut, transDoc);
|
||||
@@ -251,7 +254,6 @@ public class ImportOrdersFromEbay {
|
||||
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);
|
||||
@@ -262,7 +264,7 @@ public class ImportOrdersFromEbay {
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildCompleteSaleRequest(Delegator delegator, Locale locale, String externalId, String transactionId,
|
||||
Map<String, Object> context, StringBuffer dataItemsXml, String token) {
|
||||
Map<String, Object> context, StringBuffer dataItemsXml, String token) {
|
||||
String paid = (String) context.get("paid");
|
||||
String shipped = (String) context.get("shipped");
|
||||
|
||||
@@ -288,7 +290,7 @@ public class ImportOrdersFromEbay {
|
||||
UtilXml.addChildElementValue(transElem, "ItemID", externalId.substring(4), transDoc);
|
||||
UtilXml.addChildElementValue(transElem, "TransactionID", "0", transDoc);
|
||||
} else if (externalId.startsWith("EBS_")) {
|
||||
//UtilXml.addChildElementValue(transElem, "OrderID", externalId.substring(4), transDoc);
|
||||
// UtilXml.addChildElementValue(transElem, "OrderID", externalId.substring(4), transDoc);
|
||||
UtilXml.addChildElementValue(transElem, "TransactionID", "0", transDoc);
|
||||
UtilXml.addChildElementValue(transElem, "ItemID", externalId.substring(4), transDoc);
|
||||
}
|
||||
@@ -323,7 +325,7 @@ public class ImportOrdersFromEbay {
|
||||
} catch (Exception e) {
|
||||
Debug.logError("Exception during building complete sale request", MODULE);
|
||||
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "ordersImportFromEbay.exceptionDuringBuildingCompleteSaleRequest",
|
||||
locale));
|
||||
locale));
|
||||
}
|
||||
return ServiceUtil.returnSuccess();
|
||||
}
|
||||
@@ -350,269 +352,274 @@ public class ImportOrdersFromEbay {
|
||||
}
|
||||
|
||||
private static List<Map<String, Object>> readResponseFromEbay(String msg, Locale locale, String productStoreId, Delegator delegator,
|
||||
StringBuffer errorMessage) {
|
||||
StringBuffer errorMessage) {
|
||||
List<Map<String, Object>> orders = null;
|
||||
Document docResponse;
|
||||
Element elemResponse = 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<? extends Element> paginationList = UtilXml.childElementList(elemResponse, "PaginationResult");
|
||||
docResponse = UtilXml.readXmlDocument(msg, true);
|
||||
elemResponse = docResponse.getDocumentElement();
|
||||
} catch (SAXException | ParserConfigurationException | IOException e) {
|
||||
Debug.logError("Exception during read response from Ebay: " + e.getMessage(), MODULE);
|
||||
}
|
||||
String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
|
||||
List<? extends Element> paginationList = UtilXml.childElementList(elemResponse, "PaginationResult");
|
||||
int totalOrders = 0;
|
||||
Iterator<? extends Element> paginationElemIter = paginationList.iterator();
|
||||
while (paginationElemIter.hasNext()) {
|
||||
Element paginationElement = paginationElemIter.next();
|
||||
String totalNumberOfEntries = UtilXml.childElementValue(paginationElement, "TotalNumberOfEntries", "0");
|
||||
totalOrders = Integer.valueOf(totalNumberOfEntries);
|
||||
}
|
||||
|
||||
int totalOrders = 0;
|
||||
Iterator<? extends Element> paginationElemIter = paginationList.iterator();
|
||||
while (paginationElemIter.hasNext()) {
|
||||
Element paginationElement = paginationElemIter.next();
|
||||
String totalNumberOfEntries = UtilXml.childElementValue(paginationElement, "TotalNumberOfEntries", "0");
|
||||
totalOrders = Integer.valueOf(totalNumberOfEntries);
|
||||
}
|
||||
if (ack != null && "Success".equals(ack)) {
|
||||
orders = new LinkedList<>();
|
||||
if (totalOrders > 0) {
|
||||
// retrieve transaction array
|
||||
List<? extends Element> transactions = UtilXml.childElementList(elemResponse, "TransactionArray");
|
||||
Iterator<? extends Element> transactionsElemIter = transactions.iterator();
|
||||
while (transactionsElemIter.hasNext()) {
|
||||
Element transactionsElement = transactionsElemIter.next();
|
||||
|
||||
if (ack != null && "Success".equals(ack)) {
|
||||
orders = new LinkedList<>();
|
||||
if (totalOrders > 0) {
|
||||
// retrieve transaction array
|
||||
List<? extends Element> transactions = UtilXml.childElementList(elemResponse, "TransactionArray");
|
||||
Iterator<? extends Element> transactionsElemIter = transactions.iterator();
|
||||
while (transactionsElemIter.hasNext()) {
|
||||
Element transactionsElement = transactionsElemIter.next();
|
||||
// retrieve transaction
|
||||
List<? extends Element> transaction = UtilXml.childElementList(transactionsElement, "Transaction");
|
||||
Iterator<? extends Element> transactionElemIter = transaction.iterator();
|
||||
while (transactionElemIter.hasNext()) {
|
||||
Map<String, Object> order = new HashMap<>();
|
||||
String itemId = "";
|
||||
|
||||
// retrieve transaction
|
||||
List<? extends Element> transaction = UtilXml.childElementList(transactionsElement, "Transaction");
|
||||
Iterator<? extends Element> transactionElemIter = transaction.iterator();
|
||||
while (transactionElemIter.hasNext()) {
|
||||
Map<String, Object> order = new HashMap<>();
|
||||
String itemId = "";
|
||||
|
||||
Element transactionElement = transactionElemIter.next();
|
||||
List<? extends Element> containingOrders = UtilXml.childElementList(transactionElement, "ContainingOrder");
|
||||
if (UtilValidate.isNotEmpty(containingOrders)) {
|
||||
continue;
|
||||
}
|
||||
order.put("amountPaid", UtilXml.childElementValue(transactionElement, "AmountPaid", "0"));
|
||||
|
||||
// retrieve buyer
|
||||
List<? extends Element> buyer = UtilXml.childElementList(transactionElement, "Buyer");
|
||||
Iterator<? extends Element> buyerElemIter = buyer.iterator();
|
||||
while (buyerElemIter.hasNext()) {
|
||||
Element buyerElement = buyerElemIter.next();
|
||||
order.put("emailBuyer", UtilXml.childElementValue(buyerElement, "Email", ""));
|
||||
order.put("eiasTokenBuyer", UtilXml.childElementValue(buyerElement, "EIASToken", ""));
|
||||
order.put("ebayUserIdBuyer", UtilXml.childElementValue(buyerElement, "UserID", ""));
|
||||
|
||||
// retrieve buyer information
|
||||
List<? extends Element> buyerInfo = UtilXml.childElementList(buyerElement, "BuyerInfo");
|
||||
Iterator<? extends Element> buyerInfoElemIter = buyerInfo.iterator();
|
||||
while (buyerInfoElemIter.hasNext()) {
|
||||
Element buyerInfoElement = buyerInfoElemIter.next();
|
||||
|
||||
// retrieve shipping address
|
||||
List<? extends Element> shippingAddressInfo = UtilXml.childElementList(buyerInfoElement, "ShippingAddress");
|
||||
Iterator<? extends Element> shippingAddressElemIter = shippingAddressInfo.iterator();
|
||||
while (shippingAddressElemIter.hasNext()) {
|
||||
Element shippingAddressElement = shippingAddressElemIter.next();
|
||||
order.put("buyerName", UtilXml.childElementValue(shippingAddressElement, "Name", ""));
|
||||
order.put("shippingAddressStreet", UtilXml.childElementValue(shippingAddressElement, "Street", ""));
|
||||
order.put("shippingAddressStreet1", UtilXml.childElementValue(shippingAddressElement, "Street1", ""));
|
||||
order.put("shippingAddressStreet2", UtilXml.childElementValue(shippingAddressElement, "Street2", ""));
|
||||
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<? extends Element> shippingDetails = UtilXml.childElementList(transactionElement, "ShippingDetails");
|
||||
Iterator<? extends Element> shippingDetailsElemIter = shippingDetails.iterator();
|
||||
while (shippingDetailsElemIter.hasNext()) {
|
||||
Element shippingDetailsElement = 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<? extends Element> salesTax = UtilXml.childElementList(shippingDetailsElement, "SalesTax");
|
||||
Iterator<? extends Element> salesTaxElemIter = salesTax.iterator();
|
||||
while (salesTaxElemIter.hasNext()) {
|
||||
Element salesTaxElement = 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<? extends Element> taxTable = UtilXml.childElementList(shippingDetailsElement, "TaxTable");
|
||||
Iterator<? extends Element> taxTableElemIter = taxTable.iterator();
|
||||
while (taxTableElemIter.hasNext()) {
|
||||
Element taxTableElement = taxTableElemIter.next();
|
||||
|
||||
List<? extends Element> taxJurisdiction = UtilXml.childElementList(taxTableElement, "TaxJurisdiction");
|
||||
Iterator<? extends Element> taxJurisdictionElemIter = taxJurisdiction.iterator();
|
||||
while (taxJurisdictionElemIter.hasNext()) {
|
||||
Element taxJurisdictionElement = 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<? extends Element> item = UtilXml.childElementList(transactionElement, "Item");
|
||||
Iterator<? extends Element> itemElemIter = item.iterator();
|
||||
while (itemElemIter.hasNext()) {
|
||||
Element itemElement = itemElemIter.next();
|
||||
itemId = UtilXml.childElementValue(itemElement, "ItemID", "");
|
||||
order.put("paymentMethods", UtilXml.childElementValue(itemElement, "PaymentMethods", ""));
|
||||
order.put("quantity", UtilXml.childElementValue(itemElement, "Quantity", "0"));
|
||||
order.put("startPrice", UtilXml.childElementValue(itemElement, "StartPrice", "0"));
|
||||
order.put("title", UtilXml.childElementValue(itemElement, "Title", ""));
|
||||
|
||||
String productId = UtilXml.childElementValue(itemElement, "SKU", "");
|
||||
if (UtilValidate.isEmpty(productId)) {
|
||||
productId = UtilXml.childElementValue(itemElement, "ApplicationData", "");
|
||||
if (UtilValidate.isEmpty(productId)) {
|
||||
productId = EbayHelper.retrieveProductIdFromTitle(delegator, (String) order.get("title"));
|
||||
}
|
||||
}
|
||||
order.put("productId", productId);
|
||||
|
||||
// retrieve selling status
|
||||
List<? extends Element> sellingStatus = UtilXml.childElementList(itemElement, "SellingStatus");
|
||||
Iterator<? extends Element> sellingStatusitemElemIter = sellingStatus.iterator();
|
||||
while (sellingStatusitemElemIter.hasNext()) {
|
||||
Element sellingStatusElement = 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 quantity purchased
|
||||
order.put("quantityPurchased", UtilXml.childElementValue(transactionElement, "QuantityPurchased", "0"));
|
||||
|
||||
// retrieve status
|
||||
List<? extends Element> status = UtilXml.childElementList(transactionElement, "Status");
|
||||
Iterator<? extends Element> statusElemIter = status.iterator();
|
||||
while (statusElemIter.hasNext()) {
|
||||
Element statusElement = 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 transactionId
|
||||
String transactionId = UtilXml.childElementValue(transactionElement, "TransactionID", "");
|
||||
|
||||
// set the externalId
|
||||
if ("0".equals(transactionId)) {
|
||||
// this is a Chinese Auction: ItemID is used to uniquely identify the transaction
|
||||
order.put("externalId", "EBI_" + itemId);
|
||||
} else {
|
||||
order.put("externalId", "EBT_" + transactionId);
|
||||
}
|
||||
order.put("transactionId", "EBI_" + itemId);
|
||||
|
||||
GenericValue orderExist = externalOrderExists(delegator, (String) order.get("externalId"));
|
||||
if (orderExist != null) {
|
||||
order.put("orderId", orderExist.get("orderId"));
|
||||
} else {
|
||||
order.put("orderId", "");
|
||||
}
|
||||
|
||||
// retrieve transaction price
|
||||
order.put("transactionPrice", UtilXml.childElementValue(transactionElement, "TransactionPrice", "0"));
|
||||
|
||||
// retrieve external transaction
|
||||
List<? extends Element> externalTransaction = UtilXml.childElementList(transactionElement, "ExternalTransaction");
|
||||
Iterator<? extends Element> externalTransactionElemIter = externalTransaction.iterator();
|
||||
while (externalTransactionElemIter.hasNext()) {
|
||||
Element externalTransactionElement = 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<? extends Element> shippingServiceSelected = UtilXml.childElementList(transactionElement, "ShippingServiceSelected");
|
||||
Iterator<? extends Element> shippingServiceSelectedElemIter = shippingServiceSelected.iterator();
|
||||
while (shippingServiceSelectedElemIter.hasNext()) {
|
||||
Element shippingServiceSelectedElement = shippingServiceSelectedElemIter.next();
|
||||
order.put("shippingService", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingService", ""));
|
||||
order.put("shippingServiceCost", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingServiceCost",
|
||||
"0"));
|
||||
|
||||
String incuranceCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingInsuranceCost", "0");
|
||||
String additionalCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingServiceAdditionalCost",
|
||||
"0");
|
||||
String surchargeCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingSurcharge", "0");
|
||||
|
||||
double shippingInsuranceCost = 0;
|
||||
double shippingServiceAdditionalCost = 0;
|
||||
double shippingSurcharge = 0;
|
||||
|
||||
if (UtilValidate.isNotEmpty(incuranceCost)) {
|
||||
shippingInsuranceCost = Double.parseDouble(incuranceCost);
|
||||
}
|
||||
|
||||
if (UtilValidate.isNotEmpty(additionalCost)) {
|
||||
shippingServiceAdditionalCost = Double.parseDouble(additionalCost);
|
||||
}
|
||||
|
||||
if (UtilValidate.isNotEmpty(surchargeCost)) {
|
||||
shippingSurcharge = Double.parseDouble(surchargeCost);
|
||||
}
|
||||
|
||||
double shippingTotalAdditionalCost = shippingInsuranceCost + shippingServiceAdditionalCost + shippingSurcharge;
|
||||
String totalAdditionalCost = Double.toString(shippingTotalAdditionalCost);
|
||||
order.put("shippingTotalAdditionalCost", totalAdditionalCost);
|
||||
}
|
||||
|
||||
// retrieve paid time
|
||||
order.put("paidTime", UtilXml.childElementValue(transactionElement, "PaidTime", ""));
|
||||
|
||||
// retrieve shipped time
|
||||
order.put("shippedTime", UtilXml.childElementValue(transactionElement, "ShippedTime", ""));
|
||||
|
||||
order.put("productStoreId", productStoreId);
|
||||
|
||||
orders.add(order);
|
||||
Element transactionElement = transactionElemIter.next();
|
||||
List<? extends Element> containingOrders = UtilXml.childElementList(transactionElement, "ContainingOrder");
|
||||
if (UtilValidate.isNotEmpty(containingOrders)) {
|
||||
continue;
|
||||
}
|
||||
order.put("amountPaid", UtilXml.childElementValue(transactionElement, "AmountPaid", "0"));
|
||||
|
||||
// retrieve buyer
|
||||
List<? extends Element> buyer = UtilXml.childElementList(transactionElement, "Buyer");
|
||||
Iterator<? extends Element> buyerElemIter = buyer.iterator();
|
||||
while (buyerElemIter.hasNext()) {
|
||||
Element buyerElement = buyerElemIter.next();
|
||||
order.put("emailBuyer", UtilXml.childElementValue(buyerElement, "Email", ""));
|
||||
order.put("eiasTokenBuyer", UtilXml.childElementValue(buyerElement, "EIASToken", ""));
|
||||
order.put("ebayUserIdBuyer", UtilXml.childElementValue(buyerElement, "UserID", ""));
|
||||
|
||||
// retrieve buyer information
|
||||
List<? extends Element> buyerInfo = UtilXml.childElementList(buyerElement, "BuyerInfo");
|
||||
Iterator<? extends Element> buyerInfoElemIter = buyerInfo.iterator();
|
||||
while (buyerInfoElemIter.hasNext()) {
|
||||
Element buyerInfoElement = buyerInfoElemIter.next();
|
||||
|
||||
// retrieve shipping address
|
||||
List<? extends Element> shippingAddressInfo = UtilXml.childElementList(buyerInfoElement, "ShippingAddress");
|
||||
Iterator<? extends Element> shippingAddressElemIter = shippingAddressInfo.iterator();
|
||||
while (shippingAddressElemIter.hasNext()) {
|
||||
Element shippingAddressElement = shippingAddressElemIter.next();
|
||||
order.put("buyerName", UtilXml.childElementValue(shippingAddressElement, "Name", ""));
|
||||
order.put("shippingAddressStreet", UtilXml.childElementValue(shippingAddressElement, "Street", ""));
|
||||
order.put("shippingAddressStreet1", UtilXml.childElementValue(shippingAddressElement, "Street1", ""));
|
||||
order.put("shippingAddressStreet2", UtilXml.childElementValue(shippingAddressElement, "Street2", ""));
|
||||
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<? extends Element> shippingDetails = UtilXml.childElementList(transactionElement, "ShippingDetails");
|
||||
Iterator<? extends Element> shippingDetailsElemIter = shippingDetails.iterator();
|
||||
while (shippingDetailsElemIter.hasNext()) {
|
||||
Element shippingDetailsElement = 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<? extends Element> salesTax = UtilXml.childElementList(shippingDetailsElement, "SalesTax");
|
||||
Iterator<? extends Element> salesTaxElemIter = salesTax.iterator();
|
||||
while (salesTaxElemIter.hasNext()) {
|
||||
Element salesTaxElement = 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<? extends Element> taxTable = UtilXml.childElementList(shippingDetailsElement, "TaxTable");
|
||||
Iterator<? extends Element> taxTableElemIter = taxTable.iterator();
|
||||
while (taxTableElemIter.hasNext()) {
|
||||
Element taxTableElement = taxTableElemIter.next();
|
||||
|
||||
List<? extends Element> taxJurisdiction = UtilXml.childElementList(taxTableElement, "TaxJurisdiction");
|
||||
Iterator<? extends Element> taxJurisdictionElemIter = taxJurisdiction.iterator();
|
||||
while (taxJurisdictionElemIter.hasNext()) {
|
||||
Element taxJurisdictionElement = 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<? extends Element> item = UtilXml.childElementList(transactionElement, "Item");
|
||||
Iterator<? extends Element> itemElemIter = item.iterator();
|
||||
while (itemElemIter.hasNext()) {
|
||||
Element itemElement = itemElemIter.next();
|
||||
itemId = UtilXml.childElementValue(itemElement, "ItemID", "");
|
||||
order.put("paymentMethods", UtilXml.childElementValue(itemElement, "PaymentMethods", ""));
|
||||
order.put("quantity", UtilXml.childElementValue(itemElement, "Quantity", "0"));
|
||||
order.put("startPrice", UtilXml.childElementValue(itemElement, "StartPrice", "0"));
|
||||
order.put("title", UtilXml.childElementValue(itemElement, "Title", ""));
|
||||
|
||||
String productId = UtilXml.childElementValue(itemElement, "SKU", "");
|
||||
if (UtilValidate.isEmpty(productId)) {
|
||||
productId = UtilXml.childElementValue(itemElement, "ApplicationData", "");
|
||||
if (UtilValidate.isEmpty(productId)) {
|
||||
productId = EbayHelper.retrieveProductIdFromTitle(delegator, (String) order.get("title"));
|
||||
}
|
||||
}
|
||||
order.put("productId", productId);
|
||||
|
||||
// retrieve selling status
|
||||
List<? extends Element> sellingStatus = UtilXml.childElementList(itemElement, "SellingStatus");
|
||||
Iterator<? extends Element> sellingStatusitemElemIter = sellingStatus.iterator();
|
||||
while (sellingStatusitemElemIter.hasNext()) {
|
||||
Element sellingStatusElement = 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 quantity purchased
|
||||
order.put("quantityPurchased", UtilXml.childElementValue(transactionElement, "QuantityPurchased", "0"));
|
||||
|
||||
// retrieve status
|
||||
List<? extends Element> status = UtilXml.childElementList(transactionElement, "Status");
|
||||
Iterator<? extends Element> statusElemIter = status.iterator();
|
||||
while (statusElemIter.hasNext()) {
|
||||
Element statusElement = 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 transactionId
|
||||
String transactionId = UtilXml.childElementValue(transactionElement, "TransactionID", "");
|
||||
|
||||
// set the externalId
|
||||
if ("0".equals(transactionId)) {
|
||||
// this is a Chinese Auction: ItemID is used to uniquely identify the transaction
|
||||
order.put("externalId", "EBI_" + itemId);
|
||||
} else {
|
||||
order.put("externalId", "EBT_" + transactionId);
|
||||
}
|
||||
order.put("transactionId", "EBI_" + itemId);
|
||||
|
||||
GenericValue orderExist = null;
|
||||
try {
|
||||
orderExist = externalOrderExists(delegator, (String) order.get("externalId"));
|
||||
} catch (GenericEntityException e) {
|
||||
Debug.logError("Exception during read response from Ebay: " + e.getMessage(), MODULE);
|
||||
}
|
||||
if (orderExist != null) {
|
||||
order.put("orderId", orderExist.get("orderId"));
|
||||
} else {
|
||||
order.put("orderId", "");
|
||||
}
|
||||
|
||||
// retrieve transaction price
|
||||
order.put("transactionPrice", UtilXml.childElementValue(transactionElement, "TransactionPrice", "0"));
|
||||
|
||||
// retrieve external transaction
|
||||
List<? extends Element> externalTransaction = UtilXml.childElementList(transactionElement, "ExternalTransaction");
|
||||
Iterator<? extends Element> externalTransactionElemIter = externalTransaction.iterator();
|
||||
while (externalTransactionElemIter.hasNext()) {
|
||||
Element externalTransactionElement = 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<? extends Element> shippingServiceSelected = UtilXml.childElementList(transactionElement, "ShippingServiceSelected");
|
||||
Iterator<? extends Element> shippingServiceSelectedElemIter = shippingServiceSelected.iterator();
|
||||
while (shippingServiceSelectedElemIter.hasNext()) {
|
||||
Element shippingServiceSelectedElement = shippingServiceSelectedElemIter.next();
|
||||
order.put("shippingService", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingService", ""));
|
||||
order.put("shippingServiceCost", UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingServiceCost",
|
||||
"0"));
|
||||
|
||||
String incuranceCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingInsuranceCost", "0");
|
||||
String additionalCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingServiceAdditionalCost",
|
||||
"0");
|
||||
String surchargeCost = UtilXml.childElementValue(shippingServiceSelectedElement, "ShippingSurcharge", "0");
|
||||
|
||||
double shippingInsuranceCost = 0;
|
||||
double shippingServiceAdditionalCost = 0;
|
||||
double shippingSurcharge = 0;
|
||||
|
||||
if (UtilValidate.isNotEmpty(incuranceCost)) {
|
||||
shippingInsuranceCost = Double.parseDouble(incuranceCost);
|
||||
}
|
||||
|
||||
if (UtilValidate.isNotEmpty(additionalCost)) {
|
||||
shippingServiceAdditionalCost = Double.parseDouble(additionalCost);
|
||||
}
|
||||
|
||||
if (UtilValidate.isNotEmpty(surchargeCost)) {
|
||||
shippingSurcharge = Double.parseDouble(surchargeCost);
|
||||
}
|
||||
|
||||
double shippingTotalAdditionalCost = shippingInsuranceCost + shippingServiceAdditionalCost + shippingSurcharge;
|
||||
String totalAdditionalCost = Double.toString(shippingTotalAdditionalCost);
|
||||
order.put("shippingTotalAdditionalCost", totalAdditionalCost);
|
||||
}
|
||||
|
||||
// retrieve paid time
|
||||
order.put("paidTime", UtilXml.childElementValue(transactionElement, "PaidTime", ""));
|
||||
|
||||
// retrieve shipped time
|
||||
order.put("shippedTime", UtilXml.childElementValue(transactionElement, "ShippedTime", ""));
|
||||
|
||||
order.put("productStoreId", productStoreId);
|
||||
|
||||
orders.add(order);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<? extends Element> errorList = UtilXml.childElementList(elemResponse, "Errors");
|
||||
Iterator<? extends Element> errorElemIter = errorList.iterator();
|
||||
while (errorElemIter.hasNext()) {
|
||||
Element errorElement = errorElemIter.next();
|
||||
errorMessage.append(UtilXml.childElementValue(errorElement, "ShortMessage", ""));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debug.logError("Exception during read response from Ebay", MODULE);
|
||||
} else {
|
||||
List<? extends Element> errorList = UtilXml.childElementList(elemResponse, "Errors");
|
||||
Iterator<? extends Element> errorElemIter = errorList.iterator();
|
||||
while (errorElemIter.hasNext()) {
|
||||
Element errorElement = errorElemIter.next();
|
||||
errorMessage.append(UtilXml.childElementValue(errorElement, "ShortMessage", ""));
|
||||
}
|
||||
}
|
||||
return orders;
|
||||
}
|
||||
|
||||
private static Map<String, Object> createShoppingCart(Delegator delegator, LocalDispatcher dispatcher, Locale locale,
|
||||
Map<String, Object> parameters, boolean create) {
|
||||
Map<String, Object> parameters, boolean create) {
|
||||
try {
|
||||
String productStoreId = (String) parameters.get("productStoreId");
|
||||
GenericValue userLogin = (GenericValue) parameters.get("userLogin");
|
||||
@@ -755,8 +762,10 @@ public class ImportOrdersFromEbay {
|
||||
String contactMechId = "";
|
||||
GenericValue partyAttribute = null;
|
||||
if (UtilValidate.isNotEmpty(parameters.get("eiasTokenBuyer"))) {
|
||||
partyAttribute =
|
||||
EntityQuery.use(delegator).from("PartyAttribute").where("attrValue", parameters.get("eiasTokenBuyer")).queryFirst();
|
||||
partyAttribute = EntityQuery.use(delegator)
|
||||
.from("PartyAttribute")
|
||||
.where("attrValue", parameters.get("eiasTokenBuyer"))
|
||||
.queryFirst();
|
||||
}
|
||||
|
||||
// if we get a party, check its contact information.
|
||||
@@ -845,17 +854,16 @@ public class ImportOrdersFromEbay {
|
||||
} catch (Exception e) {
|
||||
Debug.logError("Exception in createShoppingCart: " + e.getMessage(), MODULE);
|
||||
return ServiceUtil.returnFailure(UtilProperties.getMessage(RESOURCE, "ordersImportFromEbay.exceptionInCreateShoppingCart", locale) + ":"
|
||||
+ " " + e.getMessage());
|
||||
+ " " + e.getMessage());
|
||||
}
|
||||
return ServiceUtil.returnSuccess();
|
||||
}
|
||||
|
||||
|
||||
private static GenericValue externalOrderExists(Delegator delegator, String externalId) throws GenericEntityException {
|
||||
Debug.logInfo("Checking for existing externalId: " + externalId, MODULE);
|
||||
EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("externalId",
|
||||
EntityComparisonOperator.EQUALS, externalId), EntityCondition.makeCondition("statusId", EntityComparisonOperator.NOT_EQUAL,
|
||||
"ORDER_CANCELLED")), EntityComparisonOperator.AND);
|
||||
"ORDER_CANCELLED")), EntityComparisonOperator.AND);
|
||||
GenericValue orderHeader = EntityQuery.use(delegator).from("OrderHeader").where(condition).cache(true).queryFirst();
|
||||
return orderHeader;
|
||||
}
|
||||
|
||||
@@ -80,8 +80,7 @@ public abstract class AbstractReportThread extends Thread implements InterfaceRe
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error exception in case there was an error during the execution of
|
||||
* this Thread, null otherwise.
|
||||
* Returns the error exception in case there was an error during the execution of this Thread, null otherwise.
|
||||
* @return the error exception in case there was an error, null otherwise
|
||||
*/
|
||||
public Throwable getError() {
|
||||
@@ -89,8 +88,8 @@ public abstract class AbstractReportThread extends Thread implements InterfaceRe
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all errors that occured during the report.
|
||||
* @return an error list that occured during the report
|
||||
* Returns a list of all errors that occurred during the report.
|
||||
* @return an error list that occurred during the report
|
||||
*/
|
||||
public List<?> getErrors() {
|
||||
if (getReport() != null) {
|
||||
|
||||
Reference in New Issue
Block a user