Class OdooHandler
java.lang.Object
io.openems.backend.metadata.odoo.odoo.OdooHandler
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChatterMessage
(MyEdge edge, String message) Adds a message in Odoo Chatter ('mail.thread').void
assignEdgeToUser
(MyUser user, MyEdge edge, OdooUserRole userRole) Assigns the given user with givenOdooUserRole
to the Edge.authenticate
(String username, String password) Authenticates a user using Username and Password.com.google.gson.JsonObject
authenticateSession
(String sessionId) Authenticates a user using a Session-ID.getEdgeIdBySetupPassword
(String setupPassword) Returns Edge by setupPassword, otherwise an emptyOptional
.com.google.gson.JsonObject
getEdges
(MyUser user, GetEdgesRequest.PaginationOptions paginationOptions) Gets the Edges of the given user matching theGetEdgesRequest.PaginationOptions
.com.google.gson.JsonObject
getEdgeWithRole
(MyUser user, String edgeId) Gets the edge with theRole
of the user.byte[]
getOdooSetupProtocolReport
(int setupProtocolId) Returns the Odoo report for a setup protocol.getSerialNumberForEdge
(Edge edge) Get serial number for the givenEdge
.com.google.gson.JsonObject
getSetupProtocolData
(MyUser user, String edgeName) Get latest Setup Protocol from Odoo or empty JsonObject if no protocol is available.getUserAlertingSettings
(String edgeId) get all alerting settings for specified edge.getUserAlertingSettings
(String edgeId, String userId) get alerting setting for user and edge.getUserInformation
(MyUser user) Returns information about the givenMyUser
.void
Logout a User.void
registerUser
(com.google.gson.JsonObject jsonObject, OdooUserRole role, OpenemsOEM.Manufacturer oem) Register an user in Odoo with the givenOdooUserRole
.sendNotificationMailAsync
(ZonedDateTime sentAt, String template, com.google.gson.JsonElement params) Call Odoo api to send multiple notification mails via Odoo async.void
setUserAlertingSettings
(MyUser user, String edgeId, List<AlertingSetting> userAlertingSettings) Update or create the alerting setting for the given edge und list of users.void
setUserInformation
(MyUser user, com.google.gson.JsonObject userJson) Update the givenMyUser
with information fromJsonObject
.int
submitSetupProtocol
(MyUser user, com.google.gson.JsonObject setupProtocolJson) Save the Setup Protocol to Odoo.void
updateUserLanguage
(MyUser user, Language language) Update language for the given user.void
writeEdge
(MyEdge edge, FieldValue<?>... fieldValues) Writes one field to Odoo Edge model.void
writeEdgeUser
(EdgeUser edgeUser, FieldValue<?>... fieldValues) Writes one field to Odoo EdgeUser model.
-
Field Details
-
parent
-
-
Constructor Details
-
OdooHandler
-
-
Method Details
-
writeEdge
Writes one field to Odoo Edge model.- Parameters:
edge
- the EdgefieldValues
- the FieldValues
-
writeEdgeUser
Writes one field to Odoo EdgeUser model.- Parameters:
edgeUser
- the EdgeUserfieldValues
- the FieldValues
-
addChatterMessage
Adds a message in Odoo Chatter ('mail.thread').- Parameters:
edge
- the Edgemessage
- the message
-
getEdgeIdBySetupPassword
Returns Edge by setupPassword, otherwise an emptyOptional
.- Parameters:
setupPassword
- to find Edge- Returns:
- Edge or empty
Optional
-
assignEdgeToUser
public void assignEdgeToUser(MyUser user, MyEdge edge, OdooUserRole userRole) throws OpenemsError.OpenemsNamedException Assigns the given user with givenOdooUserRole
to the Edge. If Edge already assigned to user exit method.- Parameters:
user
- the Odoo useredge
- the Odoo edgeuserRole
- the Odoo user role- Throws:
OpenemsError.OpenemsNamedException
- on error
-
authenticate
public String authenticate(String username, String password) throws OpenemsError.OpenemsNamedException Authenticates a user using Username and Password.- Parameters:
username
- the Usernamepassword
- the Password- Returns:
- the session_id
- Throws:
OpenemsError.OpenemsNamedException
- on login error
-
authenticateSession
public com.google.gson.JsonObject authenticateSession(String sessionId) throws OpenemsError.OpenemsNamedException Authenticates a user using a Session-ID.- Parameters:
sessionId
- the Odoo Session-ID- Returns:
- the
JsonObject
received from /openems_backend/info. - Throws:
OpenemsError.OpenemsNamedException
- on error
-
logout
Logout a User.- Parameters:
sessionId
- the Session-ID- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getUserInformation
Returns information about the givenMyUser
.- Parameters:
user
- theMyUser
to get information- Returns:
- the
Field.Partner
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
setUserInformation
public void setUserInformation(MyUser user, com.google.gson.JsonObject userJson) throws OpenemsError.OpenemsNamedException Update the givenMyUser
with information fromJsonObject
.- Parameters:
user
- theMyUser
to updateuserJson
- theJsonObject
information to update- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
-
getOdooSetupProtocolReport
public byte[] getOdooSetupProtocolReport(int setupProtocolId) throws OpenemsError.OpenemsNamedException Returns the Odoo report for a setup protocol.- Parameters:
setupProtocolId
- the Odoo setup protocol id- Returns:
- report as a byte array
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
submitSetupProtocol
public int submitSetupProtocol(MyUser user, com.google.gson.JsonObject setupProtocolJson) throws OpenemsError.OpenemsNamedException Save the Setup Protocol to Odoo.- Parameters:
user
-MyUser
current usersetupProtocolJson
-Field.SetupProtocol
the setup protocol- Returns:
- the Setup Protocol ID
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
registerUser
public void registerUser(com.google.gson.JsonObject jsonObject, OdooUserRole role, OpenemsOEM.Manufacturer oem) throws OpenemsError.OpenemsNamedException Register an user in Odoo with the givenOdooUserRole
.- Parameters:
jsonObject
-JsonObject
that represents an userrole
-OdooUserRole
to set for the useroem
- OEM name- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendNotificationMailAsync
public Future<OdooUtils.SuccessResponseAndHeaders> sendNotificationMailAsync(ZonedDateTime sentAt, String template, com.google.gson.JsonElement params) throws OpenemsError.OpenemsNamedException Call Odoo api to send multiple notification mails via Odoo async.- Parameters:
sentAt
- TimeStamp for last_notification fieldtemplate
- template to use for mailparams
- arguments for the template- Returns:
Future
ofOdooUtils.SuccessResponseAndHeaders
- Throws:
OpenemsError.OpenemsNamedException
- error
-
updateUserLanguage
Update language for the given user.- Parameters:
user
-MyUser
the current userlanguage
- to set- Throws:
OpenemsException
- on error
-
getSetupProtocolData
public com.google.gson.JsonObject getSetupProtocolData(MyUser user, String edgeName) throws OpenemsError.OpenemsNamedException Get latest Setup Protocol from Odoo or empty JsonObject if no protocol is available.- Parameters:
user
-MyUser
the current useredgeName
- the unique Edge name- Returns:
- the Setup Protocol as a JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getSerialNumberForEdge
Get serial number for the givenEdge
. -
getUserAlertingSettings
get all alerting settings for specified edge.- Parameters:
edgeId
- ID of Edge- Returns:
- list of alerting settings
- Throws:
OpenemsException
- on error
-
getUserAlertingSettings
public AlertingSetting getUserAlertingSettings(String edgeId, String userId) throws OpenemsException get alerting setting for user and edge.- Parameters:
edgeId
- ID of EdgeuserId
- ID of User- Returns:
AlertingSetting
or {@link null} if no settings are stored- Throws:
OpenemsException
- on error
-
setUserAlertingSettings
public void setUserAlertingSettings(MyUser user, String edgeId, List<AlertingSetting> userAlertingSettings) throws OpenemsException Update or create the alerting setting for the given edge und list of users.- Parameters:
user
- the current useredgeId
- the EdgeuserAlertingSettings
- list of users- Throws:
OpenemsException
- on error
-
getEdges
public com.google.gson.JsonObject getEdges(MyUser user, GetEdgesRequest.PaginationOptions paginationOptions) throws OpenemsError.OpenemsNamedException Gets the Edges of the given user matching theGetEdgesRequest.PaginationOptions
.- Parameters:
user
- the currentMyUser
paginationOptions
- theGetEdgesRequest.PaginationOptions
- Returns:
- the edges
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getEdgeWithRole
public com.google.gson.JsonObject getEdgeWithRole(MyUser user, String edgeId) throws OpenemsError.OpenemsNamedException Gets the edge with theRole
of the user.- Parameters:
user
- the currentMyUser
edgeId
- the id of the edge- Returns:
- the edge with the role of the user
- Throws:
OpenemsError.OpenemsNamedException
- on error
-