diff --git a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRaceLogStoreImpl.java b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRaceLogStoreImpl.java index 421c45a01e2..a1c957763d0 100644 --- a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRaceLogStoreImpl.java +++ b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRaceLogStoreImpl.java @@ -34,14 +34,18 @@ public class MongoRaceLogStoreImpl implements RaceLogStore { result = raceLogCache.get(identifier); } else { result = domainObjectFactory.loadRaceLog(identifier); - MongoRaceLogStoreVisitor listener = new MongoRaceLogStoreVisitor(identifier, mongoObjectFactory); - listeners.put(result, listener); - result.addListener(listener); + addListener(identifier, result); raceLogCache.put(identifier, result); } return result; } + private void addListener(RaceLogIdentifier identifier, final RaceLog raceLog) { + MongoRaceLogStoreVisitor listener = new MongoRaceLogStoreVisitor(identifier, mongoObjectFactory); + listeners.put(raceLog, listener); + raceLog.addListener(listener); + } + @Override public void removeRaceLog(RaceLogIdentifier identifier) { logger.info("Removing race log "+identifier+" from the database"); @@ -57,4 +61,10 @@ public class MongoRaceLogStoreImpl implements RaceLogStore { } } + @Override + public void addImportedRaceLog(RaceLog raceLog, RaceLogIdentifier identifier) { + addListener(identifier, raceLog); + raceLogCache.put(identifier, raceLog); + } + } diff --git a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRegattaLogStoreImpl.java b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRegattaLogStoreImpl.java index a53640824af..5018d0b0e1a 100644 --- a/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRegattaLogStoreImpl.java +++ b/java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoRegattaLogStoreImpl.java @@ -27,16 +27,26 @@ public class MongoRegattaLogStoreImpl implements RegattaLogStore { result = regattaLogCache.get(identifier); } else { result = domainObjectFactory.loadRegattaLog(identifier); - MongoRegattaLogStoreVisitor listener = new MongoRegattaLogStoreVisitor(identifier, mongoObjectFactory); - result.addListener(listener); + addListener(identifier, result); regattaLogCache.put(identifier, result); } return result; } + private void addListener(RegattaLikeIdentifier identifier, final RegattaLog regattaLog) { + MongoRegattaLogStoreVisitor listener = new MongoRegattaLogStoreVisitor(identifier, mongoObjectFactory); + regattaLog.addListener(listener); + } + @Override public void removeRegattaLog(RegattaLikeIdentifier identifier) { regattaLogCache.remove(identifier); mongoObjectFactory.removeRegattaLog(identifier); } + + @Override + public void addImportedRegattaLog(RegattaLog regattaLog, RegattaLikeIdentifier identifier) { + addListener(identifier, regattaLog); + regattaLogCache.put(identifier, regattaLog); + } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/RaceLogStore.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/RaceLogStore.java index c2a269e7a4c..4962caebae5 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/RaceLogStore.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/RaceLogStore.java @@ -14,5 +14,10 @@ public interface RaceLogStore { void removeRaceLog(RaceLogIdentifier identifier); void removeListenersAddedByStoreFrom(RaceLog raceLogAvailable); + + /** + * Adds the mongo listener to the raceLog and adds raceLog to cache. + */ + void addImportedRaceLog(RaceLog raceLog, RaceLogIdentifier identifier); } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/impl/EmptyRaceLogStore.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/impl/EmptyRaceLogStore.java index c67746c4e35..fa067c7832f 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/impl/EmptyRaceLogStore.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/racelog/impl/EmptyRaceLogStore.java @@ -23,4 +23,8 @@ public enum EmptyRaceLogStore implements RaceLogStore { @Override public void removeRaceLog(RaceLogIdentifier identifier) { } + + @Override + public void addImportedRaceLog(RaceLog raceLog, RaceLogIdentifier identifier) { + } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/RegattaLogStore.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/RegattaLogStore.java index 97626a8fbbb..600d572c2db 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/RegattaLogStore.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/RegattaLogStore.java @@ -12,4 +12,9 @@ public interface RegattaLogStore { * from the cache. */ void removeRegattaLog(RegattaLikeIdentifier regattaLikeId); + + /** + * Adds the mongo listener to the regatta log and adds regatta log to cache. + */ + void addImportedRegattaLog(RegattaLog regattaLog, RegattaLikeIdentifier identifier); } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/impl/EmptyRegattaLogStore.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/impl/EmptyRegattaLogStore.java index 33e3db0b9b1..4c4cd9c27b8 100644 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/impl/EmptyRegattaLogStore.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/regattalog/impl/EmptyRegattaLogStore.java @@ -18,4 +18,8 @@ public enum EmptyRegattaLogStore implements RegattaLogStore { @Override public void removeRegattaLog(RegattaLikeIdentifier regattaLikeId) { } + + @Override + public void addImportedRegattaLog(RegattaLog regattaLog, RegattaLikeIdentifier identifier) { + } } diff --git a/java/com.sap.sailing.server.test/src/com/sap/sailing/server/test/MasterDataImportTest.java b/java/com.sap.sailing.server.test/src/com/sap/sailing/server/test/MasterDataImportTest.java index 19e1201f0e9..7aabea7dc06 100755 --- a/java/com.sap.sailing.server.test/src/com/sap/sailing/server/test/MasterDataImportTest.java +++ b/java/com.sap.sailing.server.test/src/com/sap/sailing/server/test/MasterDataImportTest.java @@ -39,6 +39,7 @@ import com.sap.sailing.domain.abstractlog.AbstractLogEventAuthor; import com.sap.sailing.domain.abstractlog.impl.LogEventAuthorImpl; import com.sap.sailing.domain.abstractlog.race.CompetitorResults; import com.sap.sailing.domain.abstractlog.race.RaceLog; +import com.sap.sailing.domain.abstractlog.race.RaceLogEvent; import com.sap.sailing.domain.abstractlog.race.RaceLogEventFactory; import com.sap.sailing.domain.abstractlog.race.RaceLogFinishPositioningConfirmedEvent; import com.sap.sailing.domain.abstractlog.race.RaceLogStartTimeEvent; @@ -46,6 +47,7 @@ import com.sap.sailing.domain.abstractlog.race.RaceLogWindFixEvent; import com.sap.sailing.domain.abstractlog.race.impl.CompetitorResultsImpl; import com.sap.sailing.domain.abstractlog.race.impl.RaceLogEventFactoryImpl; import com.sap.sailing.domain.abstractlog.race.impl.RaceLogStartTimeEventImpl; +import com.sap.sailing.domain.abstractlog.race.impl.RaceLogWindFixEventImpl; import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogDeviceCompetitorMappingEvent; import com.sap.sailing.domain.abstractlog.regatta.events.RegattaLogRegisterCompetitorEvent; import com.sap.sailing.domain.abstractlog.regatta.events.impl.RegattaLogDeviceCompetitorMappingEventImpl; @@ -252,15 +254,14 @@ public class MasterDataImportTest { raceColumn.setTrackedRace(testFleet1, trackedRace); // Set log event - RaceLogEventFactory factory = new RaceLogEventFactoryImpl(); TimePoint logTimePoint = new MillisecondsTimePoint(1372489200000L); TimePoint logTimePoint2 = new MillisecondsTimePoint(1372489201000L); - RaceLogStartTimeEvent logEvent = factory.createStartTimeEvent(logTimePoint, author, 1, logTimePoint); + RaceLogStartTimeEvent logEvent = new RaceLogStartTimeEventImpl(logTimePoint, author, logTimePoint, 1, new ArrayList(), 0, logTimePoint); raceColumn.getRaceLog(testFleet1).add(logEvent); Position p = new DegreePosition(3, 3); Wind wind = new WindImpl(p, logTimePoint2, new KnotSpeedWithBearingImpl(5, new DegreeBearingImpl(12))); - RaceLogWindFixEvent windEvent = factory.createWindFixEvent(logTimePoint2, author, UUID.randomUUID(), - new ArrayList(), 2, wind); + RaceLogWindFixEvent windEvent = new RaceLogWindFixEventImpl(logTimePoint2, author, logTimePoint2, + UUID.randomUUID(), new ArrayList(), 2, wind); raceColumn.getRaceLog(testFleet1).add(windEvent); storedLogUUIDs.add(logEvent.getId()); storedLogUUIDs.add(windEvent.getId()); @@ -407,9 +408,10 @@ public class MasterDataImportTest { // Add new event to check persistence of post-import events (see bug 3230) TimePoint logTimePoint5 = new MillisecondsTimePoint(1372489310000L); UUID postImportEventId = UUID.randomUUID(); + RaceLogStartTimeEventImpl postImportLogEvent = new RaceLogStartTimeEventImpl(logTimePoint5, author, logTimePoint5, postImportEventId, + new ArrayList(), 3, logTimePoint5); raceColumnOnTarget.getRaceLog(fleet1OnTarget).add( - new RaceLogStartTimeEventImpl(logTimePoint5, author, logTimePoint5, postImportEventId, - new ArrayList(), 3, logTimePoint5)); + postImportLogEvent); // Check for regatta log event RegattaLogRegisterCompetitorEvent registerEventOnTarget = (RegattaLogRegisterCompetitorEvent) @@ -428,7 +430,8 @@ public class MasterDataImportTest { RaceLog raceLog2 = raceColumn2.getRaceLog(raceColumn2.getFleetByName(fleet1OnTarget.getName())); Assert.assertEquals(logEvent.getId(), raceLog2.getFirstRawFixAtOrAfter(logTimePoint).getId()); - Assert.assertEquals(postImportEventId, raceLog2.getFirstRawFixAtOrAfter(logTimePoint5).getId()); + RaceLogEvent postImportLogEventFromDB = raceLog2.getFirstRawFixAtOrAfter(logTimePoint5); + Assert.assertEquals(postImportEventId, postImportLogEventFromDB.getId()); // Check for persisting of regatta log events Regatta regattaOnTarget2 = dest2.getRegattaByName(TEST_LEADERBOARD_NAME); diff --git a/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/ImportMasterDataOperation.java b/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/ImportMasterDataOperation.java index 72027280753..86872dc0615 100755 --- a/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/ImportMasterDataOperation.java +++ b/java/com.sap.sailing.server/src/com/sap/sailing/server/operationaltransformation/ImportMasterDataOperation.java @@ -42,15 +42,18 @@ import com.sap.sailing.domain.leaderboard.LeaderboardGroup; import com.sap.sailing.domain.leaderboard.RegattaLeaderboard; import com.sap.sailing.domain.masterdataimport.TopLevelMasterData; import com.sap.sailing.domain.masterdataimport.WindTrackMasterData; +import com.sap.sailing.domain.persistence.DomainObjectFactory; import com.sap.sailing.domain.persistence.MongoObjectFactory; import com.sap.sailing.domain.persistence.MongoRaceLogStoreFactory; import com.sap.sailing.domain.persistence.MongoRegattaLogStoreFactory; import com.sap.sailing.domain.racelog.RaceLogIdentifier; +import com.sap.sailing.domain.racelog.RaceLogStore; import com.sap.sailing.domain.racelog.tracking.GPSFixStore; import com.sap.sailing.domain.racelogtracking.DeviceIdentifier; import com.sap.sailing.domain.regattalike.HasRegattaLike; import com.sap.sailing.domain.regattalike.IsRegattaLike; import com.sap.sailing.domain.regattalike.RegattaLikeIdentifier; +import com.sap.sailing.domain.regattalog.RegattaLogStore; import com.sap.sailing.domain.tracking.DynamicTrackedRace; import com.sap.sailing.domain.tracking.TrackedRace; import com.sap.sailing.domain.tracking.TrackedRegatta; @@ -246,8 +249,8 @@ public class ImportMasterDataOperation extends } if (leaderboard != null) { toState.addLeaderboard(leaderboard); - storeRaceLogEvents(leaderboard, toState.getMongoObjectFactory()); - storeRegattaLogEvents(leaderboard, toState.getMongoObjectFactory()); + storeRaceLogEvents(leaderboard, toState.getMongoObjectFactory(), toState.getDomainObjectFactory()); + storeRegattaLogEvents(leaderboard, toState.getMongoObjectFactory(), toState.getDomainObjectFactory()); creationCount.addOneLeaderboard(leaderboard.getName()); relinkTrackedRacesIfPossible(toState, leaderboard); toState.updateStoredLeaderboard(leaderboard); @@ -276,7 +279,8 @@ public class ImportMasterDataOperation extends * in serialized form on the {@link RaceColumn} objects, but the database doesn't yet know about them. This method uses * a MongoRaceLogStoreVisitor to store all race log events to the database. */ - private void storeRaceLogEvents(Leaderboard leaderboard, MongoObjectFactory mongoObjectFactory) { + private void storeRaceLogEvents(Leaderboard leaderboard, MongoObjectFactory mongoObjectFactory, DomainObjectFactory domainObjectFactory) { + RaceLogStore mongoRaceLogStore = MongoRaceLogStoreFactory.INSTANCE.getMongoRaceLogStore(mongoObjectFactory, domainObjectFactory); for (RaceColumn raceColumn : leaderboard.getRaceColumns()) { for (Fleet fleet : raceColumn.getFleets()) { RaceLog log = raceColumn.getRaceLog(fleet); @@ -292,6 +296,8 @@ public class ImportMasterDataOperation extends } finally { log.unlockAfterRead(); } + // Make sure listener is added to race log + mongoRaceLogStore.addImportedRaceLog(log, identifier); } } } @@ -303,7 +309,8 @@ public class ImportMasterDataOperation extends * potentially {@link HasRegattaLike has} an attached RegattaLog, which then must be stored in the database. * @see #storeRaceLogEvents(Leaderboard, MongoObjectFactory) */ - private void storeRegattaLogEvents(Leaderboard leaderboard, MongoObjectFactory mongoObjectFactory) { + private void storeRegattaLogEvents(Leaderboard leaderboard, MongoObjectFactory mongoObjectFactory, DomainObjectFactory domainObjectFactory) { + RegattaLogStore regattaLogStore = MongoRegattaLogStoreFactory.INSTANCE.getMongoRegattaLogStore(mongoObjectFactory, domainObjectFactory); if (leaderboard instanceof HasRegattaLike) { IsRegattaLike regattaLike = ((HasRegattaLike) leaderboard).getRegattaLike(); RegattaLog log = regattaLike.getRegattaLog(); @@ -318,6 +325,7 @@ public class ImportMasterDataOperation extends } finally { log.unlockAfterRead(); } + regattaLogStore.addImportedRegattaLog(log, identifier); } }