svn commit: r781926 - in /ofbiz/trunk/applications/product: servicedef/services.xml src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java

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

svn commit: r781926 - in /ofbiz/trunk/applications/product: servicedef/services.xml src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java

ashish-18
Author: ashish
Date: Fri Jun  5 06:51:03 2009
New Revision: 781926

URL: http://svn.apache.org/viewvc?rev=781926&view=rev
Log:
Wrong location was specified for this service.
Minor fix in code to return error and success message.

I will create the "How To" docs for this in next few hours on the OFBiz confluence.
As the present document is present in OFBIZ-1810.

Modified:
    ofbiz/trunk/applications/product/servicedef/services.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java

Modified: ofbiz/trunk/applications/product/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services.xml?rev=781926&r1=781925&r2=781926&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services.xml Fri Jun  5 06:51:03 2009
@@ -1235,7 +1235,7 @@
     </service>
 
     <service name="productImportFromSpreadsheet" engine="java"
-            location="org.ofbiz.poi.ImportProductServices" invoke="productImportFromSpreadsheet" auth="true">
+            location="org.ofbiz.product.spreadsheetimport.ImportProductServices" invoke="productImportFromSpreadsheet" auth="true">
         <description>Create product and inventory item</description>
         <attribute name="dirName" type="java.lang.String" mode="IN" optional="true"/>
     </service>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java?rev=781926&r1=781925&r2=781926&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java Fri Jun  5 06:51:03 2009
@@ -60,7 +60,6 @@
      */
     public static Map<String, Object> productImportFromSpreadsheet(DispatchContext dctx, Map<String, ? extends Object> context) {
         GenericDelegator delegator = dctx.getDelegator();
-        Map<String, Object> responseMsgs = FastMap.newInstance();
         // System.getProperty("user.dir") returns the path upto ofbiz home
         // directory
         String path = System.getProperty("user.dir") + "/spreadsheet";
@@ -78,17 +77,14 @@
                     }
                 }
             } else {
-                Debug.logWarning("Directory not found or can't be read", module);
-                return responseMsgs;
+                return ServiceUtil.returnError("Directory not found or can not be read");
             }
         } else {
-            Debug.logWarning("No path specified, doing nothing", module);
-            return responseMsgs;
+            return ServiceUtil.returnError("No path specified, doing nothing");
         }
 
         if (fileItems.size() < 1) {
-            Debug.logWarning("No spreadsheet exists in " + path, module);
-            return responseMsgs;
+            return ServiceUtil.returnError("No spreadsheet exists in" + path);
         }
 
         for (File item: fileItems) {
@@ -102,7 +98,7 @@
                 wb = new HSSFWorkbook(fs);
             } catch (IOException e) {
                 Debug.logError("Unable to read or create workbook from file", module);
-                return responseMsgs;
+                return ServiceUtil.returnError("Unable to read or create workbook from file");
             }
 
             // get first sheet
@@ -113,18 +109,17 @@
                 if (row != null) {
                     // read productId from first column "sheet column index
                     // starts from 0"
-                    HSSFCell cell1 = row.getCell((int) 1);
-                    cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
-                    String productId = cell1.getRichStringCellValue().toString();
+                    HSSFCell cell2 = row.getCell((int) 2);
+                    cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
+                    String productId = cell2.getRichStringCellValue().toString();
                     // read QOH from ninth column
-                    HSSFCell cell8 = row.getCell((int) 8);
+                    HSSFCell cell5 = row.getCell((int) 5);
                     BigDecimal quantityOnHand = BigDecimal.ZERO;
-                    if (cell8 != null && cell8.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
-                        quantityOnHand = new BigDecimal(cell8.getNumericCellValue());
+                    if (cell5 != null && cell5.getCellType() == HSSFCell.CELL_TYPE_NUMERIC)
+                        quantityOnHand = new BigDecimal(cell5.getNumericCellValue());
 
                     // check productId if null then skip creating inventory item
                     // too.
-
                     boolean productExists = ImportProductHelper.checkProductExists(productId, delegator);
 
                     if (productId != null && !productId.trim().equalsIgnoreCase("") && !productExists) {
@@ -137,8 +132,7 @@
                                     .getNextSeqId("InventoryItem")));
                     }
                     int rowNum = row.getRowNum() + 1;
-                    if (row.toString() != null && !row.toString().trim().equalsIgnoreCase("") && products.size() > 0
-                            && !productExists) {
+                    if (row.toString() != null && !row.toString().trim().equalsIgnoreCase("") && productExists) {
                         Debug.logWarning("Row number " + rowNum + " not imported from " + item.getName(), module);
                     }
                 }
@@ -162,6 +156,6 @@
             if (products.size() > 0)
                 Debug.logInfo("Uploaded " + uploadedProducts + " products from file " + item.getName(), module);
         }
-        return responseMsgs;
+        return ServiceUtil.returnSuccess();
     }
 }