Package io.openems.backend.metadata.file
Class FileMetadata
- java.lang.Object
-
- io.openems.backend.common.component.AbstractOpenemsBackendComponent
-
- io.openems.backend.common.metadata.AbstractMetadata
-
- io.openems.backend.metadata.file.FileMetadata
-
- All Implemented Interfaces:
Metadata
,org.osgi.service.event.EventHandler
public class FileMetadata extends AbstractMetadata implements Metadata, org.osgi.service.event.EventHandler
This implementation of MetadataService reads Edges configuration from a file. The layout of the file is as follows:{ edges: { [edgeId: string]: { comment: string, apikey: string setuppassword?: string } } }
This implementation does not require any login. It always serves the same user, which has 'ADMIN'-permissions on all given Edges.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.openems.backend.common.metadata.Metadata
Metadata.Events
-
-
Constructor Summary
Constructors Constructor Description FileMetadata()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdgeToUser(User user, Edge edge)
Assigns Edge to current user.User
authenticate(java.lang.String token)
Authenticates the User by a Token.User
authenticate(java.lang.String username, java.lang.String password)
Authenticates the User by username and password.EdgeHandler
edge()
Handles operations with Edge.java.util.Collection<Edge>
getAllOfflineEdges()
Gets all Offline-Edges.java.util.Optional<Edge>
getEdge(java.lang.String edgeId)
Get an Edge by its unique Edge-ID.java.util.Optional<Edge>
getEdgeBySetupPassword(java.lang.String setupPassword)
Get an Edge by Edge-SetupPassword.java.util.Optional<java.lang.String>
getEdgeIdForApikey(java.lang.String apikey)
Gets the Edge-ID for an API-Key, i.e.org.osgi.service.event.EventAdmin
getEventAdmin()
Returns an EventAdmin, used by Edge objects.java.util.Map<java.lang.String,Role>
getPageDevice(User user, GetEdgesRequest.PaginationOptions paginationOptions)
Gets a map of Edge-IDs with the role of the given user.Role
getRoleForEdge(User user, java.lang.String edgeId)
Gets the Role for a edge of the current user.java.util.Optional<java.lang.String>
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, java.lang.String edgeId)
Return the Setup Protocol data as a JsonObject.java.util.Optional<User>
getUser(java.lang.String userId)
Gets the User for the given User-ID.java.util.List<AlertingSetting>
getUserAlertingSettings(java.lang.String edgeId)
Gets all the alerting settings for given edge id.AlertingSetting
getUserAlertingSettings(java.lang.String edgeId, java.lang.String userId)
Gets the alerting settings for given edge id and userId.java.util.Map<java.lang.String,java.lang.Object>
getUserInformation(User user)
Gets information about the given userUser
.void
handleEvent(org.osgi.service.event.Event event)
void
logout(User user)
Closes a session for a User.void
registerUser(com.google.gson.JsonObject jsonObject, OpenemsOEM.Manufacturer oem)
Register a user.void
setUserAlertingSettings(User user, java.lang.String edgeId, java.util.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 locale)
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, logError, logInfo, logInfo, logWarn, 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
-
-
-
-
Method Detail
-
authenticate
public User authenticate(java.lang.String username, java.lang.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
public User authenticate(java.lang.String token) throws OpenemsError.OpenemsNamedException
Description copied from interface:Metadata
Authenticates the User by a Token.- Specified by:
authenticate
in interfaceMetadata
- Parameters:
token
- the Token- Returns:
- the
User
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
logout
public void logout(User user)
Description copied from interface:Metadata
Closes a session for a User.
-
getEdgeIdForApikey
public java.util.Optional<java.lang.String> getEdgeIdForApikey(java.lang.String apikey)
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
public java.util.Optional<Edge> getEdgeBySetupPassword(java.lang.String setupPassword)
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
public java.util.Optional<Edge> getEdge(java.lang.String edgeId)
Description copied from interface:Metadata
Get an Edge by its unique Edge-ID.
-
getUser
public java.util.Optional<User> getUser(java.lang.String userId)
Description copied from interface:Metadata
Gets the User for the given User-ID.
-
getAllOfflineEdges
public java.util.Collection<Edge> getAllOfflineEdges()
Description copied from interface:Metadata
Gets all Offline-Edges.- Specified by:
getAllOfflineEdges
in interfaceMetadata
- Returns:
- collection of Edges.
-
addEdgeToUser
public void addEdgeToUser(User user, Edge edge) throws OpenemsError.OpenemsNamedException
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
public java.util.Map<java.lang.String,java.lang.Object> getUserInformation(User user) throws OpenemsError.OpenemsNamedException
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, java.lang.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)
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
-
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 locale) throws OpenemsError.OpenemsNamedException
Description copied from interface:Metadata
Update language from given user.- Specified by:
updateUserLanguage
in interfaceMetadata
- Parameters:
user
-User
the current userlocale
- 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
-
edge
public EdgeHandler 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
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event)
- Specified by:
handleEvent
in interfaceorg.osgi.service.event.EventHandler
-
getSerialNumberForEdge
public java.util.Optional<java.lang.String> getSerialNumberForEdge(Edge edge)
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
-
getUserAlertingSettings
public java.util.List<AlertingSetting> getUserAlertingSettings(java.lang.String edgeId)
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
-
getUserAlertingSettings
public AlertingSetting getUserAlertingSettings(java.lang.String edgeId, java.lang.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, java.lang.String edgeId, java.util.List<AlertingSetting> users)
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
-
getPageDevice
public java.util.Map<java.lang.String,Role> 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
-
getRoleForEdge
public Role getRoleForEdge(User user, java.lang.String edgeId) throws OpenemsError.OpenemsNamedException
Description copied from interface:Metadata
Gets the Role for a edge of the current user.- Specified by:
getRoleForEdge
in interfaceMetadata
- Parameters:
user
-User
the current useredgeId
- the Edge-ID- Returns:
- the role to the edge
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
-