svn commit: r564490 - in /ofbiz/trunk/applications/product: config/ProductUiLabels.properties config/ProductUiLabels_it.properties servicedef/services.xml src/org/ofbiz/product/product/ProductsExportToGoogle.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r564490 - in /ofbiz/trunk/applications/product: config/ProductUiLabels.properties config/ProductUiLabels_it.properties servicedef/services.xml src/org/ofbiz/product/product/ProductsExportToGoogle.java

jacopoc
Author: jacopoc
Date: Thu Aug  9 23:53:05 2007
New Revision: 564490

URL: http://svn.apache.org/viewvc?view=rev&rev=564490
Log:
Implemented service to bulk export all the products in a category to Google.

Modified:
    ofbiz/trunk/applications/product/config/ProductUiLabels.properties
    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

Modified: ofbiz/trunk/applications/product/config/ProductUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/config/ProductUiLabels.properties?view=diff&rev=564490&r1=564489&r2=564490
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels.properties (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels.properties Thu Aug  9 23:53:05 2007
@@ -1490,11 +1490,15 @@
 productsExportToEbay.exceptionDuringBuildingDataItemsToEbay=Exception occurred during building data items to eBay
 productsExportToEbay.exceptionInExportToEbay=Exception in exportToEbay
 productsExportToEbay.productItemsSentCorrecltyToEbay=Product items sent correclty to eBay
+productsExportToGoogle.cannotRetrieveUserLogin=Cannot retrieve User Login
 productsExportToGoogle.errorDuringAuthenticationToGoogle=Error during authentication to Google Account
 productsExportToGoogle.errorInTheResponseFromGoogle=Error in the response from Google :
 productsExportToGoogle.exceptionDuringBuildingDataItemsToGoogle=Exception occurred during building data items to Google Base
+productsExportToGoogle.exceptionInExportProductCategoryToGoogle=Exception in exportProductCategoryToGoogle
 productsExportToGoogle.exceptionInExportToGoogle=Exception in exportToGoogle
 productsExportToGoogle.exceptionReadingResponseFromGoogle=Exception reading response from Google
+productsExportToGoogle.missingParameterProductCategoryId=Missing parameter productCategoryId
+productsExportToGoogle.noProductsAvailableInProductCategory=No products available in the selected productCategoryId
 productsExportToGoogle.productItemsSentCorrecltyToGoogle=Product items sent correclty to Google Base
 productsearchevents.added_x_product_category_members=Added ${numAdded} product category members.
 productsearchevents.error_getting_search_results=Error getting search results: ${errSearchResult}.
@@ -1899,4 +1903,4 @@
 FormFieldTitle_paymentPersonalCheck=Personal check
 FormFieldTitle_listingDuration=Listing Duration
 FormFieldTitle_startPrice=Start Price
-FormFieldTitle_testMode=Test mode
\ No newline at end of file
+FormFieldTitle_testMode=Test mode

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=564490&r1=564489&r2=564490
==============================================================================
--- ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties (original)
+++ ofbiz/trunk/applications/product/config/ProductUiLabels_it.properties Thu Aug  9 23:53:05 2007
@@ -1473,11 +1473,15 @@
 productsExportToEbay.exceptionDuringBuildingDataItemsToEbay=Eccezione accaduta durante la creazione dei dati prodotti per eBay
 productsExportToEbay.exceptionInExportToEbay=Eccezione in exportToEbay
 productsExportToEbay.productItemsSentCorrecltyToEbay=Prodotti inviati correttamente su eBay
+productsExportToGoogle.cannotRetrieveUserLogin=Non \u00e8 ricavare User Login
 productsExportToGoogle.errorDuringAuthenticationToGoogle=Errore durante l\'autenticazione su Google Account
 productsExportToGoogle.errorInTheResponseFromGoogle=Errore nella risposta di Google :
 productsExportToGoogle.exceptionDuringBuildingDataItemsToGoogle=Eccezione accaduta durante la creazione dei dati prodotti per Google Base
+productsExportToGoogle.exceptionInExportProductCategoryToGoogle=Eccezione in exportProductCategoryToGoogle
 productsExportToGoogle.exceptionInExportToGoogle=Eccezione in exportToGoogle
 productsExportToGoogle.exceptionReadingResponseFromGoogle=Eccezione leggendo la risposta da Google
+productsExportToGoogle.missingParameterProductCategoryId=Parametro productCategoryId mancante
+productsExportToGoogle.noProductsAvailableInProductCategory=Nessun prodotto disponibile nella categoria prodotto selezionata
 productsExportToGoogle.productItemsSentCorrecltyToGoogle=Prodotti inviati correttamente su Google Base
 productsearchevents.added_x_product_category_members=Aggiunti ${numAdded} membri prodotto categoria.
 productsearchevents.error_getting_search_results=Errore leggendo i risultati di ricerca: ${errSearchResult}.
@@ -1882,4 +1886,4 @@
 FormFieldTitle_paymentPersonalCheck=Assegno Personale
 FormFieldTitle_listingDuration=Durata Asta
 FormFieldTitle_startPrice=Prezzo di Partenza
-FormFieldTitle_testMode=In Modo Test
\ No newline at end of file
+FormFieldTitle_testMode=In Modo Test

Modified: ofbiz/trunk/applications/product/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?view=diff&rev=564490&r1=564489&r2=564490
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services.xml Thu Aug  9 23:53:05 2007
@@ -1121,11 +1121,19 @@
         <description>Export products to Google Base</description>
         <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="imageUrl" optional="true"/>
         <attribute type="String" mode="IN" name="actionType" optional="false"/>
         <attribute type="String" mode="IN" name="statusId" optional="false"/>
         <attribute type="String" mode="IN" name="testMode" optional="false"/>
         <attribute type="String" mode="IN" name="trackingCodeId" optional="true"/>
+    </service>
+    <service name="exportProductCategoryToGoogle" engine="java"
+             location="org.ofbiz.product.product.ProductsExportToGoogle" invoke="exportProductCategoryToGoogle" auth="true">
+        <description>Export products in a category to Google Base</description>
+        <attribute type="String" mode="IN" name="productCategoryId" optional="false"/>
+        <attribute type="String" mode="IN" name="actionType" optional="false"/>
+        <attribute type="String" mode="IN" name="webSiteUrl" optional="false"/>
+        <attribute type="String" mode="IN" name="imageUrl" optional="true"/>
     </service>
     <service name="exportToEbay" engine="java"
              location="org.ofbiz.product.product.ProductsExportToEbay" invoke="exportToEbay" auth="true">

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=564490&r1=564489&r2=564490
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductsExportToGoogle.java Thu Aug  9 23:53:05 2007
@@ -26,6 +26,7 @@
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLEncoder;
+import java.sql.Timestamp;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -104,6 +105,73 @@
         return result;
     }
   
