PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java

https://bitbucket.org/sudhirk76/ogb12
Java | 2941 lines | 2697 code | 183 blank | 61 comment | 514 complexity | ad7f06de334910d29e0260eb8f271d85 MD5 | raw file
Possible License(s): CPL-1.0, Apache-2.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.ofbiz.ebaystore;
  20. import java.io.BufferedReader;
  21. import java.io.File;
  22. import java.io.FileOutputStream;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.io.InputStreamReader;
  26. import java.io.OutputStream;
  27. import java.math.BigDecimal;
  28. import java.net.HttpURLConnection;
  29. import java.net.URL;
  30. import java.nio.ByteBuffer;
  31. import java.nio.channels.FileChannel;
  32. import java.util.Calendar;
  33. import java.util.Date;
  34. import java.util.Iterator;
  35. import java.util.List;
  36. import java.util.Locale;
  37. import java.util.Map;
  38. import javax.swing.table.AbstractTableModel;
  39. import javax.swing.table.TableModel;
  40. import javolution.util.FastList;
  41. import javolution.util.FastMap;
  42. import org.ofbiz.base.util.Debug;
  43. import org.ofbiz.base.util.UtilDateTime;
  44. import org.ofbiz.base.util.UtilGenerics;
  45. import org.ofbiz.base.util.UtilMisc;
  46. import org.ofbiz.base.util.UtilProperties;
  47. import org.ofbiz.base.util.UtilValidate;
  48. import org.ofbiz.base.util.UtilXml;
  49. import org.ofbiz.ebay.EbayHelper;
  50. import org.ofbiz.ebay.ProductsExportToEbay;
  51. import org.ofbiz.entity.Delegator;
  52. import org.ofbiz.entity.GenericEntityException;
  53. import org.ofbiz.entity.GenericValue;
  54. import org.ofbiz.entity.util.EntityUtil;
  55. import org.ofbiz.service.DispatchContext;
  56. import org.ofbiz.service.GenericServiceException;
  57. import org.ofbiz.service.LocalDispatcher;
  58. import org.ofbiz.service.ModelService;
  59. import org.ofbiz.service.ServiceUtil;
  60. import org.w3c.dom.Document;
  61. import org.w3c.dom.Element;
  62. import com.ebay.sdk.ApiContext;
  63. import com.ebay.sdk.ApiException;
  64. import com.ebay.sdk.SdkException;
  65. import com.ebay.sdk.SdkSoapException;
  66. import com.ebay.sdk.TimeFilter;
  67. import com.ebay.sdk.call.AddDisputeCall;
  68. import com.ebay.sdk.call.AddSecondChanceItemCall;
  69. import com.ebay.sdk.call.GetAllBiddersCall;
  70. import com.ebay.sdk.call.GetItemCall;
  71. import com.ebay.sdk.call.GetMyeBaySellingCall;
  72. import com.ebay.sdk.call.GetOrdersCall;
  73. import com.ebay.sdk.call.GetSellerTransactionsCall;
  74. import com.ebay.sdk.call.GetSellingManagerSoldListingsCall;
  75. import com.ebay.sdk.call.GetStoreCall;
  76. import com.ebay.sdk.call.GetStoreOptionsCall;
  77. import com.ebay.sdk.call.ReviseItemCall;
  78. import com.ebay.sdk.call.SetStoreCall;
  79. import com.ebay.sdk.call.SetStoreCategoriesCall;
  80. import com.ebay.sdk.call.VerifyAddSecondChanceItemCall;
  81. import com.ebay.sdk.util.eBayUtil;
  82. import com.ebay.soap.eBLBaseComponents.AddressType;
  83. import com.ebay.soap.eBLBaseComponents.AmountType;
  84. import com.ebay.soap.eBLBaseComponents.CheckoutStatusType;
  85. import com.ebay.soap.eBLBaseComponents.CurrencyCodeType;
  86. import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
  87. import com.ebay.soap.eBLBaseComponents.DisputeExplanationCodeType;
  88. import com.ebay.soap.eBLBaseComponents.DisputeReasonCodeType;
  89. import com.ebay.soap.eBLBaseComponents.ExternalTransactionType;
  90. import com.ebay.soap.eBLBaseComponents.GalleryTypeCodeType;
  91. import com.ebay.soap.eBLBaseComponents.GetAllBiddersModeCodeType;
  92. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsRequestType;
  93. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsResponseType;
  94. import com.ebay.soap.eBLBaseComponents.GetStoreRequestType;
  95. import com.ebay.soap.eBLBaseComponents.GetStoreResponseType;
  96. import com.ebay.soap.eBLBaseComponents.ItemArrayType;
  97. import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
  98. import com.ebay.soap.eBLBaseComponents.ItemSortTypeCodeType;
  99. import com.ebay.soap.eBLBaseComponents.ItemType;
  100. import com.ebay.soap.eBLBaseComponents.ListingTypeCodeType;
  101. import com.ebay.soap.eBLBaseComponents.MerchDisplayCodeType;
  102. import com.ebay.soap.eBLBaseComponents.OfferType;
  103. import com.ebay.soap.eBLBaseComponents.OrderStatusCodeType;
  104. import com.ebay.soap.eBLBaseComponents.OrderTransactionType;
  105. import com.ebay.soap.eBLBaseComponents.OrderType;
  106. import com.ebay.soap.eBLBaseComponents.PaginatedItemArrayType;
  107. import com.ebay.soap.eBLBaseComponents.PaginationType;
  108. import com.ebay.soap.eBLBaseComponents.PhotoDisplayCodeType;
  109. import com.ebay.soap.eBLBaseComponents.PictureDetailsType;
  110. import com.ebay.soap.eBLBaseComponents.PictureSourceCodeType;
  111. import com.ebay.soap.eBLBaseComponents.SalesTaxType;
  112. import com.ebay.soap.eBLBaseComponents.SecondChanceOfferDurationCodeType;
  113. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchType;
  114. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchTypeCodeType;
  115. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldListingsPropertyTypeCodeType;
  116. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldOrderType;
  117. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldTransactionType;
  118. import com.ebay.soap.eBLBaseComponents.SellingStatusType;
  119. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesRequestType;
  120. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesResponseType;
  121. import com.ebay.soap.eBLBaseComponents.SetStoreRequestType;
  122. import com.ebay.soap.eBLBaseComponents.SetStoreResponseType;
  123. import com.ebay.soap.eBLBaseComponents.ShippingDetailsType;
  124. import com.ebay.soap.eBLBaseComponents.ShippingServiceOptionsType;
  125. import com.ebay.soap.eBLBaseComponents.StoreCategoryUpdateActionCodeType;
  126. import com.ebay.soap.eBLBaseComponents.StoreColorSchemeType;
  127. import com.ebay.soap.eBLBaseComponents.StoreColorType;
  128. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryArrayType;
  129. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryType;
  130. import com.ebay.soap.eBLBaseComponents.StoreCustomHeaderLayoutCodeType;
  131. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderDisplayCodeType;
  132. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderType;
  133. import com.ebay.soap.eBLBaseComponents.StoreFontFaceCodeType;
  134. import com.ebay.soap.eBLBaseComponents.StoreFontSizeCodeType;
  135. import com.ebay.soap.eBLBaseComponents.StoreFontType;
  136. import com.ebay.soap.eBLBaseComponents.StoreHeaderStyleCodeType;
  137. import com.ebay.soap.eBLBaseComponents.StoreItemListLayoutCodeType;
  138. import com.ebay.soap.eBLBaseComponents.StoreItemListSortOrderCodeType;
  139. import com.ebay.soap.eBLBaseComponents.StoreLogoArrayType;
  140. import com.ebay.soap.eBLBaseComponents.StoreLogoType;
  141. import com.ebay.soap.eBLBaseComponents.StoreSubscriptionLevelCodeType;
  142. import com.ebay.soap.eBLBaseComponents.StoreThemeArrayType;
  143. import com.ebay.soap.eBLBaseComponents.StoreThemeType;
  144. import com.ebay.soap.eBLBaseComponents.StoreType;
  145. import com.ebay.soap.eBLBaseComponents.TradingRoleCodeType;
  146. import com.ebay.soap.eBLBaseComponents.TransactionType;
  147. import com.ebay.soap.eBLBaseComponents.UserType;
  148. import com.ibm.icu.text.SimpleDateFormat;
  149. public class EbayStore {
  150. private static final String resource = "EbayStoreUiLabels";
  151. private static final String module = ProductsExportToEbay.class.getName();
  152. public static ProductsExportToEbay productExportEbay = new ProductsExportToEbay();
  153. private static void appendRequesterCredentials(Element elem, Document doc, String token) {
  154. Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
  155. UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
  156. }
  157. private static Map<String, Object> postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID,
  158. String callName, String compatibilityLevel, String siteID) throws IOException {
  159. if (Debug.verboseOn()) {
  160. Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), module);
  161. }
  162. HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
  163. connection.setDoInput(true);
  164. connection.setDoOutput(true);
  165. connection.setRequestMethod("POST");
  166. connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
  167. connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
  168. connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
  169. connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
  170. connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
  171. connection.setRequestProperty("X-EBAY-API-SITEID", siteID);
  172. connection.setRequestProperty("Content-Type", "text/xml");
  173. OutputStream outputStream = connection.getOutputStream();
  174. outputStream.write(dataItems.toString().getBytes());
  175. outputStream.close();
  176. int responseCode = connection.getResponseCode();
  177. InputStream inputStream;
  178. Map<String, Object> result = FastMap.newInstance();
  179. String response = null;
  180. if (responseCode == HttpURLConnection.HTTP_CREATED ||
  181. responseCode == HttpURLConnection.HTTP_OK) {
  182. inputStream = connection.getInputStream();
  183. response = toString(inputStream);
  184. result = ServiceUtil.returnSuccess(response);
  185. } else {
  186. inputStream = connection.getErrorStream();
  187. response = toString(inputStream);
  188. result = ServiceUtil.returnFailure(response);
  189. }
  190. if (Debug.verboseOn()) {
  191. Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
  192. }
  193. return result;
  194. }
  195. private static String toString(InputStream inputStream) throws IOException {
  196. String string;
  197. StringBuilder outputBuilder = new StringBuilder();
  198. if (inputStream != null) {
  199. BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
  200. while (null != (string = reader.readLine())) {
  201. outputBuilder.append(string).append('\n');
  202. }
  203. }
  204. return outputBuilder.toString();
  205. }
  206. /* add/update/delete categories and child into your ebay store category */
  207. public static Map<String,Object> exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map<String,? extends Object> context) {
  208. Locale locale = (Locale) context.get("locale");
  209. Delegator delegator = dctx.getDelegator();
  210. Map<String, Object> result = FastMap.newInstance();
  211. SetStoreCategoriesRequestType req = null;
  212. StoreCustomCategoryArrayType categoryArrayType = null;
  213. List<GenericValue> catalogCategories = null;
  214. if (UtilValidate.isEmpty(context.get("prodCatalogId")) || UtilValidate.isEmpty(context.get("productStoreId")) || UtilValidate.isEmpty(context.get("partyId"))) {
  215. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStoreSetCatalogIdAndProductStoreId", locale));
  216. }
  217. if (!EbayStoreHelper.validatePartyAndRoleType(delegator,context.get("partyId").toString())) {
  218. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStorePartyWithoutRoleEbayAccount", UtilMisc.toMap("partyId", context.get("partyId").toString()), locale));
  219. }
  220. try {
  221. SetStoreCategoriesCall call = new SetStoreCategoriesCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  222. catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString(),"prodCatalogCategoryTypeId","PCCT_EBAY_ROOT"), UtilMisc.toList("sequenceNum ASC"));
  223. if (catalogCategories != null && catalogCategories.size() > 0) {
  224. List<StoreCustomCategoryType> listAdd = FastList.newInstance();
  225. List<StoreCustomCategoryType> listEdit = FastList.newInstance();
  226. //start at level 0 of categories
  227. for (GenericValue catalogCategory : catalogCategories) {
  228. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  229. if (productCategory != null) {
  230. String ebayCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  231. StoreCustomCategoryType categoryType = new StoreCustomCategoryType();
  232. if (ebayCategoryId == null) {
  233. categoryType.setName(productCategory.getString("categoryName"));
  234. listAdd.add(categoryType);
  235. } else {
  236. categoryType.setCategoryID(new Long(ebayCategoryId));
  237. categoryType.setName(productCategory.getString("categoryName"));
  238. listEdit.add(categoryType);
  239. }
  240. }
  241. }
  242. if (listAdd.size() > 0) {
  243. req = new SetStoreCategoriesRequestType();
  244. categoryArrayType = new StoreCustomCategoryArrayType();
  245. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  246. req.setStoreCategories(categoryArrayType);
  247. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
  248. }
  249. if (listEdit.size() > 0) {
  250. req = new SetStoreCategoriesRequestType();
  251. categoryArrayType = new StoreCustomCategoryArrayType();
  252. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  253. req.setStoreCategories(categoryArrayType);
  254. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
  255. }
  256. //start at level 1 of categories
  257. listAdd = FastList.newInstance();
  258. listEdit = FastList.newInstance();
  259. for (GenericValue catalogCategory : catalogCategories) {
  260. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  261. if (productCategory != null) {
  262. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  263. if (ebayParentCategoryId != null) {
  264. List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategory.getString("productCategoryId")), UtilMisc.toList("sequenceNum ASC"));
  265. for (GenericValue productCategoryRollup : productCategoryRollupList) {
  266. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryRollup.getString("productCategoryId")));
  267. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  268. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  269. if (ebayChildCategoryId == null) {
  270. childCategoryType.setName(productCategory.getString("categoryName"));
  271. listAdd.add(childCategoryType);
  272. } else {
  273. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  274. childCategoryType.setName(productCategory.getString("categoryName"));
  275. listEdit.add(childCategoryType);
  276. }
  277. }
  278. }
  279. if (listAdd.size() > 0) {
  280. req = new SetStoreCategoriesRequestType();
  281. categoryArrayType = new StoreCustomCategoryArrayType();
  282. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  283. req.setStoreCategories(categoryArrayType);
  284. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  285. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories, locale);
  286. }
  287. if (listEdit.size() > 0) {
  288. req = new SetStoreCategoriesRequestType();
  289. categoryArrayType = new StoreCustomCategoryArrayType();
  290. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  291. req.setStoreCategories(categoryArrayType);
  292. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  293. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories, locale);
  294. }
  295. }
  296. }
  297. //start at level 2 of categories
  298. listAdd = FastList.newInstance();
  299. listEdit = FastList.newInstance();
  300. for (GenericValue catalogCategory : catalogCategories) {
  301. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  302. if (productCategory != null) {
  303. List<GenericValue> productParentCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategory.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  304. for (GenericValue productParentCategoryRollup : productParentCategoryRollupList) {
  305. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productParentCategoryRollup.getString("productCategoryId"),context.get("partyId").toString());
  306. if (ebayParentCategoryId != null) {
  307. List<GenericValue> productChildCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productParentCategoryRollup.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  308. for (GenericValue productChildCategoryRollup : productChildCategoryRollupList) {
  309. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productChildCategoryRollup.getString("productCategoryId")));
  310. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  311. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  312. if (ebayChildCategoryId == null) {
  313. childCategoryType.setName(productCategory.getString("categoryName"));
  314. listAdd.add(childCategoryType);
  315. } else {
  316. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  317. childCategoryType.setName(productCategory.getString("categoryName"));
  318. listEdit.add(childCategoryType);
  319. }
  320. }
  321. if (listAdd.size() > 0) {
  322. req = new SetStoreCategoriesRequestType();
  323. categoryArrayType = new StoreCustomCategoryArrayType();
  324. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  325. req.setStoreCategories(categoryArrayType);
  326. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  327. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator, context.get("partyId").toString(), catalogCategories, locale);
  328. }
  329. if (listEdit.size() > 0) {
  330. req = new SetStoreCategoriesRequestType();
  331. categoryArrayType = new StoreCustomCategoryArrayType();
  332. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  333. req.setStoreCategories(categoryArrayType);
  334. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  335. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator, context.get("partyId").toString(), catalogCategories, locale);
  336. }
  337. }
  338. }
  339. }
  340. }
  341. } else {
  342. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayStoreRootCategoryNotFound", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId")), locale));
  343. }
  344. } catch (GenericEntityException e) {
  345. result = ServiceUtil.returnFailure(e.getMessage());
  346. }
  347. if (result.get("responseMessage") != null && result.get("responseMessage").equals("fail")) {
  348. result = ServiceUtil.returnError(result.get("errorMessage").toString());
  349. }
  350. return result;
  351. }
  352. public static StoreCustomCategoryType[] toStoreCustomCategoryTypeArray(List<StoreCustomCategoryType> list) {
  353. StoreCustomCategoryType[] storeCustomCategoryTypeArry = null;
  354. try {
  355. if (list != null && list.size() > 0) {
  356. storeCustomCategoryTypeArry = new StoreCustomCategoryType[list.size()];
  357. int i=0;
  358. for (StoreCustomCategoryType val : list) {
  359. storeCustomCategoryTypeArry[i] = val;
  360. }
  361. }
  362. } catch (Exception e) {
  363. Debug.logError(e.getMessage(), module);
  364. }
  365. return storeCustomCategoryTypeArry;
  366. }
  367. public static Map<String, Object> excuteExportCategoryToEbayStore(SetStoreCategoriesCall call, SetStoreCategoriesRequestType req, StoreCategoryUpdateActionCodeType actionCode,Delegator delegator, String partyId,List<GenericValue> catalogCategories, Locale locale) {
  368. Map<String, Object> result = FastMap.newInstance();
  369. SetStoreCategoriesResponseType resp = null;
  370. try {
  371. if (req != null && actionCode != null) {
  372. req.setAction(actionCode);
  373. resp = (SetStoreCategoriesResponseType) call.execute(req);
  374. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  375. StoreCustomCategoryArrayType returnedCustomCategory = resp.getCustomCategory();
  376. if (actionCode.equals(StoreCategoryUpdateActionCodeType.ADD) && returnedCustomCategory != null) {
  377. StoreCustomCategoryType[] returnCategoryTypeList = returnedCustomCategory.getCustomCategory();
  378. for (StoreCustomCategoryType returnCategoryType : returnCategoryTypeList) {
  379. List<GenericValue> productCategoryList = delegator.findByAnd("ProductCategory", UtilMisc.toMap("categoryName",returnCategoryType.getName(),"productCategoryTypeId","EBAY_CATEGORY"));
  380. for (GenericValue productCategory : productCategoryList) {
  381. if (EbayStoreHelper.veriflyCategoryInCatalog(delegator,catalogCategories,productCategory.getString("productCategoryId"))) {
  382. if (EbayStoreHelper.createEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), partyId, String.valueOf(returnCategoryType.getCategoryID()))) {
  383. Debug.logInfo("Create new ProductCategoryRollup with partyId "+partyId+" categoryId "+productCategory.getString("productCategoryId")+ " and ebayCategoryId "+String.valueOf(returnCategoryType.getCategoryID()), module);
  384. }
  385. break;
  386. }
  387. }
  388. }
  389. }
  390. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayExportToEbayStoreSuccess", locale));
  391. } else {
  392. return ServiceUtil.returnError(UtilProperties.getMessage(resource, "EbayExportToEbayStoreFailed", UtilMisc.toMap("errorString", resp.getMessage()), locale));
  393. }
  394. }
  395. } catch (ApiException e) {
  396. result = ServiceUtil.returnFailure(e.getMessage());
  397. } catch (SdkSoapException e) {
  398. result = ServiceUtil.returnFailure(e.getMessage());
  399. } catch (SdkException e) {
  400. result = ServiceUtil.returnFailure(e.getMessage());
  401. } catch (GenericEntityException e) {
  402. result = ServiceUtil.returnFailure(e.getMessage());
  403. }
  404. return result;
  405. }
  406. public static Map<String, Object> buildSetStoreXml(DispatchContext dctx, Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID) {
  407. Locale locale = (Locale)context.get("locale");
  408. try {
  409. Delegator delegator = dctx.getDelegator();
  410. // Get the list of products to be exported to eBay
  411. try {
  412. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreRequest");
  413. Element storeRequestElem = storeDocument.getDocumentElement();
  414. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  415. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  416. /*UtilXml.addChildElementValue(storeRequestElem, "SiteId", siteID, storeDocument);
  417. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  418. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);*/
  419. // Prepare data for set to XML
  420. GenericValue productStore = null;
  421. if (UtilValidate.isNotEmpty(context.get("productStoreId").toString())) {
  422. productStore = delegator.findByPrimaryKey("ProductStore",UtilMisc.toMap("productStoreId", context.get("productStoreId").toString()));
  423. }
  424. Element itemElem = UtilXml.addChildElement(storeRequestElem, "Store", storeDocument);
  425. UtilXml.addChildElementValue(itemElem, "Name", productStore.getString("storeName"), storeDocument);
  426. UtilXml.addChildElementValue(itemElem, "SubscriptionLevel", "Basic", storeDocument);
  427. UtilXml.addChildElementValue(itemElem, "Description", productStore.getString("title"), storeDocument);
  428. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  429. } catch (Exception e) {
  430. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  431. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  432. }
  433. } catch (Exception e) {
  434. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  435. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  436. }
  437. return ServiceUtil.returnSuccess();
  438. }
  439. public static String readEbayResponse(String msg, String productStoreId) {
  440. String result = "success";
  441. try {
  442. Document docResponse = UtilXml.readXmlDocument(msg, true);
  443. Element elemResponse = docResponse.getDocumentElement();
  444. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  445. if (ack != null && "Failure".equals(ack)) {
  446. String errorMessage = "";
  447. List<Element> errorList = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Errors"));
  448. Iterator<Element> errorElemIter = errorList.iterator();
  449. while (errorElemIter.hasNext()) {
  450. Element errorElement = errorElemIter.next();
  451. errorMessage = UtilXml.childElementValue(errorElement, "LongMessage");
  452. }
  453. result = errorMessage;
  454. } else {
  455. result = "Successfully exported with ID (" + productStoreId + ").";
  456. }
  457. } catch (Exception e) {
  458. Debug.logError("Error in processing xml string" + e.getMessage(), module);
  459. result = "Failure";
  460. }
  461. return result;
  462. }
  463. public static Map<String, Object> buildGetStoreXml(Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID) {
  464. Locale locale = (Locale)context.get("locale");
  465. // Get the list of products to be exported to eBay
  466. try {
  467. Document storeDocument = UtilXml.makeEmptyXmlDocument("GetStoreRequest");
  468. Element storeRequestElem = storeDocument.getDocumentElement();
  469. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  470. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  471. //UtilXml.addChildElementValue(storeRequestElem, "CategorySiteID", siteID, storeDocument);
  472. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  473. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);
  474. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  475. } catch (Exception e) {
  476. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  477. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  478. }
  479. return ServiceUtil.returnSuccess();
  480. }
  481. public static Map<String, Object> buildSetStoreCategoriesXml(DispatchContext dctx, Map<String, ? extends Object> context, StringBuffer dataStoreXml, String token, String siteID, String productCategoryId) {
  482. Delegator delegator = dctx.getDelegator();
  483. Locale locale = (Locale)context.get("locale");
  484. // Get the list of products to be exported to eBay
  485. try {
  486. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreCategoriesRequest");
  487. Element storeRequestElem = storeDocument.getDocumentElement();
  488. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  489. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  490. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  491. UtilXml.addChildElementValue(storeRequestElem, "Version", "643", storeDocument);
  492. UtilXml.addChildElementValue(storeRequestElem, "Action", "Add", storeDocument);
  493. Element StoreCategoriesElem = UtilXml.addChildElement(storeRequestElem, "StoreCategories", storeDocument);
  494. //UtilXml.addChildElementValue(StoreCategoriesElem, "Country", (String)context.get("country"), storeDocument);
  495. GenericValue category = null;
  496. if (UtilValidate.isNotEmpty(context.get("prodCatalogId"))) {
  497. category = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId));
  498. }
  499. String categoryName = category.getString("productCategoryId").toString();
  500. if (category.getString("categoryName").toString() != null) {
  501. categoryName = category.getString("categoryName").toString();
  502. }
  503. Element customCategoryElem = UtilXml.addChildElement(StoreCategoriesElem, "CustomCategory", storeDocument);
  504. //UtilXml.addChildElementValue(customCategoryElem, "CategoryID", "", storeDocument);
  505. UtilXml.addChildElementValue(customCategoryElem, "Name", categoryName, storeDocument);
  506. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  507. } catch (Exception e) {
  508. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  509. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  510. }
  511. return ServiceUtil.returnSuccess();
  512. }
  513. public static Map<String, Object> readEbayGetStoreCategoriesResponse(String msg, Locale locale) {
  514. Map<String, Object> results = null;
  515. List<Map<Object, Object>> categories = FastList.newInstance();
  516. try {
  517. Document docResponse = UtilXml.readXmlDocument(msg, true);
  518. Element elemResponse = docResponse.getDocumentElement();
  519. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  520. if (ack != null && "Failure".equals(ack)) {
  521. String errorMessage = "";
  522. List<Element> errorList = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Errors"));
  523. Iterator<Element> errorElemIter = errorList.iterator();
  524. while (errorElemIter.hasNext()) {
  525. Element errorElement = errorElemIter.next();
  526. errorMessage = UtilXml.childElementValue(errorElement, "ShortMessage", "");
  527. }
  528. return ServiceUtil.returnFailure(errorMessage);
  529. } else {
  530. // retrieve Store
  531. List<Element> Store = UtilGenerics.checkList(UtilXml.childElementList(elemResponse, "Store"));
  532. Iterator<Element> StoreElemIter = Store.iterator();
  533. while (StoreElemIter.hasNext()) {
  534. Element StoreElemIterElemIterElement = StoreElemIter.next();
  535. // retrieve Custom Category Array
  536. List<Element> customCategories = UtilGenerics.checkList(UtilXml.childElementList(StoreElemIterElemIterElement, "CustomCategories"));
  537. Iterator<Element> customCategoriesElemIter = customCategories.iterator();
  538. while (customCategoriesElemIter.hasNext()) {
  539. Element customCategoriesElemIterElement = customCategoriesElemIter.next();
  540. // retrieve CustomCategory
  541. List<Element> customCategory = UtilGenerics.checkList(UtilXml.childElementList(customCategoriesElemIterElement, "CustomCategory"));
  542. Iterator<Element> customCategoryElemIter = customCategory.iterator();
  543. while (customCategoryElemIter.hasNext()) {
  544. Map<Object, Object> categ = FastMap.newInstance();
  545. Element categoryElement = customCategoryElemIter.next();
  546. categ.put("CategoryID", UtilXml.childElementValue(categoryElement, "CategoryID"));
  547. categ.put("CategoryName", UtilXml.childElementValue(categoryElement, "Name"));
  548. categ.put("CategorySeq", UtilXml.childElementValue(categoryElement, "Order"));
  549. categories.add(categ);
  550. }
  551. }
  552. }
  553. categories = UtilMisc.sortMaps(categories, UtilMisc.toList("CategoryName"));
  554. results = UtilMisc.<String, Object>toMap("categories", categories);
  555. }
  556. } catch (Exception e) {
  557. return ServiceUtil.returnFailure();
  558. }
  559. return results;
  560. }
  561. public static Map<String, Object> getEbayStoreUser(DispatchContext dctx, Map<String, ? extends Object> context) {
  562. Map<String, Object> result = FastMap.newInstance();
  563. Delegator delegator = dctx.getDelegator();
  564. String productStoreId = (String) context.get("productStoreId");
  565. try {
  566. List<GenericValue> productStores = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStoreId, "roleTypeId", "EBAY_ACCOUNT"));
  567. if (productStores.size() != 0) {
  568. String partyId = (productStores.get(0)).getString("partyId");
  569. List<GenericValue> userLoginStore = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  570. if (userLoginStore.size() != 0) {
  571. String userLoginId = (userLoginStore.get(0)).getString("userLoginId");
  572. result.put("userLoginId", userLoginId);
  573. }
  574. }
  575. } catch (Exception e) {
  576. }
  577. return result;
  578. }
  579. /*Editing the Store Settings */
  580. /* Get store output */
  581. public static Map<String,Object> getEbayStoreOutput(DispatchContext dctx, Map<String,Object> context) {
  582. Locale locale = (Locale) context.get("locale");
  583. GenericValue userLogin = (GenericValue) context.get("userLogin");
  584. Delegator delegator = dctx.getDelegator();
  585. Map<String,Object> result = FastMap.newInstance();
  586. StoreType returnedStoreType = null;
  587. GetStoreRequestType req = new GetStoreRequestType();
  588. GetStoreResponseType resp = null;
  589. String userLoginId = null;
  590. if (context.get("productStoreId") != null) {
  591. String partyId = null;
  592. try {
  593. List<GenericValue> productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(),"roleTypeId","EBAY_ACCOUNT"));
  594. if (productStoreRoles.size() != 0) {
  595. partyId= (String)productStoreRoles.get(0).get("partyId");
  596. List<GenericValue> userLogins = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  597. if (userLogins.size() != 0) {
  598. userLoginId = (String)userLogins.get(0).get("userLoginId");
  599. }
  600. }
  601. } catch (GenericEntityException e1) {
  602. e1.printStackTrace();
  603. }
  604. Debug.logInfo("userLoginId is "+userLoginId+" and productStoreId is "+ context.get("productStoreId"), module);
  605. GetStoreCall call = new GetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  606. //call.setSite(EbayHelper.getSiteCodeType((String)context.get("productStoreId"), locale, delegator));
  607. call.setCategoryStructureOnly(false);
  608. call.setUserID(userLoginId);
  609. try {
  610. resp = (GetStoreResponseType)call.execute(req);
  611. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  612. returnedStoreType = resp.getStore();
  613. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
  614. //result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "EbayStoreLoadSuccess", locale));
  615. // update product store in ofbiz
  616. updateProductStore(dctx, context, returnedStoreType,(String) context.get("productStoreId"));
  617. Map<String,Object> ebayResp = FastMap.newInstance();
  618. ebayResp.put("storeName", returnedStoreType.getName());
  619. ebayResp.put("storeUrl", returnedStoreType.getURL());
  620. ebayResp.put("storeUrlPath", returnedStoreType.getURLPath());
  621. String desc = returnedStoreType.getDescription();
  622. if (desc != null) desc = desc.trim();
  623. ebayResp.put("storeDesc", desc);
  624. StoreLogoType logoType = returnedStoreType.getLogo();
  625. ebayResp.put("storeLogoId", logoType.getLogoID());
  626. ebayResp.put("storeLogoName", logoType.getName());
  627. ebayResp.put("storeLogoURL", logoType.getURL());
  628. StoreThemeType themeType = returnedStoreType.getTheme();
  629. ebayResp.put("storeThemeId", themeType.getThemeID());
  630. ebayResp.put("storeThemeName", themeType.getName());
  631. StoreColorSchemeType colorSchemeType = themeType.getColorScheme();
  632. ebayResp.put("storeColorSchemeId", colorSchemeType.getColorSchemeID());
  633. StoreColorType colorType = colorSchemeType.getColor();
  634. ebayResp.put("storeColorPrimary", colorType.getPrimary());
  635. ebayResp.put("storeColorAccent", colorType.getAccent());
  636. ebayResp.put("storeColorSecondary", colorType.getSecondary());
  637. StoreFontType fontType = colorSchemeType.getFont();
  638. ebayResp.put("storeDescColor", fontType.getDescColor());
  639. ebayResp.put("storeNameColor", fontType.getNameColor());
  640. ebayResp.put("storeTitleColor", fontType.getTitleColor());
  641. if (fontType != null) {// basic & advance theme
  642. String themeId = themeType.getThemeID().toString().concat("-").concat(colorSchemeType.getColorSchemeID().toString());
  643. context.put("themeId", themeId);
  644. Map<String,Object> results = retrieveThemeColorSchemeByThemeId(dctx, context);
  645. if (results != null) {
  646. Map<String,Object> storeFontScheme = UtilGenerics.checkMap(results.get("storeFontScheme"));
  647. if (storeFontScheme != null) {
  648. ebayResp.put("storeDescFontFace", storeFontScheme.get("storeFontTypeFontDescValue"));
  649. ebayResp.put("storeDescSizeCode", storeFontScheme.get("storeDescSizeValue"));
  650. ebayResp.put("storeNameFontFace", storeFontScheme.get("storeFontTypeFontFaceValue"));
  651. ebayResp.put("storeNameFontFaceSize", storeFontScheme.get("storeFontTypeSizeFaceValue"));
  652. ebayResp.put("storeTitleFontFace", storeFontScheme.get("storeFontTypeFontTitleValue"));
  653. ebayResp.put("storeTitleFontFaceSize", storeFontScheme.get("storeFontSizeTitleValue"));
  654. }
  655. }
  656. }
  657. StoreHeaderStyleCodeType storeHeaderStyleCodeType = returnedStoreType.getHeaderStyle();
  658. ebayResp.put("storeHeaderStyle", storeHeaderStyleCodeType.value());
  659. StoreHeaderStyleCodeType[] storeHeaderStyleCodeList = StoreHeaderStyleCodeType.values();
  660. if (storeHeaderStyleCodeList != null) {
  661. List<Map<String,Object>> storeHeaderStyleList = FastList.newInstance();
  662. int i=0;
  663. while (i<storeHeaderStyleCodeList.length) {
  664. Map<String,Object> storeHeaderStyleMap = FastMap.newInstance();
  665. StoreHeaderStyleCodeType storeHeaderStyleCode = storeHeaderStyleCodeList[i];
  666. storeHeaderStyleMap.put("storeHeaderStyleName", storeHeaderStyleCode.name());
  667. storeHeaderStyleMap.put("storeHeaderStyleValue", storeHeaderStyleCode.value());
  668. storeHeaderStyleList.add(storeHeaderStyleMap);
  669. i++;
  670. }
  671. ebayResp.put("storeHeaderStyleList", storeHeaderStyleList);
  672. }
  673. ebayResp.put("storeHomePage", returnedStoreType.getHomePage().toString());
  674. StoreItemListLayoutCodeType storeItemListLayoutCodeType = returnedStoreType.getItemListLayout();
  675. ebayResp.put("storeItemLayoutSelected", storeItemListLayoutCodeType.value());
  676. StoreItemListLayoutCodeType[] storeItemListLayoutCodeTypeList = StoreItemListLayoutCodeType.values();
  677. if (storeItemListLayoutCodeTypeList != null) {
  678. List<Map<String,Object>> storeItemListLayoutCodeList = FastList.newInstance();
  679. int i = 0;
  680. while (i < storeItemListLayoutCodeTypeList.length) {
  681. Map<String,Object> storeItemListLayoutCodeMap = FastMap.newInstance();
  682. StoreItemListLayoutCodeType storeItemListLayoutCode = storeItemListLayoutCodeTypeList[i];
  683. storeItemListLayoutCodeMap.put("storeItemLayoutName", storeItemListLayoutCode.name());
  684. storeItemListLayoutCodeMap.put("storeItemLayoutValue", storeItemListLayoutCode.value());
  685. storeItemListLayoutCodeList.add(storeItemListLayoutCodeMap);
  686. i++;
  687. }
  688. ebayResp.put("storeItemLayoutList", storeItemListLayoutCodeList);
  689. }
  690. StoreItemListSortOrderCodeType storeItemListSortOrderCodeType = returnedStoreType.getItemListSortOrder();
  691. ebayResp.put("storeItemSortOrderSelected", storeItemListSortOrderCodeType.value());
  692. StoreItemListSortOrderCodeType[] storeItemListSortOrderCodeTypeList = StoreItemListSortOrderCodeType.values();
  693. if (storeItemListSortOrderCodeTypeList != null) {
  694. List<Map<String,Object>> storeItemSortOrderCodeList = FastList.newInstance();
  695. int i = 0;
  696. while (i < storeItemListSortOrderCodeTypeList.length) {
  697. Map<String,Object> storeItemSortOrderCodeMap = FastMap.newInstance();
  698. StoreItemListSortOrderCodeType storeItemListLayoutCode = storeItemListSortOrderCodeTypeList[i];
  699. storeItemSortOrderCodeMap.put("storeItemSortLayoutName", storeItemListLayoutCode.name());
  700. storeItemSortOrderCodeMap.put("storeItemSortLayoutValue", storeItemListLayoutCode.value());
  701. storeItemSortOrderCodeList.add(storeItemSortOrderCodeMap);
  702. i++;
  703. }
  704. ebayResp.put("storeItemSortOrderList", storeItemSortOrderCodeList);
  705. }
  706. ebayResp.put("storeCustomHeader", returnedStoreType.getCustomHeader());
  707. StoreCustomHeaderLayoutCodeType storeCustomHeaderLayoutCodeType = returnedStoreType.getCustomHeaderLayout();
  708. ebayResp.put("storeCustomHeaderLayout", storeCustomHeaderLayoutCodeType.value());
  709. StoreCustomHeaderLayoutCodeType[] storeCustomHeaderLayoutCodeTypeList = StoreCustomHeaderLayoutCodeType.values();
  710. if (storeCustomHeaderLayoutCodeTypeList != null) {
  711. List<Map<String,Object>> storeCustomHeaderLayoutList = FastList.newInstance();
  712. int i = 0;
  713. while (i < storeCustomHeaderLayoutCodeTypeList.length) {
  714. Map<String,Object> storeCustomHeaderLayoutMap = FastMap.newInstance();
  715. StoreCustomHeaderLayoutCodeType StoreCustomHeaderLayoutCode = storeCustomHeaderLayoutCodeTypeList[i];
  716. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutName", StoreCustomHeaderLayoutCode.name());
  717. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutValue", StoreCustomHeaderLayoutCode.value());
  718. storeCustomHeaderLayoutList.add(storeCustomHeaderLayoutMap);
  719. i+

Large files files are truncated, but you can click here to view the full file