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 private static String
__GLPI_INIT_SESSION
private static String
__GLPI_KILL_SESSION
private static String
__GLPI_SEARCH_TICKET
private static String
__GLPI_SEARCH_USERS
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.private Map<Integer,I18nizableText>
_glpiStatus
private Map<Integer,I18nizableText>
_glpiType
private JSONUtils
_jsonUtils
protected long
_maxCacheSize
Maximum cache size, in number of records.private String
_pluginName
static String
ROLE
Avalon ROLE.
-
Constructor Summary
Constructors Constructor Description TicketGlpiManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Map<String,Object>
_callWebServiceApi(CloseableHttpClient httpclient, URI uri, boolean getJsonObject)
private String
_getGlpiSessionToken(CloseableHttpClient httpclient, String glpiUrl, String usertoken, String apptoken)
private boolean
_isSuccess(int statusCode)
private void
_killGlpiSessionToken(CloseableHttpClient httpclient, String glpiUrl, String sessionToken, String apptoken)
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
-
__GLPI_INIT_SESSION
private static final String __GLPI_INIT_SESSION
- See Also:
- Constant Field Values
-
__GLPI_SEARCH_USERS
private static final String __GLPI_SEARCH_USERS
- See Also:
- Constant Field Values
-
__GLPI_SEARCH_TICKET
private static final String __GLPI_SEARCH_TICKET
- See Also:
- Constant Field Values
-
__GLPI_KILL_SESSION
private static final String __GLPI_KILL_SESSION
- See Also:
- Constant Field Values
-
_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
-
_jsonUtils
private JSONUtils _jsonUtils
-
_glpiStatus
private Map<Integer,I18nizableText> _glpiStatus
-
_glpiType
private Map<Integer,I18nizableText> _glpiType
-
_pluginName
private String _pluginName
-
-
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
-
_getGlpiSessionToken
private String _getGlpiSessionToken(CloseableHttpClient httpclient, String glpiUrl, String usertoken, String apptoken) throws IOException, URISyntaxException
- Throws:
IOException
URISyntaxException
-
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
-
_killGlpiSessionToken
private void _killGlpiSessionToken(CloseableHttpClient httpclient, String glpiUrl, String sessionToken, String apptoken) throws IOException, URISyntaxException
- Throws:
IOException
URISyntaxException
-
_callWebServiceApi
private Map<String,Object> _callWebServiceApi(CloseableHttpClient httpclient, URI uri, boolean getJsonObject) throws IOException
- Throws:
IOException
-
_isSuccess
private boolean _isSuccess(int statusCode)
-
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
-
-