Class OdooClient

java.lang.Object
ch.helvethink.odoo4java.xmlrpc.OdooClient

public class OdooClient extends Object
Abstraction of Odoo's XML-RPC API
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
      Simple logger
  • Constructor Details

    • OdooClient

      public OdooClient(String instanceUrl, String dbName, String username, String password) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Constructor with direct connection
      Parameters:
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • OdooClient

      public OdooClient(String instanceUrl, String dbName, String username, String password, boolean mustConnect) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Constructor that initializes the Common API XML-RPC client
      Parameters:
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      mustConnect - - describes if we must try to connect or not
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • OdooClient

      public OdooClient(org.apache.xmlrpc.client.XmlRpcClient commonClient, String instanceUrl, String dbName, String username, String password, boolean mustConnect) throws MalformedURLException, org.apache.xmlrpc.XmlRpcException
      Constructor with all fields
      Parameters:
      commonClient - - The common XML-RPC API client
      instanceUrl - The odoo Instance URL
      dbName - The odoo DB Name
      username - The Odoo username when authenticating
      password - The Odoo password when authenticating
      mustConnect - - describes if we must try to connect or not
      Throws:
      MalformedURLException - when URI is not valid
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
  • Method Details

    • getVersion

      public String getVersion() throws org.apache.xmlrpc.XmlRpcException
      Retrieve Version from the Odoo Server
      Returns:
      Version like "17.0"
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • getAllModels

      public List<Map<String,Object>> getAllModels(String packageName) throws org.apache.xmlrpc.XmlRpcException
      Retrieve all Odoo models of the Odoo instance we're connected to
      Parameters:
      packageName - - allows to filter the names of models we want to retrieve
      Returns:
      List of Odoo models with fields like "description", "name", "access_ids", ...
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • getFields

      public Map<String,Map<String,Object>> getFields(String modelName) throws org.apache.xmlrpc.XmlRpcException
      Get fields From Odoo, for a given model
      Parameters:
      modelName - The model we want to inspect
      Returns:
      The list of fields as a Map containing the following information: string, help, type, and relation
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • findByNames

      public <T extends OdooObj> List<T> findByNames(Class<T> classToConvert, List<String> names)
      Find a list of object from names
      Type Parameters:
      T - The type of objects to return
      Parameters:
      classToConvert - The type of objects
      names - The "name" value of objects we're looking for
      Returns:
      List of found objects
    • findByCriteria

      public <T extends OdooObj> List<T> findByCriteria(int limit, Class<T> classToConvert, String... criteria) throws org.apache.xmlrpc.XmlRpcException
      Find an Odoo object using criteria. If no criteria, will send all the objects (id >=0 )
      Type Parameters:
      T - The target type
      Parameters:
      limit - Number of objects we want to retrieve
      classToConvert - Type of the target object
      criteria - The search criteria
      Returns:
      List of corresponding objects
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • findObjectById

      public <T extends OdooObj> T findObjectById(OdooId idToFetch, Class<T> classToConvert) throws org.apache.xmlrpc.XmlRpcException
      Fetch an object by its id
      Type Parameters:
      T - The type of the target Object
      Parameters:
      idToFetch - The id of the object we want to fetch
      classToConvert - The type of the target Object
      Returns:
      The object fetched
      Throws:
      org.apache.xmlrpc.XmlRpcException - when an error occurs with the XML-RPC API
    • findListByIdsInt

      public <T extends OdooObj> List<T> findListByIdsInt(List<Integer> idsToFetch, Class<T> classToConvert)
      Same as findObjectById(OdooId, Class) but with a List
      Type Parameters:
      T - The type of the target objects If an exception occured, will send back an empty list
      Parameters:
      idsToFetch - The ids of objects we want to fetch
      classToConvert - The type of the target objects
      Returns:
      List of built objects
    • findListByIds

      public <T extends OdooObj> List<T> findListByIds(List<OdooId> idsToFetch, Class<T> classToConvert)
      Same as above but with Odoo Ids
      Type Parameters:
      T - The type of the target objects
      Parameters:
      idsToFetch - The ids of objects we want to fetch under the form of OdooId
      classToConvert - The type of the target objects
      Returns:
      List of built objects