Fixes issue 34067: No UOM Conversion Rate between UOMs found warning shown.
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Tue, 27 Sep 2016 16:26:36 +0200
changeset 30320 65f08702a333
parent 30319 098fa4ba0316
child 30321 985e8955ab63
Fixes issue 34067: No UOM Conversion Rate between UOMs found warning shown.

This problem is related with Improve performance callouts project. The problem
was related with how to manage null and "null" values.

Previously it was necessary to send the "null" value as part of the callout
execution result because StringBuilder in CalloutInfo class couldn't accept
null Objects values. Then, this way the parseCalloutResponse() of the FIC
was able to retrieve the null values properly. This now is not necessary in
SimpleCallouts due to its new internal implementation.

It have been resolved this problem by sending null Object as part of the
callout execution result in both cases: When a "null" String or null
Object is recieved. Now the problem it has fixed and the null and "null"
values are managing properly.
src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java
src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java	Mon Sep 26 20:02:41 2016 +0000
+++ b/src/org/openbravo/erpCommon/ad_callouts/SimpleCallout.java	Tue Sep 27 16:26:36 2016 +0200
@@ -324,15 +324,21 @@
      */
     public void addResult(String param, Object value) {
       JSONObject columnValue = new JSONObject();
-      Object strValue = value == null ? "null" : value;
 
-      // handle case when callouts are sending us "\"\"" string.
-      if ("\"\"".equals(strValue)) {
-        strValue = "";
+      Object resultValue = value;
+      if (resultValue != null) {
+        // handle case when SimpleCallouts are sending us "\"\"" string.
+        if ("\"\"".equals(resultValue)) {
+          resultValue = "";
+        }
+        // handle case when SimpleCallouts are sending us "null" string. Force to be null object in
+        // order to ensure backwards compatibility.
+        resultValue = JsonConstants.NULL.equals(resultValue) ? null : resultValue;
       }
+
       try {
-        columnValue.put(CalloutConstants.VALUE, strValue);
-        columnValue.put(CalloutConstants.CLASSIC_VALUE, strValue);
+        columnValue.put(CalloutConstants.VALUE, resultValue);
+        columnValue.put(CalloutConstants.CLASSIC_VALUE, resultValue);
         result.put(param, columnValue);
       } catch (JSONException e) {
         log.error("Error parsing JSON Object.", e);
--- a/src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java	Mon Sep 26 20:02:41 2016 +0000
+++ b/src/org/openbravo/erpCommon/ad_callouts/SimpleCalloutInformationProvider.java	Tue Sep 27 16:26:36 2016 +0200
@@ -64,7 +64,9 @@
     JSONObject json = (JSONObject) element;
     String value = null;
     try {
-      value = json.getString(CalloutConstants.CLASSIC_VALUE);
+      if (json.has(CalloutConstants.CLASSIC_VALUE)) {
+        value = json.getString(CalloutConstants.CLASSIC_VALUE);
+      }
     } catch (JSONException e) {
       log.error("Error retrieving value from json {}", json);
     }