Class OdooUtils


  • public class OdooUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void addChatterMessage​(Credentials credentials, java.lang.String model, int id, java.lang.String message)
      Adds a message in Odoo Chatter ('mail.thread').
      protected static int create​(Credentials credentials, java.lang.String model, FieldValue<?>... fieldValues)
      Create a record in Odoo.
      protected static int create​(Credentials credentials, java.lang.String model, java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
      Create a record in Odoo.
      protected static java.lang.Integer getAsInteger​(java.lang.Object object)
      Return the Object type-safe as a Integer; or otherwise null.
      protected static java.lang.String getAsString​(java.lang.Object object)
      Return the Object type-safe as a String; or otherwise as an empty String.
      protected static java.util.Optional<java.lang.Integer> getOdooRefernceId​(java.lang.Object object)
      Return the odoo reference id as a Integer, otherwise empty Optional.
      protected static byte[] getOdooReport​(Credentials credentials, java.lang.String report, int id)
      Returns a Odoo report as a byte array.
      protected static java.lang.String login​(Credentials credentials, java.lang.String username, java.lang.String password)
      Authenticates a user using Username and Password.
      protected static java.util.Map<java.lang.String,​java.lang.Object>[] readMany​(Credentials credentials, java.lang.String model, java.lang.Integer[] ids, Field... fields)
      Reads multiple records from Odoo.
      protected static java.util.Map<java.lang.String,​java.lang.Object> readOne​(Credentials credentials, java.lang.String model, int id, Field... fields)
      Reads a record from Odoo.
      protected static int[] search​(Credentials credentials, java.lang.String model, Domain... domains)
      Executes a search on Odoo.
      protected static java.util.Map<java.lang.String,​java.lang.Object>[] searchAndRead​(Credentials credentials, java.lang.String model, Domain[] domains, Field[] fields)
      Executes a Search and read on Odoo.
      protected static java.util.Map<java.lang.String,​java.lang.Object>[] searchRead​(Credentials credentials, java.lang.String model, Field[] fields, Domain... domains)
      Search-Reads multiple records from Odoo.
      protected static void sendAdminJsonrpcRequest​(Credentials credentials, java.lang.String url, com.google.gson.JsonObject request)
      Sends a request with admin privileges.
      static OdooUtils.SuccessResponseAndHeaders sendJsonrpcRequest​(java.lang.String url, com.google.gson.JsonObject request)
      Sends a JSON-RPC Request to an Odoo server - without Cookie header.
      static OdooUtils.SuccessResponseAndHeaders sendJsonrpcRequest​(java.lang.String url, java.lang.String cookie, com.google.gson.JsonObject request)
      Sends a JSON-RPC Request to an Odoo server.
      static void write​(Credentials credentials, java.lang.String model, java.lang.Integer[] ids, FieldValue<?>... fieldValues)
      Update a record in Odoo.
      protected static void write​(Credentials credentials, java.lang.String model, java.lang.Integer[] ids, java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
      Update a record in Odoo.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_SERVER_DATE_FORMAT

        public static final java.lang.String DEFAULT_SERVER_DATE_FORMAT
        See Also:
        Constant Field Values
      • DEFAULT_SERVER_TIME_FORMAT

        public static final java.lang.String DEFAULT_SERVER_TIME_FORMAT
        See Also:
        Constant Field Values
      • DEFAULT_SERVER_DATETIME_FORMAT

        public static final java.lang.String DEFAULT_SERVER_DATETIME_FORMAT
        See Also:
        Constant Field Values
      • DATETIME_FORMATTER

        public static final java.time.format.DateTimeFormatter DATETIME_FORMATTER
    • Method Detail

      • login

        protected static java.lang.String login​(Credentials credentials,
                                                java.lang.String username,
                                                java.lang.String password)
                                         throws OpenemsError.OpenemsNamedException
        Authenticates a user using Username and Password.
        Parameters:
        credentials - used to get Odoo url
        username - the Username
        password - the Password
        Returns:
        the session_id
        Throws:
        OpenemsError.OpenemsNamedException - on login error
      • search

        protected static int[] search​(Credentials credentials,
                                      java.lang.String model,
                                      Domain... domains)
                               throws OpenemsException
        Executes a search on Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model to query (e.g. 'res.partner')
        domains - Odoo domain filters
        Returns:
        Odoo object ids
        Throws:
        OpenemsException - on error
      • readOne

        protected static java.util.Map<java.lang.String,​java.lang.Object> readOne​(Credentials credentials,
                                                                                        java.lang.String model,
                                                                                        int id,
                                                                                        Field... fields)
                                                                                 throws OpenemsException
        Reads a record from Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model to query (e.g. 'res.partner')
        id - id of model to read
        fields - fields that should be read
        Returns:
        the record as a Map
        Throws:
        OpenemsException - on error
      • searchAndRead

        protected static java.util.Map<java.lang.String,​java.lang.Object>[] searchAndRead​(Credentials credentials,
                                                                                                java.lang.String model,
                                                                                                Domain[] domains,
                                                                                                Field[] fields)
                                                                                         throws OpenemsException
        Executes a Search and read on Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model to query (e.g. 'res.partner')
        domains - Odoo domain filters
        fields - the Fields
        Returns:
        Odoo object ids
        Throws:
        OpenemsException - on error
        See Also:
        Odoo API Integration
      • readMany

        protected static java.util.Map<java.lang.String,​java.lang.Object>[] readMany​(Credentials credentials,
                                                                                           java.lang.String model,
                                                                                           java.lang.Integer[] ids,
                                                                                           Field... fields)
                                                                                    throws OpenemsException
        Reads multiple records from Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model to query (e.g. 'res.partner')
        ids - ids of model to read
        fields - fields that should be read
        Returns:
        the records as a Map array
        Throws:
        OpenemsException - on error
      • searchRead

        protected static java.util.Map<java.lang.String,​java.lang.Object>[] searchRead​(Credentials credentials,
                                                                                             java.lang.String model,
                                                                                             Field[] fields,
                                                                                             Domain... domains)
                                                                                      throws OpenemsException
        Search-Reads multiple records from Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model to query (e.g. 'res.partner')
        fields - fields that should be read
        domains - filter domains
        Returns:
        the records as a Map array
        Throws:
        OpenemsException - on error
      • addChatterMessage

        protected static void addChatterMessage​(Credentials credentials,
                                                java.lang.String model,
                                                int id,
                                                java.lang.String message)
                                         throws OpenemsException
        Adds a message in Odoo Chatter ('mail.thread').
        Parameters:
        credentials - the Odoo credentials
        model - Odoo model (e.g. 'res.partner')
        id - id of model
        message - the message
        Throws:
        OpenemsException - on error
      • create

        protected static int create​(Credentials credentials,
                                    java.lang.String model,
                                    FieldValue<?>... fieldValues)
                             throws OpenemsException
        Create a record in Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - the Oddo model
        fieldValues - fields and values that should be written
        Returns:
        Odoo id of created record
        Throws:
        OpenemsException - on error
      • create

        protected static int create​(Credentials credentials,
                                    java.lang.String model,
                                    java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
                             throws OpenemsException
        Create a record in Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - the Oddo model
        fieldValues - fields and values that should be written
        Returns:
        Odoo id of created record
        Throws:
        OpenemsException - on error
      • write

        public static void write​(Credentials credentials,
                                 java.lang.String model,
                                 java.lang.Integer[] ids,
                                 FieldValue<?>... fieldValues)
                          throws OpenemsException
        Update a record in Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - the Odoo model
        ids - ids of model to update
        fieldValues - fields and values that should be written
        Throws:
        OpenemsException - on error
      • write

        protected static void write​(Credentials credentials,
                                    java.lang.String model,
                                    java.lang.Integer[] ids,
                                    java.util.Map<java.lang.String,​java.lang.Object> fieldValues)
                             throws OpenemsException
        Update a record in Odoo.
        Parameters:
        credentials - the Odoo credentials
        model - the Odoo model
        ids - ids of model to update
        fieldValues - fields and values that should be written
        Throws:
        OpenemsException - on error
      • getAsString

        protected static java.lang.String getAsString​(java.lang.Object object)
        Return the Object type-safe as a String; or otherwise as an empty String.
        Parameters:
        object - the value as object
        Returns:
        the value as String
      • getAsInteger

        protected static java.lang.Integer getAsInteger​(java.lang.Object object)
        Return the Object type-safe as a Integer; or otherwise null.
        Parameters:
        object - the value as object
        Returns:
        the value as Integer
      • getOdooRefernceId

        protected static java.util.Optional<java.lang.Integer> getOdooRefernceId​(java.lang.Object object)
        Return the odoo reference id as a Integer, otherwise empty Optional.
        Parameters:
        object - the odoo reference to extract
        Returns:
        the odoo reference id or empty Optional
      • getOdooReport

        protected static byte[] getOdooReport​(Credentials credentials,
                                              java.lang.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 credentialss
        report - the Odoo template id
        id - the Odoo report id
        Returns:
        the Odoo report as a byte array
        Throws:
        OpenemsError.OpenemsNamedException - on error