+    public static Map exportProductCategoryToGoogle(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        Locale locale = (Locale) context.get("locale");
+        String productCategoryId = (String) context.get("productCategoryId");
+        String actionType = (String) context.get("actionType");
+        String webSiteUrl = (String) context.get("webSiteUrl");
+        String imageUrl = (String) context.get("imageUrl");
+        GenericValue userLogin = (GenericValue)context.get("userLogin");
+        if (userLogin == null) {
+            return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.cannotRetrieveUserLogin", locale));
+        }
+        
+        try {
+            if (UtilValidate.isNotEmpty(productCategoryId)) {
+                List productsList = FastList.newInstance();
+                Map result = dispatcher.runSync("getProductCategoryMembers", UtilMisc.toMap("categoryId", productCategoryId));
+                
+                if (result.get("categoryMembers") != null) {
+                    List productCategoryMembers = (List)result.get("categoryMembers");
+                    if (productCategoryMembers != null) {
+                        Iterator i = productCategoryMembers.iterator();
+                        while (i.hasNext()) {
+                            GenericValue prodCatMemb = (GenericValue) i.next();
+                            
+                            if (prodCatMemb != null) {
+                                String productId = prodCatMemb.getString("productId");
+                                
+                                if (productId != null) {
+                                    GenericValue prod = prodCatMemb.getRelatedOne("Product");
+                                    Timestamp salesDiscontinuationDate = prod.getTimestamp("salesDiscontinuationDate");
+                                    // do not consider discontinued product
+                                    if (salesDiscontinuationDate == null) {
+                                        productsList.add(productId);
+                                    }
+                                }
+                            }
+                        }  
+                    }
+                }
+                
+                if (productsList.size() == 0) {
+                    return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.noProductsAvailableInProductCategory", locale));
+                } else {
+                    Map paramIn = FastMap.newInstance();
+                    paramIn.put("selectResult", productsList);
+                    paramIn.put("webSiteUrl", webSiteUrl);
+                    paramIn.put("imageUrl", imageUrl);
+                    paramIn.put("actionType", actionType);
+                    paramIn.put("statusId", "publish");
+                    paramIn.put("testMode", "N");
+                    paramIn.put("userLogin", userLogin);
+                    result = dispatcher.runSync("exportToGoogle", paramIn);
+                    
+                    if (ServiceUtil.isError(result)) {
+                        return ServiceUtil.returnFailure(ServiceUtil.getErrorMessage(result));
+                    }    
+                }  
+            } else {
+                return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.missingParameterProductCategoryId", locale));
+            }
+        } catch (Exception e) {
+            return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "productsExportToGoogle.exceptionInExportProductCategoryToGoogle", locale));
+        }
+        
+        return ServiceUtil.returnSuccess();
+    }
+    
     private static String authenticate(String authenticationUrl, String accountEmail, String accountPassword) {
         String postOutput = null;
         String token = null;