From dccac572f8ec715770e9d26126f56a0bf8149452 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Sat, 30 Jan 2016 21:11:44 +0100 Subject: [PATCH] don't add regatta log-provided competitors if no race exists; only collect competitors from race columns Change-Id: Icd2843aba1d374cb3ac55b3575ec22e734ab9ec0 --- .../CompetitorProviderCacheInvalidationTest.java | 4 ++-- .../RegattaLogEventNotificationForwardingTest.java | 14 ++++++++++++-- ...titorProviderFromRaceColumnsAndRegattaLike.java | 7 ++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CompetitorProviderCacheInvalidationTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CompetitorProviderCacheInvalidationTest.java index 3bccce5f657..67359e4b3c8 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CompetitorProviderCacheInvalidationTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/CompetitorProviderCacheInvalidationTest.java @@ -180,8 +180,8 @@ public class CompetitorProviderCacheInvalidationTest extends AbstractLeaderboard for (Competitor c : compLists[1]) { raceLog.add(new RaceLogRegisterCompetitorEventImpl(MillisecondsTimePoint.now(), new LogEventAuthorImpl("Me", 0), 1, c)); } - //expected are only the competitors in the RaceLog, because only one RaceColumn is - //registered, which has the competitors registered in the RaceLog. + // expected are only the competitors in the RaceLog, because only one RaceColumn is + // registered, which has the competitors registered in the RaceLog. assertRegattaAndRaceCompetitors(new HashSet<>(compLists[1])); // Now we revoke that the race log provides the competitors for R1; the competitors should then // snap back to those competitors taken from the regatta log for both, the rentire leaderboard diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/RegattaLogEventNotificationForwardingTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/RegattaLogEventNotificationForwardingTest.java index f7658d1961e..31d96c7cb22 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/RegattaLogEventNotificationForwardingTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/RegattaLogEventNotificationForwardingTest.java @@ -22,8 +22,10 @@ import com.sap.sailing.domain.base.RaceColumnListener; import com.sap.sailing.domain.base.Regatta; import com.sap.sailing.domain.base.Series; import com.sap.sailing.domain.base.impl.CourseAreaImpl; +import com.sap.sailing.domain.base.impl.FleetImpl; import com.sap.sailing.domain.base.impl.RaceColumnListenerWithDefaultAction; import com.sap.sailing.domain.base.impl.RegattaImpl; +import com.sap.sailing.domain.base.impl.SeriesImpl; import com.sap.sailing.domain.common.NoWindException; import com.sap.sailing.domain.common.dto.LeaderboardDTO; import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard; @@ -156,7 +158,7 @@ public class RegattaLogEventNotificationForwardingTest extends AbstractSerializa @Test public void testAddCompetitorToRegattaAndEnsureCacheInvalidation() throws NoWindException, InterruptedException, ExecutionException { - Regatta regatta = new RegattaImpl("test", null, null, null, new HashSet(), false, new LowPoint(), "test", null, OneDesignRankingMetric::new); + Regatta regatta = createRegatta(); RegattaLeaderboard leaderboard = new RegattaLeaderboardImpl(regatta, new ThresholdBasedResultDiscardingRuleImpl(new int[0])); final TimePoint now = MillisecondsTimePoint.now(); leaderboard.getScoreCorrection().setTimePointOfLastCorrectionsValidity(now); @@ -175,10 +177,18 @@ public class RegattaLogEventNotificationForwardingTest extends AbstractSerializa assertEquals(event.getCompetitor().getName(), dto3.competitors.get(0).getName()); } + private Regatta createRegatta() { + Series series = new SeriesImpl("Test Series", /* isMedal */ false, /* fleets */ Collections.singleton(new FleetImpl("Default")), + Collections.singleton("R1"), /* trackedRegattaRegistry */ null); + Regatta regatta = new RegattaImpl("test", null, null, null, Collections.singleton(series), false, + new LowPoint(), "test", null, OneDesignRankingMetric::new); + return regatta; + } + @Test public void testAddCompetitorToRegattaAndEnsureCacheInvalidationOnDeserializedRegattaLeaderboard() throws NoWindException, InterruptedException, ExecutionException, ClassNotFoundException, IOException { - Regatta regatta = new RegattaImpl("test", null, null, null, new HashSet(), false, new LowPoint(), "test", null, OneDesignRankingMetric::new); + Regatta regatta = createRegatta(); RegattaLeaderboard leaderboard = new RegattaLeaderboardImpl(regatta, new ThresholdBasedResultDiscardingRuleImpl(new int[0])); final TimePoint now = MillisecondsTimePoint.now(); leaderboard.getScoreCorrection().setTimePointOfLastCorrectionsValidity(now); diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/CompetitorProviderFromRaceColumnsAndRegattaLike.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/CompetitorProviderFromRaceColumnsAndRegattaLike.java index 9e5219b9e2c..52a6d395f56 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/CompetitorProviderFromRaceColumnsAndRegattaLike.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/CompetitorProviderFromRaceColumnsAndRegattaLike.java @@ -17,7 +17,6 @@ import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEventVisitor; import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogRegisterCompetitorEvent; import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogRevokeEvent; import com.sap.sailing.domain.abstractlog.regatta.impl.BaseRegattaLogEventVisitor; -import com.sap.sailing.domain.abstractlog.shared.analyzing.CompetitorsInLogAnalyzer; import com.sap.sailing.domain.base.Competitor; import com.sap.sailing.domain.base.Fleet; import com.sap.sailing.domain.base.RaceColumn; @@ -165,8 +164,10 @@ public class CompetitorProviderFromRaceColumnsAndRegattaLike { } } final RegattaLog regattaLog = provider.getRegattaLike().getRegattaLog(); - Util.addAll(new CompetitorsInLogAnalyzer<>(regattaLog).analyze(), result); - // note: adding listeners is idempotent; at most one occurrence of this listener exists in the race/regatta log's + // Don't add regatta log competitors; if no race exists, the leaderboard is not considered to have any + // competitors. The competitors are collected from the races. Those, however, will be the regatta log + // competitors if the race does not define its own. + // Note: adding listeners is idempotent; at most one occurrence of this listener exists in the race/regatta log's // listeners set provider.addRaceColumnListener(raceColumnListener); // consider {@link RegattaLog} competitor changes because the RaceColumns may have added the competitors from there