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 associatingUserPopulation
s to contexts.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
__ADMIN_RIGHT_ACCESS
The id of right for administration accessprotected static String
__USER_POPULATIONS_TABLE
The name of the JDBC table for user populations by contextprotected ServiceManager
_manager
The service managerstatic String
ADMIN_CONTEXT
The "admin" contextstatic String
POPULATION_CONTEXTS_REQUEST_ATTR
The name of request attribute holding the current population contextsstatic String
ROLE
Avalon Role
-
Constructor Summary
Constructors Constructor Description PopulationContextHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Cache<String,Set<Pair<String,Integer>>>
_getCache()
Get the cacheprotected Map<String,Set<Pair<String,Integer>>>
_getCacheAsMap()
Get the cache as mapprotected CurrentUserProvider
getCurrentUserProvider()
Get the current user providerprotected ObservationManager
getObservationManager()
Get the observation managerprotected RightManager
getRightManager()
Get the right managerprotected Connection
getSQLConnection()
Get the connection to the databaseprotected UserPopulationDAO
getUserPopulationDAO()
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)void
initialize()
boolean
isLinked(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.void
service(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
-
_manager
protected ServiceManager _manager
The service manager
-
-
Constructor Detail
-
PopulationContextHelper
public PopulationContextHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize() throws Exception
- Specified by:
initialize
in 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
-
_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
-
-