Class OdooUtils
java.lang.Object
io.openems.backend.metadata.odoo.odoo.OdooUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Wrapper for the reply of a call tosendJsonrpcRequest(String, JsonObject)
. -
Method Summary
Modifier and TypeMethodDescriptionprotected static void
addChatterMessage
(Credentials credentials, String model, int id, String message) Adds a message in Odoo Chatter ('mail.thread').protected static int
create
(Credentials credentials, String model, FieldValue<?>... fieldValues) Create a record in Odoo.protected static int
Create a record in Odoo.static <T> T
Return Field value in values and cast it to type.protected static Object[]
getAsObjectArray
(Domain... domains) protected static <T> Optional<T>
getAsOptional
(Object object, Class<T> type) static <T> T
getAsOrElse
(Field field, Map<String, ?> values, Class<T> type, T alternate) Return Field value in values and cast it to type.protected static String[]
getAsStringArray
(Field... fields) protected static int
getObjectReference
(Credentials credentials, String module, String name) Executes a get object reference from Odoo.getOdooReferenceId
(Object object) protected static byte[]
getOdooReport
(Credentials credentials, String report, int id) Returns a Odoo report as a byte array.protected static String
login
(Credentials credentials, String username, String password) Authenticates a user using Username and Password.readMany
(Credentials credentials, String model, Integer[] ids, Field... fields) Reads multiple records from Odoo.readOne
(Credentials credentials, String model, int id, Field... fields) Reads a record from Odoo.protected static Integer[]
search
(Credentials credentials, String model, Domain... domains) Executes a search on Odoo.searchRead
(Credentials credentials, String model, Field[] fields, Domain... domains) Search-Reads multiple records from Odoo.protected static OdooUtils.SuccessResponseAndHeaders
sendAdminJsonrpcRequest
(Credentials credentials, String url, com.google.gson.JsonObject request) Sends a request with admin privileges.protected static OdooUtils.SuccessResponseAndHeaders
sendAdminJsonrpcRequest
(Credentials credentials, String url, com.google.gson.JsonObject request, int timeout) protected static Future<OdooUtils.SuccessResponseAndHeaders>
sendAdminJsonrpcRequestAsync
(Credentials credentials, String url, com.google.gson.JsonObject request) Sends a request with admin privileges in async.sendJsonrpcRequest
(String url, com.google.gson.JsonObject request) Sends a JSON-RPC Request to an Odoo server - without Cookie header.sendJsonrpcRequest
(String url, String cookie, com.google.gson.JsonObject request) Sends a JSON-RPC Request to an Odoo server - without Cookie header.sendJsonrpcRequest
(String url, String cookie, com.google.gson.JsonObject request, int timeout) Sends a JSON-RPC Request to an Odoo server.static void
write
(Credentials credentials, String model, Integer[] ids, FieldValue<?>... fieldValues) Update a record in Odoo.protected static void
Update a record in Odoo.
-
Method Details
-
sendJsonrpcRequest
public static OdooUtils.SuccessResponseAndHeaders sendJsonrpcRequest(String url, com.google.gson.JsonObject request) throws OpenemsError.OpenemsNamedException Sends a JSON-RPC Request to an Odoo server - without Cookie header.- Parameters:
url
- the URLrequest
- the JSON-RPC Request asJsonObject
- Returns:
- the
JsonObject
response and HTTP connection headers on success - Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendJsonrpcRequest
public static OdooUtils.SuccessResponseAndHeaders sendJsonrpcRequest(String url, String cookie, com.google.gson.JsonObject request) throws OpenemsError.OpenemsNamedException Sends a JSON-RPC Request to an Odoo server - without Cookie header.- Parameters:
url
- the URLcookie
- the Cookierequest
- the JSON-RPC Request asJsonObject
- Returns:
- the
JsonObject
response and HTTP connection headers on success - Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendJsonrpcRequest
public static OdooUtils.SuccessResponseAndHeaders sendJsonrpcRequest(String url, String cookie, com.google.gson.JsonObject request, int timeout) throws OpenemsError.OpenemsNamedException Sends a JSON-RPC Request to an Odoo server.- Parameters:
url
- the URLcookie
- a Cookie stringrequest
- the JSON-RPC Request asJsonObject
timeout
- readtimeout in milliseconds- Returns:
- the
JsonObject
response and HTTP connection headers on success - Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAdminJsonrpcRequest
protected static OdooUtils.SuccessResponseAndHeaders sendAdminJsonrpcRequest(Credentials credentials, String url, com.google.gson.JsonObject request, int timeout) throws OpenemsError.OpenemsNamedException -
sendAdminJsonrpcRequest
protected static OdooUtils.SuccessResponseAndHeaders sendAdminJsonrpcRequest(Credentials credentials, String url, com.google.gson.JsonObject request) throws OpenemsError.OpenemsNamedException Sends a request with admin privileges.- Parameters:
credentials
- the Odoo credentialsurl
- to send the requestrequest
- to send- Returns:
- SuccessResponseAndHeaders response
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAdminJsonrpcRequestAsync
protected static Future<OdooUtils.SuccessResponseAndHeaders> sendAdminJsonrpcRequestAsync(Credentials credentials, String url, com.google.gson.JsonObject request) throws OpenemsError.OpenemsNamedException Sends a request with admin privileges in async.- Parameters:
credentials
- the Odoo credentialsurl
- to send the requestrequest
- to send- Returns:
- SuccessResponseAndHeaders response as Future
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
login
protected static String login(Credentials credentials, String username, String password) throws OpenemsError.OpenemsNamedException Authenticates a user using Username and Password.- Parameters:
credentials
- used to get Odoo urlusername
- the Usernamepassword
- the Password- Returns:
- the session_id
- Throws:
OpenemsError.OpenemsNamedException
- on login error
-
getAsStringArray
-
getAsObjectArray
-
search
protected static Integer[] search(Credentials credentials, String model, Domain... domains) throws OpenemsException Executes a search on Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- Odoo model to query (e.g. 'res.partner')domains
- Odoo domain filters- Returns:
- Odoo object ids
- Throws:
OpenemsException
- on error
-
readOne
protected static Map<String,Object> readOne(Credentials credentials, String model, int id, Field... fields) throws OpenemsException Reads a record from Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- Odoo model to query (e.g. 'res.partner')id
- id of model to readfields
- fields that should be read- Returns:
- the record as a Map
- Throws:
OpenemsException
- on error
-
readMany
protected static Map<String,Object>[] readMany(Credentials credentials, String model, Integer[] ids, Field... fields) throws OpenemsException Reads multiple records from Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- Odoo model to query (e.g. 'res.partner')ids
- ids of model to readfields
- fields that should be read- Returns:
- the records as a Map array
- Throws:
OpenemsException
- on error
-
searchRead
protected static Map<String,Object>[] searchRead(Credentials credentials, String model, Field[] fields, Domain... domains) throws OpenemsException Search-Reads multiple records from Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- Odoo model to query (e.g. 'res.partner')fields
- fields that should be readdomains
- filter domains- Returns:
- the records as a Map array
- Throws:
OpenemsException
- on error
-
getObjectReference
protected static int getObjectReference(Credentials credentials, String module, String name) throws OpenemsException Executes a get object reference from Odoo.- Parameters:
credentials
- the Odoo credentialsmodule
- the Odoo modulename
- the external identifier- Returns:
- internal id of external identifier
- Throws:
OpenemsException
- on error
-
addChatterMessage
protected static void addChatterMessage(Credentials credentials, String model, int id, String message) throws OpenemsException Adds a message in Odoo Chatter ('mail.thread').- Parameters:
credentials
- the Odoo credentialsmodel
- Odoo model (e.g. 'res.partner')id
- id of modelmessage
- the message- Throws:
OpenemsException
- on error
-
create
protected static int create(Credentials credentials, String model, FieldValue<?>... fieldValues) throws OpenemsException Create a record in Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- the Oddo modelfieldValues
- fields and values that should be written- Returns:
- Odoo id of created record
- Throws:
OpenemsException
- on error
-
create
protected static int create(Credentials credentials, String model, Map<String, Object> fieldValues) throws OpenemsExceptionCreate a record in Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- the Oddo modelfieldValues
- fields and values that should be written- Returns:
- Odoo id of created record
- Throws:
OpenemsException
- on error
-
write
public static void write(Credentials credentials, String model, Integer[] ids, FieldValue<?>... fieldValues) throws OpenemsException Update a record in Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- the Odoo modelids
- ids of model to updatefieldValues
- fields and values that should be written- Throws:
OpenemsException
- on error
-
write
protected static void write(Credentials credentials, String model, Integer[] ids, Map<String, Object> fieldValues) throws OpenemsExceptionUpdate a record in Odoo.- Parameters:
credentials
- the Odoo credentialsmodel
- the Odoo modelids
- ids of model to updatefieldValues
- fields and values that should be written- Throws:
OpenemsException
- on error
-
getAsOptional
- Type Parameters:
T
- expected type- Parameters:
object
- the value as objecttype
- the expected type of object- Returns:
- the value as
Optional
String
-
getOdooReferenceId
- Parameters:
object
- the odoo reference to extract- Returns:
- the odoo reference id or empty
Optional
-
getOdooReport
protected static byte[] getOdooReport(Credentials credentials, String report, int id) throws OpenemsError.OpenemsNamedException Returns a Odoo report as a byte array. Search for the given template id in combination with the concrete report id.- Parameters:
credentials
- the Odoo credentialssreport
- the Odoo template idid
- the Odoo report id- Returns:
- the Odoo report as a byte array
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getAs
Return Field value in values and cast it to type.- Type Parameters:
T
- expected type of value- Parameters:
field
- to search forvalues
- map with values to search intype
- to cast into- Returns:
- value found in map casted to type or null on error
-
getAsOrElse
Return Field value in values and cast it to type.- Type Parameters:
T
- expected type of value- Parameters:
field
- to search forvalues
- map with values to search intype
- to cast intoalternate
- value to return- Returns:
- value found in map casted to type or alternate on error
-