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
Nested Classes Modifier and Type Class Description static class
AbstractDataSourceManager.DataSourceDefinition
This class represents the definition of a data source
-
Field Summary
Fields Modifier and Type Field Description protected CurrentUserProvider
_currentUserProvider
The current user providerprivate DataSourceConsumerExtensionPoint
_dataSourceConsumerEP
protected Map<String,AbstractDataSourceManager.DataSourceDefinition>
_dataSourcesDef
The data source definitionsprivate long
_lastUpdate
protected ObservationManager
_observationManager
The observation managerstatic String
DEFAULT_DATASOURCE_SUFFIX
The suffix of any default data source
-
Constructor Summary
Constructors Constructor Description AbstractDataSourceManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AbstractDataSourceManager.DataSourceDefinition
add(I18nizableText name, I18nizableText description, Map<String,Object> parameters, boolean isPrivate)
Add a data sourceprotected void
checkDataSources()
Check that the used data sources are indeed availableabstract void
checkParameters(Map<String,Object> parameters)
Checks the parameters of a data sourceprotected abstract void
createDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Creates a data source from its configurationvoid
delete(Collection<String> dataSourceIds, boolean forceDeletion)
Delete data sourcesprotected abstract void
deleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Deletes a data sourcevoid
dispose()
protected abstract Map<String,AbstractDataSourceManager.DataSourceDefinition>
doReadConfiguration(File file)
Actually read configuration.AbstractDataSourceManager.DataSourceDefinition
edit(String id, I18nizableText name, I18nizableText description, Map<String,Object> parameters, boolean isPrivate)
Edit a data sourceprotected abstract void
editDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Edit a data source from its configurationAbstractDataSourceManager.DataSourceDefinition
getDataSourceDefinition(String id)
Get the data source definition or null if not foundMap<String,AbstractDataSourceManager.DataSourceDefinition>
getDataSourceDefinitions(boolean includePrivate, boolean includeInternal, boolean includeDefault)
Get the data source definitionsprotected abstract String
getDataSourcePrefixId()
Get the prefix for data source identifierAbstractDataSourceManager.DataSourceDefinition
getDefaultDataSourceDefinition()
Get the default data source for this typeString
getDefaultDataSourceId()
Get the id of the default data sourceabstract File
getFileConfiguration()
Get the file configuration of data sourcesvoid
initialize()
protected abstract void
internalSetDefaultDataSource()
Set a default data source internallyprotected void
readConfiguration()
Read and update the data sources configurationprotected void
saveConfiguration()
Save the configured data sourcesprotected void
saxDataSource(ContentHandler handler, AbstractDataSourceManager.DataSourceDefinition dataSource)
SAX an instance of data sourcevoid
service(ServiceManager serviceManager)
AbstractDataSourceManager.DataSourceDefinition
setDefaultDataSource(String id)
Set the data source with the given id as the default data source-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
DEFAULT_DATASOURCE_SUFFIX
public static final String DEFAULT_DATASOURCE_SUFFIX
The suffix of any default data source- See Also:
- Constant Field Values
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_dataSourcesDef
protected Map<String,AbstractDataSourceManager.DataSourceDefinition> _dataSourcesDef
The data source definitions
-
_lastUpdate
private long _lastUpdate
-
_dataSourceConsumerEP
private DataSourceConsumerExtensionPoint _dataSourceConsumerEP
-
-
Constructor Detail
-
AbstractDataSourceManager
public AbstractDataSourceManager()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in interfaceInitializable
- Throws:
Exception
-
getFileConfiguration
public abstract File getFileConfiguration()
Get the file configuration of data sources- Returns:
- the file
-
getDataSourcePrefixId
protected abstract String getDataSourcePrefixId()
Get the prefix for data source identifier- Returns:
- the id prefix
-
checkParameters
public abstract void checkParameters(Map<String,Object> parameters) throws ItemCheckerTestFailureException
Checks the parameters of a data source- Parameters:
parameters
- the parameters of the data source- Throws:
ItemCheckerTestFailureException
- if the test failed
-
createDataSource
protected abstract void createDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Creates a data source from its configuration- Parameters:
dataSource
- the data source configuration
-
editDataSource
protected abstract void editDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Edit a data source from its configuration- Parameters:
dataSource
- the data source configuration
-
deleteDataSource
protected abstract void deleteDataSource(AbstractDataSourceManager.DataSourceDefinition dataSource)
Deletes a data source- Parameters:
dataSource
- the data source configuration
-
internalSetDefaultDataSource
protected abstract void 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
public AbstractDataSourceManager.DataSourceDefinition getDataSourceDefinition(String id)
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
public void delete(Collection<String> dataSourceIds, boolean forceDeletion)
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
public AbstractDataSourceManager.DataSourceDefinition setDefaultDataSource(String id)
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
public AbstractDataSourceManager.DataSourceDefinition 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
public String getDefaultDataSourceId()
Get the id of the default data source- Returns:
- the id of the default data source
-
readConfiguration
protected final void 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
protected void 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
protected void checkDataSources()
Check that the used data sources are indeed available
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
-