You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2014/10/28 08:51:20 UTC

svn commit: r1634805 - in /ofbiz/branches/json-integration-refactoring/applications/product: src/org/ofbiz/product/store/ProductStoreEvents.java webapp/catalog/WEB-INF/controller.xml webapp/catalog/store/ProductStoreGroupTree.ftl

Author: jacopoc
Date: Tue Oct 28 07:51:20 2014
New Revision: 1634805

URL: http://svn.apache.org/r1634805
Log:
Refactored Ajax product store tree to use the common request json response rather than a custom method.
This change removes the dependency on a specific JSON library.


Modified:
    ofbiz/branches/json-integration-refactoring/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java
    ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/WEB-INF/controller.xml
    ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl

Modified: ofbiz/branches/json-integration-refactoring/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java?rev=1634805&r1=1634804&r2=1634805&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java (original)
+++ ofbiz/branches/json-integration-refactoring/applications/product/src/org/ofbiz/product/store/ProductStoreEvents.java Tue Oct 28 07:51:20 2014
@@ -18,9 +18,6 @@
  *******************************************************************************/
 package org.ofbiz.product.store;
 
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
 import java.util.List;
 import java.util.Map;
 
@@ -30,9 +27,6 @@ import javax.servlet.http.HttpServletRes
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
-import net.sf.json.JSONObject;
-
-import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
@@ -47,7 +41,7 @@ public class ProductStoreEvents {
 
     // Please note : the structure of map in this function is according to the JSON data map of the jsTree
     @SuppressWarnings("unchecked")
-    public static void getChildProductStoreGroupTree(HttpServletRequest request, HttpServletResponse response){
+    public static String getChildProductStoreGroupTree(HttpServletRequest request, HttpServletResponse response){
         Delegator delegator = (Delegator) request.getAttribute("delegator");
         String parentGroupId = request.getParameter("parentGroupId");
         String onclickFunction = request.getParameter("onclickFunction");
@@ -92,41 +86,13 @@ public class ProductStoreEvents {
                         productStoreGroupList.add(josonMap);
                     }
                     List<Map<Object, Object>> sortedProductStoreGroupList = UtilMisc.sortMaps(productStoreGroupList, sortList);
-                    toJsonObjectList(sortedProductStoreGroupList,response);
+                    request.setAttribute("storeGroupTree", sortedProductStoreGroupList);
                 }
             }
         } catch (GenericEntityException e) {
             e.printStackTrace();
+            return "error";
         }
-    }
-
-    @SuppressWarnings("unchecked")
-    public static void toJsonObjectList(List attrList, HttpServletResponse response){
-        String jsonStr = "[";
-        for (Object attrMap : attrList) {
-            JSONObject json = JSONObject.fromObject(attrMap);
-            jsonStr = jsonStr + json.toString() + ',';
-        }
-        jsonStr = jsonStr + "{ } ]";
-        if (UtilValidate.isEmpty(jsonStr)) {
-            Debug.logError("JSON Object was empty; fatal error!",module);
-        }
-        // set the X-JSON content type
-        response.setContentType("application/json");
-        // jsonStr.length is not reliable for unicode characters
-        try {
-            response.setContentLength(jsonStr.getBytes("UTF8").length);
-        } catch (UnsupportedEncodingException e) {
-            Debug.logError("Problems with Json encoding",module);
-        }
-        // return the JSON String
-        Writer out;
-        try {
-            out = response.getWriter();
-            out.write(jsonStr);
-            out.flush();
-        } catch (IOException e) {
-            Debug.logError("Unable to get response writer",module);
-        }
+        return "success";
     }
 }

Modified: ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/WEB-INF/controller.xml?rev=1634805&r1=1634804&r2=1634805&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/WEB-INF/controller.xml (original)
+++ ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/WEB-INF/controller.xml Tue Oct 28 07:51:20 2014
@@ -1457,7 +1457,8 @@ under the License.
     <request-map uri="getProductStoreGroupRollupHierarchy">
         <security auth="false" https="true"/>
         <event type="java" path="org.ofbiz.product.store.ProductStoreEvents" invoke="getChildProductStoreGroupTree"/>
-        <response name="success" type="none"/>
+        <response name="success" type="request" value="json"/>
+        <response name="error" type="request" value="json"/>
     </request-map>
     <request-map uri="AddProductStoreToGroup">
         <security auth="true" https="true"/>

Modified: ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl?rev=1634805&r1=1634804&r2=1634805&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl (original)
+++ ofbiz/branches/json-integration-refactoring/applications/product/webapp/catalog/store/ProductStoreGroupTree.ftl Tue Oct 28 07:51:20 2014
@@ -55,7 +55,10 @@ var rawdata = [
                                 "parentGroupId" :  n.attr ? n.attr("parentGroupId").replace("node_","") : 1,
                                 "onclickFunction" : "callDocument"
                         }; 
-                    }
+                    },
+                              success : function (data) {
+                                  return data.storeGroupTree;
+                              }
                 }
             },
             "types" : {