Class JdbcGroupDirectory
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.core.impl.group.directory.jdbc.JdbcGroupDirectory
-
- All Implemented Interfaces:
GroupDirectory
,ModifiableGroupDirectory
,Cacheable
,LogEnabled
,Disposable
,Serviceable
public class JdbcGroupDirectory extends AbstractLogEnabled implements ModifiableGroupDirectory, Serviceable, Cacheable, Disposable
Standard implementation ofGroupDirectory
from the core database.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JdbcGroupDirectory.JdbcGroup
-
Nested classes/interfaces inherited from interface org.ametys.core.util.Cacheable
Cacheable.SingleCacheConfiguration
-
-
Field Summary
Fields Modifier and Type Field Description private static String
__DATASOURCE_PARAM_NAME
Name of the parameter holding the datasource idprivate static String
__GROUPS_COMPOSITION_COLUMN_GROUPID
private static String
__GROUPS_COMPOSITION_COLUMN_LOGIN
private static String
__GROUPS_COMPOSITION_COLUMN_POPULATIONID
private static String
__GROUPS_COMPOSITION_TABLE_PARAM_NAME
Name of the parameter holding the SQL table name for storing the composition (i.e.private static String
__GROUPS_LIST_COLUMN_ID
private static String
__GROUPS_LIST_COLUMN_LABEL
private static String
__GROUPS_LIST_TABLE_PARAM_NAME
Name of the parameter holding the SQL table name for storing the groupsprivate static String
__JDBC_GROUPDIRECTORY_GROUPS_BY_USER_CACHE_NAME_PREFIX
protected AbstractCacheManager
_cacheManager
The cache managerprotected CurrentUserProvider
_currentUserProvider
The current user providerprotected String
_dataSourceId
The identifier of data sourceprivate String
_groupDirectoryModelId
The id of theGroupDirectoryModel
protected String
_groupsCompositionTableName
The name of the SQL table storing the composition (i.e.protected String
_groupsListTableName
The name of the SQL table storing the groupsprotected String
_id
The idprotected I18nizableText
_label
The labelprivate boolean
_lazyInitialized
protected ObservationManager
_observationManager
The observation managerprivate Map<String,Object>
_paramValues
The map of the values of the parametersprotected SourceResolver
_sourceResolver
The cocoon source resolverprivate String
_uniqueCacheSuffix
-
Constructor Summary
Constructors Constructor Description JdbcGroupDirectory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private I18nizableText
_buildI18n(String i18Key)
protected String
_createGetGroupsClause()
Get the sql clause that gets all groupsprivate Set<String>
_executeSqlForUserGroups(UserIdentity userIdentity)
protected void
_fillGroup(JdbcGroupDirectory.JdbcGroup group, Connection connection)
Fill users set in a group.private Cache<UserIdentity,Set<String>>
_getCacheGroupsByUser()
ModifiableGroup
add(String name)
Add a new group of users.void
dispose()
AbstractCacheManager
getCacheManager()
Returns the instance of the implementation ofAbstractCacheManager
to use.ModifiableGroup
getGroup(String groupID)
Returns a particular group.String
getGroupDirectoryModelId()
Get the id of theGroupDirectoryModel
extension pointSet<Group>
getGroups()
Returns all groups.List<Group>
getGroups(int count, int offset, Map parameters)
Get groupsString
getId()
Get the id of the group directory.I18nizableText
getLabel()
Get the label of the group directory.Collection<Cacheable.SingleCacheConfiguration>
getManagedCaches()
Gets the managed caches.Map<String,Object>
getParameterValues()
Get the values of parameters (from group directory model)protected Connection
getSQLConnection()
Get the connection to the databaseSet<String>
getUserGroups(UserIdentity userIdentity)
Get all groups a particular user is in.boolean
hasComputableSize()
Determines if the cache has a computable size.void
init(String groupDirectoryModelId, Map<String,Object> paramValues)
Initialize the group directory with given parameter values.void
remove(String groupID)
Remove a group of users.void
service(ServiceManager manager)
void
setId(String id)
Set the id of the group directory.void
setLabel(I18nizableText label)
Set the label of the group directory.void
update(ModifiableGroup userGroup)
Modify an existing group of users.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.core.util.Cacheable
createCaches, getCache, isCachingEnabled, removeCaches
-
-
-
-
Field Detail
-
__DATASOURCE_PARAM_NAME
private static final String __DATASOURCE_PARAM_NAME
Name of the parameter holding the datasource id- See Also:
- Constant Field Values
-
__GROUPS_LIST_TABLE_PARAM_NAME
private static final String __GROUPS_LIST_TABLE_PARAM_NAME
Name of the parameter holding the SQL table name for storing the groups- See Also:
- Constant Field Values
-
__GROUPS_COMPOSITION_TABLE_PARAM_NAME
private static final String __GROUPS_COMPOSITION_TABLE_PARAM_NAME
Name of the parameter holding the SQL table name for storing the composition (i.e. users) of the groups- See Also:
- Constant Field Values
-
__GROUPS_LIST_COLUMN_ID
private static final String __GROUPS_LIST_COLUMN_ID
- See Also:
- Constant Field Values
-
__GROUPS_LIST_COLUMN_LABEL
private static final String __GROUPS_LIST_COLUMN_LABEL
- See Also:
- Constant Field Values
-
__GROUPS_COMPOSITION_COLUMN_GROUPID
private static final String __GROUPS_COMPOSITION_COLUMN_GROUPID
- See Also:
- Constant Field Values
-
__GROUPS_COMPOSITION_COLUMN_LOGIN
private static final String __GROUPS_COMPOSITION_COLUMN_LOGIN
- See Also:
- Constant Field Values
-
__GROUPS_COMPOSITION_COLUMN_POPULATIONID
private static final String __GROUPS_COMPOSITION_COLUMN_POPULATIONID
- See Also:
- Constant Field Values
-
__JDBC_GROUPDIRECTORY_GROUPS_BY_USER_CACHE_NAME_PREFIX
private static final String __JDBC_GROUPDIRECTORY_GROUPS_BY_USER_CACHE_NAME_PREFIX
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_sourceResolver
protected SourceResolver _sourceResolver
The cocoon source resolver
-
_cacheManager
protected AbstractCacheManager _cacheManager
The cache manager
-
_dataSourceId
protected String _dataSourceId
The identifier of data source
-
_groupsListTableName
protected String _groupsListTableName
The name of the SQL table storing the groups
-
_groupsCompositionTableName
protected String _groupsCompositionTableName
The name of the SQL table storing the composition (i.e. users) of the groups
-
_label
protected I18nizableText _label
The label
-
_groupDirectoryModelId
private String _groupDirectoryModelId
The id of theGroupDirectoryModel
-
_paramValues
private Map<String,Object> _paramValues
The map of the values of the parameters
-
_lazyInitialized
private boolean _lazyInitialized
-
_uniqueCacheSuffix
private final String _uniqueCacheSuffix
-
-
Constructor Detail
-
JdbcGroupDirectory
public JdbcGroupDirectory()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getId
public String getId()
Description copied from interface:GroupDirectory
Get the id of the group directory.- Specified by:
getId
in interfaceGroupDirectory
- Returns:
- The id of the group directory
-
getLabel
public I18nizableText getLabel()
Description copied from interface:GroupDirectory
Get the label of the group directory.- Specified by:
getLabel
in interfaceGroupDirectory
- Returns:
- The label of the group directory
-
setId
public void setId(String id)
Description copied from interface:GroupDirectory
Set the id of the group directory.- Specified by:
setId
in interfaceGroupDirectory
- Parameters:
id
- The id
-
setLabel
public void setLabel(I18nizableText label)
Description copied from interface:GroupDirectory
Set the label of the group directory.- Specified by:
setLabel
in interfaceGroupDirectory
- Parameters:
label
- The label
-
getGroupDirectoryModelId
public String getGroupDirectoryModelId()
Description copied from interface:GroupDirectory
Get the id of theGroupDirectoryModel
extension point- Specified by:
getGroupDirectoryModelId
in interfaceGroupDirectory
- Returns:
- the id of extension point
-
getParameterValues
public Map<String,Object> getParameterValues()
Description copied from interface:GroupDirectory
Get the values of parameters (from group directory model)- Specified by:
getParameterValues
in interfaceGroupDirectory
- Returns:
- the parameters' values
-
dispose
public void dispose()
- Specified by:
dispose
in interfaceDisposable
-
getManagedCaches
public Collection<Cacheable.SingleCacheConfiguration> getManagedCaches()
Description copied from interface:Cacheable
Gets the managed caches.
This is meant to be implemented in order to describe the managed caches and automatically create and remove the corresponding caches inCacheable.createCaches()
andCacheable.removeCaches()
default methods.
This is not meant to be called manually.- Specified by:
getManagedCaches
in interfaceCacheable
- Returns:
- A collection of
Cacheable.SingleCacheConfiguration
s to manage
-
hasComputableSize
public boolean hasComputableSize()
Description copied from interface:Cacheable
Determines if the cache has a computable size. This operation can be very slow.- Specified by:
hasComputableSize
in interfaceCacheable
- Returns:
true
if we can compute the size on the cache.
-
_buildI18n
private I18nizableText _buildI18n(String i18Key)
-
_getCacheGroupsByUser
private Cache<UserIdentity,Set<String>> _getCacheGroupsByUser()
-
getCacheManager
public AbstractCacheManager getCacheManager()
Description copied from interface:Cacheable
Returns the instance of the implementation ofAbstractCacheManager
to use.
This is not meant to be called manually.- Specified by:
getCacheManager
in interfaceCacheable
- Returns:
- The
AbstractCacheManager
to bind
-
init
public void init(String groupDirectoryModelId, Map<String,Object> paramValues)
Description copied from interface:GroupDirectory
Initialize the group directory with given parameter values.- Specified by:
init
in interfaceGroupDirectory
- Parameters:
groupDirectoryModelId
- The id of group directory extension pointparamValues
- The parameters' values
-
getSQLConnection
protected Connection getSQLConnection()
Get the connection to the database- Returns:
- the SQL connection
-
getGroup
public ModifiableGroup getGroup(String groupID)
Description copied from interface:GroupDirectory
Returns a particular group.- Specified by:
getGroup
in interfaceGroupDirectory
- Specified by:
getGroup
in interfaceModifiableGroupDirectory
- Parameters:
groupID
- The id of the group.- Returns:
- The group or null if the group does not exist.
-
getGroups
public Set<Group> getGroups()
Description copied from interface:GroupDirectory
Returns all groups.- Specified by:
getGroups
in interfaceGroupDirectory
- Returns:
- The groups as a Set of UserGroup, empty if an error occurs.
-
_createGetGroupsClause
protected String _createGetGroupsClause()
Get the sql clause that gets all groups- Returns:
- A non null sql clause (e.g. "select ... from ... where ...")
-
_fillGroup
protected void _fillGroup(JdbcGroupDirectory.JdbcGroup group, Connection connection) throws SQLException
Fill users set in a group.- Parameters:
group
- The group to fill.connection
- The SQL connection.- Throws:
SQLException
- If a problem occurs.
-
getUserGroups
public Set<String> getUserGroups(UserIdentity userIdentity)
Description copied from interface:GroupDirectory
Get all groups a particular user is in.- Specified by:
getUserGroups
in interfaceGroupDirectory
- Parameters:
userIdentity
- The identity of the user- Returns:
- The groups as a Set of String (group ID), empty if the login does not match.
-
_executeSqlForUserGroups
private Set<String> _executeSqlForUserGroups(UserIdentity userIdentity)
-
getGroups
public List<Group> getGroups(int count, int offset, Map parameters)
Description copied from interface:GroupDirectory
Get groups- Specified by:
getGroups
in interfaceGroupDirectory
- Parameters:
count
- The maximum number of groups to sax. (-1 to sax all)offset
- The offset to start with, first is 0.parameters
- Parameters for saxing user list differently, see implementation.- Returns:
- The matching groups
-
add
public ModifiableGroup add(String name) throws InvalidModificationException
Description copied from interface:ModifiableGroupDirectory
Add a new group of users.- Specified by:
add
in interfaceModifiableGroupDirectory
- Parameters:
name
- The name of the user group to create. Cannot be null;- Returns:
- The user group created
- Throws:
InvalidModificationException
- if the group id exists yet or if at least one of the parameter is invalid.
-
update
public void update(ModifiableGroup userGroup) throws InvalidModificationException
Description copied from interface:ModifiableGroupDirectory
Modify an existing group of users.- Specified by:
update
in interfaceModifiableGroupDirectory
- Parameters:
userGroup
- Informations about the new group. Cannot be null:- Throws:
InvalidModificationException
- if the group id does not exist yet
-
remove
public void remove(String groupID) throws InvalidModificationException
Description copied from interface:ModifiableGroupDirectory
Remove a group of users.- Specified by:
remove
in interfaceModifiableGroupDirectory
- Parameters:
groupID
- The id of the group. Cannot be null;- Throws:
InvalidModificationException
- if the group id does not exist.
-
-