mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-10 21:02:40 +00:00
Fixed bug3230 by adding the appropriate logstore listeners during import
This commit is contained in:
1 parent
63fc91191b
commit
7bbb0ffd92
8 files changed
+65
-16
No files matched your search
+13
-3
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+12
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
+4
@@ -23,4 +23,8 @@ public enum EmptyRaceLogStore implements RaceLogStore {
|
||||
@Override
|
||||
public void removeRaceLog(RaceLogIdentifier identifier) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImportedRaceLog(RaceLog raceLog, RaceLogIdentifier identifier) {
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
+4
@@ -18,4 +18,8 @@ public enum EmptyRegattaLogStore implements RegattaLogStore {
|
||||
@Override
|
||||
public void removeRegattaLog(RegattaLikeIdentifier regattaLikeId) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImportedRegattaLog(RegattaLog regattaLog, RegattaLikeIdentifier identifier) {
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -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<Competitor>(), 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<Competitor>(), 2, wind);
|
||||
RaceLogWindFixEvent windEvent = new RaceLogWindFixEventImpl(logTimePoint2, author, logTimePoint2,
|
||||
UUID.randomUUID(), new ArrayList<Competitor>(), 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<Competitor>(), 3, logTimePoint5);
|
||||
raceColumnOnTarget.getRaceLog(fleet1OnTarget).add(
|
||||
new RaceLogStartTimeEventImpl(logTimePoint5, author, logTimePoint5, postImportEventId,
|
||||
new ArrayList<Competitor>(), 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);
|
||||
|
||||
+12
-4
@@ -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 <code>MongoRaceLogStoreVisitor</code> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user