related to bug 36766: last update not updated when removing description
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 12 Sep 2017 15:50:45 +0200
changeset 32700 76e82aea8e0d
parent 32699 051e3552621f
child 32701 7fafd2a9f24b
related to bug 36766: last update not updated when removing description

The last updated information is now updated when the description of an existing attachment is cleared. This was not happening before, because the record in the OBUIAPP_Parameter_Value table was removed when the value to be assigned is null
modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachImplementationManager.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachImplementationManager.java	Mon Sep 11 12:05:17 2017 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/attachment/AttachImplementationManager.java	Tue Sep 12 15:50:45 2017 +0200
@@ -516,9 +516,15 @@
 
       String strValue = "";
       if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) {
-        // There is no value for this parameter. Remove metadataStoredValue from Database.
         metadataValues.put(strMetadataId, null);
-        OBDal.getInstance().remove(metadataStoredValue);
+        // There is no value for this parameter. Just do not create it if is new or set its value to
+        // null if it already existed in order to keep the correct last updated information of the
+        // attachment
+        if (metadataStoredValue.isNewOBObject()) {
+          OBDal.getInstance().remove(metadataStoredValue);
+        } else {
+          ParameterUtils.setParameterValue(metadataStoredValue, getJSONValue(""));
+        }
       } else {
         String strReferenceId = parameter.getReference().getId();
         if (REFERENCE_LIST.equals(strReferenceId)) {
@@ -561,12 +567,8 @@
           } else {
             strValue = value.toString();
           }
-          JSONObject jsonValue = new JSONObject();
-          try {
-            jsonValue.put("value", strValue);
-          } catch (JSONException ignore) {
-          }
-          ParameterUtils.setParameterValue(metadataStoredValue, jsonValue);
+
+          ParameterUtils.setParameterValue(metadataStoredValue, getJSONValue(strValue));
           metadataValues.put(strMetadataId, ParameterUtils.getParameterValue(metadataStoredValue));
         }
         OBDal.getInstance().save(metadataStoredValue);
@@ -581,4 +583,13 @@
 
     return metadataValues;
   }
+
+  private JSONObject getJSONValue(String value) {
+    JSONObject jsonValue = new JSONObject();
+    try {
+      jsonValue.put("value", value);
+    } catch (JSONException ignore) {
+    }
+    return jsonValue;
+  }
 }