I'm starting a project that consists in OpenBravo integration via the Restful WS Layer (may be json) That kind of integration is simple in the beggining because just consists in a rest web service client which will perform the GET, PUT, POST and DELETE actions.
My question is about how to manage the json objects and if OpenBravo brings some way to convert json objects in data access objects, in order to easier handling.
I have seen OpenBravo DAL (Data Access Layer), Is there a way to mix the rest and dal to crud the OB Objects?
Best Regards,
Here is an example which might help you...
First Let us look at this code snippet
public class SimpleRestClass extends BaseWebServiceServlet {
private static final long serialVersionUID = 1L;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
String Name = request.getParameter("Name");
String Email = request.getParameter("Email");
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("Name", Name);
map.put("Email", Email);
// map.put("Path", request.getPathInfo().toString());
list.add(map);
final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();
// write to the response
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
final Writer w = response.getWriter();
w.write(json);
w.close();
}
}
In the above code
final String json = new DataToJsonConverter().convertToJsonObjects(list).toString();
is what you are looking for. The signature of convertToJsonObjects() method is
List<JSONObject> convertToJsonObjects(List<Map<String, Object>> data)
The important class in openbravo for REST Json WS to notice is
import org.openbravo.service.json.DataToJsonConverter
This class has many more Json related methods. Hope this will help you.
If you have any questions then please feel free to ask.
Openbravo has a module called org.openbravo.service.json
The above module makes use of JSON and DAL layer of openbravo.
When we make a get request for a product, JSON module uses DAL to query the database and convert OB Object to JSON object.
When we want to create a new product , JSON module uses DAL to create a new OB Object.
The main class you may need to focus on openbravo side is,
Important link: Openbravo JSON REST