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.com.google.gson.JsonObject
getAddDeinstallAppInstanceHistory
(String edgeId, String appId, UUID instanceId, String userId) Gets the response to add a deinstall app instance history entry.com.google.gson.JsonObject
getAddInstallAppInstanceHistory
(String key, String edgeId, String appId, UUID instanceId, String userId) Gets the response to a add install app instance history entry.com.google.gson.JsonObject
getAddRegisterKeyHistory
(String edgeId, String appId, String key, MyUser user) Gets the response to register a key.com.google.gson.JsonObject
getAddUnregisterKeyHistory
(String edgeId, String appId, String key, MyUser user) Gets the response to unregister a key.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
(User user, String edgeId) Gets the edge with theRole
of the user.com.google.gson.JsonObject
getInstalledApps
(String edgeId) Gets the installed apps.com.google.gson.JsonObject
getIsKeyApplicable
(String key, String edgeId, String appId) Gets if the given key can be applied to the given app and edge id.byte[]
getOdooSetupProtocolReport
(int setupProtocolId) Returns the Odoo report for a setup protocol.com.google.gson.JsonObject
getPossibleApps
(String key, String edgeId) Gets the possible apps to install with this key.com.google.gson.JsonObject
getRegisteredKeys
(String edgeId, String appId) Gets the registered keys to a edge and app.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
. -
getIsKeyApplicable
public com.google.gson.JsonObject getIsKeyApplicable(String key, String edgeId, String appId) throws OpenemsError.OpenemsNamedException Gets if the given key can be applied to the given app and edge id.- Parameters:
key
- the key to be validatededgeId
- the edgeId the app should get installedappId
- the appId of the app that should get installed- Returns:
- the Response result as a JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getAddInstallAppInstanceHistory
public com.google.gson.JsonObject getAddInstallAppInstanceHistory(String key, String edgeId, String appId, UUID instanceId, String userId) throws OpenemsError.OpenemsNamedException Gets the response to a add install app instance history entry.- Parameters:
key
- the key to install the app withedgeId
- the id of the edge the app gets installed onappId
- the app that gets installedinstanceId
- the instanceId of the create instanceuserId
- the user who added the instance- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getAddDeinstallAppInstanceHistory
public com.google.gson.JsonObject getAddDeinstallAppInstanceHistory(String edgeId, String appId, UUID instanceId, String userId) throws OpenemsError.OpenemsNamedException Gets the response to add a deinstall app instance history entry.- Parameters:
edgeId
- the edge the app gets removed onappId
- the appId of the removed instanceinstanceId
- the instanceId of the removed instanceuserId
- the user who removed the instance- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getAddRegisterKeyHistory
public com.google.gson.JsonObject getAddRegisterKeyHistory(String edgeId, String appId, String key, MyUser user) throws OpenemsError.OpenemsNamedException Gets the response to register a key.- Parameters:
edgeId
- the edgeId the key gets registered on.appId
- the appId the key gets registered to.key
- the key that gets registereduser
- the user who registered the key- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getAddUnregisterKeyHistory
public com.google.gson.JsonObject getAddUnregisterKeyHistory(String edgeId, String appId, String key, MyUser user) throws OpenemsError.OpenemsNamedException Gets the response to unregister a key.- Parameters:
edgeId
- the edgeId the registered key was assigned to.appId
- the appId the registered key was assigned to or null if assigned to edge.key
- the registered keyuser
- the user who deregistered the key- Returns:
- the response result as a
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getRegisteredKeys
public com.google.gson.JsonObject getRegisteredKeys(String edgeId, String appId) throws OpenemsError.OpenemsNamedException Gets the registered keys to a edge and app.- Parameters:
edgeId
- the edge the key is registered onappId
- the app the key is registered to- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getPossibleApps
public com.google.gson.JsonObject getPossibleApps(String key, String edgeId) throws OpenemsError.OpenemsNamedException Gets the possible apps to install with this key.- Parameters:
key
- the apps of which keyedgeId
- the apps on which edge- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getInstalledApps
public com.google.gson.JsonObject getInstalledApps(String edgeId) throws OpenemsError.OpenemsNamedException Gets the installed apps.- Parameters:
edgeId
- the apps on which edge- Returns:
- the result as
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
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(User 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
-