Class AbstractMessagingConnector
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.messagingconnector.AbstractMessagingConnector
-
- All Implemented Interfaces:
MessagingConnector
,LogEnabled
,Initializable
,Component
,Serviceable
- Direct Known Subclasses:
BluemindConnector
,ExchangeConnector
,ZimbraConnector
public abstract class AbstractMessagingConnector extends AbstractLogEnabled implements MessagingConnector, Initializable, Serviceable
Abstract implementation ofMessagingConnector
with cache.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
AbstractMessagingConnector.EmailCacheKey
Internal class for key of events count cache(package private) class
AbstractMessagingConnector.EventCacheKey
Internal class for key of events cache(package private) class
AbstractMessagingConnector.EventCountCacheKey
Internal class for key of events count cache-
Nested classes/interfaces inherited from interface org.ametys.plugins.messagingconnector.MessagingConnector
MessagingConnector.AttendeeInformation, MessagingConnector.FreeBusyStatus, MessagingConnector.ResponseType
-
-
Field Summary
Fields Modifier and Type Field Description protected CryptoHelper
_cryptoHelper
The crypto helperprotected CurrentUserProvider
_currentUserProvider
The current user providerprivate Cache<AbstractMessagingConnector.EmailCacheKey,List<EmailMessage>>
_emailsCache
private Cache<UserIdentity,Integer>
_emailsCountCache
private Cache<MessagingConnectorException.ExceptionType,Set<UserIdentity>>
_errorCache
private Cache<AbstractMessagingConnector.EventCacheKey,List<CalendarEvent>>
_eventsCache
private Cache<AbstractMessagingConnector.EventCountCacheKey,Integer>
_eventsCountCache
private List<String>
_populationIds
private Cache<MessagingConnectorException.ExceptionType,Set<UserIdentity>>
_timeoutErrorCache
protected UserPopulationDAO
_userPopulationDAO
The user population DAOprotected UserPreferencesManager
_userPref
The user preferencesprivate static int
TIMEOUT_CACHE_DURATION_SECONDS
Duration of the cache for timeout errors, no calls will be done again for one user-
Fields inherited from interface org.ametys.plugins.messagingconnector.MessagingConnector
ROLE
-
-
Constructor Summary
Constructors Constructor Description AbstractMessagingConnector()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private MessagingConnectorException.ExceptionType
_getExceptionTypeFromCache(UserIdentity userIdentity)
private void
_invalidateExceptionForUserInCache(UserIdentity userIdentity, MessagingConnectorException.ExceptionType type)
private void
_putExceptionInCache(UserIdentity userIdentity, MessagingConnectorException.ExceptionType type)
private void
_throwMessagingConnectorExceptionIfInCache(UserIdentity userIdentity)
String
createEvent(String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser)
Create an eventvoid
deleteEvent(String eventId, UserIdentity organiser)
Delete an eventList<String>
getAllowedPopulationIds()
Get the list of population id allowed to the messaging connectorMap<String,MessagingConnector.AttendeeInformation>
getAttendees(String eventId, UserIdentity organiser)
Get the map of attendees for an eventList<CalendarEvent>
getEvents(UserIdentity userIdentity, int maxDays, int maxEvents)
Get the list of upcoming events from now for a given userint
getEventsCount(UserIdentity userIdentity, int maxDays)
Return the number of upcoming eventsMap<String,MessagingConnector.FreeBusyStatus>
getFreeBusy(Date startDate, Date endDate, boolean isAllDay, Set<String> attendees, UserIdentity organiser)
Get free/busy status for attendees for a time windowint
getUnreadEmailCount(UserIdentity userIdentity)
Return the number of unread mails for a given userList<EmailMessage>
getUnreadEmails(UserIdentity userIdentity, int maxEmails)
Return the unread emails for a given userprotected String
getUserCryptedPassword(UserIdentity userIdentity)
Get the user password, still cryptedprotected String
getUserPassword(UserIdentity userIdentity)
Get the user password for the messaging connectorvoid
initialize()
protected String
internalCreateEvent(String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser)
Create an eventprotected void
internalDeleteEvent(String eventId, UserIdentity organiser)
Delete an eventprotected Map<String,MessagingConnector.AttendeeInformation>
internalGetAttendees(String eventId, UserIdentity organiser)
Get the map of attendees for an eventprotected abstract List<EmailMessage>
internalGetEmails(UserIdentity userIdentity, int maxEmails)
Get emails (no caching)protected abstract int
internalGetEmailsCount(UserIdentity userIdentity)
Get emails count (no caching)protected abstract List<CalendarEvent>
internalGetEvents(UserIdentity userIdentity, int maxDays, int maxEvents)
Get upcoming events (no caching)protected abstract int
internalGetEventsCount(UserIdentity userIdentity, int maxDays)
Get upcoming events count (no caching)protected Map<String,MessagingConnector.FreeBusyStatus>
internalGetFreeBusy(Date startDate, Date endDate, boolean isAllDay, Set<String> attendees, UserIdentity organiser)
Get free/busy status for attendees for a time windowprotected boolean
internalIsEventExist(String eventId, UserIdentity organiser)
True if the event exist in the messaging connectorprotected void
internalSetAttendees(String eventId, Map<String,Boolean> attendees, UserIdentity organiser)
Set attendees for an eventprotected void
internalUpdateEvent(String eventId, String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser)
Update an eventprotected boolean
isAllowed(UserIdentity userIdentity)
True if the user is allowedboolean
isEventExist(String eventId, UserIdentity organiser)
True if the event exist in the messaging connectorboolean
isUserExist(UserIdentity userIdentity)
True if the user existvoid
service(ServiceManager manager)
void
setAttendees(String eventId, Map<String,Boolean> attendees, UserIdentity organiser)
Set attendees for an eventvoid
setUserPassword(UserIdentity userIdentity, String password)
Set a new password for the userboolean
supportInvitation()
Tell if the messaging connector supports event invitationboolean
supportUserCredential()
Check if a user credential should be savedvoid
updateEvent(String eventId, String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser)
Update an eventboolean
userCredentialNeeded()
Check if the service needs user credential (some implementation can use a central API key or impersonation, some don't)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
TIMEOUT_CACHE_DURATION_SECONDS
private static final int TIMEOUT_CACHE_DURATION_SECONDS
Duration of the cache for timeout errors, no calls will be done again for one user- See Also:
- Constant Field Values
-
_userPopulationDAO
protected UserPopulationDAO _userPopulationDAO
The user population DAO
-
_userPref
protected UserPreferencesManager _userPref
The user preferences
-
_cryptoHelper
protected CryptoHelper _cryptoHelper
The crypto helper
-
_currentUserProvider
protected CurrentUserProvider _currentUserProvider
The current user provider
-
_eventsCache
private Cache<AbstractMessagingConnector.EventCacheKey,List<CalendarEvent>> _eventsCache
-
_eventsCountCache
private Cache<AbstractMessagingConnector.EventCountCacheKey,Integer> _eventsCountCache
-
_emailsCache
private Cache<AbstractMessagingConnector.EmailCacheKey,List<EmailMessage>> _emailsCache
-
_emailsCountCache
private Cache<UserIdentity,Integer> _emailsCountCache
-
_errorCache
private Cache<MessagingConnectorException.ExceptionType,Set<UserIdentity>> _errorCache
-
_timeoutErrorCache
private Cache<MessagingConnectorException.ExceptionType,Set<UserIdentity>> _timeoutErrorCache
-
_populationIds
private List<String> _populationIds
-
-
Constructor Detail
-
AbstractMessagingConnector
public AbstractMessagingConnector()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
initialize
public void initialize()
- Specified by:
initialize
in interfaceInitializable
-
getAllowedPopulationIds
public List<String> getAllowedPopulationIds()
Description copied from interface:MessagingConnector
Get the list of population id allowed to the messaging connector- Specified by:
getAllowedPopulationIds
in interfaceMessagingConnector
- Returns:
- the list of population id allowed to the messaging connector
-
isAllowed
protected boolean isAllowed(UserIdentity userIdentity)
True if the user is allowed- Parameters:
userIdentity
- the user identity- Returns:
- true if the user is allowed
-
getEvents
public List<CalendarEvent> getEvents(UserIdentity userIdentity, int maxDays, int maxEvents) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Get the list of upcoming events from now for a given user- Specified by:
getEvents
in interfaceMessagingConnector
- Parameters:
userIdentity
- the owner of the eventsmaxDays
- The maximum number of days to search for from nowmaxEvents
- the maximum number of events to retrieve- Returns:
- the next events
- Throws:
MessagingConnectorException
- if failed to get events
-
getEventsCount
public int getEventsCount(UserIdentity userIdentity, int maxDays) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Return the number of upcoming events- Specified by:
getEventsCount
in interfaceMessagingConnector
- Parameters:
userIdentity
- the owner of the eventsmaxDays
- The maximum number of days to search for from now- Returns:
- the number of upcoming events
- Throws:
MessagingConnectorException
- if failed to get events' count
-
getUnreadEmails
public List<EmailMessage> getUnreadEmails(UserIdentity userIdentity, int maxEmails) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Return the unread emails for a given user- Specified by:
getUnreadEmails
in interfaceMessagingConnector
- Parameters:
userIdentity
- the recipient of the mailsmaxEmails
- The max number of emails to return- Returns:
- a mail messsages
- Throws:
MessagingConnectorException
- if failed to get mails
-
getUnreadEmailCount
public int getUnreadEmailCount(UserIdentity userIdentity) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Return the number of unread mails for a given user- Specified by:
getUnreadEmailCount
in interfaceMessagingConnector
- Parameters:
userIdentity
- the receiver of the mails- Returns:
- the number of unread mails
- Throws:
MessagingConnectorException
- if failed to get unread mails ' count
-
internalGetEvents
protected abstract List<CalendarEvent> internalGetEvents(UserIdentity userIdentity, int maxDays, int maxEvents) throws MessagingConnectorException
Get upcoming events (no caching)- Parameters:
userIdentity
- The user identitymaxDays
- The maximum number of days to search formaxEvents
- The maximum number of events to retrieve- Returns:
- The calendar events
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetEventsCount
protected abstract int internalGetEventsCount(UserIdentity userIdentity, int maxDays) throws MessagingConnectorException
Get upcoming events count (no caching)- Parameters:
userIdentity
- The user identitymaxDays
- The maximum number of days to search for- Returns:
- The number of calendar events
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetEmails
protected abstract List<EmailMessage> internalGetEmails(UserIdentity userIdentity, int maxEmails) throws MessagingConnectorException
Get emails (no caching)- Parameters:
userIdentity
- The user identitymaxEmails
- The maximum number of emails to retrieve- Returns:
- The emails
- Throws:
MessagingConnectorException
- if failed to get events from server
-
getUserPassword
protected String getUserPassword(UserIdentity userIdentity) throws UserPreferencesException
Get the user password for the messaging connector- Parameters:
userIdentity
- user to check- Returns:
- the decrypted user password
- Throws:
UserPreferencesException
- error while reading user preferences
-
getUserCryptedPassword
protected String getUserCryptedPassword(UserIdentity userIdentity) throws UserPreferencesException
Get the user password, still crypted- Parameters:
userIdentity
- user to check- Returns:
- the still crypted user password
- Throws:
UserPreferencesException
- error while reading user preferences
-
setUserPassword
public void setUserPassword(UserIdentity userIdentity, String password) throws UserPreferencesException, MessagingConnectorException
Description copied from interface:MessagingConnector
Set a new password for the user- Specified by:
setUserPassword
in interfaceMessagingConnector
- Parameters:
userIdentity
- user that have a password changepassword
- new password- Throws:
UserPreferencesException
- An exception occured while saving the passwordMessagingConnectorException
- Thrown when the messaging connector does not support user credentials
-
internalGetEmailsCount
protected abstract int internalGetEmailsCount(UserIdentity userIdentity) throws MessagingConnectorException
Get emails count (no caching)- Parameters:
userIdentity
- The user identity- Returns:
- The emails count
- Throws:
MessagingConnectorException
- if failed to get events from server
-
supportInvitation
public boolean supportInvitation() throws MessagingConnectorException
Description copied from interface:MessagingConnector
Tell if the messaging connector supports event invitation- Specified by:
supportInvitation
in interfaceMessagingConnector
- Returns:
- true if the messaging connector supports event invitation
- Throws:
MessagingConnectorException
- if failed to get events from server
-
isEventExist
public boolean isEventExist(String eventId, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
True if the event exist in the messaging connector- Specified by:
isEventExist
in interfaceMessagingConnector
- Parameters:
eventId
- the event idorganiser
- the organiser- Returns:
- true if the event exist
- Throws:
MessagingConnectorException
- if an error occurred
-
internalIsEventExist
protected boolean internalIsEventExist(String eventId, UserIdentity organiser) throws MessagingConnectorException
True if the event exist in the messaging connector- Parameters:
eventId
- the event idorganiser
- the organiser- Returns:
- true if the event exist
- Throws:
MessagingConnectorException
- if an error occurred
-
createEvent
public String createEvent(String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Create an event- Specified by:
createEvent
in interfaceMessagingConnector
- Parameters:
title
- the event titledescription
- the event descriptionplace
- the event placeisAllDay
- if the event is all daystartDate
- the event start dateendDate
- the event end daterecurrenceType
- recurrence typeuntilDate
- until date of the recurring eventattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Returns:
- the id of the event created
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalCreateEvent
protected String internalCreateEvent(String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Create an event- Parameters:
title
- the event titledescription
- the event descriptionplace
- the event placeisAllDay
- if the event is all daystartDate
- the event start dateendDate
- the event end daterecurrenceType
- recurrence typeuntilDate
- until date of the recurring eventattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Returns:
- the id of the event created
- Throws:
MessagingConnectorException
- if failed to get events from server
-
updateEvent
public void updateEvent(String eventId, String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Update an event- Specified by:
updateEvent
in interfaceMessagingConnector
- Parameters:
eventId
- the event id to deletetitle
- the event titledescription
- the event descriptionplace
- the event placeisAllDay
- if the event is all daystartDate
- the event start dateendDate
- the event end daterecurrenceType
- recurrence typeuntilDate
- until date of the recurring eventattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalUpdateEvent
protected void internalUpdateEvent(String eventId, String title, String description, String place, boolean isAllDay, Date startDate, Date endDate, EventRecurrenceTypeEnum recurrenceType, Date untilDate, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Update an event- Parameters:
eventId
- the event id to deletetitle
- the event titledescription
- the event descriptionplace
- the event placeisAllDay
- if the event is all daystartDate
- the event start dateendDate
- the event end daterecurrenceType
- recurrence typeuntilDate
- until date of the recurring eventattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
deleteEvent
public void deleteEvent(String eventId, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Delete an event- Specified by:
deleteEvent
in interfaceMessagingConnector
- Parameters:
eventId
- the event id to deleteorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalDeleteEvent
protected void internalDeleteEvent(String eventId, UserIdentity organiser) throws MessagingConnectorException
Delete an event- Parameters:
eventId
- the event id to deleteorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
getAttendees
public Map<String,MessagingConnector.AttendeeInformation> getAttendees(String eventId, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Get the map of attendees for an event- Specified by:
getAttendees
in interfaceMessagingConnector
- Parameters:
eventId
- the event idorganiser
- the event organiser- Returns:
- the map of attendees (email -> attendee information)
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetAttendees
protected Map<String,MessagingConnector.AttendeeInformation> internalGetAttendees(String eventId, UserIdentity organiser) throws MessagingConnectorException
Get the map of attendees for an event- Parameters:
eventId
- the event idorganiser
- the event organiser- Returns:
- the map of attendees (email -> attendee information)
- Throws:
MessagingConnectorException
- if failed to get events from server
-
setAttendees
public void setAttendees(String eventId, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Set attendees for an event- Specified by:
setAttendees
in interfaceMessagingConnector
- Parameters:
eventId
- the event idattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalSetAttendees
protected void internalSetAttendees(String eventId, Map<String,Boolean> attendees, UserIdentity organiser) throws MessagingConnectorException
Set attendees for an event- Parameters:
eventId
- the event idattendees
- the map of attendees (email -> optional or requested) to setorganiser
- the event organiser- Throws:
MessagingConnectorException
- if failed to get events from server
-
getFreeBusy
public Map<String,MessagingConnector.FreeBusyStatus> getFreeBusy(Date startDate, Date endDate, boolean isAllDay, Set<String> attendees, UserIdentity organiser) throws MessagingConnectorException
Description copied from interface:MessagingConnector
Get free/busy status for attendees for a time window- Specified by:
getFreeBusy
in interfaceMessagingConnector
- Parameters:
startDate
- the start dateendDate
- the end dateisAllDay
- true if is an allday eventattendees
- the list of attendees emailorganiser
- the event organiser- Returns:
- the map of attendees (email -> freeBusy status)
- Throws:
MessagingConnectorException
- if failed to get events from server
-
internalGetFreeBusy
protected Map<String,MessagingConnector.FreeBusyStatus> internalGetFreeBusy(Date startDate, Date endDate, boolean isAllDay, Set<String> attendees, UserIdentity organiser) throws MessagingConnectorException
Get free/busy status for attendees for a time window- Parameters:
startDate
- the start dateendDate
- the end dateisAllDay
- true if is an allday eventattendees
- the list of attendees emailorganiser
- the event organiser- Returns:
- the map of attendees (email -> freeBusy status)
- Throws:
MessagingConnectorException
- if failed to get events from server
-
userCredentialNeeded
public boolean userCredentialNeeded()
Description copied from interface:MessagingConnector
Check if the service needs user credential (some implementation can use a central API key or impersonation, some don't)- Specified by:
userCredentialNeeded
in interfaceMessagingConnector
- Returns:
- True if the service is configured to ask for user credential
-
supportUserCredential
public boolean supportUserCredential()
Description copied from interface:MessagingConnector
Check if a user credential should be saved- Specified by:
supportUserCredential
in interfaceMessagingConnector
- Returns:
- true if this implementation supports user credential (and is configured to use them)
-
isUserExist
public boolean isUserExist(UserIdentity userIdentity) throws MessagingConnectorException
Description copied from interface:MessagingConnector
True if the user exist- Specified by:
isUserExist
in interfaceMessagingConnector
- Parameters:
userIdentity
- the user identity- Returns:
- true if the user exist
- Throws:
MessagingConnectorException
- if failed to get events from server
-
_invalidateExceptionForUserInCache
private void _invalidateExceptionForUserInCache(UserIdentity userIdentity, MessagingConnectorException.ExceptionType type)
-
_putExceptionInCache
private void _putExceptionInCache(UserIdentity userIdentity, MessagingConnectorException.ExceptionType type)
-
_getExceptionTypeFromCache
private MessagingConnectorException.ExceptionType _getExceptionTypeFromCache(UserIdentity userIdentity)
-
_throwMessagingConnectorExceptionIfInCache
private void _throwMessagingConnectorExceptionIfInCache(UserIdentity userIdentity) throws MessagingConnectorException
- Throws:
MessagingConnectorException
-
-