svn commit: r1634885 - in /ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore: src/org/ofbiz/ebaystore/ webapp/ebaystore/WEB-INF/ webapp/ebaystore/store/

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

svn commit: r1634885 - in /ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore: src/org/ofbiz/ebaystore/ webapp/ebaystore/WEB-INF/ webapp/ebaystore/store/

jacopoc
Author: jacopoc
Date: Tue Oct 28 14:24:36 2014
New Revision: 1634885

URL: http://svn.apache.org/r1634885
Log:
Refactored Ajax-based requests for ebaystore 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/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java
    ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml
    ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl
    ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl

Modified: ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java?rev=1634885&r1=1634884&r2=1634885&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java (original)
+++ ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/src/org/ofbiz/ebaystore/EbayStoreOptions.java Tue Oct 28 14:24:36 2014
@@ -18,10 +18,6 @@
  */
 package org.ofbiz.ebaystore;
 
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -32,7 +28,6 @@ import javax.servlet.http.HttpSession;
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
-import net.sf.json.JSONObject;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilHttp;
@@ -116,7 +111,7 @@ public class EbayStoreOptions {
                                     storeColorSchemeMap.put("storeFontTypeDescColor",storeFontType.getDescColor());
                                     storeColorSchemeMap.put("storeFontTypeFontDescValue",storeFontType.getDescFace().value());
                                     storeColorSchemeMap.put("storeDescSizeValue",storeFontType.getDescSize().value());
-                                    toJsonObject(storeColorSchemeMap,response);
+                                    request.setAttribute("storeColorSchemeMap", storeColorSchemeMap);
 
                                     break;
                                 }
@@ -137,63 +132,31 @@ public class EbayStoreOptions {
         } catch (SdkException e) {
             e.printStackTrace();
             return "error";
-        } catch (EventHandlerException e) {
-            e.printStackTrace();
-            return "error";
         }
         return "success";
     }
 
