ERP 2.50:Developers Guide/Examples/Data Access Layer and REST
Using OBDal and OBCriteria
Using the DatasetService class
There are two test classes which test this service, they contain code which can be useful when working with data sets programmatically:
Calling REST Webservices through Java
Openbravo has a number of test cases which are used to test REST webservices on a running Openbravo instance. They are located in the org.openbravo.test.webservice package.
There is a read and a write/update testclass. They both inherit from the BaseWSTest class. This class has good examples of code on how-to build http connections with authentication through Java.
The WSReadTest class inherits from BaseWSTest. It contains examples of doing simple REST requests as well as using a where-clause and paging.
The WSUpdateTest class inherits from BaseWSTest. The tests which are a good basis for your own code:
- reads data through REST, changes it and posts the result back
- create a new entity through REST
- removal of an entity through a REST request
There is a blog on working with Openbravo REST webservices directly from Firefox, this can be useful for test purposes.
Using the runtime model
The Openbravo Data Access Layer implements and makes use of a runtime in-memory representation of the model. This model is also available to application developers and can be used for generic functionality.
The Data Access Layer concepts guide contains an explanation of the runtime model and a code example to convert a business object to xml: see here.
This blog also discusses coding against the runtime model. It contains example code which exports all data in Openbravo with just a few lines of code.