Package io.openems.backend.metadata.odoo
Class MetadataOdoo
java.lang.Object
io.openems.backend.common.component.AbstractOpenemsBackendComponent
io.openems.backend.common.metadata.AbstractMetadata
io.openems.backend.metadata.odoo.MetadataOdoo
- All Implemented Interfaces:
AppCenterMetadata
,AppCenterMetadata.EdgeData
,AppCenterMetadata.UiData
,Mailer
,Metadata
,org.osgi.service.event.EventHandler
public class MetadataOdoo
extends AbstractMetadata
implements AppCenterMetadata, AppCenterMetadata.EdgeData, AppCenterMetadata.UiData, Metadata, Mailer, org.osgi.service.event.EventHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.openems.backend.common.metadata.AppCenterMetadata
AppCenterMetadata.EdgeData, AppCenterMetadata.UiData
Nested classes/interfaces inherited from interface io.openems.backend.common.metadata.Metadata
Metadata.Events, Metadata.GenericSystemLog
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addEdgeToUser
(User user, Edge edge) Assigns Edge to current user.authenticate
(String sessionId) Tries to authenticate at the Odoo server using a sessionId from a cookie.authenticate
(String username, String password) Authenticates the User by username and password.edge()
Handles operations with Edge.Gets all Offline-Edges.Get an Edge by its unique Edge-ID.getEdgeBySetupPassword
(String setupPassword) Get an Edge by Edge-SetupPassword.getEdgeIdForApikey
(String apikey) Gets the Edge-ID for an API-Key, i.e.getEdgeMetadataForUser
(User user, String edgeId) Gets the Role for a edge of the current user.org.osgi.service.event.EventAdmin
Returns an EventAdmin, used by Edge objects.Gets theOdooHandler
.getPageDevice
(User user, GetEdgesRequest.PaginationOptions paginationOptions) Gets a map of Edge-IDs with the role of the given user.Gets thePostgresHandler
.getSerialNumberForEdge
(Edge edge) Get serial number for the givenEdge
.byte[]
getSetupProtocol
(User user, int setupProtocolId) Returns the Setup Protocol PDF for the given id.com.google.gson.JsonObject
getSetupProtocolData
(User user, String edgeId) Return the Setup Protocol data as a JsonObject.getSuppliableKey
(User user, String edgeId, String appId) Gets a key that can be supplied to the installation of the given app.Gets the User for the given User-ID.getUserAlertingSettings
(String edgeId) Gets all the alerting settings for given edge id.getUserAlertingSettings
(String edgeId, String userId) Gets the alerting settings for given edge id and userId.getUserInformation
(User user) Gets information about the given userUser
.void
handleEvent
(org.osgi.service.event.Event event) boolean
Gets if the given app is free.void
Log an error message including the Component ID.void
logGenericSystemLog
(Metadata.GenericSystemLog systemLog) Handles a Systemlog-Message.void
Log an info message including the Component ID.void
Closes a session for a User.void
Log a warn message including the Component ID.void
registerUser
(com.google.gson.JsonObject jsonObject, OpenemsOEM.Manufacturer oem) Register a user.void
sendAddDeinstallAppInstanceHistory
(String edgeId, String appId, UUID instanceId, String userId) Sends a request to add a deinstall history entry.void
sendAddInstallAppInstanceHistory
(String key, String edgeId, String appId, UUID instanceId, String userId) Sends a request to add a install app history entry.void
sendAddRegisterKeyHistory
(String edgeId, String appId, String key, User user) Sends a request to register a key.void
sendAddUnregisterKeyHistory
(String edgeId, String appId, String key, User user) Sends a request to unregister a key.com.google.gson.JsonObject
sendGetInstalledApps
(String edgeId) Sends a request to get all installed apps on the edge that are logged in the backend these apps may not be actually on the edge.com.google.gson.JsonArray
sendGetPossibleApps
(String key, String edgeId) Sends a request to get all apps that can be installed with the given key.com.google.gson.JsonArray
sendGetRegisteredKeys
(String edgeId, String appId) Sends a request to get all registered keys to the given edge and app.com.google.gson.JsonObject
sendIsKeyApplicable
(String key, String edgeId, String appId) Sends a request if the key can be applied to the given edge and app id.void
sendMail
(ZonedDateTime sendAt, String template, com.google.gson.JsonElement params) Send alerting mail at stamp to users.void
setUserAlertingSettings
(User user, String edgeId, List<AlertingSetting> users) Sets the alerting settings for the given list of users.void
setUserInformation
(User user, com.google.gson.JsonObject jsonObject) Update the given userUser
with new informationJsonObject
.int
submitSetupProtocol
(User user, com.google.gson.JsonObject jsonObject) Submit the installation assistant protocol.void
updateUserLanguage
(User user, Language language) Update language from given user.Methods inherited from class io.openems.backend.common.metadata.AbstractMetadata
isInitialized, setInitialized
Methods inherited from class io.openems.backend.common.component.AbstractOpenemsBackendComponent
getName, logDebug, logDebug, logError, logInfo, logWarn
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.backend.common.metadata.Metadata
addEdgeToUser, getEdgeOrError, isInitialized
-
Field Details
-
odooHandler
-
postgresHandler
-
-
Constructor Details
-
MetadataOdoo
public MetadataOdoo()
-
-
Method Details
-
authenticate
public User authenticate(String username, String password) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Authenticates the User by username and password.- Specified by:
authenticate
in interfaceMetadata
- Parameters:
username
- the Usernamepassword
- the Password- Returns:
- the
User
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
authenticate
Tries to authenticate at the Odoo server using a sessionId from a cookie.- Specified by:
authenticate
in interfaceMetadata
- Parameters:
sessionId
- the Session-ID- Returns:
- the
User
- Throws:
OpenemsException
- on errorOpenemsError.OpenemsNamedException
- on error
-
logout
Description copied from interface:Metadata
Closes a session for a User. -
getEdgeIdForApikey
Description copied from interface:Metadata
Gets the Edge-ID for an API-Key, i.e. authenticates the API-Key.- Specified by:
getEdgeIdForApikey
in interfaceMetadata
- Parameters:
apikey
- the API-Key- Returns:
- the Edge-ID or Empty
-
getEdgeBySetupPassword
Description copied from interface:Metadata
Get an Edge by Edge-SetupPassword.- Specified by:
getEdgeBySetupPassword
in interfaceMetadata
- Parameters:
setupPassword
- to find Edge- Returns:
- Edge as a Optional
-
getEdge
Description copied from interface:Metadata
Get an Edge by its unique Edge-ID. -
getUser
Description copied from interface:Metadata
Gets the User for the given User-ID. -
getAllOfflineEdges
Description copied from interface:Metadata
Gets all Offline-Edges.- Specified by:
getAllOfflineEdges
in interfaceMetadata
- Returns:
- collection of Edges.
-
getOdooHandler
Gets theOdooHandler
.- Returns:
- the
OdooHandler
-
getPostgresHandler
Gets thePostgresHandler
.- Returns:
- the
PostgresHandler
-
logInfo
Description copied from class:AbstractOpenemsBackendComponent
Log an info message including the Component ID.- Overrides:
logInfo
in classAbstractOpenemsBackendComponent
- Parameters:
log
- the Logger that is used for writing the logmessage
- the Info-message
-
logWarn
Description copied from class:AbstractOpenemsBackendComponent
Log a warn message including the Component ID.- Overrides:
logWarn
in classAbstractOpenemsBackendComponent
- Parameters:
log
- the Logger that is used for writing the logmessage
- the Warn-message
-
logError
Description copied from class:AbstractOpenemsBackendComponent
Log an error message including the Component ID.- Overrides:
logError
in classAbstractOpenemsBackendComponent
- Parameters:
log
- the Logger that is used for writing the logmessage
- the Error-message
-
addEdgeToUser
Description copied from interface:Metadata
Assigns Edge to current user.If assignment fails, an OpenemsNamedException is thrown.
- Specified by:
addEdgeToUser
in interfaceMetadata
- Parameters:
user
- TheUser
edge
- TheEdge
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getUserInformation
Description copied from interface:Metadata
Gets information about the given userUser
.- Specified by:
getUserInformation
in interfaceMetadata
- Parameters:
user
-User
to read information- Returns:
Map
about the user- Throws:
OpenemsError.OpenemsNamedException
- on error
-
setUserInformation
public void setUserInformation(User user, com.google.gson.JsonObject jsonObject) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Update the given userUser
with new informationJsonObject
.- Specified by:
setUserInformation
in interfaceMetadata
- Parameters:
user
-User
to updatejsonObject
-JsonObject
information about the user- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getSetupProtocol
public byte[] getSetupProtocol(User user, int setupProtocolId) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Returns the Setup Protocol PDF for the given id.- Specified by:
getSetupProtocol
in interfaceMetadata
- Parameters:
user
-User
the current usersetupProtocolId
- the setup protocol id to search- Returns:
- the Setup Protocol PDF as a byte array
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getSetupProtocolData
public com.google.gson.JsonObject getSetupProtocolData(User user, String edgeId) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Return the Setup Protocol data as a JsonObject.- Specified by:
getSetupProtocolData
in interfaceMetadata
- Parameters:
user
-User
the current useredgeId
- theEdge
ID to get the data- Returns:
- Setup Protocol as a JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
submitSetupProtocol
public int submitSetupProtocol(User user, com.google.gson.JsonObject jsonObject) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Submit the installation assistant protocol.- Specified by:
submitSetupProtocol
in interfaceMetadata
- Parameters:
user
-User
the current userjsonObject
-JsonObject
the setup protocol- Returns:
- id of created setup protocol
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
registerUser
public void registerUser(com.google.gson.JsonObject jsonObject, OpenemsOEM.Manufacturer oem) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Register a user.- Specified by:
registerUser
in interfaceMetadata
- Parameters:
jsonObject
-JsonObject
that represents an useroem
- OEM name- Throws:
OpenemsError.OpenemsNamedException
- on error
-
updateUserLanguage
public void updateUserLanguage(User user, Language language) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Update language from given user.- Specified by:
updateUserLanguage
in interfaceMetadata
- Parameters:
user
-User
the current userlanguage
- to set language- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getEventAdmin
public org.osgi.service.event.EventAdmin getEventAdmin()Description copied from interface:Metadata
Returns an EventAdmin, used by Edge objects.- Specified by:
getEventAdmin
in interfaceMetadata
- Returns:
EventAdmin
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event) - Specified by:
handleEvent
in interfaceorg.osgi.service.event.EventHandler
-
logGenericSystemLog
Description copied from interface:Metadata
Handles a Systemlog-Message.- Specified by:
logGenericSystemLog
in interfaceMetadata
- Parameters:
systemLog
- the log
-
edge
Description copied from interface:Metadata
Handles operations with Edge.To be completed. This should eventually replace Edge.
- Specified by:
edge
in interfaceMetadata
- Returns:
- an
EdgeHandler
-
getSerialNumberForEdge
Description copied from interface:Metadata
Get serial number for the givenEdge
.- Specified by:
getSerialNumberForEdge
in interfaceMetadata
- Parameters:
edge
-Edge
to search for serial number- Returns:
- Serial number or empty
Optional
-
sendMail
Description copied from interface:Mailer
Send alerting mail at stamp to users. -
sendIsKeyApplicable
public com.google.gson.JsonObject sendIsKeyApplicable(String key, String edgeId, String appId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata
Sends a request if the key can be applied to the given edge and app id.- Specified by:
sendIsKeyApplicable
in interfaceAppCenterMetadata
- Parameters:
key
- the key to be validatededgeId
- the edge the app gets installedappId
- the app that gets installed- Returns:
- the result as a
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAddInstallAppInstanceHistory
public void sendAddInstallAppInstanceHistory(String key, String edgeId, String appId, UUID instanceId, String userId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.EdgeData
Sends a request to add a install app history entry.- Specified by:
sendAddInstallAppInstanceHistory
in interfaceAppCenterMetadata.EdgeData
- Parameters:
key
- the key that the app gets installed withedgeId
- the edge the app gets installed onappId
- the app that gets installedinstanceId
- the instanceId of the installed appuserId
- the user who added the instance- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAddDeinstallAppInstanceHistory
public void sendAddDeinstallAppInstanceHistory(String edgeId, String appId, UUID instanceId, String userId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.EdgeData
Sends a request to add a deinstall history entry.- Specified by:
sendAddDeinstallAppInstanceHistory
in interfaceAppCenterMetadata.EdgeData
- Parameters:
edgeId
- the edge the instance gets removedappId
- the id of the appinstanceId
- the instanceId of the removed instanceuserId
- the user who removed the instance- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAddRegisterKeyHistory
public void sendAddRegisterKeyHistory(String edgeId, String appId, String key, User user) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.UiData
Sends a request to register a key.- Specified by:
sendAddRegisterKeyHistory
in interfaceAppCenterMetadata.UiData
- Parameters:
edgeId
- the edge the key gets registered toappId
- the appId that gets registeredkey
- the key to register to the appuser
- the user who added the registration- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendAddUnregisterKeyHistory
public void sendAddUnregisterKeyHistory(String edgeId, String appId, String key, User user) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.UiData
Sends a request to unregister a key.- Specified by:
sendAddUnregisterKeyHistory
in interfaceAppCenterMetadata.UiData
- Parameters:
edgeId
- the edgeappId
- the id of the appkey
- the keyuser
- the user who removed the registration- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendGetRegisteredKeys
public com.google.gson.JsonArray sendGetRegisteredKeys(String edgeId, String appId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.UiData
Sends a request to get all registered keys to the given edge and app.- Specified by:
sendGetRegisteredKeys
in interfaceAppCenterMetadata.UiData
- Parameters:
edgeId
- the edge the registered key can be applied onappId
- the app of the registed key- Returns:
- the result as a
JsonObject
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendGetPossibleApps
public com.google.gson.JsonArray sendGetPossibleApps(String key, String edgeId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata
Sends a request to get all apps that can be installed with the given key.- Specified by:
sendGetPossibleApps
in interfaceAppCenterMetadata
- Parameters:
key
- the apps of the keyedgeId
- the apps on which edge- Returns:
- the bundles and their apps
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
sendGetInstalledApps
public com.google.gson.JsonObject sendGetInstalledApps(String edgeId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.EdgeData
Sends a request to get all installed apps on the edge that are logged in the backend these apps may not be actually on the edge.- Specified by:
sendGetInstalledApps
in interfaceAppCenterMetadata.EdgeData
- Parameters:
edgeId
- the apps on which edge- Returns:
- the installed apps
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getSuppliableKey
public String getSuppliableKey(User user, String edgeId, String appId) throws OpenemsError.OpenemsNamedException Description copied from interface:AppCenterMetadata.UiData
Gets a key that can be supplied to the installation of the given app.- Specified by:
getSuppliableKey
in interfaceAppCenterMetadata.UiData
- Parameters:
user
- the requested useredgeId
- the edge to install the app onappId
- the app to install- Returns:
- the key or null if none can be supplied
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
isAppFree
Description copied from interface:AppCenterMetadata.UiData
Gets if the given app is free.- Specified by:
isAppFree
in interfaceAppCenterMetadata.UiData
- Parameters:
user
- the requested userappId
- the id of the app- Returns:
- true if the app is free
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getUserAlertingSettings
Description copied from interface:Metadata
Gets all the alerting settings for given edge id.- Specified by:
getUserAlertingSettings
in interfaceMetadata
- Parameters:
edgeId
- the Edge ID- Returns:
- List of
AlertingSetting
- Throws:
OpenemsException
- on error
-
getUserAlertingSettings
public AlertingSetting getUserAlertingSettings(String edgeId, String userId) throws OpenemsException Description copied from interface:Metadata
Gets the alerting settings for given edge id and userId.- Specified by:
getUserAlertingSettings
in interfaceMetadata
- Parameters:
edgeId
- the Edge IDuserId
- the User ID- Returns:
- List of
UserRoleDelayTime
- Throws:
OpenemsException
- on error
-
setUserAlertingSettings
public void setUserAlertingSettings(User user, String edgeId, List<AlertingSetting> users) throws OpenemsException Description copied from interface:Metadata
Sets the alerting settings for the given list of users.- Specified by:
setUserAlertingSettings
in interfaceMetadata
- Parameters:
user
-User
the current useredgeId
- the Edge-IDusers
- list of users to update- Throws:
OpenemsException
- on error
-
getPageDevice
public List<GetEdgesResponse.EdgeMetadata> getPageDevice(User user, GetEdgesRequest.PaginationOptions paginationOptions) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Gets a map of Edge-IDs with the role of the given user.- Specified by:
getPageDevice
in interfaceMetadata
- Parameters:
user
-User
the current userpaginationOptions
- the options of the requesting page- Returns:
- the role to the Edge-IDs
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
getEdgeMetadataForUser
public GetEdgesResponse.EdgeMetadata getEdgeMetadataForUser(User user, String edgeId) throws OpenemsError.OpenemsNamedException Description copied from interface:Metadata
Gets the Role for a edge of the current user.- Specified by:
getEdgeMetadataForUser
in interfaceMetadata
- Parameters:
user
-User
the current useredgeId
- the Edge-ID- Returns:
- the role to the edge
- Throws:
OpenemsError.OpenemsNamedException
- on error
-