|
Author: hansbak
Date: Sat Feb 6 02:45:55 2010 New Revision: 907161 URL: http://svn.apache.org/viewvc?rev=907161&view=rev Log: improve the ebay category export, update demo data according suggestions for more meaningfull names made in the mailing list Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml ofbiz/trunk/specialpurpose/ebaystore/data/DemoEbayStoreData.xml ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml ofbiz/trunk/specialpurpose/ebaystore/widget/EbayAccountScreens.xml ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreForms.xml ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreScreens.xml Modified: ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java (original) +++ ofbiz/trunk/specialpurpose/ebay/src/org/ofbiz/ebay/EbayHelper.java Sat Feb 6 02:45:55 2010 @@ -82,6 +82,7 @@ buildEbayConfigContext.put("compatibilityLevel", eBayConfig.getString("compatibilityLevel")); buildEbayConfigContext.put("siteID", eBayConfig.getString("siteId")); buildEbayConfigContext.put("xmlGatewayUri", eBayConfig.getString("xmlGatewayUri")); + buildEbayConfigContext.put("apiServerUrl", eBayConfig.getString("apiServerUrl")); } } else { buildEbayConfigContext.put("devID", UtilProperties.getPropertyValue(configFileName, "eBayExport.devID")); @@ -91,6 +92,7 @@ buildEbayConfigContext.put("compatibilityLevel", UtilProperties.getPropertyValue(configFileName, "eBayExport.compatibilityLevel")); buildEbayConfigContext.put("siteID", UtilProperties.getPropertyValue(configFileName, "eBayExport.siteID")); buildEbayConfigContext.put("xmlGatewayUri", UtilProperties.getPropertyValue(configFileName, "eBayExport.xmlGatewayUri")); + buildEbayConfigContext.put("apiServerUrl", UtilProperties.getPropertyValue(configFileName, "eBayExport.xmlGatewayUri")); } return buildEbayConfigContext; } Modified: ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml (original) +++ ofbiz/trunk/specialpurpose/ebay/widget/EbayForms.xml Sat Feb 6 02:45:55 2010 @@ -175,6 +175,7 @@ <field name="compatibilityLevel"><text default-value="${ebayConfig.compatibilityLevel}" size="5"/></field> <field name="siteId"><text default-value="${ebayConfig.siteId}" size="5"/></field> <field name="xmlGatewayUri"><text size="40"/></field> + <field name="apiServerUrl"><text size="40"/></field> <field name="customXml"><textarea cols="60" rows="5"/></field> <field name="webSiteId" title="${uiLabelMap.ProductWebSite}"> <drop-down> Modified: ofbiz/trunk/specialpurpose/ebaystore/data/DemoEbayStoreData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/data/DemoEbayStoreData.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/data/DemoEbayStoreData.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/data/DemoEbayStoreData.xml Sat Feb 6 02:45:55 2010 @@ -20,12 +20,12 @@ <entity-engine-xml> <!-- Ebay Store Demo Data --> - <Party partyId="esandbox10543" partyTypeId="PERSON"/> - <Person partyId="esandbox10543" firstName="Demo ebay account" lastName="USA"/> - <PartyRole partyId="esandbox10543" roleTypeId="EBAY_ACCOUNT"/> - <UserLogin userLoginId="esandbox10543" partyId="esandbox10543" currentPassword="{SHA}bbf272ce445e1c48d94096afdba6a7888c1df1fe"/> - <ProductStore productStoreId="esandbox10543_store" storeName="OFBiz Ebay Store-USA" companyName="Apache Ofbiz" title="Test esandbox10543 store" - subtitle="Part of the Open For Business Family of Open Source Software" payToPartyId="esandbox10543" daysToCancelNonPay="30" prorateShipping="Y" prorateTaxes="Y" + <Party partyId="DemoEbayAccount" partyTypeId="PERSON"/> + <Person partyId="DemoEbayAccount" firstName="Demo ebay account" lastName="USA"/> + <PartyRole partyId="DemoEbayAccount" roleTypeId="EBAY_ACCOUNT"/> + <UserLogin userLoginId="esandbox10543" partyId="DemoEbayAccount" currentPassword="{SHA}bbf272ce445e1c48d94096afdba6a7888c1df1fe"/> + <ProductStore productStoreId="90100" storeName="OFBiz Ebay Store-USA" companyName="Apache Ofbiz" title="Test esandbox10543 store" + subtitle="Part of the Open For Business Family of Open Source Software" payTopartyId="DemoEbayAccount" daysToCancelNonPay="30" prorateShipping="Y" prorateTaxes="Y" inventoryFacilityId="WebStoreWarehouse" oneInventoryFacility="Y" checkInventory="Y" reserveInventory="Y" balanceResOnOrderCreation="Y" reserveOrderEnumId="INVRO_FIFO_REC" requireInventory="N" defaultLocaleString="en_US" defaultCurrencyUomId="USD" defaultSalesChannelEnumId="EBAY_SALES_CHANNEL" allowPassword="Y" explodeOrderItems="N" retryFailedAuths="Y" reqReturnInventoryReceive="N" headerApprovedStatus="ORDER_APPROVED" itemApprovedStatus="ITEM_APPROVED" digitalItemApprovedStatus="ITEM_APPROVED" headerDeclinedStatus="ORDER_REJECTED" @@ -35,12 +35,12 @@ authErrorMessage="Problem connecting to payment processor; we will continue to retry and notify you by email." storeCreditValidDays="90" storeCreditAccountEnumId="FIN_ACCOUNT" visualThemeId="EC_DEFAULT" prodSearchExcludeVariants="Y" autoApproveInvoice="Y" shipIfCaptureFails="Y" autoApproveOrder="Y" showOutOfStockProducts="Y"/> - <ProductStoreRole partyId="esandbox10543" roleTypeId="EBAY_ACCOUNT" productStoreId="esandbox10543_store" fromDate="2010-01-01 16:19:47.058"/> - <ProductStoreCatalog productStoreId="esandbox10543_store" prodCatalogId="eBayCatalog" fromDate="2010-01-01 16:19:47.058"/> - <ProductStoreFacility productStoreId="esandbox10543_store" facilityId="WebStoreWarehouse" fromDate="2010-01-01 16:19:47.058"/> + <ProductStoreRole partyId="DemoEbayAccount" roleTypeId="EBAY_ACCOUNT" productStoreId="90100" fromDate="2010-01-01 16:19:47.058"/> + <ProductStoreCatalog productStoreId="90100" prodCatalogId="eBayCatalog" fromDate="2010-01-01 16:19:47.058"/> + <ProductStoreFacility productStoreId="90100" facilityId="WebStoreWarehouse" fromDate="2010-01-01 16:19:47.058"/> - <WebSite webSiteId="EBAY_STORE" siteName="eBay Store" standardContentPrefix="http://demo.ofbiz.org" productStoreId="esandbox10543_store"/> - <EbayConfig productStoreId="esandbox10543_store" devId="f3586481-93c7-4aaf-ab87-d383d56b71b1" appId="antwebc0f-9bf9-4829-998b-e5e8fb773ac" certId="7f363bc0-11d6-489a-a54d-4a44de82f790" compatibilityLevel="643" siteId="0" xmlGatewayUri="https://api.sandbox.ebay.com/ws/api.dll" apiServerUrl="https://api.sandbox.ebay.com/wsapi" webSiteId="EBAY_STORE"> + <WebSite webSiteId="EBAY_STORE" siteName="eBay Store" standardContentPrefix="http://demo.ofbiz.org" productStoreId="90100"/> + <EbayConfig productStoreId="90100" devId="f3586481-93c7-4aaf-ab87-d383d56b71b1" appId="antwebc0f-9bf9-4829-998b-e5e8fb773ac" certId="7f363bc0-11d6-489a-a54d-4a44de82f790" compatibilityLevel="643" siteId="0" xmlGatewayUri="https://api.sandbox.ebay.com/ws/api.dll" apiServerUrl="https://api.sandbox.ebay.com/wsapi" webSiteId="EBAY_STORE"> <token><![CDATA[AgAAAA**AQAAAA**aAAAAA**PC5MSw**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wJnY+lCZiGoA2dj6x9nY+seQ**0jgBAA**AAMAAA**YxqcpdWbgFwYg1G+3AhOonR2/yllz3IJ5VoJyU75texuETwabGgsN4f6OfeBGWejUx10heCKG7wcM4JI+Fqk8Zg64L51JL3/Vm7dYo8VHd8wfixWIdMmhheYFwOdBtxcTb93NLeJa6uxvBJYrSS7O0RcQ3KPhOVJvt7KfVT009o2/02tuX7vbMoHV+Meszli4eVAnB9Fbt6ag2nq46+2/AzMIO4rZE23ozLfh6c4W+QkD6BcaFzLmhVE+7Ni9y7y26QHfUUdjBOEF6ewLpZJsSIoQZC9y4J/yF15Ann9NiamtmFj5IeX4uNIKegEt8EwFSqtpxjgVngcAmMaM8/hk9uQVnFKHTjhK3koUrT7zu/+tk2twJfGF9odb+/5uTVJZ8Lywl/LwEdadv2wjpTdQqHF2bV84cSRhOKrlsYr9xFqgqNDpnmCFXkQKGhycWzMzxcBmiRT5VXJfBjbTGGdmfAf7TVcoU/4C3F3kvzEJhcxU9WbMvj58TmW+VvYS7oy4kOyTiyr3alkz/+HJYGIuttnkzqsIVIPaSXyyuFNWQmQL+0GlJ1n7EoKCevuVsTYgayQEN39TPeXg8ADmf5Pf19BlPxRFNkKvANxE0k3ac+whUwpkfBgx6lApOcwKQMXioi7NrN3MROL/1qrO2+N5sl4kr9nbuvEk9mPDJnmNdB7lzgoESo+se3ZmY9KJ6v08uQ02N1/SjHtmeiojayaR/DqeJiFSoAnU4winzA5GQGNjzEHUpSf1Kj+IZudhT9r]]></token> <customXml><![CDATA[<custom-xml><Currency>USD</Currency><UseTaxTable>false</UseTaxTable><DispatchTimeMax>3</DispatchTimeMax><ReturnPolicy><ReturnsAcceptedOption>ReturnsNotAccepted</ReturnsAcceptedOption></ReturnPolicy><ShippingDetails><ShippingType>Flat</ShippingType><ShippingServiceOptions><ShippingService>UPS2ndDay</ShippingService><ShippingServicePriority>1</ShippingServicePriority><ShippingServiceCost>5</ShippingServiceCost><ShippingServiceAdditionalCost>2</ShippingServiceAdditionalCost><ShippingSurcharge>1</ShippingSurcharge></ShippingServiceOptions></ShippingDetails></custom-xml>]]></customXml> </EbayConfig> Modified: ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/servicedef/services.xml Sat Feb 6 02:45:55 2010 @@ -42,6 +42,7 @@ location="org.ofbiz.ebaystore.EbayStore" invoke="exportCategoriesSelectedToEbayStore" auth="true"> <description>Export categories in store to eBay store</description> <attribute name="productStoreId" type="String" mode="IN" optional="false"/> + <attribute name="partyId" type="String" mode="IN" optional="false"/> <attribute name="prodCatalogId" type="String" mode="IN" optional="false"/> </service> Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java (original) +++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStore.java Sat Feb 6 02:45:55 2010 @@ -87,10 +87,15 @@ import com.ebay.soap.eBLBaseComponents.SellingManagerProductType; import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsArrayType; import com.ebay.soap.eBLBaseComponents.SellingManagerTemplateDetailsType; +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.StoreCustomListingHeaderLinkCodeType; @@ -108,6 +113,8 @@ 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 java.sql.Timestamp; import java.util.TimeZone; @@ -187,56 +194,209 @@ } return outputBuilder.toString(); } - - public static Map exportCategoriesSelectedToEbayStore(DispatchContext dctx, Map context) { + /* 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(); - Map response = null; - Map<String, Object> eBayConfigResult = EbayHelper.buildEbayConfig(context, delegator); - StringBuffer dataStoreXml = new StringBuffer(); + 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 { - // GetStore // - Map resultMap = buildGetStoreXml(context, dataStoreXml, eBayConfigResult.get("token").toString(), eBayConfigResult.get("siteID").toString()); - if (!ServiceUtil.isFailure(resultMap)) { - response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataStoreXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "GetStore", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString()); - String successMessage = (String)response.get("successMessage"); - if (successMessage != null) { - String isSuccess = readEbayResponse(successMessage, context.get("productStoreId").toString()); - if (isSuccess == "success"){ - List<GenericValue> catalogCategories = null; - if(UtilValidate.isNotEmpty(context.get("prodCatalogId"))){ - catalogCategories = delegator.findByAnd("ProdCatalogCategory", UtilMisc.toMap("prodCatalogId", context.get("prodCatalogId").toString())); - } - if (catalogCategories != null){ - String isSuccess2 = ""; - Iterator categoriesListIter = catalogCategories.iterator(); - while (categoriesListIter.hasNext()) { - GenericValue catalogCategory = (GenericValue) categoriesListIter.next(); - String prodCategoryId = catalogCategory.getString("productCategoryId").toString(); - - StringBuffer dataCategoriesXml = new StringBuffer(); - Map resultCategoriesMap = buildSetStoreCategoriesXml(dctx, context, dataCategoriesXml, eBayConfigResult.get("token").toString(), eBayConfigResult.get("siteID").toString(), prodCategoryId); - if (!ServiceUtil.isFailure(resultCategoriesMap)) { - response = postItem(eBayConfigResult.get("xmlGatewayUri").toString(), dataCategoriesXml, eBayConfigResult.get("devID").toString(), eBayConfigResult.get("appID").toString(), eBayConfigResult.get("certID").toString(), "SetStoreCategories", eBayConfigResult.get("compatibilityLevel").toString(), eBayConfigResult.get("siteID").toString()); - String successMessage2 = (String)response.get("successMessage"); - if (successMessage2 != null) { - isSuccess2 = readEbayResponse(successMessage2, context.get("productStoreId").toString()); + + 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; } } } } - } else { - ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(response)); + 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())); } - } else { - return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(resultMap)); } - result.put(ModelService.SUCCESS_MESSAGE, "Export categories success..."); - } catch (Exception e) { - Debug.logError("Exception in exportCategoriesSelectedToEbayStore : " + e, module); - return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToEbay.exceptionInGetEbayCategories", locale)); + } 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; } Modified: ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java (original) +++ ofbiz/trunk/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreHelper.java Sat Feb 6 02:45:55 2010 @@ -40,6 +40,7 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; @@ -139,4 +140,100 @@ } return SiteCodeType.US; } + + public static boolean validatePartyAndRoleType(Delegator delegator,String partyId){ + GenericValue partyRole = null; + try { + if (partyId == null) { + Debug.logError("Require field partyId.",module); + return false; + } + partyRole = delegator.findByPrimaryKey("PartyRole", UtilMisc.toMap("partyId", partyId,"roleTypeId","EBAY_ACCOUNT")); + if (partyRole == null) { + Debug.logError("Party Id ".concat(partyId).concat("not have roleTypeId EBAY_ACCOUNT"),module); + return false; + } + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + return false; + } + return true; + } + public static String retriveEbayCategoryIdByPartyId(Delegator delegator,String productCategoryId,String partyId){ + String ebayCategoryId = null; + List<GenericValue> productCategoryRoles = null; + try { + if (partyId == null) { + Debug.logError("Require field partyId.",module); + return ebayCategoryId; + } + productCategoryRoles = delegator.findByAnd("ProductCategoryRole", UtilMisc.toMap("productCategoryId",productCategoryId,"partyId", partyId,"roleTypeId","EBAY_ACCOUNT")); + if (productCategoryRoles != null && productCategoryRoles.size()>0) { + for (GenericValue productCategoryRole : productCategoryRoles) { + ebayCategoryId = productCategoryRole.getString("comments"); + } + } else { + Debug.logInfo("Party Id ".concat(partyId).concat(" Not found productCategoryRole with productCategoryId "+productCategoryId),module); + return ebayCategoryId; + } + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + return ebayCategoryId; + } + public static boolean createEbayCategoryIdByPartyId(Delegator delegator,String productCategoryId,String partyId,String ebayCategoryId){ + + try { + if (partyId == null && ebayCategoryId != null) { + Debug.logError("Require field partyId and ebayCategoryId.",module); + return false; + } + GenericValue productCategoryRole = delegator.makeValue("ProductCategoryRole"); + productCategoryRole.put("productCategoryId",productCategoryId); + productCategoryRole.put("partyId", partyId); + productCategoryRole.put("roleTypeId","EBAY_ACCOUNT"); + productCategoryRole.put("fromDate",UtilDateTime.nowTimestamp()); + productCategoryRole.put("comments",ebayCategoryId); + productCategoryRole.create(); + + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + return false; + } + return true; + } + public static boolean veriflyCategoryInCatalog(Delegator delegator,List<GenericValue> catalogCategories,String productCategoryId){ + boolean flag = false; + try { + for (GenericValue catalogCategory : catalogCategories) { + // check in productCatalogCategory first level 0 + if (catalogCategory.containsValue(productCategoryId)) { + flag = true; + break; + } else { + // check from child category level 1 + List<GenericValue> productCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",catalogCategory.getString("productCategoryId"))); + for (GenericValue productCategoryRollup : productCategoryRollupList) { + if (productCategoryRollup.containsValue(productCategoryId)) { + flag = true; + break; + } else { + // check from level 2 + List<GenericValue> prodCategoryRollupList = delegator.findByAnd("ProductCategoryRollup", UtilMisc.toMap("parentProductCategoryId",productCategoryRollup.getString("productCategoryId"))); + for (GenericValue prodCategoryRollup : prodCategoryRollupList) { + if (prodCategoryRollup.containsValue(productCategoryId)) { + flag = true; + break; + } + } + } + } + } + } + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + return false; + } + return flag; + } } Modified: ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml Sat Feb 6 02:45:55 2010 @@ -29,13 +29,17 @@ <security https="true" auth="true"/> <response name="success" type="view" value="main"/> </request-map> - <!-- Export categories selected to Ebay store --> + <!-- Export categories selected to Ebay store --> <request-map uri="exportCategoryEbayStore"> <security https="true" auth="true"/> <response name="success" type="view" value="exportCategoryEbayStore"/> <response name="error" type="view" value="exportCategoryEbayStore"/> </request-map> - + <request-map uri="getChildCategory"> + <security https="true" auth="true"/> + <response name="success" type="view" value="exportCategoryEbayStore"/> + <response name="error" type="view" value="exportCategoryEbayStore"/> + </request-map> <request-map uri="exportCategoriesSelectedToEbayStore"> <security https="true" auth="true"/> <event type="service" invoke="exportCategoriesSelectedToEbayStore"/> Modified: ofbiz/trunk/specialpurpose/ebaystore/widget/EbayAccountScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/widget/EbayAccountScreens.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/widget/EbayAccountScreens.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/widget/EbayAccountScreens.xml Sat Feb 6 02:45:55 2010 @@ -28,7 +28,7 @@ </actions> <widgets> <screenlet name="" title="${uiLabelMap.EbayPersonalInformation}"> - <include-form location="component://ebay/widget/EbayAccountForms.xml" name="EbayPersonalInformationForm"/> + <include-form location="component://ebaystore/widget/EbayAccountForms.xml" name="EbayPersonalInformationForm"/> </screenlet> </widgets> </section> Modified: ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreForms.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreForms.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreForms.xml Sat Feb 6 02:45:55 2010 @@ -34,7 +34,7 @@ <form name="EbayAccountList" type="single" list-name="ebayAccountList" target="getStoreDetail" odd-row-style="alternate-row" default-table-style="basic-table hover-bar"> <actions> - <script location="component://ebay/webapp/ebay/WEB-INF/actions/store/StoreAccount.groovy"/> + <script location="component://ebaystore/webapp/ebaystore/WEB-INF/actions/store/StoreAccount.groovy"/> </actions> <field name="productStoreId" title="Account" > <drop-down current="selected"> @@ -43,7 +43,7 @@ </field> <field name="submitButton" ><submit button-type="button"/></field> </form> - <form name="ListCurrentStores" type="single" target="exportCategoriesSelectedToEbayStore" + <form name="ListCurrentStores" type="single" target="exportCategoryEbayStore" header-row-style="header-row" default-table-style="basic-table"> <actions> <entity-and entity-name="ProductStoreCatalog" list="storeCatalog"> @@ -59,7 +59,42 @@ </entity-options--> </drop-down> </field> - <field name="submitButton" title="${uiLabelMap.EbayExportToEbayStore}"><submit button-type="button"/></field> + <field name="submitButton" title="Find"><submit button-type="button"/></field> + </form> + <form name="ListCategories" type="multi" use-row-submit="true" target="deleteCategoriesFromEbayStore" title="" list-name="categoriesList" + odd-row-style="alternate-row" default-table-style="basic-table hover-bar"> + <row-actions> + <entity-one entity-name="ProductCategory" value-field="prodCategory"> + <field-map field-name="productCategoryId" value="${productCategoryId}"/> + </entity-one> + <entity-and entity-name="ProductCategoryRole" list="prodCategoryRoles"> + <field-map field-name="productCategoryId" value="${productCategoryId}"/> + <field-map field-name="partyId" value="${parameters.partyId}"/> + <field-map field-name="roleTypeId" value="EBAY_ACCOUNT"/> + </entity-and> + <set field="ebayCategoryId" value="${groovy: + ebayCategoryId= ""; + if(prodCategoryRoles!=null && prodCategoryRoles.size()== 1) ebayCategoryId = prodCategoryRoles.get(0).getString("comments"); + return ebayCategoryId; + }" type="String"/> + <entity-and entity-name="ProductCategoryRollup" list="prodCategoryRollup"> + <field-map field-name="parentProductCategoryId" value="${productCategoryId}"/> + </entity-and> + </row-actions> + <field name="_rowSubmit" position="1" title="${uiLabelMap.CommonSelect}"><check/></field> + <field name="productStoreId"><hidden/></field> + <field name="prodCatalogId"><hidden/></field> + <field name="productCategoryId"><display></display></field> + <field name="categoryName"> + <hyperlink target="getChildCategory" description="${prodCategory.categoryName}"> + <parameter param-name="productStoreId"/> + <parameter from-field="parameters.prodCatalogId" param-name="prodCatalogId"/> + <parameter param-name="productCategoryId"/> + </hyperlink> + </field> + <field name="comments" title="Ebay Category Id"><display description="${ebayCategoryId}"></display></field> + <field name="subCategory"><display description="${groovy:prodCategoryRollup.size()}"></display></field> + <field name="updateButton" title="${uiLabelMap.CommonDelete}"><submit button-type="button"/></field> </form> <form name="NewEbayAccount" type="single" target="createEbayAccount"> <auto-fields-service service-name="createEbayAccount"/> Modified: ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreScreens.xml?rev=907161&r1=907160&r2=907161&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreScreens.xml (original) +++ ofbiz/trunk/specialpurpose/ebaystore/widget/EbayStoreScreens.xml Sat Feb 6 02:45:55 2010 @@ -62,19 +62,83 @@ </section> </screen> <screen name="exportCategoryEbayStore"> - <section> - <actions> - <set field="titleProperty" value="EbayExportAllCategoryToEbayStore"/> - <set field="headerItem" value="ebayStore"/> - <set field="tabButtonItem" value="ebayExportAllCategoryToEbayStore"/> - <set field="productStoreId" value="${parameters.productStoreId}"/> - </actions> - <widgets> - <decorator-screen name="permission-decorator" location="${parameters.mainDecoratorLocation}"> - <decorator-section name="body"> - <screenlet title="${uiLabelMap.EbayExportAllCategoryToEbayStore}"> - <include-form name="ListCurrentStores" location="component://ebaystore/widget/EbayStoreForms.xml"/> - </screenlet> + <section> + <actions> + <set field="titleProperty" value="EbayExportAllCategoryToEbayStore"/> + <set field="headerItem" value="ebayStore"/> + <set field="tabButtonItem" value="ebayExportAllCategoryToEbayStore"/> + <set field="productStoreId" value="${parameters.productStoreId}"/> + <entity-and entity-name="ProdCatalogCategory" list="categoriesList"> + <field-map field-name="prodCatalogId" from-field="parameters.prodCatalogId"/> + <order-by field-name="productCategoryId"/> + </entity-and> + <entity-one entity-name="ProdCatalog" value-field="prodCatalog"> + <field-map field-name="prodCatalogId" from-field="parameters.prodCatalogId"/> + <select-field field-name="catalogName"/> + </entity-one> + </actions> + <widgets> + <decorator-screen name="permission-decorator" location="${parameters.mainDecoratorLocation}"> + <decorator-section name="body"> + <section> + <condition> + <not> + <if-empty field="parameters.productCategoryId"/> + </not> + </condition> + <actions> + <entity-and entity-name="ProductCategoryRollup" list="categoriesRollupList"> + <field-map field-name="parentProductCategoryId" from-field="parameters.productCategoryId"/> + <order-by field-name="productCategoryId"/> + </entity-and> + </actions> + <widgets> + <section> + <condition> + <not> + <if-empty field="categoriesRollupList"/> + </not> + </condition> + <actions> + <set field="categoriesList" from-field="nullField"/> + <set field="categoriesList" from-field="categoriesRollupList"/> + </actions> + <widgets> + <screenlet> + <screenlet title="${uiLabelMap.EbayExportAllCategoryToEbayStore}"> + <include-form name="ListCurrentStores" location="component://ebaystore/widget/EbayStoreForms.xml"/> + </screenlet> + <screenlet navigation-form-name="ListCategories" title="List category in ${prodCatalog.catalogName}"> + <include-form name="ListCategories" location="component://ebaystore/widget/EbayStoreForms.xml"/> + </screenlet> + </screenlet> + </widgets> + <fail-widgets> + <screenlet title="${uiLabelMap.EbayExportAllCategoryToEbayStore}"> + <include-form name="ListCurrentStores" location="component://ebaystore/widget/EbayStoreForms.xml"/> + </screenlet> + <screenlet navigation-form-name="ListCategories" title="List category in ${prodCatalog.catalogName}"> + <label text="Not found child category"/> + </screenlet> + </fail-widgets> + </section> + </widgets> + <fail-widgets> + <screenlet> + <screenlet title="${uiLabelMap.EbayExportAllCategoryToEbayStore}"> + <include-form name="ListCurrentStores" location="component://ebaystore/widget/EbayStoreForms.xml"/> + </screenlet> + <screenlet navigation-form-name="ListCategories" title="List category in ${prodCatalog.catalogName}"> + <include-form name="ListCategories" location="component://ebaystore/widget/EbayStoreForms.xml"/> + </screenlet> + <link name="exportCategoriesSelectedToEbayStore" target="exportCategoriesSelectedToEbayStore" style="buttontext" text="${uiLabelMap.EbayExportToEbayStore}"> + <parameter param-name="productStoreId" from-field="productStoreId"/> + <parameter param-name="prodCatalogId" from-field="parameters.prodCatalogId"/> + <parameter param-name="partyId" from-field="parameters.partyId"/> + </link> + </screenlet> + </fail-widgets> + </section> </decorator-section> </decorator-screen> </widgets> |
| Free forum by Nabble | Edit this page |
