[calendar] Related to issue 23432: Changed API in doPostXX functions
authorDavid Baz Fayos <david.baz@openbravo.com>
Sat, 30 Mar 2013 17:37:33 +0100
changeset 20030 4ff12360eb74
parent 20029 dcf503f0d385
child 20031 e3e68152ff62
[calendar] Related to issue 23432: Changed API in doPostXX functions
in DefaultJsonDataService.java to get also original arguments
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Thu Mar 28 01:13:39 2013 +0100
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Sat Mar 30 17:37:33 2013 +0100
@@ -265,7 +265,7 @@
       jsonResponse.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS);
       jsonResult.put(JsonConstants.RESPONSE_RESPONSE, jsonResponse);
 
-      return doPostAction(parameters, jsonResult.toString(), DataSourceAction.FETCH);
+      return doPostAction(parameters, jsonResult.toString(), DataSourceAction.FETCH, null);
     } catch (Throwable t) {
       log.error(t.getMessage(), t);
       return JsonUtils.convertExceptionToJson(t);
@@ -487,7 +487,7 @@
         OBDal.getInstance().remove(bob);
 
         final String result = doPostAction(parameters, jsonResult.toString(),
-            DataSourceAction.REMOVE);
+            DataSourceAction.REMOVE, null);
 
         OBDal.getInstance().commitAndClose();
 
@@ -626,9 +626,9 @@
 
         final String result;
         if (parameters.containsKey(ADD_FLAG)) {
-          result = doPostAction(parameters, jsonResult.toString(), DataSourceAction.ADD);
+          result = doPostAction(parameters, jsonResult.toString(), DataSourceAction.ADD, content);
         } else {
-          result = doPostAction(parameters, jsonResult.toString(), DataSourceAction.UPDATE);
+          result = doPostAction(parameters, jsonResult.toString(), DataSourceAction.UPDATE, content);
         }
 
         OBDal.getInstance().commitAndClose();
@@ -717,7 +717,7 @@
   }
 
   protected String doPostAction(Map<String, String> parameters, String content,
-      DataSourceAction action) {
+      DataSourceAction action, String originalObject) {
 
     OBDal.getInstance().flush();
 
@@ -737,10 +737,10 @@
           doPostFetch(parameters, dataElement);
           break;
         case UPDATE:
-          doPostUpdate(parameters, dataElement);
+          doPostUpdate(parameters, dataElement, originalObject);
           break;
         case ADD:
-          doPostInsert(parameters, dataElement);
+          doPostInsert(parameters, dataElement, originalObject);
           break;
         case REMOVE:
           doPostRemove(parameters, dataElement);
@@ -803,9 +803,13 @@
   /**
    * Is called after the insert action in the same transaction as the insert. The inserted
    * {@link JSONObject} can be changed, the changes are sent to the client.
+   * 
+   * The originalToInsert contains the json object/array string as it was passed into the
+   * doPreInsert method. The inserted JSONObject is the object read from the database after it was
+   * inserted. So it contains the changes done by stored procedures.
    */
-  protected void doPostInsert(Map<String, String> parameters, JSONObject inserted)
-      throws JSONException {
+  protected void doPostInsert(Map<String, String> parameters, JSONObject inserted,
+      String originalToInsert) throws JSONException {
     // final String id = inserted.getString(JsonConstants.ID);
     // final String entityName = inserted.getString(JsonConstants.ENTITYNAME);
 
@@ -823,9 +827,13 @@
    * Called after the updates have been done, within the same transaction as the main update.
    * Changes to the updated {@link JSONObject} are sent to the client (but not persisted to the
    * database).
+   * 
+   * The originalToUpdate contains the json object/array string as it was passed into the
+   * doPreUpdate method. The updated JSONObject is the object read from the database after it was
+   * updated. So it contains all the changes done by stored procedures.
    */
-  protected void doPostUpdate(Map<String, String> parameters, JSONObject updated)
-      throws JSONException {
+  protected void doPostUpdate(Map<String, String> parameters, JSONObject updated,
+      String originalToUpdate) throws JSONException {
   }
 
   protected enum DataSourceAction {