Package org.ametys.plugins.glpi
Class TicketGlpiManager
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.glpi.TicketGlpiManager
-
- All Implemented Interfaces:
LogEnabled
,PluginAware
,Initializable
,Component
,Serviceable
public class TicketGlpiManager extends AbstractLogEnabled implements Component, Initializable, Serviceable, PluginAware
Connection and information from GLPI webservice
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TicketGlpiManager.GlpiCacheLoader
The Glpi cache loader.
-
Field Summary
Fields Modifier and Type Field Description protected LoadingCache<UserIdentity,Map<String,Object>>
_cache
The user information cache.protected Cache<String,Integer>
_cacheIdentities
The user information cache.protected long
_cacheTtl
The cache TTL in minutes.protected long
_maxCacheSize
Maximum cache size, in number of records.static String
ROLE
Avalon ROLE.
-
Constructor Summary
Constructors Constructor Description TicketGlpiManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCountOpenTickets(UserIdentity userIdentity)
Get the number of open ticketsI18nizableText
getGlpiStatusLabel(int status)
Get the i18n label of a GLPI statusprotected Map<String,Object>
getGlpiTickets(CloseableHttpClient httpclient, String glpiUrl, String sessionToken, String apptoken, Integer userId)
Get the GLPI ticketsI18nizableText
getGlpiTypeLabel(int type)
Get the i18n label of a GLPI ticket typeList<GlpiTicket>
getOpenTickets(UserIdentity userIdentity)
Get all information about open ticketsprotected String
getTicketSearchQuery(Integer userId)
Get the part of rest API url for tickets searchprotected Integer
getUserIdentity(CloseableHttpClient httpclient, UserIdentity userIdentity, String glpiUrl, String sessionToken, String apptoken)
Get the user identity and fill the user identities cachevoid
initialize()
protected Map<String,Object>
loadUserInfo(UserIdentity userIdentity)
Get the user collaboration information from the exchange server.protected GlpiTicket
parseTicket(Map<String,Object> data)
Parse data intoGlpiTicket
void
service(ServiceManager manager)
void
setPluginInfo(String pluginName, String featureName, String id)
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_maxCacheSize
protected long _maxCacheSize
Maximum cache size, in number of records.
-
_cacheTtl
protected long _cacheTtl
The cache TTL in minutes.
-
_cache
protected LoadingCache<UserIdentity,Map<String,Object>> _cache
The user information cache. The key of the cache is the user identity it self
-
_cacheIdentities
protected Cache<String,Integer> _cacheIdentities
The user information cache. The key of the cache is the user identity it self
-
-
Constructor Detail
-
TicketGlpiManager
public TicketGlpiManager()
-
-
Method Detail
-
setPluginInfo
public void setPluginInfo(String pluginName, String featureName, String id)
Description copied from interface:PluginAware
Sets the plugin info relative to the current component.
Note : The feature name may be null if the targeted component in declared at plugin level.- Specified by:
setPluginInfo
in interfacePluginAware
- Parameters:
pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)id
- Unique identifier of this component
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceInitializable
-
loadUserInfo
protected Map<String,Object> loadUserInfo(UserIdentity userIdentity) throws Exception
Get the user collaboration information from the exchange server.- Parameters:
userIdentity
- the user identity.- Returns:
- the user collaboration information as a Map.
- Throws:
Exception
- If an error occurred
-
getUserIdentity
protected Integer getUserIdentity(CloseableHttpClient httpclient, UserIdentity userIdentity, String glpiUrl, String sessionToken, String apptoken) throws Exception
Get the user identity and fill the user identities cache- Parameters:
httpclient
- The http client to send a request to the webserviceuserIdentity
- The current user identityglpiUrl
- The GLPI UrlsessionToken
- The session tokenapptoken
- The app token- Returns:
- The user identity corresponding, or null if not found
- Throws:
Exception
- if an error occurred
-
getGlpiTickets
protected Map<String,Object> getGlpiTickets(CloseableHttpClient httpclient, String glpiUrl, String sessionToken, String apptoken, Integer userId) throws IOException, URISyntaxException
Get the GLPI tickets- Parameters:
httpclient
- the HTTP clientglpiUrl
- The url of GLPI serversessionToken
- The session tokenapptoken
- The app tokenuserId
- The user id- Returns:
- The tickets
- Throws:
IOException
- if an error occurredURISyntaxException
- if failed to build uri
-
parseTicket
protected GlpiTicket parseTicket(Map<String,Object> data)
Parse data intoGlpiTicket
- Parameters:
data
- the json data- Returns:
- the
GlpiTicket
-
getTicketSearchQuery
protected String getTicketSearchQuery(Integer userId)
Get the part of rest API url for tickets search- Parameters:
userId
- The user id- Returns:
- The search query to concat to rest API url
-
getCountOpenTickets
public int getCountOpenTickets(UserIdentity userIdentity) throws ExecutionException
Get the number of open tickets- Parameters:
userIdentity
- The user identity- Returns:
- the number of unread mail
- Throws:
ExecutionException
- If an error occured during the connection to the server
-
getOpenTickets
public List<GlpiTicket> getOpenTickets(UserIdentity userIdentity) throws ExecutionException
Get all information about open tickets- Parameters:
userIdentity
- The user identity- Returns:
- List of all information about open tickets
- Throws:
ExecutionException
- If an error occured during the connection to the server
-
getGlpiStatusLabel
public I18nizableText getGlpiStatusLabel(int status)
Get the i18n label of a GLPI status- Parameters:
status
- The GLPI status- Returns:
- the label of status as
I18nizableText
-
getGlpiTypeLabel
public I18nizableText getGlpiTypeLabel(int type)
Get the i18n label of a GLPI ticket type- Parameters:
type
- The GLPI type- Returns:
- the label of status as
I18nizableText
-
-