diff --git a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/DomainObjectFactoryImpl.java b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/DomainObjectFactoryImpl.java index adec567b430..e49c1c5842d 100755 --- a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/DomainObjectFactoryImpl.java +++ b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/DomainObjectFactoryImpl.java @@ -1,6 +1,7 @@ package com.sap.sailing.domain.persistence.impl; import java.io.Serializable; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -73,6 +74,8 @@ import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl; import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl; import com.sap.sailing.domain.leaderboard.meta.LeaderboardGroupMetaLeaderboard; import com.sap.sailing.domain.persistence.DomainObjectFactory; +import com.sap.sailing.domain.persistence.MongoFactory; +import com.sap.sailing.domain.persistence.MongoRaceLogStoreFactory; import com.sap.sailing.domain.racelog.Flags; import com.sap.sailing.domain.racelog.RaceColumnIdentifier; import com.sap.sailing.domain.racelog.RaceLog; @@ -358,11 +361,18 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory { if (fleets.isEmpty()) { fleets.add(result.getFleet(null)); } - RaceColumn raceColumn = result.addRaceColumn((String) dbRaceColumn.get(FieldNames.LEADERBOARD_COLUMN_NAME.name()), - (Boolean) dbRaceColumn.get(FieldNames.LEADERBOARD_IS_MEDAL_RACE_COLUMN.name()), fleets.toArray(new Fleet[0])); - for (Map.Entry e : raceIdentifiers.entrySet()) { - raceColumn.setRaceIdentifier(fleetsByName.get(e.getKey()), e.getValue()); - } + try { + RaceColumn raceColumn = result.addRaceColumn((String) dbRaceColumn.get(FieldNames.LEADERBOARD_COLUMN_NAME.name()), + (Boolean) dbRaceColumn.get(FieldNames.LEADERBOARD_IS_MEDAL_RACE_COLUMN.name()), + MongoRaceLogStoreFactory.INSTANCE.getMongoRaceLogStore(MongoFactory.INSTANCE.getDefaultMongoObjectFactory(), this) + ,fleets.toArray(new Fleet[0])); + for (Map.Entry e : raceIdentifiers.entrySet()) { + raceColumn.setRaceIdentifier(fleetsByName.get(e.getKey()), e.getValue()); + } + } catch (UnknownHostException e) { + e.printStackTrace(); + } + } return result; } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/LeaderboardOfflineTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/LeaderboardOfflineTest.java index ed695f82061..4939d574412 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/LeaderboardOfflineTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/LeaderboardOfflineTest.java @@ -31,6 +31,7 @@ import com.sap.sailing.domain.leaderboard.impl.FlexibleLeaderboardImpl; import com.sap.sailing.domain.leaderboard.impl.LowPoint; import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl; import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl; +import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore; import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRank; import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors; import com.sap.sailing.domain.tracking.TrackedRace; @@ -95,7 +96,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest { Fleet defaultFleet = leaderboard.getFleet(null); final String columnName = "abc"; setupRaces(1, 0); - leaderboard.addRaceColumn(columnName, /* medalRace */ true); + leaderboard.addRaceColumn(columnName, /* medalRace */ true, EmptyRaceLogStore.INSTANCE); leaderboard.addRace(testRaces.iterator().next(), columnName, /* medalRace */ false, defaultFleet); assertTrue(leaderboard.getRaceColumnByName(columnName).isMedalRace()); } @@ -181,7 +182,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest { Fleet defaultFleet = leaderboard.getFleet(null); RaceColumn r1 = leaderboard.addRace(testRace, "R1", /* medalRace */ false, defaultFleet); raceColumnsInLeaderboard.put(testRace, r1); - RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, defaultFleet); + RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, EmptyRaceLogStore.INSTANCE, defaultFleet); scoreCorrection.setMaxPointsReason(competitor, r2, MaxPointsReason.DND); // non-discardable disqualification // assert that max points were given before discarding... assertEquals(4.0, leaderboard.getEntry(competitor, r2, MillisecondsTimePoint.now()).getNetPoints(), 0.000000001); @@ -243,7 +244,7 @@ public class LeaderboardOfflineTest extends AbstractLeaderboardTest { // add a few race columns not yet connected to a tracked race for (int j=0; j - * - * A leaderboard can be renamed. If a leaderboard is managed in a structure that keys leaderboards by name, that - * structure's rules have to be obeyed to ensure the structure's consistency. For example, - * RacingEventService has a renameLeaderboard method that ensures the internal structure's - * consistency and invokes this method. - * - * @author Axel Uhl (D043530) - * - */ -public interface FlexibleLeaderboard extends Leaderboard, Renamable { - /** - * Moves the column with the name name up. - * @param name The name of the column to move. - */ - void moveRaceColumnUp(String name); - - /** - * Moves the column with the name name down. - * @param name The name of the column to move. - */ - void moveRaceColumnDown(String name); - - /** - * Adds a new {@link RaceColumn} that has no {@link TrackedRace} associated yet to this leaderboard. - * - * @param name - * the name for the new race column such that none of the columns in {@link #getRaceColumns()} - * has that name yet; otherwise, an message will be logged, no race column will be added and - * the existing column will be returned for robustness reasons - * @param medalRace - * tells if the column to add represents a medal race which has double score and cannot be discarded - * @param fleets - * the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default - * fleet will be assigned to the race column created. - * - * @return the race column in the leaderboard used to represent the tracked race - */ - RaceColumn addRaceColumn(String name, boolean medalRace, Fleet... fleets); - - /** - * Adds a tracked race to this leaderboard. If a {@link RaceColumn} with name columnName already exists - * in this leaderboard, race is {@link RaceColumn#setTrackedRace(Fleet, TrackedRace) set as its tracked - * race} and medalRace is ignored. Otherwise, a new {@link RaceColumn} column, with race - * as its tracked race, is created and added to this leaderboard. - * - * @param medalRace - * tells if the column to add represents a medal race which has double score and cannot be discarded; - * ignored if the column named columnName already exists - * - * @param fleets - * the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default - * fleet will be assigned to the race column created. - * - * @return the race column in the leaderboard used to represent the tracked race - */ - RaceColumn addRace(TrackedRace race, String columnName, boolean medalRace, Fleet fleet); - - void removeRaceColumn(String columnName); - - void updateIsMedalRace(String raceName, boolean isMedalRace); -} +package com.sap.sailing.domain.leaderboard; + +import com.sap.sailing.domain.base.Fleet; +import com.sap.sailing.domain.base.RaceColumn; +import com.sap.sailing.domain.base.Regatta; +import com.sap.sailing.domain.base.Series; +import com.sap.sailing.domain.common.Renamable; +import com.sap.sailing.domain.racelog.RaceLogStore; +import com.sap.sailing.domain.tracking.TrackedRace; + +/** + * A leaderboard that allows its clients to flexibly modify the race columns arranged in this leaderboard without the + * need to adhere to the constraints of a {@link Regatta} with its {@link Series} and {@link Fleet}s. + *