-    public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response) throws EventHandlerException {
-        JSONObject json = JSONObject.fromObject(attrMap);
-        String jsonStr = json.toString();
-        if (jsonStr == null) {
-            throw new EventHandlerException("JSON Object was empty; fatal error!");
-        }
-        // 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) {
-            throw new EventHandlerException("Problems with Json encoding", e);
-        }
-        // return the JSON String
-        Writer out;
-        try {
-            out = response.getWriter();
-            out.write(jsonStr);
-            out.flush();
-        } catch (IOException e) {
-            throw new EventHandlerException("Unable to get response writer", e);
-        }
-    }
-
     public static String retrieveItemTemplateByTemplateGroupId(HttpServletRequest request,HttpServletResponse response) {
         Map<String, Object> paramMap = UtilHttp.getCombinedMap(request);
-        try {
-            if (paramMap.get("productStoreId") != null) {
-                String temGroupId = (String)paramMap.get("templateGroupId");
-                Map<String,Object> addItemObj = EbayEvents.getAddItemListingObject(request, EbayEvents.getApiContext(request));
-                if (UtilValidate.isNotEmpty(addItemObj)) {
-                    String refName = "itemCateFacade_".concat((String) paramMap.get("pkCategoryId"));
-                    if (UtilValidate.isNotEmpty(addItemObj.get(refName))) {
-                        EbayStoreCategoryFacade cf = (EbayStoreCategoryFacade) addItemObj.get(refName);
-                        List<Map<String,Object>> theme = cf.getAdItemTemplates(temGroupId);
-                        if (theme.size() > 0) {
-                            toJsonObjectList(theme,response);
-                        }
+        if (paramMap.get("productStoreId") != null) {
+            String temGroupId = (String)paramMap.get("templateGroupId");
+            Map<String,Object> addItemObj = EbayEvents.getAddItemListingObject(request, EbayEvents.getApiContext(request));
+            if (UtilValidate.isNotEmpty(addItemObj)) {
+                String refName = "itemCateFacade_".concat((String) paramMap.get("pkCategoryId"));
+                if (UtilValidate.isNotEmpty(addItemObj.get(refName))) {
+                    EbayStoreCategoryFacade cf = (EbayStoreCategoryFacade) addItemObj.get(refName);
+                    List<Map<String,Object>> theme = cf.getAdItemTemplates(temGroupId);
+                    if (theme.size() > 0) {
+                        request.setAttribute("itemTemplates", theme);
                     }
                 }
             }
-        } catch (EventHandlerException e) {
-            Debug.logError(e.getMessage(), module);
         }
         return "success";
     }
 
     public static String retrieveEbayCategoryByParent(HttpServletRequest request, HttpServletResponse response) {
-        List<CategoryType> results = FastList.newInstance();
+        List<CategoryType> results;
         try {
             Map<String, Object> paramMap = UtilHttp.getCombinedMap(request);
             if (paramMap.get("productStoreId") != null) {
@@ -225,7 +188,7 @@ public class EbayStoreOptions {
                         categories.add(context);
                     }
                     if (categories.size() > 0) {
-                        toJsonObjectList(categories,response);
+                        request.setAttribute("categories", categories);
                     }
                 }
             }
@@ -243,43 +206,8 @@ public class EbayStoreOptions {
         return "success";
     }
 
-    public static void toJsonObjectList(List<Map<String,Object>> list, HttpServletResponse response) throws EventHandlerException {
-        JSONObject json = null;
-        List<JSONObject> jsonList = new ArrayList<JSONObject>();
-        if (list != null) {
-            for (Map<String,Object> val : list) {
-                json = new JSONObject();
-                for (String rowKey: val.keySet()) {
-                    json.put(rowKey, val.get(rowKey));
-                }
-                jsonList.add(json);
-            }
-            String jsonStr = jsonList.toString();
-            if (jsonStr == null) {
-                throw new EventHandlerException("JSON Object was empty; fatal error!");
-            }
-            // 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) {
-                throw new EventHandlerException("Problems with Json encoding", e);
-            }
-            // return the JSON String
-            Writer out;
-            try {
-                out = response.getWriter();
-                out.write(jsonStr);
-                out.flush();
-            } catch (IOException e) {
-                throw new EventHandlerException("Unable to get response writer", e);
-            }
-        }
-    }
-    
     public static String retrieveEbayStoreCategoryByParent(HttpServletRequest request, HttpServletResponse response) {
-        List<StoreCustomCategoryType> results = FastList.newInstance();
+        List<StoreCustomCategoryType> results;
         try {
             Map<String, Object> paramMap = UtilHttp.getCombinedMap(request);
             if (paramMap.get("productStoreId") != null) {
@@ -312,12 +240,11 @@ public class EbayStoreOptions {
                         } else {
                             isLeaf = "false";
                         }
-                        //String isLeaf = String.valueOf(category.getChildCategory().!= null ? "true" : "false");
                         context.put("IsLeafCategory", isLeaf);
                         categories.add(context);
                     }
                     if (categories.size() > 0) {
-                        toJsonObjectList(categories,response);
+                        request.setAttribute("categories", categories);
                     }
                 }
             }

Modified: ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml?rev=1634885&r1=1634884&r2=1634885&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml (original)
+++ ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/WEB-INF/controller.xml Tue Oct 28 14:24:36 2014
@@ -92,8 +92,8 @@
     <request-map uri="retrieveThemeColorSchemeByThemeId">
         <security https="true" auth="true"/>
         <event type="java" path="org.ofbiz.ebaystore.EbayStoreOptions" invoke="retrieveThemeColorSchemeByThemeId"/>
-        <response name="success" type="view" value="ebayStoreDetail"/>
-        <response name="error" type="view" value="ebayStoreDetail"/>
+        <response name="success" type="request" value="json"/>
+        <response name="error" type="request" value="json"/>
     </request-map>
     <!-- Feedback -->
     <request-map uri="Feedback">
@@ -290,6 +290,7 @@
         <security https="true" auth="true"/>
         <event type="java" path="org.ofbiz.ebaystore.EbayStoreOptions" invoke="retrieveEbayCategoryByParent"/>
         <response name="success" type="request" value="json"/>
+        <response name="error" type="request" value="json"/>
     </request-map>
     <request-map uri="retrieveEbayStoreCategoryByParent">
         <security https="true" auth="true"/>
@@ -305,7 +306,8 @@
     <request-map uri="ebayAdItemTemplate">
         <security https="true" auth="true"/>
         <event type="java" path="org.ofbiz.ebaystore.EbayStoreOptions" invoke="retrieveItemTemplateByTemplateGroupId"/>
-        <response name="success" type="view" value="main"/>
+        <response name="success" type="request" value="json"/>
+        <response name="error" type="request" value="json"/>
     </request-map>
     <request-map uri="updateProductExportDetail">
         <security https="true" auth="true"/>

Modified: ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl?rev=1634885&r1=1634884&r2=1634885&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl (original)
+++ ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/StoreSetting.ftl Tue Oct 28 14:24:36 2014
@@ -34,8 +34,8 @@ under the License.
          data: pars,
          beforeStart: function() {document.getElementById('loading').innerHTML = ' ${uiLabelMap.CommonPleaseWait}';},
              success: function(data) {
-                if (data != null){
-                    var resp = eval("("+data+")");
+                if (data != null && data.storeColorSchemeMap){
+                    var resp = eval("("+data.storeColorSchemeMap+")");
                     if (resp.storeColorPrimary!=null) document.getElementById('storePrimaryColor').value =  resp.storeColorPrimary;
                     if (resp.storeColorAccent!=null) document.getElementById('storeSecondaryColor').value = resp.storeColorAccent;
                     if (resp.storeColorSecondary!=null) document.getElementById('storeAccentColor').value = resp.storeColorSecondary;

Modified: ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl?rev=1634885&r1=1634884&r2=1634885&view=diff
==============================================================================
--- ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl (original)
+++ ofbiz/branches/json-integration-refactoring/specialpurpose/ebaystore/webapp/ebaystore/store/productsearchExport.ftl Tue Oct 28 14:24:36 2014
@@ -81,9 +81,9 @@ under the License.
             },
             success: function(data) {
                 document.getElementById('loading').innerHTML = '';
-                if (data) {
+                if (data && data.categories) {
                     removeOptions(id);
-                    var resp = eval(data);
+                    var resp = eval(data.categories);
                     var leng = resp.length;
                      if (leng) {
                         for (i=0;i<leng;i++) {
@@ -112,8 +112,8 @@ under the License.
             success: function(data){
                 removeOptions('theme');
                 previewPic(":http://pics.ebay.com/aw/pics/vit/None2_sample_100x120.gif");
-                if(data!=null){
-                    var resp = eval(data);
+                if(data!=null && data.itemTemplates!=null){
+                    var resp = eval(data.itemTemplates);
                     var leng = resp.length;
                     var j = 0;
                     for (i=0;i<leng;i++) {