/apache-ofbiz-10.04.02/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java
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
Large files files are truncated, but you can click here to view the full file
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- package org.ofbiz.ebaystore;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.math.BigDecimal;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import javolution.util.FastList;
- import javolution.util.FastMap;
- import org.ofbiz.base.util.Debug;
- import org.ofbiz.base.util.StringUtil;
- import org.ofbiz.base.util.UtilDateTime;
- import org.ofbiz.base.util.UtilMisc;
- import org.ofbiz.base.util.UtilProperties;
- import org.ofbiz.base.util.UtilValidate;
- import org.ofbiz.base.util.UtilXml;
- import org.ofbiz.common.DataModelConstants;
- import org.ofbiz.entity.Delegator;
- import org.ofbiz.entity.GenericEntityException;
- import org.ofbiz.entity.GenericValue;
- import org.ofbiz.entity.condition.EntityCondition;
- import org.ofbiz.entity.condition.EntityOperator;
- import org.ofbiz.entity.transaction.TransactionUtil;
- import org.ofbiz.entity.util.EntityUtil;
- import org.ofbiz.service.DispatchContext;
- import org.ofbiz.service.GenericServiceException;
- import org.ofbiz.service.LocalDispatcher;
- import org.ofbiz.service.ModelService;
- import org.ofbiz.service.ServiceUtil;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import com.ebay.sdk.ApiContext;
- import com.ebay.sdk.ApiException;
- import com.ebay.sdk.SdkException;
- import com.ebay.sdk.SdkSoapException;
- import com.ebay.sdk.call.*;
- import com.ebay.sdk.util.eBayUtil;
- import com.ebay.soap.eBLBaseComponents.AmountType;
- import com.ebay.soap.eBLBaseComponents.CheckoutStatusCodeType;
- import com.ebay.soap.eBLBaseComponents.CurrencyCodeType;
- import com.ebay.soap.eBLBaseComponents.DeleteSellingManagerTemplateRequestType;
- import com.ebay.soap.eBLBaseComponents.DeleteSellingManagerTemplateResponseType;
- import com.ebay.soap.eBLBaseComponents.DisputeExplanationCodeType;
- import com.ebay.soap.eBLBaseComponents.DisputeReasonCodeType;
- import com.ebay.soap.eBLBaseComponents.GetAllBiddersModeCodeType;
- import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryRequestType;
- import com.ebay.soap.eBLBaseComponents.GetSellingManagerInventoryResponseType;
- import com.ebay.soap.eBLBaseComponents.GetStoreOptionsRequestType;
- import com.ebay.soap.eBLBaseComponents.GetStoreOptionsResponseType;
- import com.ebay.soap.eBLBaseComponents.GetStoreRequestType;
- import com.ebay.soap.eBLBaseComponents.GetStoreResponseType;
- import com.ebay.soap.eBLBaseComponents.ItemSortTypeCodeType;
- import com.ebay.soap.eBLBaseComponents.ListingTypeCodeType;
- import com.ebay.soap.eBLBaseComponents.MerchDisplayCodeType;
- import com.ebay.soap.eBLBaseComponents.OfferType;
- import com.ebay.soap.eBLBaseComponents.OrderTransactionArrayType;
- import com.ebay.soap.eBLBaseComponents.OrderTransactionType;
- import com.ebay.soap.eBLBaseComponents.OrderType;
- import com.ebay.soap.eBLBaseComponents.PaginationType;
- import com.ebay.soap.eBLBaseComponents.SecondChanceOfferDurationCodeType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerProductDetailsType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerProductInventoryStatusType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerProductType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerSearchType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerSearchTypeCodeType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerSoldListingsPropertyTypeCodeType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsArrayType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsType;
- import com.ebay.soap.eBLBaseComponents.SellingStatusType;
- import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesRequestType;
- import com.ebay.soap.eBLBaseComponents.SetStoreCategoriesResponseType;
- import com.ebay.soap.eBLBaseComponents.SetStoreRequestType;
- import com.ebay.soap.eBLBaseComponents.SetStoreResponseType;
- import com.ebay.soap.eBLBaseComponents.StoreCategoryUpdateActionCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreColorSchemeType;
- import com.ebay.soap.eBLBaseComponents.StoreColorType;
- import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryArrayType;
- import com.ebay.soap.eBLBaseComponents.StoreCustomCategoryType;
- import com.ebay.soap.eBLBaseComponents.StoreCustomHeaderLayoutCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderDisplayCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreCustomListingHeaderType;
- import com.ebay.soap.eBLBaseComponents.StoreFontFaceCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreFontSizeCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreFontType;
- import com.ebay.soap.eBLBaseComponents.StoreHeaderStyleCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreItemListLayoutCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreItemListSortOrderCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreLogoArrayType;
- import com.ebay.soap.eBLBaseComponents.StoreLogoType;
- import com.ebay.soap.eBLBaseComponents.StoreSubscriptionLevelCodeType;
- import com.ebay.soap.eBLBaseComponents.StoreThemeArrayType;
- import com.ebay.soap.eBLBaseComponents.StoreThemeType;
- import com.ebay.soap.eBLBaseComponents.StoreType;
- import com.ebay.soap.eBLBaseComponents.TaskStatusCodeType;
- import com.ebay.soap.eBLBaseComponents.TransactionArrayType;
- import com.ebay.soap.eBLBaseComponents.TransactionType;
- import com.ebay.soap.eBLBaseComponents.UserType;
- import com.ebay.soap.eBLBaseComponents.VerifyAddSecondChanceItemResponseType;
- import java.sql.Timestamp;
- import javax.swing.event.TableModelListener;
- import javax.swing.table.AbstractTableModel;
- import javax.swing.table.TableModel;
-
- import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
- import com.ebay.soap.eBLBaseComponents.ItemArrayType;
- import com.ebay.soap.eBLBaseComponents.ItemListCustomizationType;
- import com.ebay.soap.eBLBaseComponents.ItemType;
- import com.ebay.soap.eBLBaseComponents.PaginatedItemArrayType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerSoldOrderType;
- import com.ebay.soap.eBLBaseComponents.SellingManagerSoldTransactionType;
- import org.ofbiz.ebay.ProductsExportToEbay;
- import org.ofbiz.ebay.EbayHelper;
- public class EbayStore {
- private static final String resource = "EbayStoreUiLabels";
- private static final String module = ProductsExportToEbay.class.getName();
- public static ProductsExportToEbay productExportEbay = new ProductsExportToEbay();
- private static void appendRequesterCredentials(Element elem, Document doc, String token) {
- Element requesterCredentialsElem = UtilXml.addChildElement(elem, "RequesterCredentials", doc);
- UtilXml.addChildElementValue(requesterCredentialsElem, "eBayAuthToken", token, doc);
- }
- private static Map postItem(String postItemsUrl, StringBuffer dataItems, String devID, String appID, String certID,
- String callName, String compatibilityLevel, String siteID) throws IOException {
- if (Debug.verboseOn()) {
- Debug.logVerbose("Request of " + callName + " To eBay:\n" + dataItems.toString(), module);
- }
- HttpURLConnection connection = (HttpURLConnection)(new URL(postItemsUrl)).openConnection();
- connection.setDoInput(true);
- connection.setDoOutput(true);
- connection.setRequestMethod("POST");
- connection.setRequestProperty("X-EBAY-API-COMPATIBILITY-LEVEL", compatibilityLevel);
- connection.setRequestProperty("X-EBAY-API-DEV-NAME", devID);
- connection.setRequestProperty("X-EBAY-API-APP-NAME", appID);
- connection.setRequestProperty("X-EBAY-API-CERT-NAME", certID);
- connection.setRequestProperty("X-EBAY-API-CALL-NAME", callName);
- connection.setRequestProperty("X-EBAY-API-SITEID", siteID);
- connection.setRequestProperty("Content-Type", "text/xml");
- OutputStream outputStream = connection.getOutputStream();
- outputStream.write(dataItems.toString().getBytes());
- outputStream.close();
- int responseCode = connection.getResponseCode();
- InputStream inputStream;
- Map result = FastMap.newInstance();
- String response = null;
- if (responseCode == HttpURLConnection.HTTP_CREATED ||
- responseCode == HttpURLConnection.HTTP_OK) {
- inputStream = connection.getInputStream();
- response = toString(inputStream);
- result = ServiceUtil.returnSuccess(response);
- } else {
- inputStream = connection.getErrorStream();
- response = toString(inputStream);
- result = ServiceUtil.returnFailure(response);
- }
- if (Debug.verboseOn()) {
- Debug.logVerbose("Response of " + callName + " From eBay:\n" + response, module);
- }
- return result;
- }
- private static String toString(InputStream inputStream) throws IOException {
- String string;
- StringBuilder outputBuilder = new StringBuilder();
- if (inputStream != null) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
- while (null != (string = reader.readLine())) {
- outputBuilder.append(string).append('\n');
- }
- }
- return outputBuilder.toString();
- }
- /* add/update/delete categories and child into your ebay store category */
- public static Map<String,Object> exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map<String,? extends Object> context) {
- Locale locale = (Locale) context.get("locale");
- Delegator delegator = dctx.getDelegator();
- Map<String, Object> result = FastMap.newInstance();
- SetStoreCategoriesRequestType req = null;
- StoreCustomCategoryArrayType categoryArrayType = null;
- List<GenericValue> catalogCategories = null;
- if (UtilValidate.isEmpty(context.get("prodCatalogId")) || UtilValidate.isEmpty(context.get("productStoreId")) || UtilValidate.isEmpty(context.get("partyId"))) {
- return ServiceUtil.returnError("Please set catalogId and productStoreId.");
- }
- if (!EbayStoreHelper.validatePartyAndRoleType(delegator,context.get("partyId").toString())) {
- return ServiceUtil.returnError("Party ".concat(context.get("partyId").toString()).concat(" no roleTypeId EBAY_ACCOUNT for export categories to ebay store."));
- }
- try {
- SetStoreCategoriesCall call = new SetStoreCategoriesCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString(),"prodCatalogCategoryTypeId","PCCT_EBAY_ROOT"), UtilMisc.toList("sequenceNum ASC"));
- if (catalogCategories != null && catalogCategories.size() > 0) {
- List<StoreCustomCategoryType> listAdd = FastList.newInstance();
- List<StoreCustomCategoryType> listEdit = FastList.newInstance();
- //start at level 0 of categories
- for (GenericValue catalogCategory : catalogCategories) {
- GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
- if (productCategory != null) {
- String ebayCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
- StoreCustomCategoryType categoryType = new StoreCustomCategoryType();
- if (ebayCategoryId == null) {
- categoryType.setName(productCategory.getString("categoryName"));
- listAdd.add(categoryType);
- } else {
- categoryType.setCategoryID(new Long(ebayCategoryId));
- categoryType.setName(productCategory.getString("categoryName"));
- listEdit.add(categoryType);
- }
- }
- }
- if (listAdd.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
- req.setStoreCategories(categoryArrayType);
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories);
- }
- if (listEdit.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
- req.setStoreCategories(categoryArrayType);
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories);
- }
- //start at level 1 of categories
- listAdd = FastList.newInstance();
- listEdit = FastList.newInstance();
- for (GenericValue catalogCategory : catalogCategories) {
- GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
- if (productCategory != null) {
- String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
- if (ebayParentCategoryId != null) {
- List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId", productCategory.getString("productCategoryId")), UtilMisc.toList("sequenceNum ASC"));
- for (GenericValue productCategoryRollup : productCategoryRollupList) {
- productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryRollup.getString("productCategoryId")));
- StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
- String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), context.get("partyId").toString());
- if (ebayChildCategoryId == null) {
- childCategoryType.setName(productCategory.getString("categoryName"));
- listAdd.add(childCategoryType);
- } else {
- childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
- childCategoryType.setName(productCategory.getString("categoryName"));
- listEdit.add(childCategoryType);
- }
- }
- }
- if (listAdd.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
- req.setStoreCategories(categoryArrayType);
- req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator,context.get("partyId").toString(), catalogCategories);
- }
- if (listEdit.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
- req.setStoreCategories(categoryArrayType);
- req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator,context.get("partyId").toString(), catalogCategories);
- }
- }
- }
- //start at level 2 of categories
- listAdd = FastList.newInstance();
- listEdit = FastList.newInstance();
- for (GenericValue catalogCategory : catalogCategories) {
- GenericValue productCategory = catalogCategory.getRelatedOne("ProductCategory");
- if (productCategory != null) {
- List<GenericValue> productParentCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategory.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
- for (GenericValue productParentCategoryRollup : productParentCategoryRollupList) {
- String ebayParentCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productParentCategoryRollup.getString("productCategoryId"),context.get("partyId").toString());
- if (ebayParentCategoryId != null) {
- List<GenericValue> productChildCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productParentCategoryRollup.getString("productCategoryId")),UtilMisc.toList("sequenceNum ASC"));
- for (GenericValue productChildCategoryRollup : productChildCategoryRollupList) {
- productCategory = delegator.findByPrimaryKey("ProductCategory", UtilMisc.toMap("productCategoryId", productChildCategoryRollup.getString("productCategoryId")));
- StoreCustomCategoryType childCategoryType = new StoreCustomCategoryType();
- String ebayChildCategoryId = EbayStoreHelper.retriveEbayCategoryIdByPartyId(delegator,productCategory.getString("productCategoryId"),context.get("partyId").toString());
- if (ebayChildCategoryId == null) {
- childCategoryType.setName(productCategory.getString("categoryName"));
- listAdd.add(childCategoryType);
- } else {
- childCategoryType.setCategoryID(new Long(ebayChildCategoryId));
- childCategoryType.setName(productCategory.getString("categoryName"));
- listEdit.add(childCategoryType);
- }
- }
- if (listAdd.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listAdd));
- req.setStoreCategories(categoryArrayType);
- req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.ADD, delegator, context.get("partyId").toString(), catalogCategories);
- }
- if (listEdit.size() > 0) {
- req = new SetStoreCategoriesRequestType();
- categoryArrayType = new StoreCustomCategoryArrayType();
- categoryArrayType.setCustomCategory(toStoreCustomCategoryTypeArray(listEdit));
- req.setStoreCategories(categoryArrayType);
- req.setDestinationParentCategoryID(new Long(ebayParentCategoryId));
- result = excuteExportCategoryToEbayStore(call, req, StoreCategoryUpdateActionCodeType.RENAME, delegator, context.get("partyId").toString(), catalogCategories);
- }
- }
- }
- }
- }
- } else {
- return ServiceUtil.returnError("Not found product Category type EBAY_ROOT in catalog "+context.get("prodCatalogId"));
- }
- } catch (GenericEntityException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- if (result.get("responseMessage") != null && result.get("responseMessage").equals("fail")) result = ServiceUtil.returnError(result.get("errorMessage").toString());
- return result;
- }
- public static StoreCustomCategoryType[] toStoreCustomCategoryTypeArray(List<StoreCustomCategoryType> list) {
- StoreCustomCategoryType[] storeCustomCategoryTypeArry = null;
- try {
- if (list != null && list.size() > 0) {
- storeCustomCategoryTypeArry = new StoreCustomCategoryType[list.size()];
- int i=0;
- for (StoreCustomCategoryType val : list) {
- storeCustomCategoryTypeArry[i] = val;
- }
- }
- } catch (Exception e) {
- Debug.logError(e.getMessage(), module);
- }
- return storeCustomCategoryTypeArry;
- }
- public static Map<String, Object> excuteExportCategoryToEbayStore(SetStoreCategoriesCall call, SetStoreCategoriesRequestType req, StoreCategoryUpdateActionCodeType actionCode,Delegator delegator, String partyId,List<GenericValue> catalogCategories) {
- Map<String, Object> result = FastMap.newInstance();
- SetStoreCategoriesResponseType resp = null;
- try {
- if (req != null && actionCode != null) {
- req.setAction(actionCode);
- resp = (SetStoreCategoriesResponseType) call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- long returnTaskId = resp.getTaskID() == null? 0: resp.getTaskID().longValue();
- TaskStatusCodeType returnedStatus = resp.getStatus();
- StoreCustomCategoryArrayType returnedCustomCategory = resp.getCustomCategory();
- if (actionCode.equals(StoreCategoryUpdateActionCodeType.ADD) && returnedCustomCategory != null) {
- StoreCustomCategoryType[] returnCategoryTypeList = returnedCustomCategory.getCustomCategory();
- for (StoreCustomCategoryType returnCategoryType : returnCategoryTypeList) {
- List<GenericValue> productCategoryList = delegator.findByAnd("ProductCategory", UtilMisc.toMap("categoryName",returnCategoryType.getName(),"productCategoryTypeId","EBAY_CATEGORY"));
- for (GenericValue productCategory : productCategoryList) {
- if (EbayStoreHelper.veriflyCategoryInCatalog(delegator,catalogCategories,productCategory.getString("productCategoryId"))) {
- if (EbayStoreHelper.createEbayCategoryIdByPartyId(delegator, productCategory.getString("productCategoryId"), partyId, String.valueOf(returnCategoryType.getCategoryID()))) {
- Debug.logInfo("Create new ProductCategoryRollup with partyId "+partyId+" categoryId "+productCategory.getString("productCategoryId")+ " and ebayCategoryId "+String.valueOf(returnCategoryType.getCategoryID()), module);
- }
- break;
- }
- }
- }
- }
- result = ServiceUtil.returnSuccess("Export categories to ebay store".concat(" success."));
- } else {
- result = ServiceUtil.returnError("Fail to export categories to an ebay store ".concat(resp.getMessage()));
- }
- }
- } catch (ApiException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkSoapException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (SdkException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- } catch (GenericEntityException e) {
- result = ServiceUtil.returnFailure(e.getMessage());
- }
- return result;
- }
- public static Map buildSetStoreXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID) {
- Locale locale = (Locale)context.get("locale");
- try {
- Delegator delegator = dctx.getDelegator();
- String webSiteUrl = (String)context.get("webSiteUrl");
- List selectResult = (List)context.get("selectResult");
- StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
- // Get the list of products to be exported to eBay
- try {
- Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreRequest");
- Element storeRequestElem = storeDocument.getDocumentElement();
- storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
- appendRequesterCredentials(storeRequestElem, storeDocument, token);
- /*UtilXml.addChildElementValue(storeRequestElem, "SiteId", siteID, storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);*/
- // Prepare data for set to XML
- GenericValue productStore = null;
- if (UtilValidate.isNotEmpty(context.get("productStoreId").toString())) {
- productStore = delegator.findByPrimaryKey("ProductStore",UtilMisc.toMap("productStoreId", context.get("productStoreId").toString()));
- }
- Element itemElem = UtilXml.addChildElement(storeRequestElem, "Store", storeDocument);
- UtilXml.addChildElementValue(itemElem, "Name", (String) productStore.getString("storeName"), storeDocument);
- UtilXml.addChildElementValue(itemElem, "SubscriptionLevel", "Basic", storeDocument);
- UtilXml.addChildElementValue(itemElem, "Description", (String) productStore.getString("title"), storeDocument);
- dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
- } catch (Exception e) {
- Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- } catch (Exception e) {
- Debug.logError("Exception during building data items to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- return ServiceUtil.returnSuccess();
- }
- public static String readEbayResponse(String msg, String productStoreId) {
- String result ="success";
- try {
- Document docResponse = UtilXml.readXmlDocument(msg, true);
- Element elemResponse = docResponse.getDocumentElement();
- String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
- if (ack != null && "Failure".equals(ack)) {
- String errorMessage = "";
- List errorList = UtilXml.childElementList(elemResponse, "Errors");
- Iterator errorElemIter = errorList.iterator();
- while (errorElemIter.hasNext()) {
- Element errorElement = (Element) errorElemIter.next();
- errorMessage = UtilXml.childElementValue(errorElement, "LongMessage");
- }
- result = errorMessage;
- } else {
- String productSuccessfullyExportedMsg = "Successfully exported with ID (" + productStoreId + ").";
- result = "success";
- }
- } catch (Exception e) {
- Debug.logError("Error in processing xml string" + e.getMessage(), module);
- result = "Failure";
- }
- return result;
- }
- public static Map buildGetStoreXml(Map context, StringBuffer dataStoreXml, String token, String siteID) {
- Locale locale = (Locale)context.get("locale");
- try {
- StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
- // Get the list of products to be exported to eBay
- try {
- Document storeDocument = UtilXml.makeEmptyXmlDocument("GetStoreRequest");
- Element storeRequestElem = storeDocument.getDocumentElement();
- storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
- appendRequesterCredentials(storeRequestElem, storeDocument, token);
- //UtilXml.addChildElementValue(storeRequestElem, "CategorySiteID", siteID, storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "LevelLimit", "1", storeDocument);
- dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
- } catch (Exception e) {
- Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- } catch (Exception e) {
- Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- return ServiceUtil.returnSuccess();
- }
- public static Map buildSetStoreCategoriesXml(DispatchContext dctx, Map context, StringBuffer dataStoreXml, String token, String siteID, String productCategoryId) {
- Delegator delegator = dctx.getDelegator();
- Locale locale = (Locale)context.get("locale");
- try {
- StringUtil.SimpleEncoder encoder = StringUtil.getEncoder("xml");
- // Get the list of products to be exported to eBay
- try {
- Document storeDocument = UtilXml.makeEmptyXmlDocument("SetStoreCategoriesRequest");
- Element storeRequestElem = storeDocument.getDocumentElement();
- storeRequestElem.setAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
- appendRequesterCredentials(storeRequestElem, storeDocument, token);
- UtilXml.addChildElementValue(storeRequestElem, "DetailLevel", "ReturnAll", storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "Version", "643", storeDocument);
- UtilXml.addChildElementValue(storeRequestElem, "Action", "Add", storeDocument);
- Element StoreCategoriesElem = UtilXml.addChildElement(storeRequestElem, "StoreCategories", storeDocument);
- //UtilXml.addChildElementValue(StoreCategoriesElem, "Country", (String)context.get("country"), storeDocument);
- GenericValue category = null;
- if (UtilValidate.isNotEmpty(context.get("prodCatalogId"))) {
- category = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId));
- }
- String categoryName = category.getString("productCategoryId").toString();
- if (category.getString("categoryName").toString() != null) {
- categoryName = category.getString("categoryName").toString();
- }
- Element customCategoryElem = UtilXml.addChildElement(StoreCategoriesElem, "CustomCategory", storeDocument);
- //UtilXml.addChildElementValue(customCategoryElem, "CategoryID", "", storeDocument);
- UtilXml.addChildElementValue(customCategoryElem, "Name", categoryName, storeDocument);
- dataStoreXml.append(UtilXml.writeXmlDocument(storeDocument));
- } catch (Exception e) {
- Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- } catch (Exception e) {
- Debug.logError("Exception during building data to eBay: " + e.getMessage(), module);
- return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionDuringBuildingDataItemsToEbay", locale));
- }
- return ServiceUtil.returnSuccess();
- }
- public static Map readEbayGetStoreCategoriesResponse(String msg, Locale locale) {
- Map results = null;
- List categories = FastList.newInstance();
- try {
- Document docResponse = UtilXml.readXmlDocument(msg, true);
- Element elemResponse = docResponse.getDocumentElement();
- String ack = UtilXml.childElementValue(elemResponse, "Ack", "Failure");
- if (ack != null && "Failure".equals(ack)) {
- String errorMessage = "";
- List errorList = UtilXml.childElementList(elemResponse, "Errors");
- Iterator errorElemIter = errorList.iterator();
- while (errorElemIter.hasNext()) {
- Element errorElement = (Element) errorElemIter.next();
- errorMessage = UtilXml.childElementValue(errorElement, "ShortMessage", "");
- }
- return ServiceUtil.returnFailure(errorMessage);
- } else {
- // retrieve Store
- List Store = UtilXml.childElementList(elemResponse, "Store");
- Iterator StoreElemIter = Store.iterator();
- while (StoreElemIter.hasNext()) {
- Element StoreElemIterElemIterElement = (Element) StoreElemIter.next();
- // retrieve Custom Category Array
- List customCategories = UtilXml.childElementList(StoreElemIterElemIterElement, "CustomCategories");
- Iterator customCategoriesElemIter = customCategories.iterator();
- while (customCategoriesElemIter.hasNext()) {
- Element customCategoriesElemIterElement = (Element)customCategoriesElemIter.next();
- // retrieve CustomCategory
- List customCategory = UtilXml.childElementList(customCategoriesElemIterElement, "CustomCategory");
- Iterator customCategoryElemIter = customCategory.iterator();
- while (customCategoryElemIter.hasNext()) {
- Map categ = FastMap.newInstance();
- Element categoryElement = (Element)customCategoryElemIter.next();
- categ.put("CategoryID", UtilXml.childElementValue(categoryElement, "CategoryID"));
- categ.put("CategoryName", UtilXml.childElementValue(categoryElement, "Name"));
- categ.put("CategorySeq", UtilXml.childElementValue(categoryElement, "Order"));
- categories.add(categ);
- }
- }
- }
- categories = UtilMisc.sortMaps(categories, UtilMisc.toList("CategoryName"));
- results = UtilMisc.toMap("categories", categories);
- }
- } catch (Exception e) {
- return ServiceUtil.returnFailure();
- }
- return results;
- }
- public static Map<String, Object> getEbayStoreUser(DispatchContext dctx, Map<String, ? extends Object> context) {
- Map<String, Object> result = FastMap.newInstance();
- String errorMsg = null;
- LocalDispatcher dispatcher = dctx.getDispatcher();
- GenericValue userLogin = (GenericValue) context.get("userLogin");
- Delegator delegator = dctx.getDelegator();
- Locale locale = (Locale) context.get("locale");
- String productStoreId = (String) context.get("productStoreId");
- List itemsResult = FastList.newInstance();
- try {
- List productStores = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStoreId, "roleTypeId", "EBAY_ACCOUNT"));
- if (productStores.size() != 0) {
- String partyId = ((GenericValue) productStores.get(0)).getString("partyId");
- List userLoginStore = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
- if (userLoginStore.size() != 0) {
- String userLoginId = ((GenericValue) userLoginStore.get(0)).getString("userLoginId");
- result.put("userLoginId", userLoginId);
- }
- }
- } catch (Exception e) {
-
- }
- return result;
- }
- /*Editing the Store Settings */
- /* Get store output */
- public static Map<String,Object> getEbayStoreOutput(DispatchContext dctx, Map<String,Object> context) {
- Locale locale = (Locale) context.get("locale");
- GenericValue userLogin = (GenericValue) context.get("userLogin");
- Delegator delegator = dctx.getDelegator();
- Map<String,Object> result = FastMap.newInstance();
- StoreType returnedStoreType = null;
- GetStoreRequestType req = new GetStoreRequestType();
- GetStoreResponseType resp = null;
- String userLoginId = null;
- String password = null;
- if (context.get("productStoreId") != null) {
- String partyId = null;
- try {
- List<GenericValue> productStoreRoles = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", context.get("productStoreId").toString(),"roleTypeId","EBAY_ACCOUNT"));
- if (productStoreRoles.size() != 0) {
- partyId= (String)productStoreRoles.get(0).get("partyId");
- List<GenericValue> userLogins = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
- if (userLogins.size() != 0) {
- userLoginId = (String)userLogins.get(0).get("userLoginId");
- password = (String)userLogins.get(0).get("currentPassword");
- }
-
- }
- } catch (GenericEntityException e1) {
- e1.printStackTrace();
- }
- Debug.logInfo("userLoginId is "+userLoginId+" and productStoreId is "+ context.get("productStoreId"), module);
- GetStoreCall call = new GetStoreCall(EbayStoreHelper.getApiContext((String)context.get("productStoreId"), locale, delegator));
- //call.setSite(EbayHelper.getSiteCodeType((String)context.get("productStoreId"), locale, delegator));
- call.setCategoryStructureOnly(false);
- call.setUserID(userLoginId);
- try {
- resp = (GetStoreResponseType)call.execute(req);
- if (resp != null && "SUCCESS".equals(resp.getAck().toString())) {
- returnedStoreType = resp.getStore();
- result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
- //result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "EbayStoreLoadSuccess", locale));
- // update product store in ofbiz
- updateProductStore(dctx, context, returnedStoreType,(String) context.get("productStoreId"));
- Map<String,Object> ebayResp = FastMap.newInstance();
- ebayResp.put("storeName", returnedStoreType.getName());
- ebayResp.put("storeUrl", returnedStoreType.getURL());
- ebayResp.put("storeUrlPath", returnedStoreType.getURLPath());
- String desc = returnedStoreType.getDescription();
- if (desc != null) desc = desc.trim();
- ebayResp.put("storeDesc", desc);
- StoreLogoType logoType = returnedStoreType.getLogo();
- ebayResp.put("storeLogoId", logoType.getLogoID());
- ebayResp.put("storeLogoName", logoType.getName());
- ebayResp.put("storeLogoURL", logoType.getURL());
- StoreThemeType themeType = returnedStoreType.getTheme();
- ebayResp.put("storeThemeId", themeType.getThemeID());
- ebayResp.put("storeThemeName", themeType.getName());
- StoreColorSchemeType colorSchemeType = themeType.getColorScheme();
- ebayResp.put("storeColorSchemeId", colorSchemeType.getColorSchemeID());
- StoreColorType colorType = colorSchemeType.getColor();
- ebayResp.put("storeColorPrimary", colorType.getPrimary());
- ebayResp.put("storeColorAccent", colorType.getAccent());
- ebayResp.put("storeColorSecondary", colorType.getSecondary());
- StoreFontType fontType = colorSchemeType.getFont();
- ebayResp.put("storeDescColor", fontType.getDescColor());
- ebayResp.put("storeNameColor", fontType.getNameColor());
- ebayResp.put("storeTitleColor", fontType.getTitleColor());
- if (fontType != null) {// basic & advance theme
- String themeId = themeType.getThemeID().toString().concat("-").concat(colorSchemeType.getColorSchemeID().toString());
- context.put("themeId", themeId);
- Map<String,Object> results = retrieveThemeColorSchemeByThemeId(dctx, context);
- if (results != null) {
- Map<String,Object> storeFontScheme = (Map<String,Object>) results.get("storeFontScheme");
- if (storeFontScheme != null) {
- ebayResp.put("storeDescFontFace", storeFontScheme.get("storeFontTypeFontDescValue"));
- ebayResp.put("storeDescSizeCode", storeFontScheme.get("storeDescSizeValue"));
- ebayResp.put("storeNameFontFace", storeFontScheme.get("storeFontTypeFontFaceValue"));
- ebayResp.put("storeNameFontFaceSize", storeFontScheme.get("storeFontTypeSizeFaceValue"));
- ebayResp.put("storeTitleFontFace", storeFontScheme.get("storeFontTypeFontTitleValue"));
- ebayResp.put("storeTitleFontFaceSize", storeFontScheme.get("storeFontSizeTitleValue"));
- }
- }
- }
- StoreHeaderStyleCodeType storeHeaderStyleCodeType = returnedStoreType.getHeaderStyle();
- ebayResp.put("storeHeaderStyle", storeHeaderStyleCodeType.value());
- StoreHeaderStyleCodeType[] storeHeaderStyleCodeList = storeHeaderStyleCodeType.values();
- if (storeHeaderStyleCodeList != null) {
- List<Map<String,Object>> storeHeaderStyleList = FastList.newInstance();
- int i=0;
- while (i<storeHeaderStyleCodeList.length) {
- Map<String,Object> storeHeaderStyleMap = FastMap.newInstance();
- StoreHeaderStyleCodeType storeHeaderStyleCode = storeHeaderStyleCodeList[i];
- storeHeaderStyleMap.put("storeHeaderStyleName", storeHeaderStyleCode.name());
- storeHeaderStyleMap.put("storeHeaderStyleValue", storeHeaderStyleCode.value());
- storeHeaderStyleList.add(storeHeaderStyleMap);
- i++;
- }
- ebayResp.put("storeHeaderStyleList", storeHeaderStyleList);
- }
- ebayResp.put("storeHomePage", returnedStoreType.getHomePage().toString());
- StoreItemListLayoutCodeType storeItemListLayoutCodeType = returnedStoreType.getItemListLayout();
- ebayResp.put("storeItemLayoutSelected", storeItemListLayoutCodeType.value());
- StoreItemListLayoutCodeType[] storeItemListLayoutCodeTypeList = storeItemListLayoutCodeType.values();
- if (storeItemListLayoutCodeTypeList != null) {
- List<Map<String,Object>> storeItemListLayoutCodeList = FastList.newInstance();
- int i = 0;
- while (i < storeItemListLayoutCodeTypeList.length) {
- Map<String,Object> storeItemListLayoutCodeMap = FastMap.newInstance();
- StoreItemListLayoutCodeType storeItemListLayoutCode = storeItemListLayoutCodeTypeList[i];
- storeItemListLayoutCodeMap.put("storeItemLayoutName", storeItemListLayoutCode.name());
- storeItemListLayoutCodeMap.put("storeItemLayoutValue", storeItemListLayoutCode.value());
- storeItemListLayoutCodeList.add(storeItemListLayoutCodeMap);
- i++;
- }
- ebayResp.put("storeItemLayoutList", storeItemListLayoutCodeList);
- }
- StoreItemListSortOrderCodeType storeItemListSortOrderCodeType = returnedStoreType.getItemListSortOrder();
- ebayResp.put("storeItemSortOrderSelected", storeItemListSortOrderCodeType.value());
- StoreItemListSortOrderCodeType[] storeItemListSortOrderCodeTypeList = storeItemListSortOrderCodeType.values();
- if (storeItemListSortOrderCodeTypeList != null) {
- List<Map<String,Object>> storeItemSortOrderCodeList = FastList.newInstance();
- int i = 0;
- while (i < storeItemListSortOrderCodeTypeList.length) {
- Map<String,Object> storeItemSortOrderCodeMap = FastMap.newInstance();
- StoreItemListSortOrderCodeType storeItemListLayoutCode = storeItemListSortOrderCodeTypeList[i];
- storeItemSortOrderCodeMap.put("storeItemSortLayoutName", storeItemListLayoutCode.name());
- storeItemSortOrderCodeMap.put("storeItemSortLayoutValue", storeItemListLayoutCode.value());
- storeItemSortOrderCodeList.add(storeItemSortOrderCodeMap);
- i++;
- }
- ebayResp.put("storeItemSortOrderList", storeItemSortOrderCodeList);
- }
- ebayResp.put("storeCustomHeader", returnedStoreType.getCustomHeader());
- StoreCustomHeaderLayoutCodeType storeCustomHeaderLayoutCodeType = returnedStoreType.getCustomHeaderLayout();
- ebayResp.put("storeCustomHeaderLayout", storeCustomHeaderLayoutCodeType.value());
- StoreCustomHeaderLayoutCodeType[] storeCustomHeaderLayoutCodeTypeList = storeCustomHeaderLayoutCodeType.values();
- if (storeCustomHeaderLayoutCodeTypeList != null) {
- List<Map<String,Object>> storeCustomHeaderLayoutList = FastList.newInstance();
- int i = 0;
- while (i < storeCustomHeaderLayoutCodeTypeList.length) {
- Map<String,Object> storeCustomHeaderLayoutMap = FastMap.newInstance();
- StoreCustomHeaderLayoutCodeType StoreCustomHeaderLayoutCode = storeCustomHeaderLayoutCodeTypeList[i];
- storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutName", StoreCustomHeaderLayoutCode.name());
- storeCustomHeaderLayoutMap.put("storeCustomHeaderLayoutValue", StoreCustomHeaderLayoutCod…
Large files files are truncated, but you can click here to view the full file