Package ch.helvethink.odoo4java.xmlrpc
Class OdooClient
java.lang.Object
ch.helvethink.odoo4java.xmlrpc.OdooClient
- All Implemented Interfaces:
OdooRpcClient
Abstraction of Odoo's XML-RPC API
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOdooClient(OdooXmlRpcClient commonClient, String instanceUrl, String dbName, String username, String password, boolean mustConnect) Constructor with all fieldsOdooClient(String instanceUrl, String dbName, String username, String password) Constructor with direct connectionOdooClient(String instanceUrl, String dbName, String username, String password, boolean mustConnect) Constructor that initializes the Common API XML-RPC client -
Method Summary
Modifier and TypeMethodDescriptionfindByCriteria(int limit, Class<T> classToConvert, String... criteria) Find an Odoo object using criteria.findByNames(Class<T> classToConvert, List<String> names) Find a list of object from namesfindListByIds(List<OdooId> idsToFetch, Class<T> classToConvert) Same as above but with Odoo IdsfindListByIdsInt(List<Integer> idsToFetch, Class<T> classToConvert) Same asfindObjectById(OdooId, Class)but with a List<T extends OdooObj>
TfindObjectById(OdooId idToFetch, Class<T> classToConvert) Fetch an object by its idgetAllModels(String packageName) Retrieve all Odoo models of the Odoo instance we're connected toGet fields From Odoo, for a given modelRetrieve Version from the Odoo Server
-
Field Details
-
LOG
public static final org.slf4j.Logger LOGSimple 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 URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticating- Throws:
MalformedURLException- when URI is not validorg.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 Constructor that initializes the Common API XML-RPC client- Parameters:
instanceUrl- The odoo Instance URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticatingmustConnect- - describes if we must try to connect or not- Throws:
MalformedURLException- when URI is not valid
-
OdooClient
public OdooClient(OdooXmlRpcClient commonClient, String instanceUrl, String dbName, String username, String password, boolean mustConnect) throws MalformedURLException Constructor with all fields- Parameters:
commonClient- - The common XML-RPC API clientinstanceUrl- The odoo Instance URLdbName- The odoo DB Nameusername- The Odoo username when authenticatingpassword- The Odoo password when authenticatingmustConnect- - describes if we must try to connect or not- Throws:
MalformedURLException- when URI is not valid
-
-
Method Details
-
getVersion
Retrieve Version from the Odoo Server- Returns:
- Version like "17.0"
-
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, getFieldsObject>> (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
Find a list of object from names- Type Parameters:
T- The type of objects to return- Parameters:
classToConvert- The type of objectsnames- 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) Find an Odoo object using criteria. If no criteria, will send all the objects (id >=0 )- Specified by:
findByCriteriain interfaceOdooRpcClient- Type Parameters:
T- The target type- Parameters:
limit- Number of objects we want to retrieveclassToConvert- Type of the target objectcriteria- The search criteria- Returns:
- List of corresponding objects
-
findObjectById
Fetch an object by its id- Specified by:
findObjectByIdin interfaceOdooRpcClient- Type Parameters:
T- The type of the target Object- Parameters:
idToFetch- The id of the object we want to fetchclassToConvert- The type of the target Object- Returns:
- The object fetched
-
findListByIdsInt
public <T extends OdooObj> List<T> findListByIdsInt(List<Integer> idsToFetch, Class<T> classToConvert) Same asfindObjectById(OdooId, Class)but with a List- Specified by:
findListByIdsIntin interfaceOdooRpcClient- 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 fetchclassToConvert- The type of the target objects- Returns:
- List of built objects
-
findListByIds
Same as above but with Odoo Ids- Specified by:
findListByIdsin interfaceOdooRpcClient- Type Parameters:
T- The type of the target objects- Parameters:
idsToFetch- The ids of objects we want to fetch under the form ofOdooIdclassToConvert- The type of the target objects- Returns:
- List of built objects
-