+ * + * A leaderboard can be renamed. If a leaderboard is managed in a structure that keys leaderboards by name, that + * structure's rules have to be obeyed to ensure the structure's consistency. For example, + * RacingEventService has a renameLeaderboard method that ensures the internal structure's + * consistency and invokes this method. + * + * @author Axel Uhl (D043530) + * + */ +public interface FlexibleLeaderboard extends Leaderboard, Renamable { + /** + * Moves the column with the name name up. + * @param name The name of the column to move. + */ + void moveRaceColumnUp(String name); + + /** + * Moves the column with the name name down. + * @param name The name of the column to move. + */ + void moveRaceColumnDown(String name); + + /** + * Adds a new {@link RaceColumn} that has no {@link TrackedRace} associated yet to this leaderboard. + * + * @param name + * the name for the new race column such that none of the columns in {@link #getRaceColumns()} + * has that name yet; otherwise, an message will be logged, no race column will be added and + * the existing column will be returned for robustness reasons + * @param medalRace + * tells if the column to add represents a medal race which has double score and cannot be discarded + * @param fleets + * the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default + * fleet will be assigned to the race column created. + * + * @return the race column in the leaderboard used to represent the tracked race + */ + RaceColumn addRaceColumn(String name, boolean medalRace, RaceLogStore raceLogStore, Fleet... fleets); + + /** + * Adds a tracked race to this leaderboard. If a {@link RaceColumn} with name columnName already exists + * in this leaderboard, race is {@link RaceColumn#setTrackedRace(Fleet, TrackedRace) set as its tracked + * race} and medalRace is ignored. Otherwise, a new {@link RaceColumn} column, with race + * as its tracked race, is created and added to this leaderboard. + * + * @param medalRace + * tells if the column to add represents a medal race which has double score and cannot be discarded; + * ignored if the column named columnName already exists + * + * @param fleets + * the fleets to add to the {@link RaceColumn} created. If no fleets are specified, a single default + * fleet will be assigned to the race column created. + * + * @return the race column in the leaderboard used to represent the tracked race + */ + RaceColumn addRace(TrackedRace race, String columnName, boolean medalRace, Fleet fleet); + + void removeRaceColumn(String columnName); + + void updateIsMedalRace(String raceName, boolean isMedalRace); +} diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/FlexibleLeaderboardImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/FlexibleLeaderboardImpl.java index ec088c0e24f..a40cfb21e74 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/FlexibleLeaderboardImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/leaderboard/impl/FlexibleLeaderboardImpl.java @@ -16,6 +16,7 @@ import com.sap.sailing.domain.leaderboard.FlexibleRaceColumn; import com.sap.sailing.domain.leaderboard.ScoringScheme; import com.sap.sailing.domain.leaderboard.SettableScoreCorrection; import com.sap.sailing.domain.leaderboard.ThresholdBasedResultDiscardingRule; +import com.sap.sailing.domain.racelog.RaceLogStore; import com.sap.sailing.domain.tracking.TrackedRace; /** @@ -64,7 +65,7 @@ public class FlexibleLeaderboardImpl extends AbstractLeaderboardImpl implements } @Override - public RaceColumn addRaceColumn(String name, boolean medalRace, Fleet... fleets) { + public RaceColumn addRaceColumn(String name, boolean medalRace, RaceLogStore raceLogStore, Fleet... fleets) { FlexibleRaceColumn column = getRaceColumnByName(name); if (column != null) { final String msg = "Trying to create race column with duplicate name "+name+" in leaderboard +"+getName(); diff --git a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboardGroups.java b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboardGroups.java index d20531bd293..b349852e74f 100755 --- a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboardGroups.java +++ b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboardGroups.java @@ -46,6 +46,7 @@ import com.sap.sailing.domain.persistence.DomainObjectFactory; import com.sap.sailing.domain.persistence.MongoObjectFactory; import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl; import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl; +import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore; import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors; import com.sap.sailing.mongodb.MongoDBService; import com.sap.sailing.server.RacingEventService; @@ -423,7 +424,7 @@ public class TestStoringAndRetrievingLeaderboardGroups extends AbstractMongoDBTe final FlexibleLeaderboard leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ScoreCorrectionImpl(), new ResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null); final Fleet fleet = leaderboard.getFleet(null); - final RaceColumn race = leaderboard.addRaceColumn(columnName, false, fleet); + final RaceColumn race = leaderboard.addRaceColumn(columnName, false, EmptyRaceLogStore.INSTANCE, fleet); leaderboards.add(leaderboard); final LeaderboardGroup group = new LeaderboardGroupImpl(groupName, groupDescription, false, leaderboards); diff --git a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboards.java b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboards.java index 6e594a9c7c4..b517788ec4f 100755 --- a/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboards.java +++ b/java/com.sap.sailing.mongodb.test/src/com/sap/sailing/mongodb/test/TestStoringAndRetrievingLeaderboards.java @@ -34,6 +34,7 @@ import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl; import com.sap.sailing.domain.leaderboard.impl.ScoreCorrectionImpl; import com.sap.sailing.domain.persistence.impl.DomainObjectFactoryImpl; import com.sap.sailing.domain.persistence.impl.MongoObjectFactoryImpl; +import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore; import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRank; import com.sap.sailing.domain.test.mock.MockedTrackedRaceWithFixedRankAndManyCompetitors; import com.sap.sailing.domain.tracking.TrackedRace; @@ -49,10 +50,10 @@ public class TestStoringAndRetrievingLeaderboards extends AbstractMongoDBTest { final int[] discardIndexResultsStartingWithHowManyRaces = new int[] { 5, 8 }; FlexibleLeaderboardImpl leaderboard = new FlexibleLeaderboardImpl(leaderboardName, new ScoreCorrectionImpl(), new ResultDiscardingRuleImpl(discardIndexResultsStartingWithHowManyRaces), new LowPoint(), null); - leaderboard.addRaceColumn("R1", /* medalRace */ false); - RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false); + leaderboard.addRaceColumn("R1", /* medalRace */ false, EmptyRaceLogStore.INSTANCE); + RaceColumn r2 = leaderboard.addRaceColumn("R2", /* medalRace */ false, EmptyRaceLogStore.INSTANCE); r2.setFactor(1.5); - RaceColumn r3 = leaderboard.addRaceColumn("R3", /* medalRace */ false); + RaceColumn r3 = leaderboard.addRaceColumn("R3", /* medalRace */ false, EmptyRaceLogStore.INSTANCE); r3.setFactor(2.5); new MongoObjectFactoryImpl(db).storeLeaderboard(leaderboard); Leaderboard loadedLeaderboard = new DomainObjectFactoryImpl(db).loadLeaderboard(leaderboardName, /* regattaRegistry */ null); diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/RacingEventService.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/RacingEventService.java index bd8f29317ff..b0a7268a0e6 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/RacingEventService.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/RacingEventService.java @@ -39,6 +39,7 @@ import com.sap.sailing.domain.leaderboard.LeaderboardGroup; import com.sap.sailing.domain.leaderboard.LeaderboardRegistry; import com.sap.sailing.domain.leaderboard.RegattaLeaderboard; import com.sap.sailing.domain.leaderboard.ScoringScheme; +import com.sap.sailing.domain.racelog.RaceLogStore; import com.sap.sailing.domain.swisstimingadapter.SwissTimingFactory; import com.sap.sailing.domain.tracking.RaceListener; import com.sap.sailing.domain.tracking.RaceTracker; @@ -252,7 +253,7 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch */ void renameLeaderboard(String oldName, String newName); - RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace); + RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace, RaceLogStore raceLogStore); void moveLeaderboardColumnUp(String leaderboardName, String columnName); diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/impl/RacingEventServiceImpl.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/impl/RacingEventServiceImpl.java index 2e6baae63a0..74625f97d86 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/impl/RacingEventServiceImpl.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/impl/RacingEventServiceImpl.java @@ -72,6 +72,7 @@ import com.sap.sailing.domain.persistence.DomainObjectFactory; import com.sap.sailing.domain.persistence.MongoFactory; import com.sap.sailing.domain.persistence.MongoObjectFactory; import com.sap.sailing.domain.racelog.RaceLogEvent; +import com.sap.sailing.domain.racelog.RaceLogStore; import com.sap.sailing.domain.swisstimingadapter.Race; import com.sap.sailing.domain.swisstimingadapter.SailMasterConnector; import com.sap.sailing.domain.swisstimingadapter.SailMasterMessage; @@ -355,12 +356,12 @@ public class RacingEventServiceImpl implements RacingEventService, RegattaListen } @Override - public RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace) { + public RaceColumn addColumnToLeaderboard(String columnName, String leaderboardName, boolean medalRace, RaceLogStore raceLogStore) { Leaderboard leaderboard = getLeaderboardByName(leaderboardName); if (leaderboard != null) { if (leaderboard instanceof FlexibleLeaderboard) { // uses the default fleet as the single fleet for the new column - RaceColumn result = ((FlexibleLeaderboard) leaderboard).addRaceColumn(columnName, medalRace, + RaceColumn result = ((FlexibleLeaderboard) leaderboard).addRaceColumn(columnName, medalRace, raceLogStore, leaderboard.getFleet(null)); updateStoredLeaderboard((FlexibleLeaderboard) leaderboard); return result; diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/AddColumnToLeaderboard.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/AddColumnToLeaderboard.java index 2bb369605d9..ae9cee84a30 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/AddColumnToLeaderboard.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/AddColumnToLeaderboard.java @@ -25,7 +25,7 @@ public class AddColumnToLeaderboard extends AbstractLeaderboardColumnOperation