ParseBaseOffersXMLModel.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.it.ocs.ebaySales.model;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Map;
  5. import org.dom4j.Document;
  6. import org.dom4j.Element;
  7. import com.it.ocs.synchronou.model.ParseXMLModel;
  8. import com.it.ocs.synchronou.model.XMLNode;
  9. import com.it.ocs.synchronou.util.ValidationUtil;
  10. public class ParseBaseOffersXMLModel extends ParseXMLModel {
  11. public ParseBaseOffersXMLModel(Document document, String nameSpace) {
  12. super(document, nameSpace);
  13. }
  14. @Override
  15. public List<Map<String, Object>> getResult() {
  16. XMLNode[] columns = {XMLNode.getInstance("Role"),
  17. XMLNode.getInstance("BuyItNowPrice",XMLNode.EBAY_PRICE,"currencyID"),
  18. XMLNode.getInstance("ItemID"),
  19. XMLNode.getInstance("Title")
  20. };
  21. List<Map<String, Object>> result = new ArrayList<>();
  22. List<Element> elements = this.getElementChild("ItemBestOffersArray_ItemBestOffers");
  23. for (Element element : elements) {
  24. Map<String, Object> map = parseRecord(element, columns);
  25. String newPrice = map.get("BuyItNowPrice").toString();
  26. if(null != newPrice && newPrice.contains(" ")){
  27. String str[] = newPrice.split(" ");
  28. map.put("currencyID", str[0]);
  29. map.put("BuyItNowPrice", str[1]);
  30. }else{
  31. map.put("currencyID", "");
  32. }
  33. List<Map<String,Object>> bestOffers = getBestOffers(this.getElementChildByElement(element, "BestOfferArray_BestOffer"));
  34. for(Map<String,Object> offer : bestOffers){
  35. offer.putAll(map);
  36. result.add(offer);
  37. }
  38. }
  39. return result;
  40. }
  41. private List<Map<String,Object>> getBestOffers(List<Element> elementChild) {
  42. XMLNode [] columns = {XMLNode.getInstance("BestOfferID"),
  43. XMLNode.getInstance("ExpirationTime",XMLNode.EBAY_DATE),
  44. XMLNode.getInstance("Email"),
  45. XMLNode.getInstance("FeedbackScore"),
  46. XMLNode.getInstance("RegistrationDate",XMLNode.EBAY_DATE),
  47. XMLNode.getInstance("UserID"),
  48. XMLNode.getInstance("StateOrProvince"),
  49. XMLNode.getInstance("CountryName"),
  50. XMLNode.getInstance("PostalCode"),
  51. XMLNode.getInstance("Price"),
  52. XMLNode.getInstance("Status"),
  53. XMLNode.getInstance("Quantity"),
  54. XMLNode.getInstance("BuyerMessage"),
  55. XMLNode.getInstance("SellerMessage"),
  56. XMLNode.getInstance("BestOfferCodeType")
  57. };
  58. List<Map<String,Object>> list = new ArrayList<>();
  59. for(Element element :elementChild){
  60. list.add(parseRecord(element,columns));
  61. }
  62. return list;
  63. }
  64. public int getTotalPages() {
  65. String count = this.getValueByName(this.getRoot(), "TotalNumberOfPages");
  66. if (ValidationUtil.isNullOrEmpty(count)) {
  67. return 0;
  68. } else {
  69. return Integer.parseInt(count);
  70. }
  71. }
  72. }