Author: jacopoc
Date: Fri Jul 6 03:35:12 2007 New Revision: 553830 URL: http://svn.apache.org/viewvc?view=rev&rev=553830 Log: Applied patch by Marco Risaliti with a lot of improvements to the Google Export integration. Part of OFBIZ-1095 Modified: ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties ofbiz/trunk/applications/product/servicedef/services.xml ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl ofbiz/trunk/framework/common/config/CommonUiLabels.properties ofbiz/trunk/framework/common/config/CommonUiLabels_it.properties Modified: ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties (original) +++ ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties Fri Jul 6 03:35:12 2007 @@ -552,6 +552,9 @@ ProductExpireDate=Data Scadenza ProductExpireResultsFrom=Risultati Scaduti Da ProductExplodeOrderItems=Esplodi Righe Ordine +ProductExportDeactivated=Disattiva +ProductExportPublish=Pubblica +ProductExportPublishDraft=Pubblica come Bozza ProductExportToGoogle=Esportazione Su Google Base ProductExportNoTrackingRequested=Non Richiesto ProductFacilities=Stabilimenti Modified: ofbiz/trunk/applications/product/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services.xml Fri Jul 6 03:35:12 2007 @@ -1119,9 +1119,11 @@ <service name="exportToGoogle" engine="java" location="org.ofbiz.product.product.ProductsExportToGoogle" invoke="exportToGoogle" auth="true"> <description>Export products to Google Base</description> - <attribute type="String" mode="IN" name="products" optional="false"/> + <attribute type="List" mode="IN" name="selectResult" optional="false"/> <attribute type="String" mode="IN" name="webSiteUrl" optional="false"/> <attribute type="String" mode="IN" name="imageUrl" optional="false"/> + <attribute type="String" mode="IN" name="actionType" optional="false"/> + <attribute type="String" mode="IN" name="statusId" optional="false"/> <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/> </service> </services> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java Fri Jul 6 03:35:12 2007 @@ -60,7 +60,6 @@ private static final String resource = "ProductUiLabels"; private static final String module = ProductsExportToGoogle.class.getName(); - private static final String xmlHeader = "<?xml version=\'1.0\' encoding='UTF-8'?>\n"; public static Map exportToGoogle(DispatchContext dctx, Map context) { Locale locale = (Locale) context.get("locale"); @@ -84,17 +83,20 @@ StringBuffer dataItemsXml = new StringBuffer(); - if (!ServiceUtil.isFailure(buildDataItemsXml(dctx, context, dataItemsXml))) { + Map result = buildDataItemsXml(dctx, context, dataItemsXml); + if (!ServiceUtil.isFailure(result)) { String token = authenticate(authenticationUrl, accountEmail, accountPassword); if (token != null) { - Map result = postItem(token, postItemsUrl, developerKey, dataItemsXml); + result = postItem(token, postItemsUrl, developerKey, dataItemsXml); if (ServiceUtil.isFailure(result)) return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(result)); } else { Debug.logError("Error during authentication to Google Account", module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.errorDuringAuthenticationToGoogle", locale)); } + } else { + return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(result)); } } catch (Exception e) { Debug.logError("Exception in exportToGoogle", module); @@ -208,7 +210,7 @@ result = ServiceUtil.returnSuccess(toString(inputStream)); } else if (responseCode == HttpURLConnection.HTTP_OK) { inputStream = connection.getInputStream(); - result = ServiceUtil.returnFailure(toString(inputStream)); + result = ServiceUtil.returnSuccess(toString(inputStream)); } else { inputStream = connection.getErrorStream(); result = ServiceUtil.returnFailure(toString(inputStream)); @@ -221,13 +223,15 @@ try { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - String products = (String)context.get("products"); + List selectResult = (List)context.get("selectResult"); String webSiteUrl = (String)context.get("webSiteUrl"); String imageUrl = (String)context.get("imageUrl"); + String actionType = (String)context.get("actionType"); + String statusId = (String)context.get("statusId"); String trackingCodeId = (String)context.get("trackingCodeId"); // Get the list of products to be exported to Google Base - List productsList = delegator.findByCondition("Product", new EntityExpr("productId", EntityOperator.IN, StringUtil.split(products, ",")), null, null); + List productsList = delegator.findByCondition("Product", new EntityExpr("productId", EntityOperator.IN, selectResult), null, null); // Get the tracking code if (UtilValidate.isEmpty(trackingCodeId) || "_NA_".equals(trackingCodeId)) { @@ -244,8 +248,6 @@ feedElem.setAttribute("xmlns:g", "http://base.google.com/ns/1.0"); feedElem.setAttribute("xmlns:batch", "http://schemas.google.com/gdata/batch"); - dataItemsXml.append(xmlHeader); - // Iterate the product list getting all the relevant data Iterator productsListItr = productsList.iterator(); while(productsListItr.hasNext()) { @@ -265,7 +267,7 @@ Element entryElem = UtilXml.addChildElement(feedElem, "entry", feedDocument); Element batchElem = UtilXml.addChildElement(entryElem, "batch:operation", feedDocument); - batchElem.setAttribute("type", "insert"); + batchElem.setAttribute("type", actionType); UtilXml.addChildElementValue(entryElem, "title", title, feedDocument); @@ -290,16 +292,8 @@ appControlElem.setAttribute("xmlns:app", "http://purl.org/atom/app#"); UtilXml.addChildElementValue(appControlElem, "app:draft", "yes", feedDocument); } - OutputStream os = new ByteArrayOutputStream(); - OutputFormat format = new OutputFormat(); - format.setOmitDocumentType(true); - format.setOmitXMLDeclaration(true); - format.setIndenting(false); - XMLSerializer serializer = new XMLSerializer(os, format); - serializer.asDOMSerializer(); - serializer.serialize(feedDocument.getDocumentElement()); - dataItemsXml.append(os.toString()); + dataItemsXml.append(UtilXml.writeXmlDocument(feedDocument)); } catch (Exception e) { Debug.logError("Exception during building data items to Google", module); return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.exceptionDuringBuildingDataItemsToGoogle", locale)); @@ -318,18 +312,8 @@ boolean validPriceFound = ((Boolean)map.get("validPriceFound")).booleanValue(); boolean isSale = ((Boolean)map.get("isSale")).booleanValue(); if (validPriceFound) { - // "price" is a mandatory output - priceString = UtilFormatOut.formatPrice((Double)map.get("price")); - } - /* - if (isSale && null != map.get("price")) { priceString = UtilFormatOut.formatPrice((Double)map.get("price")); - } else if (null != map.get("defaultPrice")) { - priceString = UtilFormatOut.formatPrice((Double)map.get("defaultPrice")); - } else if (null != map.get("listPrice")) { - priceString = UtilFormatOut.formatPrice((Double)map.get("listPrice")); } - */ } catch(Exception e){ Debug.logError("Exception calculating price for product [" + product.getString("productId") + "]", module); } Modified: ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml (original) +++ ofbiz/trunk/applications/product/webapp/catalog/find/ExportForms.xml Fri Jul 6 03:35:12 2007 @@ -20,11 +20,26 @@ <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-form.xsd"> - <form name="ProductsExportToGoogle" type="single" target="exportProductsToGoogle"> - <field name="products"><hidden/></field> + <field name="selectResult"><hidden/></field> <field name="webSiteUrl"><text size="50" maxlength="250"/></field> <field name="imageUrl"><text size="50" maxlength="250"/></field> + <field name="actionType" widget-style="selectBox"> + <drop-down no-current-selected-key="insert"> + <option key="insert" description="${uiLabelMap.CommonInsert}"/> + <option key="update" description="${uiLabelMap.CommonUpdate}"/> + <!-- for the moment delete action type is not allowed + <option key="delete" description="${uiLabelMap.CommonDelete}"/> + --> + </drop-down> + </field> + <field name="statusId" widget-style="selectBox"> + <drop-down no-current-selected-key="deactivate"> + <option key="deactivate" description="${uiLabelMap.ProductExportDeactivated}"/> + <option key="draft" description="${uiLabelMap.ProductExportPublishDraft}"/> + <option key="publish" description="${uiLabelMap.ProductExportPublish}"/> + </drop-down> + </field> <field name="trackingCodeId" widget-style="selectBox"> <drop-down no-current-selected-key="_NA_"> <option key="_NA_" description="${uiLabelMap.ProductExportNoTrackingRequested}"/> Modified: ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl (original) +++ ofbiz/trunk/applications/product/webapp/catalog/find/keywordsearch.ftl Fri Jul 6 03:35:12 2007 @@ -29,26 +29,6 @@ </#if> <#if productIds?has_content> -<table border="0" width="100%" cellpadding="2"> - <tr> - <td align="right"> - <b> - <#if 0 < viewIndex?int> - <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> | - </#if> - <#if 0 < listSize?int> - <span class="tabletext">${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize}</span> - </#if> - <#if highIndex?int < listSize?int> - | <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a> - </#if> - </b> - </td> - </tr> -</table> -</#if> - -<#if productIds?has_content> <script language="JavaScript" type="text/javascript"> function checkProductToBagTextArea(field, idValue) { fullValue = idValue + "\n"; @@ -68,36 +48,57 @@ } } - function exportToGoogle() { - var products = new Array(); - var idx = 0; - for (var i = 0; i < document.products.elements.length; i++) { - var element = document.products.elements[i]; - var sname = element.name.substring(0,12); - var product = "product" + element.name.substring(12); - if (sname == "selectResult" && element.checked) { - products[idx] = document.products.elements[product].value; - idx++; + function toggleAll(e) { + var cform = document.products; + var len = cform.elements.length; + for (var i = 0; i < len; i++) { + var element = cform.elements[i]; + if (element.name == "selectResult" && element.checked != e.checked) { + toggle(element); } } - if (idx == 0) { - alert('At least one product has to be selected'); - } else { - document.exportToGoogle.action="<@ofbizUrl>ProductsExportToGoogle</@ofbizUrl>"; - document.exportToGoogle.products.value = products; - document.exportToGoogle.submit(); - } + } + + function toggle(e) { + e.checked = !e.checked; + } + + function exportToGoogle() { + document.products.action="<@ofbizUrl>ProductsExportToGoogle</@ofbizUrl>"; + document.products.submit(); } </script> -<form name="products"> + +<#if productIds?has_content> +<table border="0" width="100%" cellpadding="2"> + <tr> + <td align="left"><input type="checkbox" name="selectAll" value="0" onclick="javascript:toggleAll(this);"> <b>${uiLabelMap.ProductProduct}</b></td> + <td align="right"> + <b> + <#if 0 < viewIndex?int> + <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> | + </#if> + <#if 0 < listSize?int> + <span class="tabletext">${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize}</span> + </#if> + <#if highIndex?int < listSize?int> + | <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a> + </#if> + </b> + </td> + </tr> + <tr><td colspan="2"><hr class="sepbar"/></td></tr> +</table> +</#if> + +<form method="post" name="products"> <table width="100%" cellpadding="0" cellspacing="0"> <#assign listIndex = lowIndex> <#list productIds as productId><#-- note that there is no boundary range because that is being done before the list is put in the content --> <#assign product = delegator.findByPrimaryKey("Product", Static["org.ofbiz.base.util.UtilMisc"].toMap("productId", productId))> <tr> <td> - <input type="hidden" name="product${productId_index}" value="${productId}"/> - <input type="checkbox" name="selectResult${productId_index}" onchange="checkProductToBagTextArea(this, '${productId}');"/> + <input type="checkbox" name="selectResult" value="${productId}" onchange="checkProductToBagTextArea(this, '${productId}');"/> <a href="<@ofbizUrl>EditProduct?productId=${productId}</@ofbizUrl>" class="buttontext">[${productId}] ${(product.internalName)?if_exists}</a> </td> </tr> @@ -112,13 +113,13 @@ <td align="right"> <b> <#if 0 < viewIndex?int> - <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">[${uiLabelMap.CommonPrevious}]</a> | + <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex-1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonPrevious}</a> | </#if> <#if 0 < listSize?int> <span class="tabletext">${lowIndex+1} - ${highIndex} ${uiLabelMap.CommonOf} ${listSize}</span> </#if> <#if highIndex?int < listSize?int> - | <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">[${uiLabelMap.CommonNext}]</a> + | <a href="<@ofbizUrl>keywordsearch/~VIEW_INDEX=${viewIndex+1}/~VIEW_SIZE=${viewSize}/~clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonNext}</a> </#if> </b> </td> @@ -221,9 +222,6 @@ <b>${uiLabelMap.ProductSearchExportProductList}:</b> <a href="<@ofbizUrl>searchExportProductList?clearSearch=N</@ofbizUrl>" class="buttontext">${uiLabelMap.ProductSearchExport}</a> <#if productIds?has_content> <a href="javascript:exportToGoogle();" class="buttontext">${uiLabelMap.ProductExportToGoogle}</a> - <form method="post" name="exportToGoogle"> - <input type="hidden" name="products"> - </form> </#if> </div> </#if> Modified: ofbiz/trunk/framework/common/config/CommonUiLabels.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels.properties?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/framework/common/config/CommonUiLabels.properties (original) +++ ofbiz/trunk/framework/common/config/CommonUiLabels.properties Fri Jul 6 03:35:12 2007 @@ -207,6 +207,7 @@ CommonInThe=In The CommonInformation=Information CommonInput=Input +CommonInsert=Insert CommonInto=Into CommonIntroductionDate=Introduction Date CommonIsA=is a @@ -290,6 +291,8 @@ CommonOther=Other CommonOverridesSelection=(overrides either of the above selections.) CommonPage=Page +CommonPagingOff=Paging Off +CommonPagingOn=Paging On CommonPartyID=Party Id CommonPassword=Password CommonPasswordChange=Please Change Your Password Modified: ofbiz/trunk/framework/common/config/CommonUiLabels_it.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/config/CommonUiLabels_it.properties?view=diff&rev=553830&r1=553829&r2=553830 ============================================================================== --- ofbiz/trunk/framework/common/config/CommonUiLabels_it.properties (original) +++ ofbiz/trunk/framework/common/config/CommonUiLabels_it.properties Fri Jul 6 03:35:12 2007 @@ -197,6 +197,7 @@ CommonInThe=Nel CommonInformation=Informazione CommonInput=Input +CommonInsert=Inserisci CommonInto=Nel CommonIntroductionDate=Data Introduzione CommonIsA=\u00e8 un @@ -278,6 +279,8 @@ CommonOther=Altro CommonOverridesSelection=(sovrapponi entrambe le selezioni sopra) CommonPage=Pagina +CommonPagingOff=Disattiva Paginazione +CommonPagingOn=Attiva Paginazione CommonPartyID=Codice Soggetto CommonPassword=Password CommonPerform=Esegui |
Free forum by Nabble | Edit this page |