PageRenderTime 75ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/apache-ofbiz-10.04.02/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java

https://bitbucket.org/kphaneendrudu/myrep
Java | 2194 lines | 1991 code | 149 blank | 54 comment | 390 complexity | 2dbd3ec86132ca8f060411cfab90261c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, CPL-1.0, Apache-2.0
  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.IOException;
  22. import java.io.InputStream;
  23. import java.io.InputStreamReader;
  24. import java.io.OutputStream;
  25. import java.math.BigDecimal;
  26. import java.net.HttpURLConnection;
  27. import java.net.URL;
  28. import java.util.Calendar;
  29. import java.util.Date;
  30. import java.util.Iterator;
  31. import java.util.List;
  32. import java.util.Locale;
  33. import java.util.Map;
  34. import javolution.util.FastList;
  35. import javolution.util.FastMap;
  36. import org.ofbiz.base.util.Debug;
  37. import org.ofbiz.base.util.StringUtil;
  38. import org.ofbiz.base.util.UtilDateTime;
  39. import org.ofbiz.base.util.UtilMisc;
  40. import org.ofbiz.base.util.UtilProperties;
  41. import org.ofbiz.base.util.UtilValidate;
  42. import org.ofbiz.base.util.UtilXml;
  43. import org.ofbiz.common.DataModelConstants;
  44. import org.ofbiz.entity.Delegator;
  45. import org.ofbiz.entity.GenericEntityException;
  46. import org.ofbiz.entity.GenericValue;
  47. import org.ofbiz.entity.condition.EntityCondition;
  48. import org.ofbiz.entity.condition.EntityOperator;
  49. import org.ofbiz.entity.transaction.TransactionUtil;
  50. import org.ofbiz.entity.util.EntityUtil;
  51. import org.ofbiz.service.DispatchContext;
  52. import org.ofbiz.service.GenericServiceException;
  53. import org.ofbiz.service.LocalDispatcher;
  54. import org.ofbiz.service.ModelService;
  55. import org.ofbiz.service.ServiceUtil;
  56. import org.w3c.dom.Document;
  57. import org.w3c.dom.Element;
  58. import com.ebay.sdk.ApiContext;
  59. import com.ebay.sdk.ApiException;
  60. import com.ebay.sdk.SdkException;
  61. import com.ebay.sdk.SdkSoapException;
  62. import com.ebay.sdk.call.*;
  63. import com.ebay.sdk.util.eBayUtil;
  64. import com.ebay.soap.eBLBaseComponents.AmountType;
  65. import com.ebay.soap.eBLBaseComponents.CheckoutStatusCodeType;
  66. import com.ebay.soap.eBLBaseComponents.CurrencyCodeType;
  67. import com.ebay.soap.eBLBaseComponents.DeleteSellingManagerTemplateRequestType;
  68. import com.ebay.soap.eBLBaseComponents.DeleteSellingManagerTemplateResponseType;
  69. import com.ebay.soap.eBLBaseComponents.DisputeExplanationCodeType;
  70. import com.ebay.soap.eBLBaseComponents.DisputeReasonCodeType;
  71. import com.ebay.soap.eBLBaseComponents.GetAllBiddersModeCodeType;
  72. import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryRequestType;
  73. import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryResponseType;
  74. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsRequestType;
  75. import com.ebay.soap.eBLBaseComponents.GetStoreOptionsResponseType;
  76. import com.ebay.soap.eBLBaseComponents.GetStoreRequestType;
  77. import com.ebay.soap.eBLBaseComponents.GetStoreResponseType;
  78. import com.ebay.soap.eBLBaseComponents.ItemSortTypeCodeType;
  79. import com.ebay.soap.eBLBaseComponents.ListingTypeCodeType;
  80. import com.ebay.soap.eBLBaseComponents.MerchDisplayCodeType;
  81. import com.ebay.soap.eBLBaseComponents.OfferType;
  82. import com.ebay.soap.eBLBaseComponents.OrderTransactionArrayType;
  83. import com.ebay.soap.eBLBaseComponents.OrderTransactionType;
  84. import com.ebay.soap.eBLBaseComponents.OrderType;
  85. import com.ebay.soap.eBLBaseComponents.PaginationType;
  86. import com.ebay.soap.eBLBaseComponents.SecondChanceOfferDurationCodeType;
  87. import com.ebay.soap.eBLBaseComponents.SellingManagerProductDetailsType;
  88. import com.ebay.soap.eBLBaseComponents.SellingManagerProductInventoryStatusType;
  89. import com.ebay.soap.eBLBaseComponents.SellingManagerProductType;
  90. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchType;
  91. import com.ebay.soap.eBLBaseComponents.SellingManagerSearchTypeCodeType;
  92. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldListingsPropertyTypeCodeType;
  93. import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsArrayType;
  94. import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsType;
  95. import com.ebay.soap.eBLBaseComponents.SellingStatusType;
  96. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesRequestType;
  97. import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesResponseType;
  98. import com.ebay.soap.eBLBaseComponents.SetStoreRequestType;
  99. import com.ebay.soap.eBLBaseComponents.SetStoreResponseType;
  100. import com.ebay.soap.eBLBaseComponents.StoreCategoryUpdateActionCodeType;
  101. import com.ebay.soap.eBLBaseComponents.StoreColorSchemeType;
  102. import com.ebay.soap.eBLBaseComponents.StoreColorType;
  103. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryArrayType;
  104. import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryType;
  105. import com.ebay.soap.eBLBaseComponents.StoreCustomHeaderLayoutCodeType;
  106. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderDisplayCodeType;
  107. import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderType;
  108. import com.ebay.soap.eBLBaseComponents.StoreFontFaceCodeType;
  109. import com.ebay.soap.eBLBaseComponents.StoreFontSizeCodeType;
  110. import com.ebay.soap.eBLBaseComponents.StoreFontType;
  111. import com.ebay.soap.eBLBaseComponents.StoreHeaderStyleCodeType;
  112. import com.ebay.soap.eBLBaseComponents.StoreItemListLayoutCodeType;
  113. import com.ebay.soap.eBLBaseComponents.StoreItemListSortOrderCodeType;
  114. import com.ebay.soap.eBLBaseComponents.StoreLogoArrayType;
  115. import com.ebay.soap.eBLBaseComponents.StoreLogoType;
  116. import com.ebay.soap.eBLBaseComponents.StoreSubscriptionLevelCodeType;
  117. import com.ebay.soap.eBLBaseComponents.StoreThemeArrayType;
  118. import com.ebay.soap.eBLBaseComponents.StoreThemeType;
  119. import com.ebay.soap.eBLBaseComponents.StoreType;
  120. import com.ebay.soap.eBLBaseComponents.TaskStatusCodeType;
  121. import com.ebay.soap.eBLBaseComponents.TransactionArrayType;
  122. import com.ebay.soap.eBLBaseComponents.TransactionType;
  123. import com.ebay.soap.eBLBaseComponents.UserType;
  124. import com.ebay.soap.eBLBaseComponents.VerifyAddSecondChanceItemResponseType;
  125. import java.sql.Timestamp;
  126. import javax.swing.event.TableModelListener;
  127. import javax.swing.table.AbstractTableModel;
  128. import javax.swing.table.TableModel;
  129. import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
  130. import com.ebay.soap.eBLBaseComponents.ItemArrayType;
  131. import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
  132. import com.ebay.soap.eBLBaseComponents.ItemType;
  133. import com.ebay.soap.eBLBaseComponents.PaginatedItemArrayType;
  134. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldOrderType;
  135. import com.ebay.soap.eBLBaseComponents.SellingManagerSoldTransactionType;
  136. import org.ofbiz.ebay.ProductsExportToEbay;
  137. import org.ofbiz.ebay.EbayHelper;
  138. public class EbayStore {
  139. private static final String resource = "EbayStoreUiLabels";
  140. private static final String module = ProductsExportToEbay.class.getName();
  141. public static ProductsExportToEbay productExportEbay = new ProductsExportToEbay();
  142. private static void appendRequesterCredentials(Element elem, Document doc, String token) {
  143. Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
  144. UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
  145. }
  146. private static Map postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID,
  147. String callName, String compatibilityLevel, String siteID) throws IOException {
  148. if (Debug.verboseOn()) {
  149. Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), module);
  150. }
  151. HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
  152. connection.setDoInput(true);
  153. connection.setDoOutput(true);
  154. connection.setRequestMethod("POST");
  155. connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
  156. connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
  157. connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
  158. connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
  159. connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
  160. connection.setRequestProperty("X-EBAY-API-SITEID", siteID);
  161. connection.setRequestProperty("Content-Type", "text/xml");
  162. OutputStream outputStream = connection.getOutputStream();
  163. outputStream.write(dataItems.toString().getBytes());
  164. outputStream.close();
  165. int responseCode = connection.getResponseCode();
  166. InputStream inputStream;
  167. Map result = FastMap.newInstance();
  168. String response = null;
  169. if (responseCode == HttpURLConnection.HTTP_CREATED ||
  170. responseCode == HttpURLConnection.HTTP_OK) {
  171. inputStream = connection.getInputStream();
  172. response = toString(inputStream);
  173. result = ServiceUtil.returnSuccess(response);
  174. } else {
  175. inputStream = connection.getErrorStream();
  176. response = toString(inputStream);
  177. result = ServiceUtil.returnFailure(response);
  178. }
  179. if (Debug.verboseOn()) {
  180. Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
  181. }
  182. return result;
  183. }
  184. private static String toString(InputStream inputStream) throws IOException {
  185. String string;
  186. StringBuilder outputBuilder = new StringBuilder();
  187. if (inputStream != null) {
  188. BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
  189. while (null != (string = reader.readLine())) {
  190. outputBuilder.append(string).append('\n');
  191. }
  192. }
  193. return outputBuilder.toString();
  194. }
  195. /* add/update/delete categories and child into your ebay store category */
  196. public static Map<String,Object> exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map<String,? extends Object> context) {
  197. Locale locale = (Locale) context.get("locale");
  198. Delegator delegator = dctx.getDelegator();
  199. Map<String, Object> result = FastMap.newInstance();
  200. SetStoreCategoriesRequestType req = null;
  201. StoreCustomCategoryArrayType categoryArrayType = null;
  202. List<GenericValue> catalogCategories = null;
  203. if (UtilValidate.isEmpty(context.get("prodCatalogId")) || UtilValidate.isEmpty(context.get("productStoreId")) || UtilValidate.isEmpty(context.get("partyId"))) {
  204. return ServiceUtil.returnError("Please set catalogId and productStoreId.");
  205. }
  206. if (!EbayStoreHelper.validatePartyAndRoleType(delegator,context.get("partyId").toString())) {
  207. return ServiceUtil.returnError("Party ".concat(context.get("partyId").toString()).concat(" no roleTypeId EBAY_ACCOUNT for export categories to ebay store."));
  208. }
  209. try {
  210. SetStoreCategoriesCall call = new SetStoreCategoriesCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  211. catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString(),"prodCatalogCategoryTypeId","PCCT_EBAY_ROOT"), UtilMisc.toList("sequenceNum ASC"));
  212. if (catalogCategories != null && catalogCategories.size() > 0) {
  213. List<StoreCustomCategoryType> listAdd = FastList.newInstance();
  214. List<StoreCustomCategoryType> listEdit = FastList.newInstance();
  215. //start at level 0 of categories
  216. for (GenericValue catalogCategory : catalogCategories) {
  217. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  218. if (productCategory != null) {
  219. String ebayCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  220. StoreCustomCategoryType categoryType = new StoreCustomCategoryType();
  221. if (ebayCategoryId == null) {
  222. categoryType.setName(productCategory.getString("categoryName"));
  223. listAdd.add(categoryType);
  224. } else {
  225. categoryType.setCategoryID(new Long(ebayCategoryId));
  226. categoryType.setName(productCategory.getString("categoryName"));
  227. listEdit.add(categoryType);
  228. }
  229. }
  230. }
  231. if (listAdd.size() > 0) {
  232. req = new SetStoreCategoriesRequestType();
  233. categoryArrayType = new StoreCustomCategoryArrayType();
  234. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  235. req.setStoreCategories(categoryArrayType);
  236. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories);
  237. }
  238. if (listEdit.size() > 0) {
  239. req = new SetStoreCategoriesRequestType();
  240. categoryArrayType = new StoreCustomCategoryArrayType();
  241. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  242. req.setStoreCategories(categoryArrayType);
  243. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories);
  244. }
  245. //start at level 1 of categories
  246. listAdd = FastList.newInstance();
  247. listEdit = FastList.newInstance();
  248. for (GenericValue catalogCategory : catalogCategories) {
  249. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  250. if (productCategory != null) {
  251. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  252. if (ebayParentCategoryId != null) {
  253. List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategory.getString("productCategoryId")), UtilMisc.toList("sequenceNum ASC"));
  254. for (GenericValue productCategoryRollup : productCategoryRollupList) {
  255. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryRollup.getString("productCategoryId")));
  256. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  257. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
  258. if (ebayChildCategoryId == null) {
  259. childCategoryType.setName(productCategory.getString("categoryName"));
  260. listAdd.add(childCategoryType);
  261. } else {
  262. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  263. childCategoryType.setName(productCategory.getString("categoryName"));
  264. listEdit.add(childCategoryType);
  265. }
  266. }
  267. }
  268. if (listAdd.size() > 0) {
  269. req = new SetStoreCategoriesRequestType();
  270. categoryArrayType = new StoreCustomCategoryArrayType();
  271. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  272. req.setStoreCategories(categoryArrayType);
  273. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  274. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories);
  275. }
  276. if (listEdit.size() > 0) {
  277. req = new SetStoreCategoriesRequestType();
  278. categoryArrayType = new StoreCustomCategoryArrayType();
  279. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  280. req.setStoreCategories(categoryArrayType);
  281. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  282. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories);
  283. }
  284. }
  285. }
  286. //start at level 2 of categories
  287. listAdd = FastList.newInstance();
  288. listEdit = FastList.newInstance();
  289. for (GenericValue catalogCategory : catalogCategories) {
  290. GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
  291. if (productCategory != null) {
  292. List<GenericValue> productParentCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategory.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  293. for (GenericValue productParentCategoryRollup : productParentCategoryRollupList) {
  294. String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productParentCategoryRollup.getString("productCategoryId"),context.get("partyId").toString());
  295. if (ebayParentCategoryId != null) {
  296. List<GenericValue> productChildCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productParentCategoryRollup.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
  297. for (GenericValue productChildCategoryRollup : productChildCategoryRollupList) {
  298. productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productChildCategoryRollup.getString("productCategoryId")));
  299. StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
  300. String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
  301. if (ebayChildCategoryId == null) {
  302. childCategoryType.setName(productCategory.getString("categoryName"));
  303. listAdd.add(childCategoryType);
  304. } else {
  305. childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
  306. childCategoryType.setName(productCategory.getString("categoryName"));
  307. listEdit.add(childCategoryType);
  308. }
  309. }
  310. if (listAdd.size() > 0) {
  311. req = new SetStoreCategoriesRequestType();
  312. categoryArrayType = new StoreCustomCategoryArrayType();
  313. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
  314. req.setStoreCategories(categoryArrayType);
  315. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  316. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator, context.get("partyId").toString(), catalogCategories);
  317. }
  318. if (listEdit.size() > 0) {
  319. req = new SetStoreCategoriesRequestType();
  320. categoryArrayType = new StoreCustomCategoryArrayType();
  321. categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
  322. req.setStoreCategories(categoryArrayType);
  323. req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
  324. result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator, context.get("partyId").toString(), catalogCategories);
  325. }
  326. }
  327. }
  328. }
  329. }
  330. } else {
  331. return ServiceUtil.returnError("Not found product Category type EBAY_ROOT in catalog "+context.get("prodCatalogId"));
  332. }
  333. } catch (GenericEntityException e) {
  334. result = ServiceUtil.returnFailure(e.getMessage());
  335. }
  336. if (result.get("responseMessage") != null && result.get("responseMessage").equals("fail")) result = ServiceUtil.returnError(result.get("errorMessage").toString());
  337. return result;
  338. }
  339. public static StoreCustomCategoryType[] toStoreCustomCategoryTypeArray(List<StoreCustomCategoryType> list) {
  340. StoreCustomCategoryType[] storeCustomCategoryTypeArry = null;
  341. try {
  342. if (list != null && list.size() > 0) {
  343. storeCustomCategoryTypeArry = new StoreCustomCategoryType[list.size()];
  344. int i=0;
  345. for (StoreCustomCategoryType val : list) {
  346. storeCustomCategoryTypeArry[i] = val;
  347. }
  348. }
  349. } catch (Exception e) {
  350. Debug.logError(e.getMessage(), module);
  351. }
  352. return storeCustomCategoryTypeArry;
  353. }
  354. public static Map<String, Object> excuteExportCategoryToEbayStore(SetStoreCategoriesCall call, SetStoreCategoriesRequestType req, StoreCategoryUpdateActionCodeType actionCode,Delegator delegator, String partyId,List<GenericValue> catalogCategories) {
  355. Map<String, Object> result = FastMap.newInstance();
  356. SetStoreCategoriesResponseType resp = null;
  357. try {
  358. if (req != null && actionCode != null) {
  359. req.setAction(actionCode);
  360. resp = (SetStoreCategoriesResponseType) call.execute(req);
  361. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  362. long returnTaskId = resp.getTaskID() == null? 0: resp.getTaskID().longValue();
  363. TaskStatusCodeType returnedStatus = resp.getStatus();
  364. StoreCustomCategoryArrayType returnedCustomCategory = resp.getCustomCategory();
  365. if (actionCode.equals(StoreCategoryUpdateActionCodeType.ADD) && returnedCustomCategory != null) {
  366. StoreCustomCategoryType[] returnCategoryTypeList = returnedCustomCategory.getCustomCategory();
  367. for (StoreCustomCategoryType returnCategoryType : returnCategoryTypeList) {
  368. List<GenericValue> productCategoryList = delegator.findByAnd("ProductCategory", UtilMisc.toMap("categoryName",returnCategoryType.getName(),"productCategoryTypeId","EBAY_CATEGORY"));
  369. for (GenericValue productCategory : productCategoryList) {
  370. if (EbayStoreHelper.veriflyCategoryInCatalog(delegator,catalogCategories,productCategory.getString("productCategoryId"))) {
  371. if (EbayStoreHelper.createEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), partyId, String.valueOf(returnCategoryType.getCategoryID()))) {
  372. Debug.logInfo("Create new ProductCategoryRollup with partyId "+partyId+" categoryId "+productCategory.getString("productCategoryId")+ " and ebayCategoryId "+String.valueOf(returnCategoryType.getCategoryID()), module);
  373. }
  374. break;
  375. }
  376. }
  377. }
  378. }
  379. result = ServiceUtil.returnSuccess("Export categories to ebay store".concat(" success."));
  380. } else {
  381. result = ServiceUtil.returnError("Fail to export categories to an ebay store ".concat(resp.getMessage()));
  382. }
  383. }
  384. } catch (ApiException e) {
  385. result = ServiceUtil.returnFailure(e.getMessage());
  386. } catch (SdkSoapException e) {
  387. result = ServiceUtil.returnFailure(e.getMessage());
  388. } catch (SdkException e) {
  389. result = ServiceUtil.returnFailure(e.getMessage());
  390. } catch (GenericEntityException e) {
  391. result = ServiceUtil.returnFailure(e.getMessage());
  392. }
  393. return result;
  394. }
  395. public static Map buildSetStoreXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID) {
  396. Locale locale = (Locale)context.get("locale");
  397. try {
  398. Delegator delegator = dctx.getDelegator();
  399. String webSiteUrl = (String)context.get("webSiteUrl");
  400. List selectResult = (List)context.get("selectResult");
  401. StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
  402. // Get the list of products to be exported to eBay
  403. try {
  404. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreRequest");
  405. Element storeRequestElem = storeDocument.getDocumentElement();
  406. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  407. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  408. /*UtilXml.addChildElementValue(storeRequestElem, "SiteId", siteID, storeDocument);
  409. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  410. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);*/
  411. // Prepare data for set to XML
  412. GenericValue productStore = null;
  413. if (UtilValidate.isNotEmpty(context.get("productStoreId").toString())) {
  414. productStore = delegator.findByPrimaryKey("ProductStore",UtilMisc.toMap("productStoreId", context.get("productStoreId").toString()));
  415. }
  416. Element itemElem = UtilXml.addChildElement(storeRequestElem, "Store", storeDocument);
  417. UtilXml.addChildElementValue(itemElem, "Name", (String) productStore.getString("storeName"), storeDocument);
  418. UtilXml.addChildElementValue(itemElem, "SubscriptionLevel", "Basic", storeDocument);
  419. UtilXml.addChildElementValue(itemElem, "Description", (String) productStore.getString("title"), storeDocument);
  420. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  421. } catch (Exception e) {
  422. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  423. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  424. }
  425. } catch (Exception e) {
  426. Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
  427. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  428. }
  429. return ServiceUtil.returnSuccess();
  430. }
  431. public static String readEbayResponse(String msg, String productStoreId) {
  432. String result ="success";
  433. try {
  434. Document docResponse = UtilXml.readXmlDocument(msg, true);
  435. Element elemResponse = docResponse.getDocumentElement();
  436. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  437. if (ack != null && "Failure".equals(ack)) {
  438. String errorMessage = "";
  439. List errorList = UtilXml.childElementList(elemResponse, "Errors");
  440. Iterator errorElemIter = errorList.iterator();
  441. while (errorElemIter.hasNext()) {
  442. Element errorElement = (Element) errorElemIter.next();
  443. errorMessage = UtilXml.childElementValue(errorElement, "LongMessage");
  444. }
  445. result = errorMessage;
  446. } else {
  447. String productSuccessfullyExportedMsg = "Successfully exported with ID (" + productStoreId + ").";
  448. result = "success";
  449. }
  450. } catch (Exception e) {
  451. Debug.logError("Error in processing xml string" + e.getMessage(), module);
  452. result = "Failure";
  453. }
  454. return result;
  455. }
  456. public static Map buildGetStoreXml(Map context, StringBuffer dataStoreXml, String token, String siteID) {
  457. Locale locale = (Locale)context.get("locale");
  458. try {
  459. StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
  460. // Get the list of products to be exported to eBay
  461. try {
  462. Document storeDocument = UtilXml.makeEmptyXmlDocument("GetStoreRequest");
  463. Element storeRequestElem = storeDocument.getDocumentElement();
  464. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  465. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  466. //UtilXml.addChildElementValue(storeRequestElem, "CategorySiteID", siteID, storeDocument);
  467. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  468. UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);
  469. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  470. } catch (Exception e) {
  471. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  472. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  473. }
  474. } catch (Exception e) {
  475. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  476. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  477. }
  478. return ServiceUtil.returnSuccess();
  479. }
  480. public static Map buildSetStoreCategoriesXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID, String productCategoryId) {
  481. Delegator delegator = dctx.getDelegator();
  482. Locale locale = (Locale)context.get("locale");
  483. try {
  484. StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
  485. // Get the list of products to be exported to eBay
  486. try {
  487. Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreCategoriesRequest");
  488. Element storeRequestElem = storeDocument.getDocumentElement();
  489. storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
  490. appendRequesterCredentials(storeRequestElem, storeDocument, token);
  491. UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
  492. UtilXml.addChildElementValue(storeRequestElem, "Version", "643", storeDocument);
  493. UtilXml.addChildElementValue(storeRequestElem, "Action", "Add", storeDocument);
  494. Element StoreCategoriesElem = UtilXml.addChildElement(storeRequestElem, "StoreCategories", storeDocument);
  495. //UtilXml.addChildElementValue(StoreCategoriesElem, "Country", (String)context.get("country"), storeDocument);
  496. GenericValue category = null;
  497. if (UtilValidate.isNotEmpty(context.get("prodCatalogId"))) {
  498. category = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId));
  499. }
  500. String categoryName = category.getString("productCategoryId").toString();
  501. if (category.getString("categoryName").toString() != null) {
  502. categoryName = category.getString("categoryName").toString();
  503. }
  504. Element customCategoryElem = UtilXml.addChildElement(StoreCategoriesElem, "CustomCategory", storeDocument);
  505. //UtilXml.addChildElementValue(customCategoryElem, "CategoryID", "", storeDocument);
  506. UtilXml.addChildElementValue(customCategoryElem, "Name", categoryName, storeDocument);
  507. dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
  508. } catch (Exception e) {
  509. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  510. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  511. }
  512. } catch (Exception e) {
  513. Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
  514. return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
  515. }
  516. return ServiceUtil.returnSuccess();
  517. }
  518. public static Map readEbayGetStoreCategoriesResponse(String msg, Locale locale) {
  519. Map results = null;
  520. List categories = FastList.newInstance();
  521. try {
  522. Document docResponse = UtilXml.readXmlDocument(msg, true);
  523. Element elemResponse = docResponse.getDocumentElement();
  524. String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
  525. if (ack != null && "Failure".equals(ack)) {
  526. String errorMessage = "";
  527. List errorList = UtilXml.childElementList(elemResponse, "Errors");
  528. Iterator errorElemIter = errorList.iterator();
  529. while (errorElemIter.hasNext()) {
  530. Element errorElement = (Element) errorElemIter.next();
  531. errorMessage = UtilXml.childElementValue(errorElement, "ShortMessage", "");
  532. }
  533. return ServiceUtil.returnFailure(errorMessage);
  534. } else {
  535. // retrieve Store
  536. List Store = UtilXml.childElementList(elemResponse, "Store");
  537. Iterator StoreElemIter = Store.iterator();
  538. while (StoreElemIter.hasNext()) {
  539. Element StoreElemIterElemIterElement = (Element) StoreElemIter.next();
  540. // retrieve Custom Category Array
  541. List customCategories = UtilXml.childElementList(StoreElemIterElemIterElement, "CustomCategories");
  542. Iterator customCategoriesElemIter = customCategories.iterator();
  543. while (customCategoriesElemIter.hasNext()) {
  544. Element customCategoriesElemIterElement = (Element)customCategoriesElemIter.next();
  545. // retrieve CustomCategory
  546. List customCategory = UtilXml.childElementList(customCategoriesElemIterElement, "CustomCategory");
  547. Iterator customCategoryElemIter = customCategory.iterator();
  548. while (customCategoryElemIter.hasNext()) {
  549. Map categ = FastMap.newInstance();
  550. Element categoryElement = (Element)customCategoryElemIter.next();
  551. categ.put("CategoryID", UtilXml.childElementValue(categoryElement, "CategoryID"));
  552. categ.put("CategoryName", UtilXml.childElementValue(categoryElement, "Name"));
  553. categ.put("CategorySeq", UtilXml.childElementValue(categoryElement, "Order"));
  554. categories.add(categ);
  555. }
  556. }
  557. }
  558. categories = UtilMisc.sortMaps(categories, UtilMisc.toList("CategoryName"));
  559. results = UtilMisc.toMap("categories", categories);
  560. }
  561. } catch (Exception e) {
  562. return ServiceUtil.returnFailure();
  563. }
  564. return results;
  565. }
  566. public static Map<String, Object> getEbayStoreUser(DispatchContext dctx, Map<String, ? extends Object> context) {
  567. Map<String, Object> result = FastMap.newInstance();
  568. String errorMsg = null;
  569. LocalDispatcher dispatcher = dctx.getDispatcher();
  570. GenericValue userLogin = (GenericValue) context.get("userLogin");
  571. Delegator delegator = dctx.getDelegator();
  572. Locale locale = (Locale) context.get("locale");
  573. String productStoreId = (String) context.get("productStoreId");
  574. List itemsResult = FastList.newInstance();
  575. try {
  576. List productStores = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStoreId, "roleTypeId", "EBAY_ACCOUNT"));
  577. if (productStores.size() != 0) {
  578. String partyId = ((GenericValue) productStores.get(0)).getString("partyId");
  579. List userLoginStore = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  580. if (userLoginStore.size() != 0) {
  581. String userLoginId = ((GenericValue) userLoginStore.get(0)).getString("userLoginId");
  582. result.put("userLoginId", userLoginId);
  583. }
  584. }
  585. } catch (Exception e) {
  586. }
  587. return result;
  588. }
  589. /*Editing the Store Settings */
  590. /* Get store output */
  591. public static Map<String,Object> getEbayStoreOutput(DispatchContext dctx, Map<String,Object> context) {
  592. Locale locale = (Locale) context.get("locale");
  593. GenericValue userLogin = (GenericValue) context.get("userLogin");
  594. Delegator delegator = dctx.getDelegator();
  595. Map<String,Object> result = FastMap.newInstance();
  596. StoreType returnedStoreType = null;
  597. GetStoreRequestType req = new GetStoreRequestType();
  598. GetStoreResponseType resp = null;
  599. String userLoginId = null;
  600. String password = null;
  601. if (context.get("productStoreId") != null) {
  602. String partyId = null;
  603. try {
  604. List<GenericValue> productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(),"roleTypeId","EBAY_ACCOUNT"));
  605. if (productStoreRoles.size() != 0) {
  606. partyId= (String)productStoreRoles.get(0).get("partyId");
  607. List<GenericValue> userLogins = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
  608. if (userLogins.size() != 0) {
  609. userLoginId = (String)userLogins.get(0).get("userLoginId");
  610. password = (String)userLogins.get(0).get("currentPassword");
  611. }
  612. }
  613. } catch (GenericEntityException e1) {
  614. e1.printStackTrace();
  615. }
  616. Debug.logInfo("userLoginId is "+userLoginId+" and productStoreId is "+ context.get("productStoreId"), module);
  617. GetStoreCall call = new GetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  618. //call.setSite(EbayHelper.getSiteCodeType((String)context.get("productStoreId"), locale, delegator));
  619. call.setCategoryStructureOnly(false);
  620. call.setUserID(userLoginId);
  621. try {
  622. resp = (GetStoreResponseType)call.execute(req);
  623. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  624. returnedStoreType = resp.getStore();
  625. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
  626. //result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "EbayStoreLoadSuccess", locale));
  627. // update product store in ofbiz
  628. updateProductStore(dctx, context, returnedStoreType,(String) context.get("productStoreId"));
  629. Map<String,Object> ebayResp = FastMap.newInstance();
  630. ebayResp.put("storeName", returnedStoreType.getName());
  631. ebayResp.put("storeUrl", returnedStoreType.getURL());
  632. ebayResp.put("storeUrlPath", returnedStoreType.getURLPath());
  633. String desc = returnedStoreType.getDescription();
  634. if (desc != null) desc = desc.trim();
  635. ebayResp.put("storeDesc", desc);
  636. StoreLogoType logoType = returnedStoreType.getLogo();
  637. ebayResp.put("storeLogoId", logoType.getLogoID());
  638. ebayResp.put("storeLogoName", logoType.getName());
  639. ebayResp.put("storeLogoURL", logoType.getURL());
  640. StoreThemeType themeType = returnedStoreType.getTheme();
  641. ebayResp.put("storeThemeId", themeType.getThemeID());
  642. ebayResp.put("storeThemeName", themeType.getName());
  643. StoreColorSchemeType colorSchemeType = themeType.getColorScheme();
  644. ebayResp.put("storeColorSchemeId", colorSchemeType.getColorSchemeID());
  645. StoreColorType colorType = colorSchemeType.getColor();
  646. ebayResp.put("storeColorPrimary", colorType.getPrimary());
  647. ebayResp.put("storeColorAccent", colorType.getAccent());
  648. ebayResp.put("storeColorSecondary", colorType.getSecondary());
  649. StoreFontType fontType = colorSchemeType.getFont();
  650. ebayResp.put("storeDescColor", fontType.getDescColor());
  651. ebayResp.put("storeNameColor", fontType.getNameColor());
  652. ebayResp.put("storeTitleColor", fontType.getTitleColor());
  653. if (fontType != null) {// basic & advance theme
  654. String themeId = themeType.getThemeID().toString().concat("-").concat(colorSchemeType.getColorSchemeID().toString());
  655. context.put("themeId", themeId);
  656. Map<String,Object> results = retrieveThemeColorSchemeByThemeId(dctx, context);
  657. if (results != null) {
  658. Map<String,Object> storeFontScheme = (Map<String,Object>) results.get("storeFontScheme");
  659. if (storeFontScheme != null) {
  660. ebayResp.put("storeDescFontFace", storeFontScheme.get("storeFontTypeFontDescValue"));
  661. ebayResp.put("storeDescSizeCode", storeFontScheme.get("storeDescSizeValue"));
  662. ebayResp.put("storeNameFontFace", storeFontScheme.get("storeFontTypeFontFaceValue"));
  663. ebayResp.put("storeNameFontFaceSize", storeFontScheme.get("storeFontTypeSizeFaceValue"));
  664. ebayResp.put("storeTitleFontFace", storeFontScheme.get("storeFontTypeFontTitleValue"));
  665. ebayResp.put("storeTitleFontFaceSize", storeFontScheme.get("storeFontSizeTitleValue"));
  666. }
  667. }
  668. }
  669. StoreHeaderStyleCodeType storeHeaderStyleCodeType = returnedStoreType.getHeaderStyle();
  670. ebayResp.put("storeHeaderStyle", storeHeaderStyleCodeType.value());
  671. StoreHeaderStyleCodeType[] storeHeaderStyleCodeList = storeHeaderStyleCodeType.values();
  672. if (storeHeaderStyleCodeList != null) {
  673. List<Map<String,Object>> storeHeaderStyleList = FastList.newInstance();
  674. int i=0;
  675. while (i<storeHeaderStyleCodeList.length) {
  676. Map<String,Object> storeHeaderStyleMap = FastMap.newInstance();
  677. StoreHeaderStyleCodeType storeHeaderStyleCode = storeHeaderStyleCodeList[i];
  678. storeHeaderStyleMap.put("storeHeaderStyleName", storeHeaderStyleCode.name());
  679. storeHeaderStyleMap.put("storeHeaderStyleValue", storeHeaderStyleCode.value());
  680. storeHeaderStyleList.add(storeHeaderStyleMap);
  681. i++;
  682. }
  683. ebayResp.put("storeHeaderStyleList", storeHeaderStyleList);
  684. }
  685. ebayResp.put("storeHomePage", returnedStoreType.getHomePage().toString());
  686. StoreItemListLayoutCodeType storeItemListLayoutCodeType = returnedStoreType.getItemListLayout();
  687. ebayResp.put("storeItemLayoutSelected", storeItemListLayoutCodeType.value());
  688. StoreItemListLayoutCodeType[] storeItemListLayoutCodeTypeList = storeItemListLayoutCodeType.values();
  689. if (storeItemListLayoutCodeTypeList != null) {
  690. List<Map<String,Object>> storeItemListLayoutCodeList = FastList.newInstance();
  691. int i = 0;
  692. while (i < storeItemListLayoutCodeTypeList.length) {
  693. Map<String,Object> storeItemListLayoutCodeMap = FastMap.newInstance();
  694. StoreItemListLayoutCodeType storeItemListLayoutCode = storeItemListLayoutCodeTypeList[i];
  695. storeItemListLayoutCodeMap.put("storeItemLayoutName", storeItemListLayoutCode.name());
  696. storeItemListLayoutCodeMap.put("storeItemLayoutValue", storeItemListLayoutCode.value());
  697. storeItemListLayoutCodeList.add(storeItemListLayoutCodeMap);
  698. i++;
  699. }
  700. ebayResp.put("storeItemLayoutList", storeItemListLayoutCodeList);
  701. }
  702. StoreItemListSortOrderCodeType storeItemListSortOrderCodeType = returnedStoreType.getItemListSortOrder();
  703. ebayResp.put("storeItemSortOrderSelected", storeItemListSortOrderCodeType.value());
  704. StoreItemListSortOrderCodeType[] storeItemListSortOrderCodeTypeList = storeItemListSortOrderCodeType.values();
  705. if (storeItemListSortOrderCodeTypeList != null) {
  706. List<Map<String,Object>> storeItemSortOrderCodeList = FastList.newInstance();
  707. int i = 0;
  708. while (i < storeItemListSortOrderCodeTypeList.length) {
  709. Map<String,Object> storeItemSortOrderCodeMap = FastMap.newInstance();
  710. StoreItemListSortOrderCodeType storeItemListLayoutCode = storeItemListSortOrderCodeTypeList[i];
  711. storeItemSortOrderCodeMap.put("storeItemSortLayoutName", storeItemListLayoutCode.name());
  712. storeItemSortOrderCodeMap.put("storeItemSortLayoutValue", storeItemListLayoutCode.value());
  713. storeItemSortOrderCodeList.add(storeItemSortOrderCodeMap);
  714. i++;
  715. }
  716. ebayResp.put("storeItemSortOrderList", storeItemSortOrderCodeList);
  717. }
  718. ebayResp.put("storeCustomHeader", returnedStoreType.getCustomHeader());
  719. StoreCustomHeaderLayoutCodeType storeCustomHeaderLayoutCodeType = returnedStoreType.getCustomHeaderLayout();
  720. ebayResp.put("storeCustomHeaderLayout", storeCustomHeaderLayoutCodeType.value());
  721. StoreCustomHeaderLayoutCodeType[] storeCustomHeaderLayoutCodeTypeList = storeCustomHeaderLayoutCodeType.values();
  722. if (storeCustomHeaderLayoutCodeTypeList != null) {
  723. List<Map<String,Object>> storeCustomHeaderLayoutList = FastList.newInstance();
  724. int i = 0;
  725. while (i < storeCustomHeaderLayoutCodeTypeList.length) {
  726. Map<String,Object> storeCustomHeaderLayoutMap = FastMap.newInstance();
  727. StoreCustomHeaderLayoutCodeType StoreCustomHeaderLayoutCode = storeCustomHeaderLayoutCodeTypeList[i];
  728. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutName", StoreCustomHeaderLayoutCode.name());
  729. storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutValue", StoreCustomHeaderLayoutCode.value());
  730. storeCustomHeaderLayoutList.add(storeCustomHeaderLayoutMap);
  731. i++;
  732. }
  733. ebayResp.put("storeCustomHeaderLayoutList", storeCustomHeaderLayoutList);
  734. }
  735. StoreCustomListingHeaderType storeCustomListingHeaderType = returnedStoreType.getCustomListingHeader();
  736. if (storeCustomListingHeaderType != null) {
  737. StoreCustomListingHeaderDisplayCodeType storeCustomListingHeaderDisplayCodeType = storeCustomListingHeaderType.getDisplayType();
  738. ebayResp.put("isLogo", storeCustomListingHeaderType.isLogo());
  739. ebayResp.put("isSearchBox", storeCustomListingHeaderType.isSearchBox());
  740. ebayResp.put("isAddToFavoriteStores", storeCustomListingHeaderType.isAddToFavoriteStores());
  741. ebayResp.put("isSignUpForStoreNewsletter", storeCustomListingHeaderType.isSignUpForStoreNewsletter());
  742. ebayResp.put("storeCustomListingHeaderDisplayName", storeCustomListingHeaderDisplayCodeType.name());
  743. ebayResp.put("storeCustomListingHeaderDisplayValue", storeCustomListingHeaderDisplayCodeType.value());
  744. StoreCustomListingHeaderDisplayCodeType[] storeCustomListingHeaderDisplayCodeTypeList = storeCustomListingHeaderDisplayCodeType.values();
  745. if (storeCustomListingHeaderDisplayCodeTypeList != null) {
  746. List<Map<String,Object>> storeCustomListingHeaderDisplayCodeList = FastList.newInstance();
  747. int i = 0;
  748. while (i < storeCustomListingHeaderDisplayCodeTypeList.length) {
  749. Map<String,Object> storeCustomListingHeaderDisplayCodeMap = FastMap.newInstance();
  750. StoreCustomListingHeaderDisplayCodeType storeCustomListingHeaderDisplayCode = storeCustomListingHeaderDisplayCodeTypeList[i];
  751. storeCustomListingHeaderDisplayCodeMap.put("storeCustomHeaderLayoutName", storeCustomListingHeaderDisplayCode.name());
  752. storeCustomListingHeaderDisplayCodeMap.put("storeCustomHeaderLayoutValue", storeCustomListingHeaderDisplayCode.value());
  753. storeCustomListingHeaderDisplayCodeList.add(storeCustomListingHeaderDisplayCodeMap);
  754. i++;
  755. }
  756. ebayResp.put("storeCustomListingHeaderDisplayList", storeCustomListingHeaderDisplayCodeList);
  757. }
  758. }
  759. //CustomListingHeader
  760. MerchDisplayCodeType merchDisplayCodeType = returnedStoreType.getMerchDisplay();
  761. ebayResp.put("storeMerchDisplay",merchDisplayCodeType.value());
  762. MerchDisplayCodeType[] merchDisplayCodeTypeList = merchDisplayCodeType.values();
  763. if (merchDisplayCodeTypeList != null) {
  764. List<Map<String,Object>> merchDisplayCodeList = FastList.newInstance();
  765. int i = 0;
  766. while (i < merchDisplayCodeTypeList.length) {
  767. Map<String,Object> merchDisplayCodeMap = FastMap.newInstance();
  768. MerchDisplayCodeType merchDisplayCode = merchDisplayCodeTypeList[i];
  769. merchDisplayCodeMap.put("merchDisplayCodeName", merchDisplayCode.name());
  770. merchDisplayCodeMap.put("merchDisplayCodeValue", merchDisplayCode.value());
  771. merchDisplayCodeList.add(merchDisplayCodeMap);
  772. i++;
  773. }
  774. ebayResp.put("storeMerchDisplayList",merchDisplayCodeList);
  775. }
  776. Calendar calendar = returnedStoreType.getLastOpenedTime();
  777. ebayResp.put("storeLastOpenedTime", calendar.getTime().toString());
  778. ebayResp.put("storeSubscriptionLevel", returnedStoreType.getSubscriptionLevel().value());
  779. StoreSubscriptionLevelCodeType[] storeSubscriptionlevelList = returnedStoreType.getSubscriptionLevel().values();
  780. if (storeSubscriptionlevelList != null) {
  781. List<Map<String,Object>> storeSubscriptionLevelCodeList = FastList.newInstance();
  782. int i = 0;
  783. while (i < storeSubscriptionlevelList.length) {
  784. Map<String,Object> storeSubscriptionLevelCodeMap = FastMap.newInstance();
  785. StoreSubscriptionLevelCodeType storeSubscriptionLevelCode= storeSubscriptionlevelList[i];
  786. storeSubscriptionLevelCodeMap.put("storeSubscriptionLevelCodeName", storeSubscriptionLevelCode.name());
  787. storeSubscriptionLevelCodeMap.put("storeSubscriptionLevelCodeValue", storeSubscriptionLevelCode.value());
  788. storeSubscriptionLevelCodeList.add(storeSubscriptionLevelCodeMap);
  789. i++;
  790. }
  791. ebayResp.put("storeSubscriptionLevelList", storeSubscriptionLevelCodeList);
  792. }
  793. result.put("ebayStore", ebayResp);
  794. } else {
  795. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store : getEbayStoreOutput", resp.getErrors(0).getLongMessage());
  796. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  797. result.put(ModelService.ERROR_MESSAGE, resp.getAck().toString() +":"+ resp.getMessage());
  798. }
  799. } catch (ApiException e) {
  800. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  801. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  802. } catch (SdkSoapException e) {
  803. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  804. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  805. } catch (SdkException e) {
  806. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
  807. result.put(ModelService.ERROR_MESSAGE, e.getMessage());
  808. }
  809. }
  810. return result;
  811. }
  812. public static void updateProductStore(DispatchContext dctx, Map<String,Object> context, StoreType returnStoreType, String productStoreId) {
  813. LocalDispatcher dispatcher = dctx.getDispatcher();
  814. try {
  815. Map<String,Object> inMap = FastMap.newInstance();
  816. if (returnStoreType != null) {
  817. inMap.put("productStoreId", productStoreId);
  818. inMap.put("storeName", returnStoreType.getName());
  819. inMap.put("subtitle", returnStoreType.getDescription());
  820. inMap.put("title", returnStoreType.getName());
  821. inMap.put("userLogin", context.get("userLogin"));
  822. dispatcher.runSync("updateProductStore", inMap);
  823. }
  824. } catch (Exception e) {
  825. Debug.logError("error message"+e, module);
  826. }
  827. }
  828. public static Map<String,Object> retrieveThemeColorSchemeByThemeId(DispatchContext dctx, Map<String,Object> context) {
  829. GenericValue userLogin = (GenericValue) context.get("userLogin");
  830. Locale locale = (Locale) context.get("locale");
  831. Delegator delegator = dctx.getDelegator();
  832. Map<String,Object> result = FastMap.newInstance();
  833. GetStoreOptionsRequestType req = null;
  834. GetStoreOptionsResponseType resp = null;
  835. StoreThemeArrayType returnedBasicThemeArray = null;
  836. try {
  837. if (context.get("productStoreId") != null) {
  838. String themeId = (String)context.get("themeId");
  839. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  840. req = new GetStoreOptionsRequestType();
  841. resp = (GetStoreOptionsResponseType) call.execute(req);
  842. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  843. returnedBasicThemeArray = resp.getBasicThemeArray();
  844. StoreThemeType[] storeBasicTheme = returnedBasicThemeArray.getTheme();
  845. int i = 0;
  846. String colorSchemeId = themeId.substring(themeId.indexOf("-") + 1);
  847. themeId = themeId.substring(0,themeId.indexOf("-"));
  848. Map<String,Object> storeColorSchemeMap = null;
  849. while (i < storeBasicTheme.length) {
  850. StoreThemeType storeThemeType = (StoreThemeType) storeBasicTheme[i];
  851. if (themeId.equals(storeThemeType.getThemeID().toString())) {
  852. StoreColorSchemeType colorSchemeType = storeThemeType.getColorScheme();
  853. if (colorSchemeType != null) {
  854. if (colorSchemeId.equals(colorSchemeType.getColorSchemeID().toString())) {
  855. // get font,size and color
  856. storeColorSchemeMap = FastMap.newInstance();
  857. StoreFontType storeFontType = colorSchemeType.getFont();
  858. storeColorSchemeMap.put("storeFontTypeFontFaceValue", storeFontType.getNameFace().value());
  859. storeColorSchemeMap.put("storeFontTypeSizeFaceValue", storeFontType.getNameSize().value());
  860. storeColorSchemeMap.put("storeFontTypeFontTitleValue", storeFontType.getTitleFace().value());
  861. storeColorSchemeMap.put("storeFontSizeTitleValue", storeFontType.getTitleSize().value());
  862. storeColorSchemeMap.put("storeFontTypeFontDescValue", storeFontType.getDescFace().value());
  863. storeColorSchemeMap.put("storeDescSizeValue", storeFontType.getDescSize().value());
  864. break;
  865. }
  866. }
  867. }
  868. i++;
  869. }
  870. result.put("storeFontScheme", storeColorSchemeMap);
  871. } else {
  872. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveThemeColorSchemeByThemeId", resp.getErrors(0).getLongMessage());
  873. }
  874. }
  875. } catch (ApiException e) {
  876. e.printStackTrace();
  877. } catch (SdkSoapException e) {
  878. e.printStackTrace();
  879. } catch (SdkException e) {
  880. e.printStackTrace();
  881. }
  882. return result;
  883. }
  884. public static Map<String,Object> retrievePredesignedLogoOption(DispatchContext dctx, Map<String,Object> context) {
  885. GenericValue userLogin = (GenericValue) context.get("userLogin");
  886. Map<String,Object> result = FastMap.newInstance();
  887. Locale locale = (Locale) context.get("locale");
  888. Delegator delegator = dctx.getDelegator();
  889. GetStoreOptionsRequestType req = null;
  890. StoreLogoArrayType returnedLogoArray = null;
  891. GetStoreOptionsResponseType resp = null;
  892. try {
  893. if (context.get("productStoreId") != null) {
  894. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  895. req = new GetStoreOptionsRequestType();
  896. resp = (GetStoreOptionsResponseType) call.execute(req);
  897. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  898. returnedLogoArray = resp.getLogoArray();
  899. int i = 0;
  900. List<Map<String,Object>> logoList = FastList.newInstance();
  901. while (i < returnedLogoArray.getLogoLength()) {
  902. Map<String,Object> logo = FastMap.newInstance();
  903. StoreLogoType storeLogoType = (StoreLogoType) returnedLogoArray.getLogo(i);
  904. logo.put("storeLogoId", storeLogoType.getLogoID());
  905. logo.put("storeLogoName", storeLogoType.getName());
  906. logo.put("storeLogoURL", storeLogoType.getURL());
  907. logoList.add(logo);
  908. i++;
  909. }
  910. result = ServiceUtil.returnSuccess("load store logo data success..");
  911. result.put("storeLogoOptList", logoList);
  912. } else {
  913. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrievePredesignedLogoOption", resp.getErrors(0).getLongMessage());
  914. }
  915. }
  916. } catch (ApiException e) {
  917. e.printStackTrace();
  918. } catch (SdkSoapException e) {
  919. e.printStackTrace();
  920. } catch (SdkException e) {
  921. e.printStackTrace();
  922. }
  923. return result;
  924. }
  925. public static Map<String,Object> retrieveBasicThemeArray(DispatchContext dctx, Map<String,Object> context) {
  926. Map<String,Object> result = FastMap.newInstance();
  927. GenericValue userLogin = (GenericValue) context.get("userLogin");
  928. Locale locale = (Locale) context.get("locale");
  929. Delegator delegator = dctx.getDelegator();
  930. GetStoreOptionsRequestType req = null;
  931. StoreThemeArrayType returnedBasicThemeArray = null;
  932. GetStoreOptionsResponseType resp = null;
  933. try {
  934. if (context.get("productStoreId") != null) {
  935. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  936. req = new GetStoreOptionsRequestType();
  937. resp = (GetStoreOptionsResponseType) call.execute(req);
  938. StoreColorSchemeType storeFontColorSchemeType = null;
  939. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  940. returnedBasicThemeArray = resp.getBasicThemeArray();
  941. int i = 0;
  942. List<Map<String,Object>> themeList = FastList.newInstance();
  943. while (i < returnedBasicThemeArray.getThemeLength()) {
  944. Map<String,Object> basictheme = FastMap.newInstance();
  945. StoreThemeType storeBasicThemeType = (StoreThemeType) returnedBasicThemeArray.getTheme(i);
  946. basictheme.put("storeThemeId", storeBasicThemeType.getThemeID());
  947. basictheme.put("storeThemeName", storeBasicThemeType.getName());
  948. StoreColorSchemeType storeColorSchemeType = storeBasicThemeType.getColorScheme();
  949. basictheme.put("storeColorSchemeId",storeColorSchemeType.getColorSchemeID());
  950. basictheme.put("storeColorSchemeName",storeColorSchemeType.getName());
  951. if (storeFontColorSchemeType == null) {
  952. storeFontColorSchemeType = storeBasicThemeType.getColorScheme();
  953. }
  954. themeList.add(basictheme);
  955. i++;
  956. }
  957. result = ServiceUtil.returnSuccess("load store Basic Theme option data success..");
  958. result.put("storeThemeList", themeList);
  959. } else {
  960. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveBasicThemeArray", resp.getErrors(0).getLongMessage());
  961. }
  962. }
  963. } catch (ApiException e) {
  964. e.printStackTrace();
  965. } catch (SdkSoapException e) {
  966. e.printStackTrace();
  967. } catch (SdkException e) {
  968. e.printStackTrace();
  969. }
  970. return result;
  971. }
  972. public static Map<String,Object> retrieveAdvancedThemeArray(DispatchContext dctx, Map<String,Object> context) {
  973. Map<String,Object> result = FastMap.newInstance();
  974. GenericValue userLogin = (GenericValue) context.get("userLogin");
  975. Locale locale = (Locale) context.get("locale");
  976. Delegator delegator = dctx.getDelegator();
  977. GetStoreOptionsRequestType req = null;
  978. StoreThemeArrayType returnedAdvancedThemeArray = null;
  979. GetStoreOptionsResponseType resp = null;
  980. try {
  981. if (context.get("productStoreId") != null) {
  982. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  983. req = new GetStoreOptionsRequestType();
  984. resp = (GetStoreOptionsResponseType) call.execute(req);
  985. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  986. result = ServiceUtil.returnSuccess("load store advanced Theme option data success..");
  987. returnedAdvancedThemeArray = resp.getAdvancedThemeArray();
  988. int i = 0;
  989. List<Map<String,Object>> themeList = FastList.newInstance();
  990. while (i < returnedAdvancedThemeArray.getThemeLength()) {
  991. Map<String,Object> advanceTheme = FastMap.newInstance();
  992. StoreThemeType storeThemeType = returnedAdvancedThemeArray.getTheme(i);
  993. advanceTheme.put("storeThemeId",storeThemeType.getThemeID());
  994. advanceTheme.put("storeThemeName",storeThemeType.getName());
  995. themeList.add(advanceTheme);
  996. i++;
  997. }
  998. result.put("storeThemeList", themeList);
  999. int j = 0;
  1000. StoreColorSchemeType[] storeColorSchemeTypes = returnedAdvancedThemeArray.getGenericColorSchemeArray().getColorScheme();
  1001. List<Map<String,Object>> themeColorList = FastList.newInstance();
  1002. while (j < storeColorSchemeTypes.length) {
  1003. Map<String,Object> advanceColorTheme = FastMap.newInstance();
  1004. StoreColorSchemeType storeColorSchemeType = (StoreColorSchemeType) storeColorSchemeTypes[j];
  1005. advanceColorTheme.put("storeColorSchemeId", storeColorSchemeType.getColorSchemeID());
  1006. advanceColorTheme.put("storeColorName", storeColorSchemeType.getName());
  1007. themeColorList.add(advanceColorTheme);
  1008. j++;
  1009. }
  1010. result.put("storeAdvancedThemeColorOptList", themeColorList);
  1011. } else {
  1012. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveAdvancedThemeArray", resp.getErrors(0).getLongMessage());
  1013. }
  1014. //this.returnedSubscriptionArray = resp.getSubscriptionArray();
  1015. }
  1016. } catch (ApiException e) {
  1017. e.printStackTrace();
  1018. } catch (SdkSoapException e) {
  1019. e.printStackTrace();
  1020. } catch (SdkException e) {
  1021. e.printStackTrace();
  1022. }
  1023. return result;
  1024. }
  1025. public static Map<String,Object> retrieveStoreFontTheme(DispatchContext dctx, Map<String,Object> context) {
  1026. Map<String,Object> result = FastMap.newInstance();
  1027. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1028. Locale locale = (Locale) context.get("locale");
  1029. Delegator delegator = dctx.getDelegator();
  1030. GetStoreOptionsRequestType req = null;
  1031. StoreThemeArrayType returnedThemeArray = null;
  1032. GetStoreOptionsResponseType resp = null;
  1033. try {
  1034. if (context.get("productStoreId") != null) {
  1035. GetStoreOptionsCall call = new GetStoreOptionsCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  1036. req = new GetStoreOptionsRequestType();
  1037. resp = (GetStoreOptionsResponseType) call.execute(req);
  1038. StoreColorSchemeType storeFontColorSchemeType = null;
  1039. Map<String,Object> advanceFontTheme = FastMap.newInstance();
  1040. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  1041. returnedThemeArray = resp.getAdvancedThemeArray();
  1042. int i = 0;
  1043. List<Map<String,Object>> themeList = FastList.newInstance();
  1044. StoreColorSchemeType[] storeColorSchemeTypes = returnedThemeArray.getGenericColorSchemeArray().getColorScheme();
  1045. while (i < storeColorSchemeTypes.length) {
  1046. StoreColorSchemeType storeColorSchemeType = (StoreColorSchemeType) storeColorSchemeTypes[i];
  1047. StoreFontType storeFontType = storeColorSchemeType.getFont();
  1048. advanceFontTheme.put("storeFontTypeNameFaceColor",storeFontType.getNameColor());
  1049. int j = 0;
  1050. StoreFontFaceCodeType[] storeFontNameFaceCodeTypes = storeFontType.getNameFace().values();
  1051. List<Map<String,Object>> nameFaces = FastList.newInstance();
  1052. while (j < storeFontNameFaceCodeTypes.length) {
  1053. Map<String,Object> storeFontNameFaceCodeTypeMap = FastMap.newInstance();
  1054. StoreFontFaceCodeType storeFontNameFaceCodeType = (StoreFontFaceCodeType) storeFontNameFaceCodeTypes[j];
  1055. storeFontNameFaceCodeTypeMap.put("storeFontValue", storeFontNameFaceCodeType.value());
  1056. storeFontNameFaceCodeTypeMap.put("storeFontName", storeFontNameFaceCodeType.name());
  1057. nameFaces.add(storeFontNameFaceCodeTypeMap);
  1058. j++;
  1059. }
  1060. advanceFontTheme.put("storeFontTypeFontFaceList",nameFaces);
  1061. j = 0;
  1062. StoreFontSizeCodeType[] storeFontSizeCodeTypes = storeFontType.getNameSize().values();
  1063. List<Map<String,Object>> sizeFaces = FastList.newInstance();
  1064. while (j < storeFontSizeCodeTypes.length) {
  1065. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1066. StoreFontSizeCodeType storeFontSizeCodeType = (StoreFontSizeCodeType) storeFontSizeCodeTypes[j];
  1067. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1068. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1069. sizeFaces.add(storeFontSizeCodeTypeMap);
  1070. j++;
  1071. }
  1072. advanceFontTheme.put("storeFontTypeSizeFaceList", sizeFaces);
  1073. advanceFontTheme.put("storeFontTypeTitleColor", storeFontType.getTitleColor());
  1074. j = 0;
  1075. StoreFontFaceCodeType[] storeFontTypeTitleFaces = storeFontType.getTitleFace().values();
  1076. List<Map<String,Object>> titleFaces = FastList.newInstance();
  1077. while (j < storeFontTypeTitleFaces.length) {
  1078. Map<String,Object> storeFontTypeTitleFaceMap = FastMap.newInstance();
  1079. StoreFontFaceCodeType storeFontTypeTitleFace = (StoreFontFaceCodeType) storeFontTypeTitleFaces[j];
  1080. storeFontTypeTitleFaceMap.put("storeFontValue", storeFontTypeTitleFace.value());
  1081. storeFontTypeTitleFaceMap.put("storeFontName", storeFontTypeTitleFace.name());
  1082. titleFaces.add(storeFontTypeTitleFaceMap);
  1083. j++;
  1084. }
  1085. advanceFontTheme.put("storeFontTypeFontTitleList",titleFaces);
  1086. j = 0;
  1087. StoreFontSizeCodeType[] storeTitleSizeCodeTypes = storeFontType.getTitleSize().values();
  1088. List<Map<String,Object>> titleSizes = FastList.newInstance();
  1089. while (j < storeTitleSizeCodeTypes.length) {
  1090. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1091. StoreFontSizeCodeType storeFontSizeCodeType = (StoreFontSizeCodeType) storeTitleSizeCodeTypes[j];
  1092. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1093. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1094. titleSizes.add(storeFontSizeCodeTypeMap);
  1095. j++;
  1096. }
  1097. advanceFontTheme.put("storeFontSizeTitleList",titleSizes);
  1098. advanceFontTheme.put("storeFontTypeDescColor", storeFontType.getDescColor());
  1099. j = 0;
  1100. StoreFontFaceCodeType[] storeFontTypeDescFaces = storeFontType.getDescFace().values();
  1101. List<Map<String,Object>> descFaces = FastList.newInstance();
  1102. while (j < storeFontTypeDescFaces.length) {
  1103. Map<String,Object> storeFontTypeDescFaceMap = FastMap.newInstance();
  1104. StoreFontFaceCodeType storeFontTypeDescFace = (StoreFontFaceCodeType) storeFontTypeDescFaces[j];
  1105. storeFontTypeDescFaceMap.put("storeFontValue", storeFontTypeDescFace.value());
  1106. storeFontTypeDescFaceMap.put("storeFontName", storeFontTypeDescFace.name());
  1107. descFaces.add(storeFontTypeDescFaceMap);
  1108. j++;
  1109. }
  1110. advanceFontTheme.put("storeFontTypeFontDescList",descFaces);
  1111. j = 0;
  1112. StoreFontSizeCodeType[] storeDescSizeCodeTypes = storeFontType.getDescSize().values();
  1113. List<Map<String,Object>> descSizes = FastList.newInstance();
  1114. while (j < storeDescSizeCodeTypes.length) {
  1115. Map<String,Object> storeFontSizeCodeTypeMap = FastMap.newInstance();
  1116. StoreFontSizeCodeType storeFontSizeCodeType = (StoreFontSizeCodeType) storeDescSizeCodeTypes[j];
  1117. storeFontSizeCodeTypeMap.put("storeFontSizeValue", storeFontSizeCodeType.value());
  1118. storeFontSizeCodeTypeMap.put("storeFontSizeName", storeFontSizeCodeType.name());
  1119. descSizes.add(storeFontSizeCodeTypeMap);
  1120. j++;
  1121. }
  1122. advanceFontTheme.put("storeDescSizeList",descSizes);
  1123. i++;
  1124. }
  1125. result = ServiceUtil.returnSuccess("load store Basic Theme option data success..");
  1126. result.put("advanceFontTheme", advanceFontTheme);
  1127. } else {
  1128. EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get store option : retrieveStoreFontTheme", resp.getErrors(0).getLongMessage());
  1129. }
  1130. }
  1131. } catch (ApiException e) {
  1132. e.printStackTrace();
  1133. } catch (SdkSoapException e) {
  1134. e.printStackTrace();
  1135. } catch (SdkException e) {
  1136. e.printStackTrace();
  1137. }
  1138. return result;
  1139. }
  1140. public static Map<String,Object> setEbayStoreInput(DispatchContext dctx, Map<String,Object> context) {
  1141. Map<String,Object> result = FastMap.newInstance();
  1142. Locale locale = (Locale) context.get("locale");
  1143. Delegator delegator = dctx.getDelegator();
  1144. SetStoreRequestType req = null;
  1145. StoreThemeArrayType returnedThemeArray = null;
  1146. SetStoreResponseType resp = null;
  1147. StoreType storeType = null;
  1148. try {
  1149. if (context.get("productStoreId") != null) {
  1150. SetStoreCall call = new SetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
  1151. req = new SetStoreRequestType();
  1152. storeType = new StoreType();
  1153. storeType.setName((String)context.get("storeName"));
  1154. storeType.setDescription((String)context.get("storeDesc"));
  1155. storeType.setURL((String)context.get("storeUrl"));
  1156. storeType.setURLPath("");
  1157. StoreLogoType storeLogo = new StoreLogoType();
  1158. if (context.get("storeLogoURL") == null) {
  1159. if (context.get("storeLogoId") != null) storeLogo.setLogoID(Integer.parseInt((String)context.get("storeLogoId")));
  1160. storeLogo.setName((String)context.get("storeLogoName"));
  1161. } else {
  1162. storeLogo.setURL((String)context.get("storeLogoURL"));
  1163. }
  1164. storeType.setLogo(storeLogo);
  1165. StoreThemeType storeTheme = new StoreThemeType();
  1166. StoreColorSchemeType storeColorScheme = null;
  1167. StoreColorType storecolor = null;
  1168. StoreFontType storeFont = null;
  1169. if (context.get("themeType").equals("Advanced")) {
  1170. storeColorScheme = new StoreColorSchemeType();
  1171. if (context.get("storeAdvancedThemeColor") != null) storeColorScheme.setColorSchemeID(Integer.parseInt((String)context.get("storeAdvancedThemeColor")));
  1172. storecolor = new StoreColorType();
  1173. storecolor.setPrimary((String)context.get("storePrimaryColor"));
  1174. storecolor.setSecondary((String)context.get("storeSecondaryColor"));
  1175. storecolor.setAccent((String)context.get("storeAccentColor"));
  1176. storeColorScheme.setColor(storecolor);
  1177. storeTheme.setColorScheme(storeColorScheme);
  1178. storeTheme.setName(null);
  1179. storeTheme.setThemeID(Integer.parseInt((String)context.get("storeAdvancedTheme")));
  1180. } else if (context.get("themeType").equals("Basic")) {
  1181. storeColorScheme = new StoreColorSchemeType();
  1182. if (context.get("storeBasicTheme")!=null) {
  1183. String storeBasicTheme = (String)context.get("storeBasicTheme");
  1184. String storeThemeId = null;
  1185. String storeColorSchemeId = null;
  1186. if (storeBasicTheme.indexOf("-") != -1) {
  1187. storeThemeId = storeBasicTheme.substring(0, storeBasicTheme.indexOf("-"));
  1188. storeColorSchemeId = storeBasicTheme.substring(storeBasicTheme.indexOf("-")+1);
  1189. }
  1190. if (storeColorSchemeId != null) storeColorScheme.setColorSchemeID(Integer.parseInt(storeColorSchemeId));
  1191. storecolor = new StoreColorType();
  1192. storecolor.setPrimary((String)context.get("storePrimaryColor"));
  1193. storecolor.setSecondary((String)context.get("storeSecondaryColor"));
  1194. storecolor.setAccent((String)context.get("storeAccentColor"));
  1195. storeColorScheme.setColor(storecolor);
  1196. storeFont = new StoreFontType();
  1197. storeFont.setNameColor((String)context.get("storeNameFontColor"));
  1198. storeFont.setNameFace(StoreFontFaceCodeType.valueOf((String)context.get("storeNameFont")));
  1199. storeFont.setNameSize(StoreFontSizeCodeType.valueOf((String)context.get("storeNameFontSize")));
  1200. storeFont.setTitleColor((String)context.get("storeTitleFontColor"));
  1201. storeFont.setTitleFace(StoreFontFaceCodeType.valueOf((String)context.get("storeTitleFont")));
  1202. storeFont.setTitleSize(StoreFontSizeCodeType.valueOf((String)context.get("storeTitleFontSize")));
  1203. storeFont.setDescColor((String)context.get("storeDescFontColor"));
  1204. storeFont.setDescFace(StoreFontFaceCodeType.valueOf((String)context.get("storeDescFont")));
  1205. storeFont.setDescSize(StoreFontSizeCodeType.valueOf((String)context.get("storeDescFontSize")));
  1206. storeColorScheme.setFont(storeFont);
  1207. storeTheme.setColorScheme(storeColorScheme);
  1208. storeTheme.setName(null);
  1209. storeTheme.setThemeID(Integer.parseInt(storeThemeId));
  1210. }
  1211. }
  1212. storeType.setTheme(storeTheme);
  1213. storeType.setHeaderStyle(StoreHeaderStyleCodeType.valueOf((String)context.get("storeHeaderStyle")));
  1214. storeType.setItemListLayout(StoreItemListLayoutCodeType.valueOf((String)context.get("storeItemLayout")));
  1215. storeType.setItemListSortOrder(StoreItemListSortOrderCodeType.valueOf((String)context.get("storeItemSortOrder")));
  1216. storeType.setMerchDisplay(MerchDisplayCodeType.valueOf((String)context.get("storeMerchDisplay")));
  1217. storeType.setSubscriptionLevel(StoreSubscriptionLevelCodeType.valueOf((String)context.get("storeSubscriptionDisplay")));
  1218. storeType.setCustomHeader((String)context.get("storeCustomHeader"));
  1219. storeType.setCustomHeaderLayout(StoreCustomHeaderLayoutCodeType.valueOf((String)context.get("storeCustomHeaderLayout")));
  1220. StoreCustomListingHeaderType storeCustomListingHeader = new StoreCustomListingHeaderType();
  1221. if ( storeType == null )
  1222. throw new SdkException("StoreType property is not set.");
  1223. req.setStore(storeType);
  1224. resp = (SetStoreResponseType) call.execute(req);
  1225. if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
  1226. result = ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "EbayStoreSaveSuccess",locale));
  1227. } else {
  1228. result = ServiceUtil.returnError(resp.getMessage());
  1229. }
  1230. LocalDispatcher dispatcher = dctx.getDispatcher();
  1231. Map<String,Object> results = dispatcher.runSync("getEbayStoreOutput",UtilMisc.toMap("productStoreId",(String) context.get("productStoreId"),"userLogin",context.get("userLogin")));
  1232. if (results != null) {
  1233. result.put("ebayStore", results.get("ebayStore"));
  1234. }
  1235. }
  1236. } catch (ApiException e) {
  1237. result = ServiceUtil.returnError(e.getMessage());
  1238. } catch (SdkSoapException e) {
  1239. result = ServiceUtil.returnError(e.getMessage());
  1240. } catch (SdkException e) {
  1241. result = ServiceUtil.returnError(e.getMessage());
  1242. } catch (GenericServiceException e) {
  1243. result = ServiceUtil.returnError(e.getMessage());
  1244. }
  1245. return result;
  1246. }
  1247. public static Map<String, Object> getEbayActiveItems(DispatchContext dctx, Map<String, ? extends Object> context) {
  1248. Map<String, Object> result = FastMap.newInstance();
  1249. LocalDispatcher dispatcher = dctx.getDispatcher();
  1250. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1251. Delegator delegator = dctx.getDelegator();
  1252. Locale locale = (Locale) context.get("locale");
  1253. String productStoreId = (String) context.get("productStoreId");
  1254. List activeItems = FastList.newInstance();
  1255. try {
  1256. Map<String, Object> inMap = FastMap.newInstance();
  1257. inMap.put("productStoreId", productStoreId);
  1258. inMap.put("userLogin", userLogin);
  1259. Map<String, Object> resultUser = dispatcher.runSync("getEbayStoreUser", inMap);
  1260. String userID = (String) resultUser.get("userLoginId");
  1261. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1262. GetMyeBaySellingCall getMyeBaySellingCall = new GetMyeBaySellingCall(apiContext);
  1263. ItemListCustomizationType activeList = new ItemListCustomizationType();
  1264. getMyeBaySellingCall.setActiveList(activeList );
  1265. DetailLevelCodeType[] level = {DetailLevelCodeType.RETURN_ALL};
  1266. getMyeBaySellingCall.setDetailLevel(level);
  1267. getMyeBaySellingCall.getMyeBaySelling();
  1268. PaginatedItemArrayType itemListCustomizationType = getMyeBaySellingCall.getReturnedActiveList();
  1269. if (itemListCustomizationType != null) {
  1270. ItemArrayType itemArrayType = itemListCustomizationType.getItemArray();
  1271. int itemArrayTypeSize = itemArrayType.getItemLength();
  1272. for (int i = 0; i < itemArrayTypeSize; i++) {
  1273. Map<String, Object> entry = FastMap.newInstance();
  1274. ItemType item = itemArrayType.getItem(i);
  1275. entry.put("itemId", item.getItemID());
  1276. entry.put("title", item.getTitle());
  1277. if (item.getPictureDetails() != null) {
  1278. String url[] = item.getPictureDetails().getPictureURL();
  1279. if (url.length != 0) {
  1280. entry.put("pictureURL", url[0]);
  1281. } else {
  1282. entry.put("pictureURL", null);
  1283. }
  1284. } else {
  1285. entry.put("pictureURL", null);
  1286. }
  1287. entry.put("timeLeft",item.getTimeLeft());
  1288. if (item.getBuyItNowPrice() != null) {
  1289. entry.put("buyItNowPrice", item.getBuyItNowPrice().getValue());
  1290. } else {
  1291. entry.put("buyItNowPrice", null);
  1292. }
  1293. if (item.getStartPrice() != null) {
  1294. entry.put("startPrice", item.getStartPrice().getValue());
  1295. } else {
  1296. entry.put("startPrice", null);
  1297. }
  1298. if (item.getListingDetails() != null) {
  1299. entry.put("relistedItemId", item.getListingDetails().getRelistedItemID());
  1300. } else {
  1301. entry.put("relistedItemId", null);
  1302. }
  1303. if (item.getListingType() != null) {
  1304. entry.put("listingType", item.getListingType().value());
  1305. } else {
  1306. entry.put("listingType", null);
  1307. }
  1308. activeItems.add(entry);
  1309. }
  1310. }
  1311. result.put("activeItems", activeItems);
  1312. } catch (Exception e) {
  1313. // TODO Auto-generated catch block
  1314. return ServiceUtil.returnError(e.getMessage());
  1315. }
  1316. return result;
  1317. }
  1318. public static Map<String, Object> getEbaySoldItems(DispatchContext dctx, Map<String, ? extends Object> context) {
  1319. Map<String, Object> result = FastMap.newInstance();
  1320. LocalDispatcher dispatcher = dctx.getDispatcher();
  1321. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1322. Delegator delegator = dctx.getDelegator();
  1323. Locale locale = (Locale) context.get("locale");
  1324. String productStoreId = (String) context.get("productStoreId");
  1325. String filter = (String) context.get("filter");
  1326. String itemId = (String) context.get("itemId");
  1327. String buyerId = (String) context.get("buyerId");
  1328. String listingType = (String) context.get("listingType");
  1329. List soldItems = FastList.newInstance();
  1330. try {
  1331. Map<String, Object> inMap = FastMap.newInstance();
  1332. inMap.put("productStoreId", productStoreId);
  1333. inMap.put("userLogin", userLogin);
  1334. Map<String, Object> resultUser = dispatcher.runSync("getEbayStoreUser", inMap);
  1335. String userID = (String) resultUser.get("userLoginId");
  1336. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1337. GetSellingManagerSoldListingsCall sellingManagerSoldListings = new GetSellingManagerSoldListingsCall(apiContext);
  1338. if (UtilValidate.isNotEmpty(filter)) {
  1339. SellingManagerSoldListingsPropertyTypeCodeType[] filterObject = {SellingManagerSoldListingsPropertyTypeCodeType.valueOf(filter)};
  1340. sellingManagerSoldListings.setFilter(filterObject );
  1341. }
  1342. if (UtilValidate.isNotEmpty(itemId)) {
  1343. SellingManagerSearchType search = new SellingManagerSearchType();
  1344. search.setSearchType(SellingManagerSearchTypeCodeType.ITEM_ID);
  1345. search.setSearchValue(itemId);
  1346. sellingManagerSoldListings.setSearch(search);
  1347. }
  1348. if (UtilValidate.isNotEmpty(buyerId)) {
  1349. SellingManagerSearchType search = new SellingManagerSearchType();
  1350. search.setSearchType(SellingManagerSearchTypeCodeType.BUYER_USER_ID);
  1351. search.setSearchValue(buyerId);
  1352. sellingManagerSoldListings.setSearch(search);
  1353. }
  1354. sellingManagerSoldListings.getSellingManagerSoldListings();
  1355. SellingManagerSoldOrderType[] sellingManagerSoldOrders = sellingManagerSoldListings.getReturnedSaleRecord();
  1356. if (UtilValidate.isNotEmpty(sellingManagerSoldOrders)) {
  1357. int soldOrderLength = sellingManagerSoldOrders.length;
  1358. for (int i = 0; i < soldOrderLength; i++) {
  1359. SellingManagerSoldOrderType sellingManagerSoldOrder = sellingManagerSoldOrders[i];
  1360. if (sellingManagerSoldOrder != null) {
  1361. SellingManagerSoldTransactionType[] sellingManagerSoldTransactions = sellingManagerSoldOrder.getSellingManagerSoldTransaction();
  1362. int sellingManagerSoldTransactionLength = sellingManagerSoldTransactions.length;
  1363. for (int j = 0; j < sellingManagerSoldTransactionLength; j++) {
  1364. Map<String, Object> entry = FastMap.newInstance();
  1365. SellingManagerSoldTransactionType sellingManagerSoldTransaction = sellingManagerSoldTransactions[j];
  1366. entry.put("itemId", sellingManagerSoldTransaction.getItemID());
  1367. entry.put("title", sellingManagerSoldTransaction.getItemTitle());
  1368. entry.put("transactionId", sellingManagerSoldTransaction.getTransactionID().toString());
  1369. entry.put("quantity", sellingManagerSoldTransaction.getQuantitySold());
  1370. entry.put("listingType", sellingManagerSoldTransaction.getListingType().value());
  1371. String buyer = null;
  1372. if (sellingManagerSoldOrder.getBuyerID() != null) {
  1373. buyer = sellingManagerSoldOrder.getBuyerID();
  1374. }
  1375. entry.put("buyer", buyer);
  1376. String buyerEmail = null;
  1377. if (sellingManagerSoldOrder.getBuyerID() != null) {
  1378. buyerEmail = sellingManagerSoldOrder.getBuyerEmail();
  1379. }
  1380. entry.put("buyerEmail", buyerEmail);
  1381. GetItemCall api = new GetItemCall(apiContext);
  1382. api.setItemID(sellingManagerSoldTransaction.getItemID());
  1383. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1384. DetailLevelCodeType.RETURN_ALL,
  1385. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1386. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1387. };
  1388. api.setDetailLevel(detailLevels);
  1389. ItemType itemType = api.getItem();
  1390. String itemUrl = null;
  1391. if (itemType.getListingDetails() != null) {
  1392. itemUrl = itemType.getListingDetails().getViewItemURL();
  1393. }
  1394. entry.put("itemUrl", itemUrl);
  1395. String itemUrlNatural = null;
  1396. if (itemType.getListingDetails() != null) {
  1397. itemUrlNatural = itemType.getListingDetails().getViewItemURLForNaturalSearch();
  1398. }
  1399. entry.put("itemUrlNatural", itemUrlNatural);
  1400. String unpaidItemStatus = null;
  1401. if (sellingManagerSoldOrder.getUnpaidItemStatus() != null) {
  1402. unpaidItemStatus = sellingManagerSoldOrder.getUnpaidItemStatus().value();
  1403. }
  1404. entry.put("unpaidItemStatus", unpaidItemStatus);
  1405. Date creationTime = null;
  1406. if (sellingManagerSoldOrder.getCreationTime() != null) {
  1407. creationTime = sellingManagerSoldOrder.getCreationTime().getTime();
  1408. }
  1409. entry.put("creationTime", creationTime);
  1410. double totalAmount = 0;
  1411. if (sellingManagerSoldOrder.getTotalAmount() != null) {
  1412. totalAmount = sellingManagerSoldOrder.getTotalAmount().getValue();
  1413. }
  1414. entry.put("totalAmount", totalAmount);
  1415. if (sellingManagerSoldOrder.getSalePrice() != null) {
  1416. entry.put("salePrice", sellingManagerSoldOrder.getSalePrice().getValue());
  1417. }
  1418. Date paidTime = null;
  1419. String checkoutStatus = null;
  1420. String shippedStatus = null;
  1421. Date shippedTime = null;
  1422. if (sellingManagerSoldOrder.getOrderStatus() != null) {
  1423. if (sellingManagerSoldOrder.getOrderStatus().getPaidTime() != null) {
  1424. paidTime = sellingManagerSoldOrder.getOrderStatus().getPaidTime().getTime();
  1425. }
  1426. if (sellingManagerSoldOrder.getOrderStatus().getCheckoutStatus() != null) {
  1427. checkoutStatus = sellingManagerSoldOrder.getOrderStatus().getCheckoutStatus().value();
  1428. }
  1429. if (sellingManagerSoldOrder.getOrderStatus().getShippedStatus() != null) {
  1430. shippedStatus = sellingManagerSoldOrder.getOrderStatus().getShippedStatus().value();
  1431. }
  1432. if (sellingManagerSoldOrder.getOrderStatus().getShippedTime() != null) {
  1433. shippedTime = sellingManagerSoldOrder.getOrderStatus().getShippedTime().getTime();
  1434. }
  1435. }
  1436. entry.put("paidTime", paidTime);
  1437. entry.put("checkoutStatus", checkoutStatus);
  1438. entry.put("shippedStatus", shippedStatus);
  1439. entry.put("shippedTime", shippedTime);
  1440. soldItems.add(entry);
  1441. }
  1442. }
  1443. }
  1444. }
  1445. result.put("soldItems", soldItems);
  1446. } catch (Exception e) {
  1447. return ServiceUtil.returnError(e.getMessage());
  1448. }
  1449. return result;
  1450. }
  1451. public static Map<String, Object> exportProductsFromEbayStore(DispatchContext dctx, Map context) {
  1452. Map<String,Object> result = FastMap.newInstance();
  1453. Locale locale = (Locale) context.get("locale");
  1454. Delegator delegator = dctx.getDelegator();
  1455. LocalDispatcher dispatcher = dctx.getDispatcher();
  1456. Map<String, Object> eBayConfigResult = EbayHelper.buildEbayConfig(context, delegator);
  1457. Map response = null;
  1458. try {
  1459. GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", context.get("productId").toString()));
  1460. int intAtp = 1;
  1461. String facilityId = "";
  1462. if (UtilValidate.isNotEmpty(context.get("requireEbayInventory")) && "on".equals(context.get("requireEbayInventory").toString())) {
  1463. GenericValue ebayProductStore = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("EbayProductStoreInventory", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(), "productId", context.get("productId")))));
  1464. if (UtilValidate.isNotEmpty(ebayProductStore)) {
  1465. facilityId = ebayProductStore.getString("facilityId");
  1466. BigDecimal atp = ebayProductStore.getBigDecimal("availableToPromiseListing");
  1467. intAtp = atp.intValue();
  1468. if (intAtp == 0) {
  1469. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1470. result.put(ModelService.ERROR_MESSAGE, "ATP is not enough, can not create listing.");
  1471. }
  1472. }
  1473. }
  1474. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1475. if (UtilValidate.isNotEmpty(context.get("productCategoryId"))) {
  1476. GenericValue prodCategoryMember = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productCategoryId", context.get("productCategoryId"),"productId", context.get("productId")))));
  1477. if (UtilValidate.isNotEmpty(prodCategoryMember)) {
  1478. GenericValue prodCategoryRole = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId", prodCategoryMember.get("productCategoryId").toString(), "partyId", userLogin.get("partyId"),"roleTypeId", "EBAY_ACCOUNT"))));
  1479. if (UtilValidate.isNotEmpty(prodCategoryRole)) {
  1480. context.put("ebayCategory", prodCategoryRole.get("comments"));
  1481. } else {
  1482. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1483. result.put(ModelService.ERROR_MESSAGE, "Category not found for this product on ebay.");
  1484. }
  1485. }
  1486. } else {
  1487. List<GenericValue> prodCategoryMember = EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryMember", UtilMisc.toMap("productId", context.get("productId"))));
  1488. Iterator prodCategoryMemberIter = prodCategoryMember.iterator();
  1489. while (prodCategoryMemberIter.hasNext()) {
  1490. GenericValue prodCategory = (GenericValue) prodCategoryMemberIter.next();
  1491. GenericValue prodCatalogCategory = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId"), "productCategoryId", prodCategory.get("productCategoryId").toString()))));
  1492. if (UtilValidate.isNotEmpty(prodCatalogCategory)) {
  1493. GenericValue prodCategoryRole = EntityUtil.getFirst(EntityUtil.filterByDate(delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId", prodCatalogCategory.get("productCategoryId").toString(), "partyId", userLogin.get("partyId"),"roleTypeId", "EBAY_ACCOUNT"))));
  1494. if (UtilValidate.isNotEmpty(prodCategoryRole)) {
  1495. context.put("ebayCategory", prodCategoryRole.get("comments"));
  1496. } else {
  1497. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1498. result.put(ModelService.ERROR_MESSAGE, "Category not found for this product on ebay.");
  1499. }
  1500. }
  1501. }
  1502. }
  1503. if (intAtp != 0) {
  1504. if (UtilValidate.isNotEmpty(context.get("listingTypeAuc")) && "on".equals(context.get("listingTypeAuc").toString())) {
  1505. context.put("listingFormat", "Chinese");
  1506. context.put("listingDuration", context.get("listingDurationAuc").toString());
  1507. StringBuffer dataItemsXml = new StringBuffer();
  1508. Map resultMap = ProductsExportToEbay.buildDataItemsXml(dctx, context, dataItemsXml, eBayConfigResult.get("token").toString(), product);
  1509. if (!ServiceUtil.isFailure(resultMap)) {
  1510. response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "AddItem", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
  1511. if (ServiceUtil.isFailure(response)) {
  1512. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response));
  1513. }
  1514. if (UtilValidate.isNotEmpty(response)) {
  1515. ProductsExportToEbay.exportToEbayResponse((String) response.get("successMessage"), product);
  1516. }
  1517. } else {
  1518. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap));
  1519. }
  1520. }
  1521. if (UtilValidate.isNotEmpty(context.get("listingTypeFixed")) && "on".equals(context.get("listingTypeFixed").toString())) {
  1522. context.put("listingFormat", "FixedPriceItem");
  1523. context.put("listingDuration", context.get("listingDurationFixed").toString());
  1524. StringBuffer dataItemsXml = new StringBuffer();
  1525. Map resultMap = ProductsExportToEbay.buildDataItemsXml(dctx, context, dataItemsXml, eBayConfigResult.get("token").toString(), product);
  1526. if (!ServiceUtil.isFailure(resultMap)) {
  1527. response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataItemsXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "AddItem", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString());
  1528. if (ServiceUtil.isFailure(response)) {
  1529. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response));
  1530. }
  1531. if (UtilValidate.isNotEmpty(response)) {
  1532. ProductsExportToEbay.exportToEbayResponse((String) response.get("successMessage"), product);
  1533. }
  1534. } else {
  1535. return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap));
  1536. }
  1537. }
  1538. }
  1539. if (UtilValidate.isNotEmpty(productExportEbay.getProductExportSuccessMessageList())) {
  1540. if ((facilityId != "") && (intAtp != 0)) {
  1541. int newAtp = intAtp - 1;
  1542. Map<String,Object> inMap = FastMap.newInstance();
  1543. inMap.put("productStoreId", context.get("productStoreId").toString());
  1544. inMap.put("facilityId", facilityId);
  1545. inMap.put("productId", context.get("productId"));
  1546. inMap.put("availableToPromiseListing", new BigDecimal(newAtp));
  1547. inMap.put("userLogin", context.get("userLogin"));
  1548. dispatcher.runSync("updateEbayProductStoreInventory", inMap);
  1549. }
  1550. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
  1551. result.put(ModelService.SUCCESS_MESSAGE, "Export products listing success..");
  1552. }
  1553. if (UtilValidate.isNotEmpty(productExportEbay.getproductExportFailureMessageList())) {
  1554. result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL);
  1555. result.put(ModelService.ERROR_MESSAGE_LIST, productExportEbay.getproductExportFailureMessageList());
  1556. }
  1557. }catch (Exception e) {
  1558. return ServiceUtil.returnError(e.getMessage());
  1559. }
  1560. return result;
  1561. }
  1562. public static DisputeExplanationCodeType getEbayDisputeExplanationCodeType(String disputeExplanationCode) {
  1563. DisputeExplanationCodeType disputeExplanationCodeType = null;
  1564. if (disputeExplanationCode != null) {
  1565. if (disputeExplanationCode.equals("BUYER_HAS_NOT_RESPONDED")) {
  1566. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_HAS_NOT_RESPONDED;
  1567. } else if (disputeExplanationCode.equals("BUYER_REFUSED_TO_PAY")) {
  1568. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_REFUSED_TO_PAY;
  1569. } else if (disputeExplanationCode.equals("BUYER_RETURNED_ITEM_FOR_REFUND")) {
  1570. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_RETURNED_ITEM_FOR_REFUND;
  1571. } else if (disputeExplanationCode.equals("UNABLE_TO_RESOLVE_TERMS")) {
  1572. disputeExplanationCodeType = DisputeExplanationCodeType.UNABLE_TO_RESOLVE_TERMS;
  1573. } else if (disputeExplanationCode.equals("BUYER_PURCHASING_MISTAKE")) {
  1574. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_PURCHASING_MISTAKE;
  1575. } else if (disputeExplanationCode.equals("SHIP_COUNTRY_NOT_SUPPORTED")) {
  1576. disputeExplanationCodeType = DisputeExplanationCodeType.SHIP_COUNTRY_NOT_SUPPORTED;
  1577. } else if (disputeExplanationCode.equals("SHIPPING_ADDRESS_NOT_CONFIRMED")) {
  1578. disputeExplanationCodeType = DisputeExplanationCodeType.SHIPPING_ADDRESS_NOT_CONFIRMED;
  1579. } else if (disputeExplanationCode.equals("PAYMENT_METHOD_NOT_SUPPORTED")) {
  1580. disputeExplanationCodeType = DisputeExplanationCodeType.PAYMENT_METHOD_NOT_SUPPORTED;
  1581. } else if (disputeExplanationCode.equals("BUYER_NO_LONGER_REGISTERED")) {
  1582. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_NO_LONGER_REGISTERED;
  1583. } else if (disputeExplanationCode.equals("BUYER_NO_LONGER_REGISTERED")) {
  1584. disputeExplanationCodeType = DisputeExplanationCodeType.BUYER_NO_LONGER_REGISTERED;
  1585. } else {
  1586. disputeExplanationCodeType = DisputeExplanationCodeType.OTHER_EXPLANATION;
  1587. }
  1588. } else {
  1589. disputeExplanationCodeType = DisputeExplanationCodeType.OTHER_EXPLANATION;
  1590. }
  1591. return disputeExplanationCodeType;
  1592. }
  1593. public static DisputeReasonCodeType getEbayDisputeReasonCodeType(String disputeReasonCode) {
  1594. DisputeReasonCodeType disputeReasonCodeType = null;
  1595. if (disputeReasonCode != null) {
  1596. if (disputeReasonCode.equals("TRANSACTION_MUTUALLY_CANCELED")) {
  1597. disputeReasonCodeType = DisputeReasonCodeType.TRANSACTION_MUTUALLY_CANCELED;
  1598. } else if (disputeReasonCode.equals("BUYER_HAS_NOT_PAID")) {
  1599. disputeReasonCodeType = DisputeReasonCodeType.BUYER_HAS_NOT_PAID;
  1600. }
  1601. }
  1602. return disputeReasonCodeType;
  1603. }
  1604. public static Map<String, Object> addEbayDispute(DispatchContext dctx, Map<String, ? extends Object> context) {
  1605. Map<String, Object> result = FastMap.newInstance();
  1606. LocalDispatcher dispatcher = dctx.getDispatcher();
  1607. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1608. Delegator delegator = dctx.getDelegator();
  1609. Locale locale = (Locale) context.get("locale");
  1610. String productStoreId = (String) context.get("productStoreId");
  1611. List soldItems = FastList.newInstance();
  1612. try {
  1613. String itemId = (String) context.get("itemId");
  1614. String transactionId = (String) context.get("transactionId");
  1615. DisputeReasonCodeType drct = EbayStore.getEbayDisputeReasonCodeType((String)context.get("disputeReasonCodeType"));
  1616. DisputeExplanationCodeType dect = EbayStore.getEbayDisputeExplanationCodeType((String) context.get("disputeExplanationCodeType"));
  1617. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1618. DetailLevelCodeType.RETURN_ALL,
  1619. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1620. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1621. };
  1622. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1623. AddDisputeCall api = new AddDisputeCall(apiContext);
  1624. api.setDetailLevel(detailLevels);
  1625. api.setItemID(itemId);
  1626. api.setTransactionID(transactionId);
  1627. api.setDisputeExplanation(dect);
  1628. api.setDisputeReason(drct);
  1629. String disputeId = api.addDispute();
  1630. result.put("disputeId", disputeId);
  1631. } catch (Exception e) {
  1632. return ServiceUtil.returnError(e.getMessage());
  1633. }
  1634. return result;
  1635. }
  1636. public static Map<String, Object> verifyEbayAddSecondChanceItem(DispatchContext dctx, Map<String, ? extends Object> context) {
  1637. Map<String, Object> result = FastMap.newInstance();
  1638. boolean checkVerify = false;
  1639. LocalDispatcher dispatcher = dctx.getDispatcher();
  1640. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1641. Delegator delegator = dctx.getDelegator();
  1642. Locale locale = (Locale) context.get("locale");
  1643. String productStoreId = (String) context.get("productStoreId");
  1644. String itemID = (String) context.get("itemId");
  1645. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1646. try {
  1647. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1648. DetailLevelCodeType.RETURN_ALL,
  1649. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1650. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1651. };
  1652. VerifyAddSecondChanceItemCall verify = new VerifyAddSecondChanceItemCall(apiContext);
  1653. verify.setItemID(itemID);
  1654. verify.setDetailLevel(detailLevels);
  1655. verify.setDuration(SecondChanceOfferDurationCodeType.DAYS_1);
  1656. Map<String, Object> serviceMap = FastMap.newInstance();
  1657. serviceMap.put("itemId", itemID);
  1658. serviceMap.put("productStoreId", productStoreId);
  1659. serviceMap.put("locale", locale);
  1660. serviceMap.put("userLogin", userLogin);
  1661. Map<String, Object> bidderTest = (Map) getEbayAllBidders(dctx, serviceMap);
  1662. List<Map> test = (List) bidderTest.get("allBidders");
  1663. if (test.size() != 0) {
  1664. verify.setRecipientBidderUserID((String) test.get(0).get("userId"));
  1665. }
  1666. VerifyAddSecondChanceItemResponseType verifyResult = verify.verifyAddSecondChanceItem();
  1667. result.put("checkVerify", true);
  1668. } catch (Exception e) {
  1669. result.put("checkVerify", checkVerify);
  1670. result.put("errorMessage", "This item ( " + itemID + " ) can not add second chance offer.");
  1671. result.put("responseMessage", "error");
  1672. return result;
  1673. }
  1674. return result;
  1675. }
  1676. public static Map<String, Object> getEbayAllBidders(DispatchContext dctx, Map<String, ? extends Object> context) {
  1677. Map<String, Object> result = FastMap.newInstance();
  1678. List<Map> allBidders = FastList.newInstance();
  1679. LocalDispatcher dispatcher = dctx.getDispatcher();
  1680. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1681. Delegator delegator = dctx.getDelegator();
  1682. Locale locale = (Locale) context.get("locale");
  1683. String productStoreId = (String) context.get("productStoreId");
  1684. String itemID = (String) context.get("itemId");
  1685. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1686. try {
  1687. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1688. DetailLevelCodeType.RETURN_ALL,
  1689. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1690. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1691. };
  1692. GetAllBiddersCall api = new GetAllBiddersCall(apiContext);
  1693. api.setDetailLevel(detailLevels);
  1694. api.setItemID(itemID);
  1695. api.setCallMode(GetAllBiddersModeCodeType.VIEW_ALL);
  1696. OfferType[] bidders = api.getAllBidders();
  1697. for (int count = 0; count < bidders.length; count++) {
  1698. Map<String, Object> entry = FastMap.newInstance();
  1699. OfferType offer = bidders[count];
  1700. entry.put("userId", offer.getUser().getUserID());
  1701. entry.put("bidder", offer.getUser());
  1702. allBidders.add(entry);
  1703. }
  1704. result.put("allBidders", allBidders);
  1705. } catch (Exception e) {
  1706. Debug.logError(e.getMessage(), module);
  1707. result.put("allBidders", allBidders);
  1708. return result;
  1709. }
  1710. return result;
  1711. }
  1712. public static Map<String, Object> addEbaySecondChanceOffer(DispatchContext dctx, Map<String, ? extends Object> context) {
  1713. Map<String, Object> result = FastMap.newInstance();
  1714. LocalDispatcher dispatcher = dctx.getDispatcher();
  1715. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1716. Delegator delegator = dctx.getDelegator();
  1717. Locale locale = (Locale) context.get("locale");
  1718. String productStoreId = (String) context.get("productStoreId");
  1719. String durationString = (String) context.get("duration");
  1720. String itemID = (String) context.get("itemId");
  1721. String sellerMessage = (String) context.get("sellerMessage");
  1722. String recipientBidderUserID = (String) context.get("recipientBidderUserId");
  1723. try {
  1724. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1725. AddSecondChanceItemCall api = new AddSecondChanceItemCall(apiContext);
  1726. SecondChanceOfferDurationCodeType duration = SecondChanceOfferDurationCodeType.valueOf(durationString);
  1727. api.setDuration(duration);
  1728. AmountType buyItNowPrice = new AmountType();
  1729. if (UtilValidate.isNotEmpty((String) context.get("buyItNowPrice"))) {
  1730. buyItNowPrice.setValue(Double.parseDouble((String) context.get("buyItNowPrice")));
  1731. buyItNowPrice.setCurrencyID(CurrencyCodeType.USD);
  1732. api.setBuyItNowPrice(buyItNowPrice);
  1733. }
  1734. api.setRecipientBidderUserID(recipientBidderUserID);
  1735. api.setItemID(itemID);
  1736. api.setSellerMessage(sellerMessage);
  1737. api.addSecondChanceItem();
  1738. } catch (Exception e) {
  1739. return ServiceUtil.returnError(e.getMessage());
  1740. }
  1741. return ServiceUtil.returnSuccess("Add Second Chance Offer Successful.");
  1742. }
  1743. public Map<String, Object> getMyeBaySelling(DispatchContext dctx, Map<String, ? extends Object> context) {
  1744. Map<String, Object>result = FastMap.newInstance();
  1745. LocalDispatcher dispatcher = dctx.getDispatcher();
  1746. GenericValue userLogin = (GenericValue) context.get("userLogin");
  1747. Delegator delegator = dctx.getDelegator();
  1748. Locale locale = (Locale) context.get("locale");
  1749. String productStoreId = (String) context.get("productStoreId");
  1750. List unsoldItems = FastList.newInstance();
  1751. try {
  1752. Map<String, Object> inMap = FastMap.newInstance();
  1753. inMap.put("productStoreId", productStoreId);
  1754. inMap.put("userLogin", userLogin);
  1755. Map<String, Object> resultUser = dispatcher.runSync("getEbayStoreUser", inMap);
  1756. String userID = (String) resultUser.get("userLoginId");
  1757. ApiContext apiContext = EbayStoreHelper.getApiContext(productStoreId, locale, delegator);
  1758. GetMyeBaySellingCall api = new GetMyeBaySellingCall(apiContext);
  1759. ItemListCustomizationType itemListType = new ItemListCustomizationType();
  1760. itemListType.setInclude(Boolean.TRUE);
  1761. String entriesPerPage = (String) context.get("entriesPerPage");
  1762. String pageNumber = (String) context.get("pageNumber");
  1763. String listingType = (String) context.get("listingType");
  1764. PaginationType page = new PaginationType();
  1765. if (UtilValidate.isNotEmpty(entriesPerPage)) {
  1766. page.setEntriesPerPage(Integer.valueOf(entriesPerPage));
  1767. }
  1768. if (UtilValidate.isNotEmpty(pageNumber)) {
  1769. page.setPageNumber(Integer.valueOf(pageNumber));
  1770. }
  1771. itemListType.setPagination(page);
  1772. if (UtilValidate.isNotEmpty(listingType)) {
  1773. itemListType.setListingType(ListingTypeCodeType.valueOf(listingType));
  1774. }
  1775. DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] {
  1776. DetailLevelCodeType.RETURN_ALL,
  1777. DetailLevelCodeType.ITEM_RETURN_ATTRIBUTES,
  1778. DetailLevelCodeType.ITEM_RETURN_DESCRIPTION
  1779. };
  1780. api.setDetailLevel(detailLevels);
  1781. api.setActiveList(itemListType);
  1782. api.setScheduledList(itemListType);
  1783. api.setSoldList(itemListType);
  1784. api.setUnsoldList(itemListType);
  1785. api.getMyeBaySelling();
  1786. ItemType[] tempActiveItems = null;
  1787. if (api.getReturnedActiveList() != null) tempActiveItems = (api.getReturnedActiveList().getItemArray()).getItem();
  1788. final ItemType[] activeItems = tempActiveItems;
  1789. // Display active items in table.
  1790. AbstractTableModel dataModel = new AbstractTableModel() {
  1791. public int getColumnCount() { return 0; }
  1792. public int getRowCount() { return activeItems == null ? 0 : activeItems.length;}
  1793. public Map<String, Object> getValueAt(int row, int col) {
  1794. ItemType item = activeItems[row];
  1795. return itemToColumns(item);
  1796. }
  1797. };
  1798. //add To List
  1799. List<Map> activeList = getDataModelToList(dataModel);
  1800. int activeSize = dataModel.getRowCount();
  1801. ItemType[] tempItems = null;
  1802. if (api.getReturnedScheduledList() != null) tempItems = (api.getReturnedScheduledList().getItemArray()).getItem();
  1803. final ItemType[] scheItems = tempItems;
  1804. // Display Scheduled items in table.
  1805. dataModel = new AbstractTableModel() {
  1806. public int getColumnCount() { return 0; }
  1807. public int getRowCount() { return scheItems == null ? 0 : scheItems.length;}
  1808. public Map<String, Object> getValueAt(int row, int col) {
  1809. ItemType item = scheItems[row];
  1810. return schItemToColumns(item);
  1811. }
  1812. };
  1813. // set data
  1814. List<Map> scheduledList = getDataModelToList(dataModel);
  1815. int scheduledSize = dataModel.getRowCount();
  1816. OrderTransactionType[] tempSoldItems = null;
  1817. if (UtilValidate.isNotEmpty(api.getReturnedSoldList())) tempSoldItems = (api.getReturnedSoldList().getOrderTransactionArray()).getOrderTransaction();
  1818. // add to list
  1819. List<Map> soldList = EbayStore.getOrderTransactions(tempSoldItems);
  1820. int soldSize = tempSoldItems == null ? 0 : tempSoldItems.length;
  1821. ItemType[] tempUnSoldItems = null;
  1822. if (UtilValidate.isNotEmpty(api.getReturnedUnsoldList())) tempUnSoldItems = (api.getReturnedUnsoldList().getItemArray()).getItem();
  1823. final ItemType[] unSoldItems = tempUnSoldItems;
  1824. // Display unsold items in table.
  1825. dataModel = new AbstractTableModel() {
  1826. public int getColumnCount() { return 0; }
  1827. public int getRowCount() { return unSoldItems == null ? 0 : unSoldItems.length;}
  1828. public Map<String, Object> getValueAt(int row, int col) {
  1829. ItemType item = unSoldItems[row];
  1830. return unsoldItemToColumns(item);
  1831. }
  1832. };
  1833. // add to list
  1834. List<Map> unsoldList = getDataModelToList(dataModel);
  1835. int unsoldSize = dataModel.getRowCount();
  1836. //list to result
  1837. result.put("activeItems", activeList);
  1838. result.put("soldItems", soldList);
  1839. result.put("unsoldItems", unsoldList);
  1840. result.put("scheduledItems", scheduledList);
  1841. //page control to result;
  1842. result.put("activeSize", activeSize);
  1843. result.put("soldSize", soldSize);
  1844. result.put("unsoldeSize", unsoldSize);
  1845. result.put("scheduledSize", scheduledSize);
  1846. } catch (Exception e) {
  1847. return ServiceUtil.returnError(e.getMessage());
  1848. }
  1849. return result;
  1850. }
  1851. // set output data list (MyeBaySelling)
  1852. public List<Map> getDataModelToList(TableModel dataModel) {
  1853. List<Map> list = FastList.newInstance();
  1854. for (int rowIndex = 0; rowIndex < dataModel.getRowCount(); rowIndex++) {
  1855. list.add((Map<String, Object>) dataModel.getValueAt(rowIndex, 0));
  1856. }
  1857. return list;
  1858. }
  1859. static Map<String, Object> itemToColumns(ItemType item) {
  1860. Map<String, Object> cols = FastMap.newInstance();
  1861. int i = 0;
  1862. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1863. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1864. SellingStatusType sst = item.getSellingStatus();
  1865. double currentPrice = 0;
  1866. int bidCount = 0;
  1867. double reservPrice = 0;
  1868. int hitCount = 0;
  1869. if (UtilValidate.isNotEmpty(sst)) {
  1870. AmountType amt = sst.getCurrentPrice();
  1871. currentPrice = amt != null ? (new Double(amt.getValue())) : 0;
  1872. bidCount = sst.getBidCount() != null ? sst.getBidCount() : 0;
  1873. }
  1874. cols.put("buyItNowPrice", item.getBuyItNowPrice().getValue());
  1875. cols.put("currentPrice", currentPrice);
  1876. cols.put("bidCount", bidCount);
  1877. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1878. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1879. Integer quantity = item.getQuantity();
  1880. String quantityStr = null;
  1881. if (UtilValidate.isNotEmpty(quantity)) quantityStr = quantity.toString();
  1882. cols.put("quantity", quantityStr);
  1883. cols.put("listingType", item.getListingType().value());
  1884. cols.put("viewItemURL", item.getListingDetails().getViewItemURL());
  1885. cols.put("SKU", item.getSKU());
  1886. if (UtilValidate.isNotEmpty(item.getReservePrice())) reservPrice = item.getReservePrice().getValue();
  1887. cols.put("reservePrice", reservPrice);
  1888. cols.put("hitCount", item.getHitCount() != null ? item.getHitCount() : 0);
  1889. return cols;
  1890. }
  1891. static Map<String, Object> schItemToColumns(ItemType item) {
  1892. Map<String, Object> cols = FastMap.newInstance();
  1893. int i = 0;
  1894. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1895. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1896. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1897. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1898. AmountType amt = item.getStartPrice();
  1899. cols.put("StartPrice", amt != null ? (new Double(amt.getValue()).toString()) : "");
  1900. Integer quantity = item.getQuantity();
  1901. String quantityStr = null;
  1902. if (UtilValidate.isNotEmpty(quantity)) {
  1903. quantityStr = quantity.toString();
  1904. }
  1905. cols.put("quantity", quantityStr);
  1906. cols.put("listingType", item.getListingType().value());
  1907. return cols;
  1908. }
  1909. static Map<String, Object> unsoldItemToColumns(ItemType item) {
  1910. Map<String, Object> cols = FastMap.newInstance();
  1911. int i = 0;
  1912. cols.put("itemId", item.getItemID() != null ? item.getItemID() : "");
  1913. cols.put("title", item.getTitle() != null ? item.getTitle() : "");
  1914. AmountType amt = item.getStartPrice();
  1915. cols.put("price", amt != null ? (new Double(amt.getValue()).toString()) : "");
  1916. java.util.Calendar startTime = item.getListingDetails() == null ? null : item.getListingDetails().getStartTime();
  1917. cols.put("startTime", startTime != null ? eBayUtil.toAPITimeString(startTime.getTime()) : "");
  1918. java.util.Calendar endTime = item.getListingDetails() == null ? null : item.getListingDetails().getEndTime();
  1919. cols.put("endTime", endTime != null ? eBayUtil.toAPITimeString(endTime.getTime()) : "");
  1920. Integer quantity = item.getQuantity();
  1921. String quantityStr = null;
  1922. if (UtilValidate.isNotEmpty(quantity)) {
  1923. quantityStr = quantity.toString();
  1924. }
  1925. cols.put("quantity", quantityStr);
  1926. cols.put("listingType", item.getListingType().value());
  1927. return cols;
  1928. }
  1929. public static List<Map> getOrderTransactions(OrderTransactionType[] orderTrans) {
  1930. List<Map> colsList = FastList.newInstance();
  1931. OrderTransactionType orderTran = null;
  1932. OrderType order = null;
  1933. TransactionType transaction= null;
  1934. for (int rowIndex = 0; rowIndex < orderTrans.length; rowIndex++) {
  1935. orderTran = orderTrans[rowIndex];
  1936. order = orderTran.getOrder();
  1937. transaction = orderTran.getTransaction();
  1938. if (UtilValidate.isNotEmpty(order)) {
  1939. TransactionType[] trans = order.getTransactionArray().getTransaction();
  1940. String orderId = order.getOrderID();
  1941. for (int rowIndex1 = 0; rowIndex1 < trans.length; rowIndex1++) {
  1942. colsList.add(EbayStore.getTransaction(trans[rowIndex1]));
  1943. }
  1944. } else {
  1945. colsList.add(EbayStore.getTransaction(transaction));
  1946. }
  1947. }
  1948. return colsList;
  1949. }
  1950. public static Map<String, Object> getTransaction(TransactionType transaction){
  1951. Map<String, Object> cols = FastMap.newInstance();
  1952. ItemType item = transaction.getItem();
  1953. String itemId = null;
  1954. String title = null;
  1955. if (UtilValidate.isNotEmpty(item)) {
  1956. itemId = item.getItemID();
  1957. title = item.getTitle();
  1958. }
  1959. cols.put("itemId", itemId);
  1960. cols.put("title", title);
  1961. UserType buyer = transaction.getBuyer();
  1962. String user = null;
  1963. if (UtilValidate.isNotEmpty(buyer)) user = buyer.getUserID();
  1964. cols.put("buyer", user);
  1965. cols.put("listingType", item.getListingType().value());
  1966. Date paidTime = null;
  1967. String checkoutStatus = null;
  1968. String eBayPaymentStatus = null;
  1969. String completeStatus = null;
  1970. String buyerPaidStatus = null;
  1971. Date shippedTime = null;
  1972. String unpaidItemStatus = null;
  1973. String transactionId = null;
  1974. double totalPrice = 0;
  1975. double transactionPrice = 0;
  1976. Date createdDate = null;
  1977. String sellerPaidStatus = null;
  1978. String orderId = null;
  1979. double adjustmentAmount = 0;
  1980. double amountPaid = 0;
  1981. if (UtilValidate.isNotEmpty(transaction.getStatus())) {
  1982. if (UtilValidate.isNotEmpty(transaction.getStatus().getCheckoutStatus())) {
  1983. checkoutStatus = transaction.getStatus().getCheckoutStatus().value();
  1984. }
  1985. if (UtilValidate.isNotEmpty(transaction.getStatus().getEBayPaymentStatus())) {
  1986. eBayPaymentStatus = transaction.getStatus().getEBayPaymentStatus().value();
  1987. }
  1988. if (UtilValidate.isNotEmpty(transaction.getStatus().getCompleteStatus())) {
  1989. completeStatus = transaction.getStatus().getCompleteStatus().value();
  1990. }
  1991. }
  1992. if (UtilValidate.isNotEmpty(transaction.getBuyerPaidStatus())) {
  1993. buyerPaidStatus = transaction.getBuyerPaidStatus().value();
  1994. }
  1995. if (UtilValidate.isNotEmpty(transaction.getPaidTime())) {
  1996. paidTime = transaction.getPaidTime().getTime();
  1997. }
  1998. if (UtilValidate.isNotEmpty(transaction.getShippedTime())) {
  1999. shippedTime = transaction.getShippedTime().getTime();
  2000. }
  2001. if (UtilValidate.isNotEmpty(transaction.getTransactionID())) {
  2002. transactionId = transaction.getTransactionID().toString();
  2003. }
  2004. if (UtilValidate.isNotEmpty(transaction.getTotalPrice())) {
  2005. totalPrice = transaction.getTotalPrice().getValue();
  2006. }
  2007. if (UtilValidate.isNotEmpty(transaction.getTransactionPrice())) {
  2008. transactionPrice = transaction.getTransactionPrice().getValue();
  2009. }
  2010. if (UtilValidate.isNotEmpty(transaction.getCreatedDate())) {
  2011. createdDate = transaction.getCreatedDate().getTime();
  2012. }
  2013. if (UtilValidate.isNotEmpty(transaction.getSellerPaidStatus())) {
  2014. sellerPaidStatus = transaction.getSellerPaidStatus().value();
  2015. }
  2016. if (UtilValidate.isNotEmpty(transaction.getContainingOrder())) {
  2017. if (UtilValidate.isNotEmpty(transaction.getContainingOrder().getCheckoutStatus())) {
  2018. checkoutStatus = transaction.getContainingOrder().getCheckoutStatus().getStatus().value();
  2019. }
  2020. orderId = transaction.getContainingOrder().getOrderID();
  2021. }
  2022. if (UtilValidate.isNotEmpty(transaction.getAdjustmentAmount())) {
  2023. adjustmentAmount = transaction.getAdjustmentAmount().getValue();
  2024. }
  2025. if (UtilValidate.isNotEmpty(transaction.getAmountPaid())) {
  2026. amountPaid = transaction.getAmountPaid().getValue();
  2027. }
  2028. cols.put("amountPaid", amountPaid);
  2029. cols.put("adjustmentAmount", adjustmentAmount);
  2030. cols.put("orderId", orderId);
  2031. cols.put("checkoutStatus", checkoutStatus);
  2032. cols.put("eBayPaymentStatus", eBayPaymentStatus);
  2033. cols.put("completeStatus", completeStatus);
  2034. cols.put("buyerPaidStatus", buyerPaidStatus);
  2035. cols.put("paidTime", paidTime);
  2036. cols.put("shippedTime", shippedTime);
  2037. cols.put("quantity", transaction.getQuantityPurchased());
  2038. cols.put("transactionId", transactionId);
  2039. cols.put("transactionPrice", transactionPrice);
  2040. cols.put("totalPrice", totalPrice);
  2041. cols.put("createdDate", createdDate);
  2042. cols.put("sellerPaidStatus", sellerPaidStatus);
  2043. return cols;
  2044. }
  2045. }