Package org.ametys.core.user.population
Class PopulationContextHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.user.population.PopulationContextHelper
-
- All Implemented Interfaces:
LogEnabled,Initializable,Component,Serviceable
- Direct Known Subclasses:
PopulationContextHelper,SitePopulationContextHelper
public class PopulationContextHelper extends AbstractLogEnabled implements Component, Serviceable, Initializable
Helper for associatingUserPopulations to contexts.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String__ADMIN_RIGHT_ACCESSThe id of right for administration accessprotected static String__USER_POPULATIONS_TABLEThe name of the JDBC table for user populations by contextprivate AbstractCacheManager_abstractCacheManagerprivate static Comparator<Pair<String,Integer>>_COMPARATORprivate CurrentUserProvider_currentUserProviderprotected ServiceManager_managerThe service managerprivate ObservationManager_observationManagerprivate RightManager_rightManagerprivate UserPopulationDAO_userPopulationDAOThe DAO forUserPopulationsstatic StringADMIN_CONTEXTThe "admin" contextprivate static StringIS_CACHE_FILLEDstatic StringPOPULATION_CONTEXTS_REQUEST_ATTRThe name of request attribute holding the current population contextsstatic StringROLEAvalon Role
-
Constructor Summary
Constructors Constructor Description PopulationContextHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Map<String,Set<Pair<String,Integer>>>_getAllPopulationContent()create a population content map from the databaseprotected Cache<String,Set<Pair<String,Integer>>>_getCache()Get the cacheprotected Map<String,Set<Pair<String,Integer>>>_getCacheAsMap()Get the cache as mapprivate Set<String>_getPopulationsOnContextFromDatabase(String context, boolean withDisabled)protected CurrentUserProvidergetCurrentUserProvider()Get the current user providerprotected ObservationManagergetObservationManager()Get the observation managerprotected RightManagergetRightManager()Get the right managerprotected ConnectiongetSQLConnection()Get the connection to the databaseprotected UserPopulationDAOgetUserPopulationDAO()Get the DAO for user populationsSet<String>getUserPopulationsOnContext(String context, boolean withDisabled)Gets the populations linked to the given context (need the population to be enabled)Set<String>getUserPopulationsOnContexts(Collection<String> contexts, boolean withDisabled)Gets the populations linked to at least one of the given contexts (need the population to be enabled)Set<String>getUserPopulationsOnContexts(Collection<String> contexts, boolean withDisabled, boolean checkRights)Gets the populations linked to at least one of the given contexts (need the population to be enabled)voidinitialize()booleanisLinked(String upId)Returns true if the user population is linked to a context.Set<String>link(String context, Collection<String> ids)Links given populations to a context.voidservice(ServiceManager manager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
POPULATION_CONTEXTS_REQUEST_ATTR
public static final String POPULATION_CONTEXTS_REQUEST_ATTR
The name of request attribute holding the current population contexts- See Also:
- Constant Field Values
-
ADMIN_CONTEXT
public static final String ADMIN_CONTEXT
The "admin" context- See Also:
- Constant Field Values
-
__USER_POPULATIONS_TABLE
protected static final String __USER_POPULATIONS_TABLE
The name of the JDBC table for user populations by context- See Also:
- Constant Field Values
-
__ADMIN_RIGHT_ACCESS
protected static final String __ADMIN_RIGHT_ACCESS
The id of right for administration access- See Also:
- Constant Field Values
-
_COMPARATOR
private static final Comparator<Pair<String,Integer>> _COMPARATOR
-
IS_CACHE_FILLED
private static final String IS_CACHE_FILLED
- See Also:
- Constant Field Values
-
_manager
protected ServiceManager _manager
The service manager
-
_userPopulationDAO
private UserPopulationDAO _userPopulationDAO
The DAO forUserPopulations
-
_observationManager
private ObservationManager _observationManager
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
-
_rightManager
private RightManager _rightManager
-
_abstractCacheManager
private AbstractCacheManager _abstractCacheManager
-
-
Constructor Detail
-
PopulationContextHelper
public PopulationContextHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initializein interfaceInitializable- Throws:
Exception
-
getObservationManager
protected ObservationManager getObservationManager()
Get the observation manager- Returns:
- the
-
getUserPopulationDAO
protected UserPopulationDAO getUserPopulationDAO()
Get the DAO for user populations- Returns:
- the DAO for user populations
-
getCurrentUserProvider
protected CurrentUserProvider getCurrentUserProvider()
Get the current user provider- Returns:
- the current user provider
-
getRightManager
protected RightManager getRightManager()
Get the right manager- Returns:
- the right manager
-
getSQLConnection
protected Connection getSQLConnection()
Get the connection to the database- Returns:
- the SQL connection
-
link
public Set<String> link(String context, Collection<String> ids)
Links given populations to a context.- Parameters:
context- The contextids- The ids of the populations to link- Returns:
- The ids of the changed user populations (the ones unlinked and the ones linked)
-
getUserPopulationsOnContext
public Set<String> getUserPopulationsOnContext(String context, boolean withDisabled)
Gets the populations linked to the given context (need the population to be enabled)- Parameters:
context- The contextwithDisabled- True to also return disabled populations- Returns:
- The ids of populations linked to the context
-
getUserPopulationsOnContexts
public Set<String> getUserPopulationsOnContexts(Collection<String> contexts, boolean withDisabled, boolean checkRights)
Gets the populations linked to at least one of the given contexts (need the population to be enabled)- Parameters:
contexts- The contextswithDisabled- True to also return disabled populationscheckRights- True to check that current user belongs to one of populations or is an administrator user- Returns:
- The ids of populations linked to the contexts
-
getUserPopulationsOnContexts
public Set<String> getUserPopulationsOnContexts(Collection<String> contexts, boolean withDisabled)
Gets the populations linked to at least one of the given contexts (need the population to be enabled)- Parameters:
contexts- The contextswithDisabled- True to also return disabled populations- Returns:
- The ids of populations linked to the contexts
-
_getPopulationsOnContextFromDatabase
private Set<String> _getPopulationsOnContextFromDatabase(String context, boolean withDisabled)
-
_getAllPopulationContent
private Map<String,Set<Pair<String,Integer>>> _getAllPopulationContent()
create a population content map from the database- Returns:
- Non null map of population content
-
_getCache
protected Cache<String,Set<Pair<String,Integer>>> _getCache()
Get the cache- Returns:
- Non null cache
-
_getCacheAsMap
protected Map<String,Set<Pair<String,Integer>>> _getCacheAsMap()
Get the cache as map- Returns:
- Non null cache
-
-