Class AbstractNotificationRulesManager<T,H extends AuthorityHolder>
- java.lang.Object
-
- jetbrains.buildServer.notification.impl.AbstractNotificationRulesManager<T,H>
-
- Type Parameters:
T
- notification rules holder id type (long ro user, String for user group)H
- notification rules holder type (SUser, or SUserGroup)
- All Implemented Interfaces:
EventListener
,NotificationRulesListener<T>
- Direct Known Subclasses:
GroupNotificationRulesManager
,UserNotificationRulesManager
public abstract class AbstractNotificationRulesManager<T,H extends AuthorityHolder> extends Object implements NotificationRulesListener<T>
Code refactored from Pavel Sher's NotificationRulesManagerImpl class.- Author:
- Maxim Podkolzine (maxim.podkolzine@jetbrains.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractNotificationRulesManager.DBWatchType
Uncoupling database representation and java/UI representation.
-
Field Summary
Fields Modifier and Type Field Description protected GenericQuery
DELETE_ALL_NOTIFICATION_EVENTS_QUERY
protected GenericQuery
DELETE_ALL_WATCHED_BUILDS_QUERY
protected GenericQuery
DELETE_NOTIFICATION_DATA_QUERY
protected NumericIdSequences
myIdSequences
protected ProjectManager
myProjectManager
protected NotificationRuleFactory
myRulesFactory
protected SecurityContextEx
mySecurityContext
protected SQLRunnerEx
mySQLRunner
-
Constructor Summary
Constructors Constructor Description AbstractNotificationRulesManager(ProjectManager projectManager, SecurityContextEx securityContext, NotificationRuleFactory rulesFactory, SQLRunnerEx sqlRunner, NumericIdSequences idSequences, NotificationRuleIdProvider ruleIdProvider, EventDispatcher<ProjectsImportListener> projectImportListenerEventDispatcher)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addListener(NotificationRulesListener<T> listener)
long
addNewRule(T holderId, String notificatorType, NotificationRule rule)
void
applyOrder(T holderId, String notificatorType, long[] ruleIds)
void
buildTypeCopied(String newBuildTypeId, String oldBuildTypeId)
void
buildTypesCopied(Map<String,String> map, List<String> notificatorTypes)
protected abstract void
checkHolderExists(T holderId)
Same as previous, but throws an exception if holder does not exist.protected void
clearCaches()
protected abstract NotificationRuleInit
createRuleForProjectsAndBuildTypes(T holderId, Collection<SProject> projects, Collection<SBuildType> buildTypes, Collection<NotificationRule.Event> events, Map<String,String> additionalData)
Collection<Long>
findConflictingRules(T holderId, String notificatorType, WatchedBuilds watch)
protected abstract H
findHolder(T holderId)
Possible implementations:NotificationRule
findRuleById(T holderId, long ruleId)
Map<T,List<NotificationRule>>
findRulesByNotificatorType(String notificatorType)
Map<T,List<NotificationRule>>
findRulesByNotificatorType(String notificatorType, DBFunctions dbFunctions)
Map<T,List<NotificationRule>>
findRulesByNotificatorType(String notificatorType, Filter<NotificationRule> filter)
Collection<NotificationRulesListener<T>>
getListeners()
protected abstract long
getNextRuleId()
List<NotificationRule>
getNotificationRules(T holderId, String notificatorType)
NotificationRulesManager API.protected abstract String
instantiateTemplate(String sql)
Implement this method with your specifications of the DB column name and table prefix.protected static String
instantiateTemplate(String sql, String holderIdColumnName, String tablePrefix)
Example usage:boolean
isRulesWithEventsConfigured(T holderId, String notificatorType)
void
notificationRulesChanged(T holderId, String notificatorType)
Notification rules changed for the notification rules holder.protected abstract void
notifyHolderChanged(T holderId)
Notify other nodes that notification rules holder with given Id was changedvoid
removeRule(T holderId, long ruleId)
void
removeRule(T holderId, NotificationRule rule)
protected abstract T
retrieveHolderId(ResultSet rs, int columnIndex)
Possible implementations:void
setNotificationRules(T holderId, String notificatorType, List<NotificationRule> rules)
void
updateNotificationRule(T holderId, String notifierType, NotificationRule rule)
Persists changed notifitaion rule.
-
-
-
Field Detail
-
myProjectManager
protected final ProjectManager myProjectManager
-
mySecurityContext
protected final SecurityContextEx mySecurityContext
-
myRulesFactory
protected final NotificationRuleFactory myRulesFactory
-
mySQLRunner
protected final SQLRunnerEx mySQLRunner
-
myIdSequences
protected final NumericIdSequences myIdSequences
-
DELETE_ALL_NOTIFICATION_EVENTS_QUERY
protected final GenericQuery DELETE_ALL_NOTIFICATION_EVENTS_QUERY
-
DELETE_NOTIFICATION_DATA_QUERY
protected final GenericQuery DELETE_NOTIFICATION_DATA_QUERY
-
DELETE_ALL_WATCHED_BUILDS_QUERY
protected final GenericQuery DELETE_ALL_WATCHED_BUILDS_QUERY
-
-
Constructor Detail
-
AbstractNotificationRulesManager
public AbstractNotificationRulesManager(@NotNull ProjectManager projectManager, @NotNull SecurityContextEx securityContext, @NotNull NotificationRuleFactory rulesFactory, @NotNull SQLRunnerEx sqlRunner, @NotNull NumericIdSequences idSequences, @NotNull NotificationRuleIdProvider ruleIdProvider, @NotNull EventDispatcher<ProjectsImportListener> projectImportListenerEventDispatcher)
-
-
Method Detail
-
getNotificationRules
@NotNull public List<NotificationRule> getNotificationRules(@NotNull T holderId, @NotNull String notificatorType)
NotificationRulesManager API.
-
isRulesWithEventsConfigured
public boolean isRulesWithEventsConfigured(@NotNull T holderId, @NotNull String notificatorType)
-
notifyHolderChanged
protected abstract void notifyHolderChanged(@Nullable T holderId)
Notify other nodes that notification rules holder with given Id was changed- Parameters:
holderId
- id of notification rules holder
-
updateNotificationRule
public void updateNotificationRule(@NotNull T holderId, @NotNull String notifierType, @NotNull NotificationRule rule)
Persists changed notifitaion rule. There is no checks whether the rule is actually changed. Holder should exist.- Parameters:
holderId
-notifierType
-rule
-
-
buildTypeCopied
public void buildTypeCopied(@NotNull String newBuildTypeId, @NotNull String oldBuildTypeId)
-
buildTypesCopied
public void buildTypesCopied(@NotNull Map<String,String> map, List<String> notificatorTypes)
-
setNotificationRules
public void setNotificationRules(@NotNull T holderId, @NotNull String notificatorType, @NotNull List<NotificationRule> rules)
-
findRulesByNotificatorType
public Map<T,List<NotificationRule>> findRulesByNotificatorType(@NotNull String notificatorType)
-
findRulesByNotificatorType
public Map<T,List<NotificationRule>> findRulesByNotificatorType(@NotNull String notificatorType, @NotNull Filter<NotificationRule> filter)
- Parameters:
notificatorType
-filter
- CollectionsUtil.ACCEPT_ALL (or CollectionsUtil.acceptAllFilter()) should be used if all rules are needed- Returns:
-
findRulesByNotificatorType
public Map<T,List<NotificationRule>> findRulesByNotificatorType(@NotNull String notificatorType, @NotNull DBFunctions dbFunctions)
-
removeRule
public void removeRule(@NotNull T holderId, long ruleId) throws UserNotFoundException
- Throws:
UserNotFoundException
-
removeRule
public void removeRule(@NotNull T holderId, @NotNull NotificationRule rule) throws UserNotFoundException
- Throws:
UserNotFoundException
-
applyOrder
public void applyOrder(@NotNull T holderId, @NotNull String notificatorType, long[] ruleIds)
-
addNewRule
public long addNewRule(@NotNull T holderId, @NotNull String notificatorType, @NotNull NotificationRule rule) throws UserNotFoundException, DuplicateNotificationRuleException
-
findConflictingRules
public Collection<Long> findConflictingRules(@NotNull T holderId, @NotNull String notificatorType, @NotNull WatchedBuilds watch)
-
findRuleById
@Nullable public NotificationRule findRuleById(@NotNull T holderId, long ruleId) throws UserNotFoundException
- Throws:
UserNotFoundException
-
addListener
public void addListener(@NotNull NotificationRulesListener<T> listener)
-
getListeners
@NotNull public Collection<NotificationRulesListener<T>> getListeners()
-
retrieveHolderId
@NotNull protected abstract T retrieveHolderId(ResultSet rs, int columnIndex) throws SQLException
Possible implementations:return rs.getLong(columnIndex);
orreturn rs.getString(columnIndex);
- Parameters:
rs
- result setcolumnIndex
- the column- Returns:
- the id
- Throws:
SQLException
- if database error occured
-
createRuleForProjectsAndBuildTypes
@Nullable protected abstract NotificationRuleInit createRuleForProjectsAndBuildTypes(@NotNull T holderId, @NotNull Collection<SProject> projects, @NotNull Collection<SBuildType> buildTypes, @NotNull Collection<NotificationRule.Event> events, @NotNull Map<String,String> additionalData)
-
findHolder
protected abstract H findHolder(@NotNull T holderId)
Possible implementations:return myUserModel.findUserById(holderId);
orreturn myUserGroupsManager.findUserGroupByCode(holderId);
- Parameters:
holderId
- holder id- Returns:
- the holder, or null
-
checkHolderExists
protected abstract void checkHolderExists(@NotNull T holderId) throws RuntimeException
Same as previous, but throws an exception if holder does not exist.- Parameters:
holderId
- holder id- Throws:
RuntimeException
- exception to throw
-
clearCaches
protected void clearCaches()
-
notificationRulesChanged
public void notificationRulesChanged(@NotNull T holderId, String notificatorType)
Description copied from interface:NotificationRulesListener
Notification rules changed for the notification rules holder.- Specified by:
notificationRulesChanged
in interfaceNotificationRulesListener<T>
- Parameters:
holderId
- given holder id.notificatorType
- notificator type for which rules changed.
-
instantiateTemplate
protected static String instantiateTemplate(String sql, String holderIdColumnName, String tablePrefix)
Example usage:instantiateTemplate(sql, "user_id", "user");
- Parameters:
sql
- templateholderIdColumnName
- the actual column nametablePrefix
- the actual table prefix- Returns:
- sql query
-
instantiateTemplate
@NotNull protected abstract String instantiateTemplate(String sql)
Implement this method with your specifications of the DB column name and table prefix. UseinstantiateTemplate(String, String, String)
method below.- Parameters:
sql
- the sql template- Returns:
- sql query
-
getNextRuleId
protected abstract long getNextRuleId()
-
-