Package org.ametys.core.datasource
Class AbstractDataSourceManager
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.core.datasource.AbstractDataSourceManager
- All Implemented Interfaces:
LogEnabled
,Disposable
,Initializable
,Component
,Serviceable
- Direct Known Subclasses:
LDAPDataSourceManager
,SQLDataSourceManager
public abstract class AbstractDataSourceManager
extends AbstractLogEnabled
implements Component, Initializable, Serviceable, Disposable
Abstract component to handle data source
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This class represents the definition of a data source -
Field Summary
Modifier and TypeFieldDescriptionprotected CurrentUserProvider
The current user providerThe data source definitionsprotected ObservationManager
The observation managerstatic final String
The suffix of any default data source -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd
(I18nizableText name, I18nizableText description, Map<String, Object> parameters, boolean isPrivate) Add a data sourceprotected void
Check that the used data sources are indeed availableabstract void
checkParameters
(Map<String, Object> parameters) Checks the parameters of a data sourceprotected abstract void
Creates a data source from its configurationvoid
delete
(Collection<String> dataSourceIds, boolean forceDeletion) Delete data sourcesprotected abstract void
Deletes a data sourcevoid
dispose()
protected abstract Map<String,
AbstractDataSourceManager.DataSourceDefinition> doReadConfiguration
(File file) Actually read configuration.edit
(String id, I18nizableText name, I18nizableText description, Map<String, Object> parameters, boolean isPrivate) Edit a data sourceprotected abstract void
Edit a data source from its configurationGet the data source definition or null if not foundgetDataSourceDefinitions
(boolean includePrivate, boolean includeInternal, boolean includeDefault) Get the data source definitionsprotected abstract String
Get the prefix for data source identifierGet the default data source for this typeGet the id of the default data sourceabstract File
Get the file configuration of data sourcesvoid
protected abstract void
Set a default data source internallyprotected final void
Read and update the data sources configurationprotected void
Save the configured data sourcesprotected void
saxDataSource
(ContentHandler handler, AbstractDataSourceManager.DataSourceDefinition dataSource) SAX an instance of data sourcevoid
service
(ServiceManager serviceManager) Set the data source with the given id as the default data sourceMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
DEFAULT_DATASOURCE_SUFFIX
The suffix of any default data source- See Also:
-
_observationManager
The observation manager -
_currentUserProvider
The current user provider -
_dataSourcesDef
The data source definitions
-
-
Constructor Details
-
AbstractDataSourceManager
public AbstractDataSourceManager()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
getFileConfiguration
Get the file configuration of data sources- Returns:
- the file
-
getDataSourcePrefixId
Get the prefix for data source identifier- Returns:
- the id prefix
-
checkParameters
public abstract void checkParameters(Map<String, Object> parameters) throws ItemCheckerTestFailureExceptionChecks the parameters of a data source- Parameters:
parameters
- the parameters of the data source- Throws:
ItemCheckerTestFailureException
- if the test failed
-
createDataSource
Creates a data source from its configuration- Parameters:
dataSource
- the data source configuration
-
editDataSource
Edit a data source from its configuration- Parameters:
dataSource
- the data source configuration
-
deleteDataSource
Deletes a data source- Parameters:
dataSource
- the data source configuration
-
internalSetDefaultDataSource
Set a default data source internally -
getDataSourceDefinitions
public Map<String,AbstractDataSourceManager.DataSourceDefinition> getDataSourceDefinitions(boolean includePrivate, boolean includeInternal, boolean includeDefault) Get the data source definitions- Parameters:
includePrivate
- true to include private data sourcesincludeInternal
- true to include internal data sources. Not used by default.includeDefault
- true to include an additional data source definition for each default data source- Returns:
- the data source definitions
-
getDataSourceDefinition
Get the data source definition or null if not found- Parameters:
id
- the id of data source- Returns:
- the data source definition or null if not found
-
add
public AbstractDataSourceManager.DataSourceDefinition add(I18nizableText name, I18nizableText description, Map<String, Object> parameters, boolean isPrivate) Add a data source- Parameters:
name
- the namedescription
- the descriptionparameters
- the parametersisPrivate
- true if private- Returns:
- the created data source definition
-
edit
public AbstractDataSourceManager.DataSourceDefinition edit(String id, I18nizableText name, I18nizableText description, Map<String, Object> parameters, boolean isPrivate) Edit a data source- Parameters:
id
- the idname
- the namedescription
- the descriptionparameters
- the parametersisPrivate
- true if private- Returns:
- the edited data source definition
-
delete
Delete data sources- Parameters:
dataSourceIds
- the ids of the data sources to deleteforceDeletion
- Force the remove event the datasource seems to be in use
-
setDefaultDataSource
Set the data source with the given id as the default data source- Parameters:
id
- the id of the data source- Returns:
- the
AbstractDataSourceManager.DataSourceDefinition
of the data source set as default
-
getDefaultDataSourceDefinition
Get the default data source for this type- Returns:
- the definition object of the default data source. Can return null if no datasource is defined.
-
getDefaultDataSourceId
Get the id of the default data source- Returns:
- the id of the default data source
-
readConfiguration
Read and update the data sources configuration -
doReadConfiguration
protected abstract Map<String,AbstractDataSourceManager.DataSourceDefinition> doReadConfiguration(File file) Actually read configuration.- Parameters:
file
- the definitions file.- Returns:
- all definitions.
-
saveConfiguration
Save the configured data sources -
saxDataSource
protected void saxDataSource(ContentHandler handler, AbstractDataSourceManager.DataSourceDefinition dataSource) throws SAXException SAX an instance of data source- Parameters:
handler
- the content handler to sax intodataSource
- the data source- Throws:
SAXException
- if an error occurred while SAXing
-
checkDataSources
Check that the used data sources are indeed available -
dispose
- Specified by:
dispose
in interfaceDisposable
-