Package io.openems.edge.core.appmanager
Class AbstractOpenemsApp<PROPERTY extends Nameable>
java.lang.Object
io.openems.edge.core.appmanager.AbstractOpenemsApp<PROPERTY>
- All Implemented Interfaces:
ComponentManagerSupplier
,ComponentUtilSupplier
,OpenemsApp
- Direct Known Subclasses:
AbstractEnumOpenemsApp
,AbstractOpenemsAppWithProps
public abstract class AbstractOpenemsApp<PROPERTY extends Nameable>
extends Object
implements OpenemsApp, ComponentUtilSupplier, ComponentManagerSupplier
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.osgi.service.cm.ConfigurationAdmin
protected final org.osgi.service.component.ComponentContext
protected final ComponentManager
protected final ComponentUtil
Fields inherited from interface io.openems.edge.core.appmanager.OpenemsApp
FALLBACK_IMAGE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractOpenemsApp
(ComponentManager componentManager, org.osgi.service.component.ComponentContext componentContext, org.osgi.service.cm.ConfigurationAdmin cm, ComponentUtil componentUtil) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ThrowingTriFunction<ConfigurationTarget,
Map<PROPERTY, com.google.gson.JsonElement>, Language, AppConfiguration, OpenemsError.OpenemsNamedException> Provides a factory forAppConfigurations
.protected final void
assertCheckables
(ConfigurationTarget t, Checkable... checkables) protected static final String
base64OfImage
(URL url) static ResourceBundle
Gets theResourceBundle
based on the givenLanguage
.static com.google.gson.JsonObject
fillUpProperties
(OpenemsApp app, com.google.gson.JsonObject original) Creates a copy of the original configuration and fills up properties which are binded bidirectional.protected AppAssistant
getAppAssistant
(User user) Gets theAppAssistant
for thisOpenemsApp
.getAppConfiguration
(ConfigurationTarget target, com.google.gson.JsonObject config, Language language) Gets theAppConfiguration
needed for theOpenemsApp
.getAppId()
Gets the unique App-ID of theOpenemsApp
.Gets theOpenemsAppPermissions
of thisOpenemsApp
.Gets aComponentManager
.Gets aComponentUtil
.protected static final EdgeConfig.Component
getComponentWithFactoryId
(List<EdgeConfig.Component> components, String factoryId) protected String
getId
(ConfigurationTarget t, Map<PROPERTY, com.google.gson.JsonElement> map, PROPERTY p, String defaultId) Gets the id of the map with the given default idgetImage()
Gets the image of theOpenemsApp
in Base64 encoding.Gets the name of theOpenemsApp
.protected static String
getNullableTranslation
(Language language, String key) Gets allOpenemsAppPropertyDefinition
of the app.protected final PROPERTY
getPropertyByName
(String name) getShortName
(Language language) Gets the short name of theOpenemsApp
.protected static String
getTranslation
(Language language, String key) static ResourceBundle
getTranslationBundle
(Language language) Gets theResourceBundle
based on the givenLanguage
.protected ValidatorConfig.Builder
getValidationErrors
(com.google.gson.JsonObject jProperties, List<Dependency> dependecies) Validate the App configuration.final ValidatorConfig
Gets theValidatorConfig
of thisOpenemsApp
.protected String
getValueOrDefault
(Map<PROPERTY, com.google.gson.JsonElement> map, PROPERTY property, String defaultValue) Gets the value of the property in the map or the defaulValue if the property was not found.boolean
hasProperty
(String property) Checks if the given property is in the Property class included.protected ThrowingBiFunction<ConfigurationTarget,
Map<PROPERTY, com.google.gson.JsonElement>, Map<String, Map<String, ?>>, OpenemsError.OpenemsNamedException> The returning function gets called during app add or update.protected abstract PROPERTY[]
void
validate
(OpenemsAppInstance instance) Validate theOpenemsApp
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.edge.core.appmanager.OpenemsApp
flags, getAppDescriptor, getCardinality, getCategories
-
Field Details
-
componentManager
-
cm
protected final org.osgi.service.cm.ConfigurationAdmin cm -
componentContext
protected final org.osgi.service.component.ComponentContext componentContext -
componentUtil
-
-
Constructor Details
-
AbstractOpenemsApp
protected AbstractOpenemsApp(ComponentManager componentManager, org.osgi.service.component.ComponentContext componentContext, org.osgi.service.cm.ConfigurationAdmin cm, ComponentUtil componentUtil)
-
-
Method Details
-
appPropertyConfigurationFactory
protected abstract ThrowingTriFunction<ConfigurationTarget,Map<PROPERTY, appPropertyConfigurationFactory()com.google.gson.JsonElement>, Language, AppConfiguration, OpenemsError.OpenemsNamedException> Provides a factory forAppConfigurations
.- Returns:
- a
ThrowingFunction
that creates aAppConfiguration
from aMap
of configuration properties for a givenConfigurationTarget
in the specified language.
-
assertCheckables
protected final void assertCheckables(ConfigurationTarget t, Checkable... checkables) throws OpenemsError.OpenemsNamedException -
getAppConfiguration
public AppConfiguration getAppConfiguration(ConfigurationTarget target, com.google.gson.JsonObject config, Language language) throws OpenemsError.OpenemsNamedException Description copied from interface:OpenemsApp
Gets theAppConfiguration
needed for theOpenemsApp
.- Specified by:
getAppConfiguration
in interfaceOpenemsApp
- Parameters:
target
- theConfigurationTarget
config
- the configured app 'properties'language
- the language of the configuration- Returns:
- the app Configuration
- Throws:
OpenemsError.OpenemsNamedException
-
getAppId
Description copied from interface:OpenemsApp
Gets the unique App-ID of theOpenemsApp
.- Specified by:
getAppId
in interfaceOpenemsApp
- Returns:
- a unique PID, usually the
ComponentConstants.COMPONENT_NAME
of the OSGi Component provider.
-
getId
protected String getId(ConfigurationTarget t, Map<PROPERTY, com.google.gson.JsonElement> map, PROPERTY p, String defaultId) Gets the id of the map with the given default ide. g. defaultId: "ess0" => the next available id with the base-name "ess" and the the next available number
- Parameters:
t
- the configuration targetmap
- the configuration mapp
- the Property which stores the iddefaultId
- the defaultId to be used- Returns:
- the found id
-
getValidationErrors
protected List<String> getValidationErrors(com.google.gson.JsonObject jProperties, List<Dependency> dependecies) Validate the App configuration.- Parameters:
jProperties
- a JsonObject holding the App propertiesdependecies
- the dependencies of the current instance- Returns:
- a list of validation errors. Empty list says 'no errors'
-
getValidatorConfig
Description copied from interface:OpenemsApp
Gets theValidatorConfig
of thisOpenemsApp
.- Specified by:
getValidatorConfig
in interfaceOpenemsApp
- Returns:
- the ValidatorConfig
-
getValidateBuilder
-
getValueOrDefault
protected String getValueOrDefault(Map<PROPERTY, com.google.gson.JsonElement> map, PROPERTY property, String defaultValue) Gets the value of the property in the map or the defaulValue if the property was not found.- Parameters:
map
- the configuration mapproperty
- the property to be searched fordefaultValue
- the default value- Returns:
- the String value
-
hasProperty
Checks if the given property is in the Property class included.- Parameters:
property
- the enum property- Returns:
- true if it is included else false
-
installationValidation
protected ThrowingBiFunction<ConfigurationTarget,Map<PROPERTY, installationValidation()com.google.gson.JsonElement>, Map<String, Map<String, ?>>, OpenemsError.OpenemsNamedException> The returning function gets called during app add or update. The returnedCheckable
s are executed after setting the network configuration.e. g. the function can return a
Checkable
for checking if a device is reachable via network.- Returns:
- a factory function which returns
Checkable
s
-
validate
Description copied from interface:OpenemsApp
Validate theOpenemsApp
.- Specified by:
validate
in interfaceOpenemsApp
- Parameters:
instance
- the app instance- Throws:
OpenemsError.OpenemsNamedException
-
fillUpProperties
public static com.google.gson.JsonObject fillUpProperties(OpenemsApp app, com.google.gson.JsonObject original) Creates a copy of the original configuration and fills up properties which are binded bidirectional.e. g. a property in a component is the same as one configured in the app so it directly gets stored in the component configuration and not twice to avoid miss matching errors.
- Parameters:
original
- the original configurationapp
- the app to get the properties from- Returns:
- a copy of the original one with the filled up properties
-
getAppPermissions
Description copied from interface:OpenemsApp
Gets theOpenemsAppPermissions
of thisOpenemsApp
.- Specified by:
getAppPermissions
in interfaceOpenemsApp
- Returns:
- the permissions
-
getName
Description copied from interface:OpenemsApp
Gets the name of theOpenemsApp
.- Specified by:
getName
in interfaceOpenemsApp
- Parameters:
language
- the language of the name- Returns:
- a human readable name
-
getShortName
Description copied from interface:OpenemsApp
Gets the short name of theOpenemsApp
.- Specified by:
getShortName
in interfaceOpenemsApp
- Parameters:
language
- the language of the name- Returns:
- a human readable short name; can be null
-
getImage
Description copied from interface:OpenemsApp
Gets the image of theOpenemsApp
in Base64 encoding.- Specified by:
getImage
in interfaceOpenemsApp
- Returns:
- a image representing the
OpenemsApp
-
getProperties
Description copied from interface:OpenemsApp
Gets allOpenemsAppPropertyDefinition
of the app.- Specified by:
getProperties
in interfaceOpenemsApp
- Returns:
- the
OpenemsAppPropertyDefinitions
-
getAppAssistant
Description copied from interface:OpenemsApp
Gets theAppAssistant
for thisOpenemsApp
.- Specified by:
getAppAssistant
in interfaceOpenemsApp
- Parameters:
user
- theUser
- Returns:
- the AppAssistant
-
getAppAssistant
-
propertyValues
-
getPropertyByName
-
getTranslation
-
getNullableTranslation
-
getTranslationBundle
Gets theResourceBundle
based on the givenLanguage
.- Parameters:
language
- theLanguage
of the translations- Returns:
- the
ResourceBundle
-
createResourceBundle
Gets theResourceBundle
based on the givenLanguage
.Used in
OpenemsApps
to create theirType.getParamter()
.- Parameters:
l
- theLanguage
of the translations- Returns:
- the
ResourceBundle
-
base64OfImage
-
getComponentWithFactoryId
protected static final EdgeConfig.Component getComponentWithFactoryId(List<EdgeConfig.Component> components, String factoryId) -
getComponentManager
Description copied from interface:ComponentManagerSupplier
Gets aComponentManager
.- Specified by:
getComponentManager
in interfaceComponentManagerSupplier
- Returns:
- the
ComponentManager
-
getComponentUtil
Description copied from interface:ComponentUtilSupplier
Gets aComponentUtil
.- Specified by:
getComponentUtil
in interfaceComponentUtilSupplier
- Returns:
- the
ComponentUtil
-