How To Implement JsonDataServiceExtraActions Hook
Overview
This section explains how to implement JsonDataServiceExtraActions Hook. This hook is called before and after each operation of DefaultJSONDataService class.
Hook Implementation
The hook is implemented by extending the JsonDataServiceExtraActions class. This class has two methods to implement:
-
doPreAction method: This void method is called at the beginning of each
DefaultJSONDataServiceaction. It has 3 parameters:- parameters: The Map with the parameters of the
DataSourcecall. - data:
JSONArraywith the records that are going to be inserted, updated or deleted. Modify this object in case it is required to modify the data before executing the action. Fetch operations receive an empty array. - action:
DataSourceActionenum value with the action of the DataSource call. Possible values areFETCH,ADD,UPDATEandREMOVE.
- parameters: The Map with the parameters of the
-
doPostAction method: This void method is called at the end of each
DefaultJSONDataServiceaction. It has 4 parameters:- parameters: The Map with the parameters of the DataSource call.
- content:
JSONObjectwith the current content that is returned to the client. Modify this object in case it is required to modify the data before is returned. - action:
DataSourceActionenum value with the action of the DataSource call. Possible values are FETCH,ADD,UPDATEandREMOVE. - originalObject:
JSONObjectString available only onADDandUPDATEwith the original values of the data.
Example
This example logs a line every time a window is loaded. You can find the code described below in the org.openbravo.platform.features module.
public class JsonDataServiceExtraActionsExample implements JsonDataServiceExtraActions {
private static final Logger log = LoggerFactory
.getLogger(JsonDataServiceExtraActionsExample.class);
@Override
public void doPreAction(Map<String, String> parameters, JSONArray newData, DataSourceAction action) {
log.debug("JsonDataServiceExtraActionsExample doPreAction implementation");
}
@Override
public void doPostAction(Map<String, String> parameters, JSONObject content,
DataSourceAction action, String originalObject) {
}
}
This work is a derivative of How To Implement JsonDataServiceExtraActions Hook by Openbravo Wiki, used under CC BY-SA 2.5 ES. This work is licensed under CC BY-SA 2.5 by Etendo.