Merge branch 'master' of ssh://sapsailing.com/home/trac/git

This commit is contained in:
Generic Wiki User
2020-10-21 08:00:03 +00:00
9 changed files with 59 additions and 120 deletions
@@ -53,7 +53,7 @@ public class GetFavoritesAction implements SailingAction<FavoritesResult> {
boolean notifyAboutResults = false;
if (preferences != null) {
for (CompetitorNotificationPreference pref : preferences.getCompetitors()) {
final String competitorId = pref.getCompetitorId();
final String competitorId = pref.getCompetitorIdAsString();
final RacingEventService racingEventService = ctx.getRacingEventService();
final CompetitorAndBoatStore competitorAndBoatStore = racingEventService.getCompetitorAndBoatStore();
DynamicCompetitor competitor = competitorAndBoatStore.getExistingCompetitorByIdAsString(competitorId);
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import com.google.gwt.core.shared.GwtIncompatible;
import com.sap.sailing.domain.base.CompetitorAndBoatStore;
import com.sap.sailing.gwt.home.communication.SailingAction;
import com.sap.sailing.gwt.home.communication.SailingDispatchContext;
import com.sap.sailing.gwt.home.communication.event.SimpleCompetitorWithIdDTO;
@@ -33,20 +32,13 @@ public class SaveFavoriteCompetitorsAction implements SailingAction<VoidResult>,
public VoidResult execute(SailingDispatchContext ctx) throws DispatchException {
CompetitorNotificationPreferences prefs = new CompetitorNotificationPreferences(ctx.getRacingEventService());
List<CompetitorNotificationPreference> competitorPreferences = new ArrayList<>();
CompetitorAndBoatStore competitorStore = ctx.getRacingEventService().getCompetitorAndBoatStore();
for (SimpleCompetitorWithIdDTO competitorDTO : favorites.getSelectedCompetitors()) {
String competitorId = competitorDTO.getIdAsString();
if (competitorStore.getExistingCompetitorByIdAsString(competitorId) != null) {
competitorPreferences
.add(new CompetitorNotificationPreference(competitorId, favorites.isNotifyAboutResults()));
} else {
throw new DispatchException(
"Competitor with ID: " + competitorId + "is not an existing Competitor on this server.");
}
String competitorIdAsString = competitorDTO.getIdAsString();
competitorPreferences.add(new CompetitorNotificationPreference(competitorIdAsString, favorites.isNotifyAboutResults()));
}
prefs.setCompetitors(competitorPreferences);
ctx.setPreferenceForCurrentUser(CompetitorNotificationPreferences.PREF_NAME, prefs);
return new VoidResult();
}
}
@@ -2198,17 +2198,17 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
@Override
public void correctedScoreChanged(Competitor competitor, RaceColumn raceColumn, Double oldCorrectedScore,
Double newCorrectedScore) {
notifyForCompetitorIfNotAlreadyNotifiedRecently(competitor, raceColumn);
notifyForCompetitorScoreCorrectionUpdateIfNotAlreadyNotifiedRecently(competitor, raceColumn);
}
@Override
public void maxPointsReasonChanged(Competitor competitor, RaceColumn raceColumn, MaxPointsReason oldMaxPointsReason, MaxPointsReason newMaxPointsReason) {
notifyForCompetitorIfNotAlreadyNotifiedRecently(competitor, raceColumn);
notifyForCompetitorScoreCorrectionUpdateIfNotAlreadyNotifiedRecently(competitor, raceColumn);
}
@Override
public void carriedPointsChanged(Competitor competitor, Double oldCarriedPoints, Double newCarriedPoints) {
notifyForCompetitorIfNotAlreadyNotifiedRecently(competitor, /* no raceColumn in case of carried points */ null);
notifyForCompetitorScoreCorrectionUpdateIfNotAlreadyNotifiedRecently(competitor, /* no raceColumn in case of carried points */ null);
}
@Override
@@ -2242,7 +2242,7 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
* may be {@code null} which means that something may have changed for the competitor outside of a
* specific race column, such as the carried points
*/
private void notifyForCompetitorIfNotAlreadyNotifiedRecently(Competitor competitor, RaceColumn raceColumn) {
private void notifyForCompetitorScoreCorrectionUpdateIfNotAlreadyNotifiedRecently(Competitor competitor, RaceColumn raceColumn) {
final TimePoint now = MillisecondsTimePoint.now();
if (notificationService != null && (!lastNotificationForCompetitor.containsKey(competitor) ||
lastNotificationForCompetitor.get(competitor).until(now).compareTo(HOW_LONG_BETWEEN_TWO_NOTIFICATIONS_FOR_SIMILAR_EVENT) >= 0)) {
@@ -3,34 +3,26 @@ package com.sap.sailing.server.impl.preferences;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.CompetitorAndBoatStore;
import com.sap.sailing.domain.base.impl.DynamicCompetitor;
import com.sap.sailing.server.impl.preferences.model.CompetitorNotificationPreference;
import com.sap.sailing.server.impl.preferences.model.CompetitorNotificationPreferences;
import com.sap.sse.security.PreferenceObjectBasedNotificationSet;
import com.sap.sse.security.StoreServiceTrackerCustomizer;
import com.sap.sse.security.interfaces.UserStore;
/**
* {@link PreferenceObjectBasedNotificationSet} for associations of {@link Competitor} to a set of users to notify about
* specific events for the {@link Competitor}. Subclasses define the concrete case of notification based on the flags in
* {@link CompetitorNotificationPreference} via implementing {@link #shouldNotifyFor(CompetitorNotificationPreference)}.
* {@link PreferenceObjectBasedNotificationSet} for associations of {@link Competitor}'s {@link Competitor#getId() IDs}
* in {@link String} form to a set of users to notify about specific events for the {@link Competitor}. Subclasses
* define the concrete case of notification based on the flags in {@link CompetitorNotificationPreference} via
* implementing {@link #shouldNotifyFor(CompetitorNotificationPreference)}.
*/
public abstract class AbstractCompetitorNotificationSet
extends PreferenceObjectBasedNotificationSet<CompetitorNotificationPreferences, Competitor> {
private static final Logger logger = Logger.getLogger(AbstractCompetitorNotificationSet.class.getName());
private CompetitorAndBoatStore competitorAndBoatStore;
private ServiceTracker<CompetitorAndBoatStore, CompetitorAndBoatStore> tracker;
extends PreferenceObjectBasedNotificationSet<CompetitorNotificationPreferences, String> {
public AbstractCompetitorNotificationSet(UserStore userStore, CompetitorAndBoatStore competitorAndBoatStore) {
super(CompetitorNotificationPreferences.PREF_NAME, userStore);
this.competitorAndBoatStore = competitorAndBoatStore;
}
/**
@@ -38,38 +30,16 @@ public abstract class AbstractCompetitorNotificationSet
*/
public AbstractCompetitorNotificationSet(BundleContext bundleContext) {
super(CompetitorNotificationPreferences.PREF_NAME, bundleContext);
if (bundleContext == null) {
this.tracker = null;
} else {
this.tracker = new ServiceTracker<CompetitorAndBoatStore, CompetitorAndBoatStore>(bundleContext,
CompetitorAndBoatStore.class,
new StoreServiceTrackerCustomizer<CompetitorAndBoatStore>(bundleContext, logger) {
@Override
protected void setStore(CompetitorAndBoatStore store) {
AbstractCompetitorNotificationSet.this.competitorAndBoatStore = store;
}
@Override
protected void removeStore() {
AbstractCompetitorNotificationSet.this.competitorAndBoatStore = null;
}
@Override
protected CompetitorAndBoatStore getStore() {
return AbstractCompetitorNotificationSet.this.competitorAndBoatStore;
}
});
this.tracker.open();
}
}
@Override
protected Collection<Competitor> calculateObjectsToNotify(CompetitorNotificationPreferences preference) {
Set<Competitor> result = new HashSet<>();
protected Collection<String> calculateObjectsToNotify(CompetitorNotificationPreferences preference) {
final Set<String> result = new HashSet<>();
for (CompetitorNotificationPreference pref : preference.getCompetitors()) {
if (shouldNotifyFor(pref)) {
String competitorId = pref.getCompetitorId();
DynamicCompetitor competitor = competitorAndBoatStore.getExistingCompetitorByIdAsString(competitorId);
if (competitor != null) {
result.add(competitor);
final String competitorIdAsString = pref.getCompetitorIdAsString();
if (competitorIdAsString != null) {
result.add(competitorIdAsString);
}
}
}
@@ -12,11 +12,6 @@ import com.sap.sse.security.interfaces.UserStore;
* whenever new results are available for a {@link Competitor}.
*/
public class CompetitorResultsNotificationSet extends AbstractCompetitorNotificationSet {
public CompetitorResultsNotificationSet(UserStore store, CompetitorAndBoatStore competitorAndBoatStore) {
super(store, competitorAndBoatStore);
}
/**
* Constructor used to automatically track {@link UserStore} and {@link CompetitorAndBoatStore} as OSGi service.
*/
@@ -28,5 +23,4 @@ public class CompetitorResultsNotificationSet extends AbstractCompetitorNotifica
protected boolean shouldNotifyFor(CompetitorNotificationPreference pref) {
return pref.isNotifyAboutResults();
}
}
@@ -15,9 +15,9 @@ public class CompetitorNotificationPreference extends AbstractGenericSerializabl
notifyAboutResults = new BooleanSetting("notifyAboutResults", this, false);
}
public CompetitorNotificationPreference(String competitorId, boolean notifyAboutResults) {
public CompetitorNotificationPreference(String competitorIdAsString, boolean notifyAboutResults) {
this();
this.competitorId.setValue(competitorId);
this.competitorId.setValue(competitorIdAsString);
this.notifyAboutResults.setValue(notifyAboutResults);
}
@@ -30,7 +30,7 @@ public class CompetitorNotificationPreference extends AbstractGenericSerializabl
// The usage of Java Serialization isn't planned by now, either.
}
public String getCompetitorId() {
public String getCompetitorIdAsString() {
return competitorId.getValue();
}
@@ -14,7 +14,6 @@ import org.osgi.framework.BundleContext;
import com.sap.sailing.domain.base.BoatClass;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.CompetitorAndBoatStore;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.Fleet;
import com.sap.sailing.domain.base.RaceColumn;
@@ -34,7 +33,6 @@ import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.i18n.impl.ResourceBundleStringMessagesImpl;
import com.sap.sse.mail.queue.MailQueue;
import com.sap.sse.security.interfaces.UserStore;
public class SailingNotificationServiceImpl implements SailingNotificationService {
public static final String STRING_MESSAGES_BASE_NAME = "stringmessages/StringMessages";
@@ -57,17 +55,6 @@ public class SailingNotificationServiceImpl implements SailingNotificationServic
new CompetitorResultsNotificationSet(bundleContext));
}
/**
* Constructor used for unit tests to not need BundelContext but directly work with a given UserStore.
* @throws MalformedURLException
*/
public SailingNotificationServiceImpl(UserStore userStore, CompetitorAndBoatStore competitorAndBoatStore, MailQueue mailQueue) throws MalformedURLException {
this(mailQueue,
new BoatClassResultsNotificationSet(userStore),
new BoatClassUpcomingRaceNotificationSet(userStore),
new CompetitorResultsNotificationSet(userStore, competitorAndBoatStore));
}
public SailingNotificationServiceImpl(MailQueue mailQueue, BoatClassResultsNotificationSet boatClassResults,
BoatClassUpcomingRaceNotificationSet boatClassUpcomingRace,
CompetitorResultsNotificationSet competitorResults) throws MalformedURLException {
@@ -264,9 +251,9 @@ public class SailingNotificationServiceImpl implements SailingNotificationServic
public void notifyUserOnCompetitorPassesFinish(Competitor competitor, TrackedRace trackedRace,
Leaderboard leaderboard, RaceColumn raceColumn, Fleet fleet) {
doWithEvent(leaderboard, (event, leaderboardGroup) -> {
mailQueue.addNotification(new NotificationSetNotification<Competitor>(competitor, competitorResults) {
mailQueue.addNotification(new NotificationSetNotification<String>(competitor.getId().toString(), competitorResults) {
@Override
protected NotificationMailTemplate getMailTemplate(Competitor objectToNotifyAbout, Locale locale) {
protected NotificationMailTemplate getMailTemplate(String objectToNotifyAbout, Locale locale) {
String raceDescription = calculateRaceDescription(locale, event, leaderboard, raceColumn, fleet);
return new NotificationMailTemplate(
messages.get(locale, "competitorPassesFinishSubject", competitor.getName()),
@@ -282,10 +269,9 @@ public class SailingNotificationServiceImpl implements SailingNotificationServic
@Override
public void notifyUserOnCompetitorScoreCorrections(Competitor competitor, Leaderboard leaderboard) {
doWithEvent(leaderboard, (event, leaderboardGroup) -> {
mailQueue.addNotification(new NotificationSetNotification<Competitor>(competitor, competitorResults) {
mailQueue.addNotification(new NotificationSetNotification<String>(competitor.getId().toString(), competitorResults) {
@Override
protected NotificationMailTemplate getMailTemplate(Competitor objectToNotifyAbout, Locale locale) {
protected NotificationMailTemplate getMailTemplate(String objectToNotifyAbout, Locale locale) {
String leaderboardDescription = calculateLeaderboardDescription(locale, event, leaderboard);
return new NotificationMailTemplate(
messages.get(locale, "competitorScoreCorrectionSubject", competitor.getName()),
@@ -65,7 +65,7 @@ public class PreferenceObjectBasedNotificationSetTest {
@Test
public void noPreferenceAvailableTest() {
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
Assert.assertTrue(Util.isEmpty(notificationSet.getUsersnamesToNotifyFor(prefKey)));
Assert.assertTrue(Util.isEmpty(notificationSet.getUserNamesToNotifyFor(prefKey)));
}
@Test
@@ -73,9 +73,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.registerPreferenceConverter(prefKey, prefConverter);
store.setPreferenceObject(user1, prefKey, values1);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
@Test
@@ -83,9 +83,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.registerPreferenceConverter(prefKey, prefConverter);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.setPreferenceObject(user1, prefKey, values1);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
@Test
@@ -94,9 +94,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user1, prefKey, values1);
store.setPreferenceObject(user2, prefKey, values2);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1, user2)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1, user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values(user2)));
}
@Test
@@ -105,9 +105,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user1, prefKey, values1);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.setPreferenceObject(user1, prefKey, values2);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values(user1)));
}
@Test
@@ -117,9 +117,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user2, prefKey, allValues);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.setPreferenceObject(user1, prefKey, values2);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1, user2)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values(user1, user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1, user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values(user1, user2)));
}
@Test
@@ -129,9 +129,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user2, prefKey, values2);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.unsetPreference(user1, prefKey);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user2)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values(user2)));
}
@Test
@@ -140,9 +140,9 @@ public class PreferenceObjectBasedNotificationSetTest {
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.setPreferenceObject(user1, prefKey, values1);
store.unsetPreference(user1, prefKey);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
@Test
@@ -150,7 +150,7 @@ public class PreferenceObjectBasedNotificationSetTest {
store.registerPreferenceConverter(prefKey, prefConverter);
store.setPreferenceObject(user1, prefKey, values1);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor("x"), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor("x"), values()));
}
@Test
@@ -160,9 +160,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user1, prefKey, values1);
store.setPreferenceObject(user1, otherPrefKey, values2);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values(user1)));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
@Test
@@ -243,9 +243,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user1, prefKey, values1);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.deleteUser(user1);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
@Test
@@ -255,9 +255,9 @@ public class PreferenceObjectBasedNotificationSetTest {
store.setPreferenceObject(user1, prefKey, values1);
PreferenceObjectBasedNotificationSetImpl notificationSet = new PreferenceObjectBasedNotificationSetImpl(prefKey, store);
store.removePreferenceConverter(prefKey);
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUsersnamesToNotifyFor(C), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(A), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(B), values()));
Assert.assertTrue(Util.equals(notificationSet.getUserNamesToNotifyFor(C), values()));
}
private static HashSet<String> values(String... values) {
@@ -139,7 +139,7 @@ public abstract class PreferenceObjectBasedNotificationSet<PrefT, T> implements
*/
protected abstract Collection<T> calculateObjectsToNotify(PrefT preference);
public Iterable<String> getUsersnamesToNotifyFor(T object) {
public Iterable<String> getUserNamesToNotifyFor(T object) {
LockUtil.lockForRead(lock);
try {
return new HashSet<>(Util.get(notifications, object, Collections.emptySet()));
@@ -153,7 +153,7 @@ public abstract class PreferenceObjectBasedNotificationSet<PrefT, T> implements
* Users without a verified email address will be skipped.
*/
public void forUsersWithVerifiedEmailMappedTo(T object, Consumer<User> consumer) {
for (String username : getUsersnamesToNotifyFor(object)) {
for (String username : getUserNamesToNotifyFor(object)) {
// User objects can change silently. So we just keep the usernames and get the associated user objects on
// the fly.
User user = store.getUserByName(username);
@@ -176,13 +176,10 @@ public abstract class PreferenceObjectBasedNotificationSet<PrefT, T> implements
: calculateObjectsToNotify(oldPreference);
Collection<T> newObjectsToNotify = newPreference == null ? Collections.emptySet()
: calculateObjectsToNotify(newPreference);
Set<T> objectsToRemove = new HashSet<>(oldObjectsToNotify);
objectsToRemove.removeAll(newObjectsToNotify);
Set<T> objectsToAdd = new HashSet<>(newObjectsToNotify);
objectsToAdd.removeAll(oldObjectsToNotify);
LockUtil.lockForWrite(lock);
try {
for (T objectToRemove : objectsToRemove) {