Merge remote-tracking branch 'origin/master' into gpsfixstore-independent-of-race

Conflicts:
	java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/impl/AbstractTimePoint.java
	java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/MongoObjectFactory.java
	java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/DomainObjectFactoryImpl.java
	java/com.sap.sailing.domain.persistence/src/com/sap/sailing/domain/persistence/impl/MongoObjectFactoryImpl.java
	java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/racelog/RaceLog.java
	java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/racelog/impl/NoAddingRaceLogWrapper.java
	java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/racelog/impl/RaceLogImpl.java
	java/com.sap.sailing.domain.shared.android/src/com/sap/sailing/domain/tracking/impl/TrackImpl.java
	java/com.sap.sailing.domain.swisstimingadapter.test/src/com/sap/sailing/domain/swisstimingadapter/test/EndToEndListeningStoreAndFowardTest.java
	java/com.sap.sailing.domain.swisstimingadapter/src/com/sap/sailing/domain/swisstimingadapter/SwissTimingFactory.java
	java/com.sap.sailing.domain.swisstimingadapter/src/com/sap/sailing/domain/swisstimingadapter/impl/SwissTimingFactoryImpl.java
	java/com.sap.sailing.domain.swisstimingadapter/src/com/sap/sailing/domain/swisstimingadapter/impl/SwissTimingRaceTrackerImpl.java
	java/com.sap.sailing.domain.swisstimingadapter/src/com/sap/sailing/domain/swisstimingadapter/impl/SwissTimingTrackingConnectivityParameters.java
	java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/AbstractMockedRaceMarkPassingTest.java
	java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisMarkPassingTest.java
	java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRMarkPassingTest.java
	java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/mock/MockedTrackedRace.java
	java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/DynamicTrackedRaceImpl.java
	java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedRaceImpl.java
	java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/MockedTrackedRace.java
	java/com.sap.sailing.gwt.ui.test/src/com/sap/sailing/gwt/ui/test/SailingServiceImplMock.java
	java/com.sap.sailing.gwt.ui/META-INF/MANIFEST.MF
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/AdminConsoleEntryPoint.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/LeaderboardConfigPanel.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/adminconsole/RaceCourseManagementPanel.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingService.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/SailingServiceAsync.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.java
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages.properties
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/client/StringMessages_de.properties
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SailingServiceImpl.java
	java/com.sap.sailing.server.replication.test/src/com/sap/sailing/server/replication/test/AbstractServerReplicationTest.java
	java/com.sap.sailing.server.test/src/com/sap/sailing/server/test/MasterDataImportTest.java
	java/com.sap.sailing.server/META-INF/MANIFEST.MF
	java/com.sap.sailing.server/SailingServer (No Proxy).launch
	java/com.sap.sailing.server/SailingServer (No Proxy, Jetty on 8889).launch
	java/com.sap.sailing.server/SailingServer (No Proxy, Jetty on 8889, Monitoring).launch
	java/com.sap.sailing.server/SailingServer (No Proxy, No Tests).launch
	java/com.sap.sailing.server/SailingServer (No Proxy, Remote Debug SAP VM).launch
	java/com.sap.sailing.server/SailingServer (Proxy).launch
	java/com.sap.sailing.server/SailingServer (Proxy, Jetty on 8889).launch
	java/com.sap.sailing.server/SailingServer (Proxy, Remote Debug SAP VM).launch
	java/com.sap.sailing.server/SailingServer (Proxy, SwissTiming Live Simulation).launch
	java/com.sap.sailing.server/src/com/sap/sailing/server/RacingEventService.java
	java/com.sap.sailing.server/src/com/sap/sailing/server/impl/Activator.java
	java/com.sap.sailing.server/src/com/sap/sailing/server/impl/RacingEventServiceImpl.java
This commit is contained in:
Fredrik Teschke committed 2014-03-28 18:34:58 +01:00
commit 821f1307bf
1198 files changed
+70980 -30339

No files matched your search

@@ -1,110 +1,114 @@
package com.sap.sailing.domain.persistence;
import java.io.Serializable;
import com.mongodb.DB;
import com.mongodb.DBObject;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.base.Regatta;
import com.sap.sailing.domain.base.Series;
import com.sap.sailing.domain.base.configuration.DeviceConfiguration;
import com.sap.sailing.domain.base.configuration.DeviceConfigurationMatcher;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.TrackedRegatta;
/**
* Offers methods to construct {@link DBObject MongoDB objects} from domain objects.
*
* @author Axel Uhl (d043530)
*
*/
public interface MongoObjectFactory {
/**
* Registers for changes of the wind coming from <code>windSource</code> on the <code>trackedRace</code>. Each
* update received will be appended to the MongoDB and can later be retrieved. The key used to identify the race is
* the {@link RaceDefinition#getName() race name} and the {@link Regatta#getName() regatta name}.
*/
void addWindTrackDumper(TrackedRegatta trackedRegatta, TrackedRace trackedRace, WindSource windSource);
/**
* Stores the configuration data of <code>leaderboard</code> in the Mongo DB associated with this
* factory.
*/
void storeLeaderboard(Leaderboard leaderboard);
/**
* Removes the leaderboard named <code>name</code> from the database.
*/
void removeLeaderboard(String leaderboardName);
void renameLeaderboard(String oldName, String newName);
/**
* Stores the group, if it doesn't exist or updates it. Leaderboards in the group, which aren't stored in the
* database, will be stored. If the leaderboard group has an {@link LeaderboardGroup#getOverallLeaderboard() overall
* leaderboard}, it will be stored / updated as well.
*/
void storeLeaderboardGroup(LeaderboardGroup leaderboardGroup);
/**
* Removes the group with the name <code>groupName</code> from the database.
*/
void removeLeaderboardGroup(String groupName);
/**
* Renames the group with the name <code>oldName</code>.
*/
void renameLeaderboardGroup(String oldName, String newName);
/**
* Stores the event with its name, venue and the venue's course areas. The regattas obtained by
* {@link Event#getRegattas()} are <em>not</em> stored by this call. They need to be stored separately
* by calls to {@link #storeRegatta} where a reference to their owning event is stored.
*/
void storeEvent(Event event);
/**
* Renames the event with the name <code>oldName</code>.
*/
void renameEvent(Serializable id, String newName);
/**
* Removes the event named <code>eventName</code> from the database.
*/
void removeEvent(Serializable id);
/**
* Stores the regatta together with its name, {@link Series} definitions and an optional link to the
* {@link Event} to which the regatta belongs.
*/
void storeRegatta(Regatta regatta);
void removeRegatta(Regatta regatta);
void storeRegattaForRaceID(String id, Regatta regatta);
void removeRegattaForRaceID(String raceIDAsString, Regatta regatta);
/**
* Stores a competitor, including the team and boat. This should not be done for competitors for which
* the master data is supplied by other systems, such as TracTrac, but rather for smartphone tracking,
* where this data is otherwise not recoverable.
* @param competitor the competitor to store/update in the database
*/
void storeCompetitor(Competitor competitor);
void removeAllCompetitors();
void removeCompetitor(Competitor competitor);
DB getDatabase();
void storeDeviceConfiguration(DeviceConfigurationMatcher matcher, DeviceConfiguration configuration);
void removeDeviceConfiguration(DeviceConfigurationMatcher matcher);
}
package com.sap.sailing.domain.persistence;
import java.io.Serializable;
import com.mongodb.DB;
import com.mongodb.DBObject;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.base.Regatta;
import com.sap.sailing.domain.base.Series;
import com.sap.sailing.domain.base.configuration.DeviceConfiguration;
import com.sap.sailing.domain.base.configuration.DeviceConfigurationMatcher;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.TrackedRegatta;
/**
* Offers methods to construct {@link DBObject MongoDB objects} from domain objects.
*
* @author Axel Uhl (d043530)
*
*/
public interface MongoObjectFactory {
/**
* Registers for changes of the wind coming from <code>windSource</code> on the <code>trackedRace</code>. Each
* update received will be appended to the MongoDB and can later be retrieved. The key used to identify the race is
* the {@link RaceDefinition#getName() race name} and the {@link Regatta#getName() regatta name}.
*/
void addWindTrackDumper(TrackedRegatta trackedRegatta, TrackedRace trackedRace, WindSource windSource);
/**
* Stores the configuration data of <code>leaderboard</code> in the Mongo DB associated with this
* factory.
*/
void storeLeaderboard(Leaderboard leaderboard);
/**
* Removes the leaderboard named <code>name</code> from the database.
*/
void removeLeaderboard(String leaderboardName);
void renameLeaderboard(String oldName, String newName);
/**
* Stores the group, if it doesn't exist or updates it. Leaderboards in the group, which aren't stored in the
* database, will be stored. If the leaderboard group has an {@link LeaderboardGroup#getOverallLeaderboard() overall
* leaderboard}, it will be stored / updated as well.
*/
void storeLeaderboardGroup(LeaderboardGroup leaderboardGroup);
/**
* Removes the group with the name <code>groupName</code> from the database.
*/
void removeLeaderboardGroup(String groupName);
/**
* Renames the group with the name <code>oldName</code>.
*/
void renameLeaderboardGroup(String oldName, String newName);
/**
* Stores the event with its name, venue and the venue's course areas. The regattas obtained by
* {@link Event#getRegattas()} are <em>not</em> stored by this call. They need to be stored separately
* by calls to {@link #storeRegatta} where a reference to their owning event is stored.
*/
void storeEvent(Event event);
/**
* Renames the event with the name <code>oldName</code>.
*/
void renameEvent(Serializable id, String newName);
/**
* Removes the event named <code>eventName</code> from the database.
*/
void removeEvent(Serializable id);
/**
* Stores the regatta together with its name, {@link Series} definitions and an optional link to the
* {@link Event} to which the regatta belongs.
* @param oldSeriesNameNewName
*/
void storeRegatta(Regatta regatta);
void removeRegatta(Regatta regatta);
void storeRegattaForRaceID(String id, Regatta regatta);
void removeRegattaForRaceID(String raceIDAsString, Regatta regatta);
/**
* Stores a competitor, including the team and boat. This should not be done for competitors for which
* the master data is supplied by other systems, such as TracTrac, but rather for smartphone tracking,
* where this data is otherwise not recoverable.
* @param competitor the competitor to store/update in the database
*/
void storeCompetitor(Competitor competitor);
void removeAllCompetitors();
void removeCompetitor(Competitor competitor);
DB getDatabase();
void storeDeviceConfiguration(DeviceConfigurationMatcher matcher, DeviceConfiguration configuration);
void removeDeviceConfiguration(DeviceConfigurationMatcher matcher);
void removeRaceLog(RaceLogIdentifier identifier);
}
@@ -2,6 +2,8 @@ package com.sap.sailing.domain.persistence;
import com.sap.sailing.domain.persistence.impl.MongoRaceLogStoreFactoryImpl;
import com.sap.sailing.domain.racelog.RaceLogEventVisitor;
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
import com.sap.sailing.domain.racelog.RaceLogStore;
public interface MongoRaceLogStoreFactory {
@@ -12,4 +14,6 @@ public interface MongoRaceLogStoreFactory {
* and mongo.dbName[=&lt;contents of constant {@link #DEFAULT_DB_NAME}&gt;] specified in the bundle context
*/
RaceLogStore getMongoRaceLogStore(MongoObjectFactory mongoObjectFactory, DomainObjectFactory domainObjectFactory);
RaceLogEventVisitor getMongoRaceLogStoreVisitor(RaceLogIdentifier identifier, MongoObjectFactory mongoObjectFactory);
}
@@ -25,6 +25,7 @@ import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.util.JSON;
import com.sap.sailing.domain.base.BoatClass;
import com.sap.sailing.domain.base.Competitor;
@@ -205,9 +206,12 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
}
private TimePoint loadTimePoint(DBObject object, FieldNames field) {
Object loaded = object.get(field.name());
if (loaded == null) return null;
return new MillisecondsTimePoint(((Number) loaded).longValue());
TimePoint result = null;
Number timePointAsNumber = (Number) object.get(field.name());
if (timePointAsNumber != null) {
result = new MillisecondsTimePoint(timePointAsNumber.longValue());
}
return result;
}
/**
@@ -237,7 +241,30 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
windTracks.ensureIndex(FieldNames.RACE_ID.name()); // for new programmatic access
windTracks.ensureIndex(FieldNames.REGATTA_NAME.name()); // for export or human look-up
// for legacy access to not yet migrated fixes
windTracks.ensureIndex(new BasicDBObjectBuilder().add(FieldNames.EVENT_NAME.name(), 1).add(FieldNames.RACE_NAME.name(), 1).get());
windTracks.ensureIndex(new BasicDBObjectBuilder().add(FieldNames.EVENT_NAME.name(), 1)
.add(FieldNames.RACE_NAME.name(), 1).get());
// Unique index
try {
windTracks.ensureIndex(
new BasicDBObjectBuilder().add(FieldNames.RACE_ID.name(), 1)
.add(FieldNames.WIND_SOURCE_NAME.name(), 1).add(FieldNames.WIND_SOURCE_ID.name(), 1)
.add(FieldNames.WIND.name() + "." + FieldNames.TIME_AS_MILLIS.name(), 1).get(),
new BasicDBObjectBuilder().add("unique", true).add("dropDups", true).get());
} catch (MongoException exception) {
if (exception.getCode() == 10092) {
logger.warning(String.format(
"Setting the unique index on the %s collection failed because you have too many duplicates. "
+ "This leads to the mongo error code %s and the following message: %s \nTo fix this follow "
+ "the steps provided on the wiki page: http://wiki.sapsailing.com/wiki/cook-book#Remove-"
+ "duplicates-from-WIND_TRACK-collection", CollectionNames.WIND_TRACKS.name(),
exception.getCode(), exception.getMessage()));
} else {
logger.severe(String.format(
"Setting the unique index on the %s collection failed with error code %s and message: %s",
CollectionNames.WIND_TRACKS.name(), exception.getCode(), exception.getMessage()));
}
}
}
@Override
@@ -870,10 +897,11 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
private Event loadEvent(DBObject eventDBObject) {
String name = (String) eventDBObject.get(FieldNames.EVENT_NAME.name());
UUID id = (UUID) eventDBObject.get(FieldNames.EVENT_ID.name());
String publicationUrl = (String) eventDBObject.get(FieldNames.EVENT_PUBLICATION_URL.name());
TimePoint startDate = loadTimePoint(eventDBObject, FieldNames.EVENT_START_DATE);
TimePoint endDate = loadTimePoint(eventDBObject, FieldNames.EVENT_END_DATE);
boolean isPublic = eventDBObject.get(FieldNames.EVENT_IS_PUBLIC.name()) != null ? (Boolean) eventDBObject.get(FieldNames.EVENT_IS_PUBLIC.name()) : false;
Venue venue = loadVenue((DBObject) eventDBObject.get(FieldNames.VENUE.name()));
Event result = new EventImpl(name, venue, publicationUrl, isPublic, id);
Event result = new EventImpl(name, startDate, endDate, venue, isPublic, id);
return result;
}
@@ -11,8 +11,9 @@ public enum FieldNames {
*/
EVENT_NAME,
EVENT_ID,
EVENT_PUBLICATION_URL,
EVENT_IS_PUBLIC,
EVENT_START_DATE,
EVENT_END_DATE,
REGATTA_NAME,
REGATTA_ID,
@@ -140,11 +140,15 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
}
public void storeTimePoint(TimePoint timePoint, DBObject result, FieldNames field) {
result.put(field.name(), timePoint.asMillis());
if (timePoint != null) {
result.put(field.name(), timePoint.asMillis());
}
}
public void storeTimed(Timed timed, DBObject result) {
storeTimePoint(timed.getTimePoint(), result, FieldNames.TIME_AS_MILLIS);
if (timed.getTimePoint() != null) {
storeTimePoint(timed.getTimePoint(), result, FieldNames.TIME_AS_MILLIS);
}
}
public void storeSpeedWithBearing(SpeedWithBearing speedWithBearing, DBObject result) {
@@ -464,7 +468,8 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
DBObject eventDBObject = new BasicDBObject();
eventDBObject.put(FieldNames.EVENT_NAME.name(), event.getName());
eventDBObject.put(FieldNames.EVENT_ID.name(), event.getId());
eventDBObject.put(FieldNames.EVENT_PUBLICATION_URL.name(), event.getPublicationUrl());
storeTimePoint(event.getStartDate(), eventDBObject, FieldNames.EVENT_START_DATE);
storeTimePoint(event.getEndDate(), eventDBObject, FieldNames.EVENT_END_DATE);
eventDBObject.put(FieldNames.EVENT_IS_PUBLIC.name(), event.isPublic());
DBObject venueDBObject = getVenueAsDBObject(event.getVenue());
eventDBObject.put(FieldNames.VENUE.name(), venueDBObject);
@@ -538,7 +543,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
DBObject query = new BasicDBObject(FieldNames.REGATTA_NAME.name(), regatta.getName());
regattasCollection.remove(query);
}
private BasicDBList storeSeries(Iterable<? extends Series> series) {
BasicDBList dbSeries = new BasicDBList();
for (Series s : series) {
@@ -617,159 +622,151 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogFlagEvent flagEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogFlagEvent(flagEvent));
return result;
}
private void storeRaceLogIdentifier(RaceLogIdentifier raceLogIdentifier, DBObject result) {
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogStartTimeEvent startTimeEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogStartTimeEvent(startTimeEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogPassChangeEvent passChangeEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogPassChangeEvent(passChangeEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogRaceStatusEvent raceStatusEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogRaceStatusEvent(raceStatusEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogCourseAreaChangedEvent courseAreaChangedEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogCourseAreaChangedEvent(courseAreaChangedEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogCourseDesignChangedEvent courseDesignChangedEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogCourseDesignChangedEvent(courseDesignChangedEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogFinishPositioningListChangedEvent finishPositioningListChangedEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogFinishPositioningListChangedEvent(finishPositioningListChangedEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogFinishPositioningConfirmedEvent finishPositioningConfirmedEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogFinishPositioningConfirmedEvent(finishPositioningConfirmedEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogPathfinderEvent pathfinderEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogPathfinderEvent(pathfinderEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogGateLineOpeningTimeEvent gateLineOpeningTimeEvent) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogGateLineOpeningTimeEvent(gateLineOpeningTimeEvent));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogStartProcedureChangedEvent event) {
DBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogStartProcedureChangedEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogProtestStartTimeEvent event) {
DBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogProtestStartTimeEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RaceLogWindFixEvent event) {
DBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogWindFix(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, DeviceCompetitorMappingEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogDeviceCompetitorMappingEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, DeviceMarkMappingEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogDeviceMarkMappingEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, DenoteForTrackingEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogDenoteForTrackingEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, StartTrackingEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogStartTrackingEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RevokeEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogRevokeEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, RegisterCompetitorEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogRegisterCompetitorEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, DefineMarkEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogDefineMarkEvent(event));
return result;
}
public DBObject storeRaceLogEntry(RaceLogIdentifier raceLogIdentifier, CloseOpenEndedDeviceMappingEvent event) {
BasicDBObject result = new BasicDBObject();
result.put(FieldNames.RACE_LOG_IDENTIFIER.name(), TripleSerializer.serialize(raceLogIdentifier.getIdentifier()));
storeRaceLogIdentifier(raceLogIdentifier, result);
result.put(FieldNames.RACE_LOG_EVENT.name(), storeRaceLogCloseOpenEndedDeviceMappingEvent(event));
return result;
}
@@ -777,7 +774,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogWindFix(RaceLogWindFixEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogWindFixEvent.class.getSimpleName());
result.put(FieldNames.WIND.name(), storeWind(event.getWindFix()));
return result;
@@ -786,7 +782,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogProtestStartTimeEvent(RaceLogProtestStartTimeEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogProtestStartTimeEvent.class.getSimpleName());
storeTimePoint(event.getProtestStartTime(), result, FieldNames.RACE_LOG_PROTEST_START_TIME);
return result;
@@ -795,7 +790,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogStartProcedureChangedEvent(RaceLogStartProcedureChangedEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogStartProcedureChangedEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_START_PROCEDURE_TYPE.name(), event.getStartProcedureType().name());
return result;
@@ -804,9 +798,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogPathfinderEvent(RaceLogPathfinderEvent pathfinderEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(pathfinderEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogPathfinderEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_PATHFINDER_ID.name(), pathfinderEvent.getPathfinderId());
return result;
}
@@ -831,7 +823,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogDeviceCompetitorMappingEvent(DeviceCompetitorMappingEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DeviceCompetitorMappingEvent.class.getSimpleName());
storeRaceLogDeviceMappingEvent(event, result);
result.put(FieldNames.COMPETITOR_ID.name(), event.getMappedTo().getId());
@@ -841,7 +832,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogDeviceMarkMappingEvent(DeviceMarkMappingEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DeviceMarkMappingEvent.class.getSimpleName());
storeRaceLogDeviceMappingEvent(event, result);
result.put(FieldNames.MARK_ID.name(), event.getMappedTo().getId());
@@ -851,7 +841,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogDenoteForTrackingEvent(DenoteForTrackingEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DenoteForTrackingEvent.class.getSimpleName());
result.put(FieldNames.RACE_NAME.name(), event.getRaceName());
result.put(FieldNames.BOAT_CLASS_NAME.name(), event.getBoatClass().getName());
@@ -861,7 +850,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogStartTrackingEvent(StartTrackingEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), StartTrackingEvent.class.getSimpleName());
return result;
}
@@ -869,7 +857,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogRevokeEvent(RevokeEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RevokeEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_REVOKED_EVENT_ID.name(), event.getRevokedEventId());
return result;
@@ -878,7 +865,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogRegisterCompetitorEvent(RegisterCompetitorEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RegisterCompetitorEvent.class.getSimpleName());
return result;
}
@@ -886,7 +872,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogDefineMarkEvent(DefineMarkEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), DefineMarkEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_MARK.name(), storeMark(event.getMark()));
return result;
@@ -895,7 +880,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogCloseOpenEndedDeviceMappingEvent(CloseOpenEndedDeviceMappingEvent event) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(event, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), CloseOpenEndedDeviceMappingEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_DEVICE_MAPPING_EVENT_ID.name(), event.getDeviceMappingEventId());
storeTimePoint(event.getClosingTimePoint(), result, FieldNames.RACE_LOG_CLOSING_TIMEPOINT);
@@ -905,9 +889,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
public DBObject storeRaceLogFlagEvent(RaceLogFlagEvent flagEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(flagEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogFlagEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_EVENT_FLAG_UPPER.name(), flagEvent.getUpperFlag().name());
result.put(FieldNames.RACE_LOG_EVENT_FLAG_LOWER.name(), flagEvent.getLowerFlag().name());
result.put(FieldNames.RACE_LOG_EVENT_FLAG_DISPLAYED.name(), String.valueOf(flagEvent.isDisplayed()));
@@ -917,9 +899,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private DBObject storeRaceLogStartTimeEvent(RaceLogStartTimeEvent startTimeEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(startTimeEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogStartTimeEvent.class.getSimpleName());
storeTimePoint(startTimeEvent.getStartTime(), result, FieldNames.RACE_LOG_EVENT_START_TIME);
result.put(FieldNames.RACE_LOG_EVENT_NEXT_STATUS.name(), startTimeEvent.getNextStatus().name());
return result;
@@ -947,7 +927,6 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private DBObject storeRaceLogPassChangeEvent(RaceLogPassChangeEvent passChangeEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(passChangeEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogPassChangeEvent.class.getSimpleName());
return result;
}
@@ -955,9 +934,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private DBObject storeRaceLogRaceStatusEvent(RaceLogRaceStatusEvent raceStatusEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(raceStatusEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogRaceStatusEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_EVENT_NEXT_STATUS.name(), raceStatusEvent.getNextStatus().name());
return result;
}
@@ -965,9 +942,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private DBObject storeRaceLogCourseAreaChangedEvent(RaceLogCourseAreaChangedEvent courseAreaChangedEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(courseAreaChangedEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogCourseAreaChangedEvent.class.getSimpleName());
result.put(FieldNames.COURSE_AREA_ID.name(), courseAreaChangedEvent.getCourseAreaId());
return result;
}
@@ -975,9 +950,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private DBObject storeRaceLogCourseDesignChangedEvent(RaceLogCourseDesignChangedEvent courseDesignChangedEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(courseDesignChangedEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogCourseDesignChangedEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_COURSE_DESIGN_NAME.name(), courseDesignChangedEvent.getCourseDesign().getName());
result.put(FieldNames.RACE_LOG_COURSE_DESIGN.name(), storeCourseBase(courseDesignChangedEvent.getCourseDesign()));
return result;
@@ -986,9 +959,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogFinishPositioningListChangedEvent(RaceLogFinishPositioningListChangedEvent finishPositioningListChangedEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(finishPositioningListChangedEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogFinishPositioningListChangedEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_POSITIONED_COMPETITORS.name(), storePositionedCompetitors(finishPositioningListChangedEvent.getPositionedCompetitorsIDsNamesMaxPointsReasons()));
return result;
@@ -997,9 +968,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogFinishPositioningConfirmedEvent(RaceLogFinishPositioningConfirmedEvent finishPositioningConfirmedEvent) {
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(finishPositioningConfirmedEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogFinishPositioningConfirmedEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_POSITIONED_COMPETITORS.name(), storePositionedCompetitors(finishPositioningConfirmedEvent.getPositionedCompetitorsIDsNamesMaxPointsReasons()));
return result;
@@ -1008,9 +977,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private Object storeRaceLogGateLineOpeningTimeEvent(RaceLogGateLineOpeningTimeEvent gateLineOpeningTimeEvent){
DBObject result = new BasicDBObject();
storeRaceLogEventProperties(gateLineOpeningTimeEvent, result);
result.put(FieldNames.RACE_LOG_EVENT_CLASS.name(), RaceLogGateLineOpeningTimeEvent.class.getSimpleName());
result.put(FieldNames.RACE_LOG_GATE_LINE_OPENING_TIME.name(), gateLineOpeningTimeEvent.getGateLineOpeningTimes().getGateLaunchStopTime());
result.put(FieldNames.RACE_LOG_GOLF_DOWN_TIME.name(), gateLineOpeningTimeEvent.getGateLineOpeningTimes().getGolfDownTime());
return result;
@@ -1018,19 +985,16 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
private BasicDBList storePositionedCompetitors(List<Triple<Serializable, String, MaxPointsReason>> positionedCompetitors) {
BasicDBList dbList = new BasicDBList();
if (positionedCompetitors != null) {
for (Triple<Serializable, String, MaxPointsReason> competitorPair : positionedCompetitors) {
dbList.add(storePositionedCompetitor(competitorPair));
}
}
return dbList;
}
private DBObject storePositionedCompetitor(Triple<Serializable, String, MaxPointsReason> competitorTriple) {
DBObject result = new BasicDBObject();
result.put(FieldNames.COMPETITOR_ID.name(), competitorTriple.getA());
result.put(FieldNames.COMPETITOR_DISPLAY_NAME.name(), competitorTriple.getB());
result.put(FieldNames.LEADERBOARD_SCORE_CORRECTION_MAX_POINTS_REASON.name(), competitorTriple.getC().name());
@@ -1177,4 +1141,16 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
.add(FieldNames.DEVICE_TYPE_ID.name(), deviceTypeId)
.add(FieldNames.DEVICE_STRING_REPRESENTATION.name(), device.getStringRepresentation()).get();
}
void storeRaceLogEventEvent(DBObject eventEntry) {
getRaceLogCollection().insert(eventEntry);
logger.fine("Inserted event entry into mongo race log collection");
}
@Override
public void removeRaceLog(RaceLogIdentifier identifier) {
DBObject query = new BasicDBObject();
storeRaceLogIdentifier(identifier, query);
getRaceLogCollection().remove(query);
}
}
@@ -1,9 +1,10 @@
package com.sap.sailing.domain.persistence.impl;
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.racelog.RaceLogEventVisitor;
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
import com.sap.sailing.domain.racelog.RaceLogStore;
public class MongoRaceLogStoreFactoryImpl implements MongoRaceLogStoreFactory {
@@ -11,4 +12,9 @@ public class MongoRaceLogStoreFactoryImpl implements MongoRaceLogStoreFactory {
public RaceLogStore getMongoRaceLogStore(MongoObjectFactory mongoObjectFactory, DomainObjectFactory domainObjectFactory) {
return new MongoRaceLogStoreImpl(mongoObjectFactory, domainObjectFactory);
}
@Override
public RaceLogEventVisitor getMongoRaceLogStoreVisitor(RaceLogIdentifier identifier, MongoObjectFactory mongoObjectFactory) {
return new MongoRaceLogStoreVisitor(identifier, mongoObjectFactory);
}
}
@@ -39,6 +39,12 @@ public class MongoRaceLogStoreImpl implements RaceLogStore {
return result;
}
@Override
public void removeRaceLog(RaceLogIdentifier identifier) {
raceLogCache.remove(identifier);
mongoObjectFactory.removeRaceLog(identifier);
}
@Override
public void removeListenersAddedByStoreFrom(RaceLog raceLog) {
RaceLogEventVisitor visitor = listeners.get(raceLog);
@@ -1,177 +1,169 @@
package com.sap.sailing.domain.persistence.impl;
import java.util.logging.Logger;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.sap.sailing.domain.persistence.MongoObjectFactory;
import com.sap.sailing.domain.racelog.RaceLogCourseAreaChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogCourseDesignChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogEventVisitor;
import com.sap.sailing.domain.racelog.RaceLogFinishPositioningConfirmedEvent;
import com.sap.sailing.domain.racelog.RaceLogFinishPositioningListChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogFlagEvent;
import com.sap.sailing.domain.racelog.RaceLogGateLineOpeningTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
import com.sap.sailing.domain.racelog.RaceLogPassChangeEvent;
import com.sap.sailing.domain.racelog.RaceLogPathfinderEvent;
import com.sap.sailing.domain.racelog.RaceLogProtestStartTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogRaceStatusEvent;
import com.sap.sailing.domain.racelog.RaceLogStartProcedureChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogStartTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogWindFixEvent;
import com.sap.sailing.domain.racelog.RevokeEvent;
import com.sap.sailing.domain.racelog.tracking.CloseOpenEndedDeviceMappingEvent;
import com.sap.sailing.domain.racelog.tracking.DefineMarkEvent;
import com.sap.sailing.domain.racelog.tracking.DenoteForTrackingEvent;
import com.sap.sailing.domain.racelog.tracking.DeviceCompetitorMappingEvent;
import com.sap.sailing.domain.racelog.tracking.DeviceMarkMappingEvent;
import com.sap.sailing.domain.racelog.tracking.RegisterCompetitorEvent;
import com.sap.sailing.domain.racelog.tracking.StartTrackingEvent;
public class MongoRaceLogStoreVisitor implements RaceLogEventVisitor {
private final RaceLogIdentifier raceLogIdentifier;
private final MongoObjectFactoryImpl mongoObjectFactory;
private final DBCollection raceLogsCollection;
private final static Logger logger = Logger.getLogger(MongoRaceLogStoreVisitor.class.getName());
public MongoRaceLogStoreVisitor(RaceLogIdentifier identifier, MongoObjectFactory mongoObjectFactory) {
super();
this.raceLogIdentifier = identifier;
this.mongoObjectFactory = (MongoObjectFactoryImpl) mongoObjectFactory;
this.raceLogsCollection = this.mongoObjectFactory.getRaceLogCollection();
}
private void storeEventInCollection(DBObject eventEntry) {
raceLogsCollection.insert(eventEntry);
logger.fine("Inserted event entry into mongo race log collection");
}
@Override
public void visit(RaceLogFlagEvent event) {
DBObject flagEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(flagEventTrackEntry);
}
@Override
public void visit(RaceLogPassChangeEvent event) {
DBObject passChangeEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(passChangeEventTrackEntry);
}
@Override
public void visit(RaceLogRaceStatusEvent event) {
DBObject raceStatusEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(raceStatusEventTrackEntry);
}
@Override
public void visit(RaceLogStartTimeEvent event) {
DBObject startTimeEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(startTimeEventTrackEntry);
}
@Override
public void visit(RaceLogCourseAreaChangedEvent event) {
DBObject courseAreaChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(courseAreaChangedEventTrackEntry);
}
@Override
public void visit(RaceLogCourseDesignChangedEvent event) {
DBObject courseDesignChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(courseDesignChangedEventTrackEntry);
}
@Override
public void visit(RaceLogFinishPositioningListChangedEvent event) {
DBObject finishPositioningListChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(finishPositioningListChangedEventTrackEntry);
}
@Override
public void visit(RaceLogFinishPositioningConfirmedEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RaceLogPathfinderEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RaceLogGateLineOpeningTimeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RaceLogStartProcedureChangedEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RaceLogProtestStartTimeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RaceLogWindFixEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(DeviceCompetitorMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(DeviceMarkMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(DenoteForTrackingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(StartTrackingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RevokeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(RegisterCompetitorEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(DefineMarkEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
@Override
public void visit(CloseOpenEndedDeviceMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
storeEventInCollection(object);
}
}
package com.sap.sailing.domain.persistence.impl;
import java.util.logging.Logger;
import com.mongodb.DBObject;
import com.sap.sailing.domain.persistence.MongoObjectFactory;
import com.sap.sailing.domain.racelog.RaceLogCourseAreaChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogCourseDesignChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogEventVisitor;
import com.sap.sailing.domain.racelog.RaceLogFinishPositioningConfirmedEvent;
import com.sap.sailing.domain.racelog.RaceLogFinishPositioningListChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogFlagEvent;
import com.sap.sailing.domain.racelog.RaceLogGateLineOpeningTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogIdentifier;
import com.sap.sailing.domain.racelog.RaceLogPassChangeEvent;
import com.sap.sailing.domain.racelog.RaceLogPathfinderEvent;
import com.sap.sailing.domain.racelog.RaceLogProtestStartTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogRaceStatusEvent;
import com.sap.sailing.domain.racelog.RaceLogStartProcedureChangedEvent;
import com.sap.sailing.domain.racelog.RaceLogStartTimeEvent;
import com.sap.sailing.domain.racelog.RaceLogWindFixEvent;
import com.sap.sailing.domain.racelog.RevokeEvent;
import com.sap.sailing.domain.racelog.tracking.CloseOpenEndedDeviceMappingEvent;
import com.sap.sailing.domain.racelog.tracking.DefineMarkEvent;
import com.sap.sailing.domain.racelog.tracking.DenoteForTrackingEvent;
import com.sap.sailing.domain.racelog.tracking.DeviceCompetitorMappingEvent;
import com.sap.sailing.domain.racelog.tracking.DeviceMarkMappingEvent;
import com.sap.sailing.domain.racelog.tracking.RegisterCompetitorEvent;
import com.sap.sailing.domain.racelog.tracking.StartTrackingEvent;
public class MongoRaceLogStoreVisitor implements RaceLogEventVisitor {
private final RaceLogIdentifier raceLogIdentifier;
private final MongoObjectFactoryImpl mongoObjectFactory;
final static Logger logger = Logger.getLogger(MongoRaceLogStoreVisitor.class.getName());
public MongoRaceLogStoreVisitor(RaceLogIdentifier identifier, MongoObjectFactory mongoObjectFactory) {
super();
this.raceLogIdentifier = identifier;
this.mongoObjectFactory = (MongoObjectFactoryImpl) mongoObjectFactory;
}
@Override
public void visit(RaceLogFlagEvent event) {
DBObject flagEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(flagEventTrackEntry);
}
@Override
public void visit(RaceLogPassChangeEvent event) {
DBObject passChangeEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(passChangeEventTrackEntry);
}
@Override
public void visit(RaceLogRaceStatusEvent event) {
DBObject raceStatusEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(raceStatusEventTrackEntry);
}
@Override
public void visit(RaceLogStartTimeEvent event) {
DBObject startTimeEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(startTimeEventTrackEntry);
}
@Override
public void visit(RaceLogCourseAreaChangedEvent event) {
DBObject courseAreaChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(courseAreaChangedEventTrackEntry);
}
@Override
public void visit(RaceLogCourseDesignChangedEvent event) {
DBObject courseDesignChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(courseDesignChangedEventTrackEntry);
}
@Override
public void visit(RaceLogFinishPositioningListChangedEvent event) {
DBObject finishPositioningListChangedEventTrackEntry = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(finishPositioningListChangedEventTrackEntry);
}
@Override
public void visit(RaceLogFinishPositioningConfirmedEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RaceLogPathfinderEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RaceLogGateLineOpeningTimeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RaceLogStartProcedureChangedEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RaceLogProtestStartTimeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RaceLogWindFixEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(DeviceCompetitorMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(DeviceMarkMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(DenoteForTrackingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(StartTrackingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RevokeEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(RegisterCompetitorEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(DefineMarkEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
@Override
public void visit(CloseOpenEndedDeviceMappingEvent event) {
DBObject object = mongoObjectFactory.storeRaceLogEntry(raceLogIdentifier, event);
mongoObjectFactory.storeRaceLogEventEvent(object);
}
}
@@ -12,8 +12,19 @@ import java.util.List;
*/
public interface MediaDB {
/**
* Stores a new track to the database, returning the db-generated id.
*/
String insertMediaTrack(String title, String url, Date startTime, int durationInMillis, String mimeType);
/**
* Stores a new track to the database, using the db id of the specified trackToImport.
* @return true if a new track has been added to db, e.g. the specified dbId didn't exist.
* @throws NullpointerException When trackToImport.dbId is null.
* @throws IllegalArgumentException When track with specified dbId already exists.
*/
void insertMediaTrackWithId(String dbId, String videoTitle, String url, Date startTime, int durationInMillis, String mimeType);
List<DBMediaTrack> loadAllMediaTracks();
void deleteMediaTrack(String dbId);
@@ -33,6 +44,9 @@ public interface MediaDB {
return "0";
}
@Override
public void insertMediaTrackWithId(String dbId, String videoTitle, String url, Date startTime, int durationInMillis, String mimeType) {};
@Override
public List<DBMediaTrack> loadAllMediaTracks() {
return Collections.emptyList();
@@ -55,5 +69,4 @@ public interface MediaDB {
};
}
@@ -11,6 +11,8 @@ import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.WriteConcern;
import com.sap.sailing.domain.persistence.media.DBMediaTrack;
import com.sap.sailing.domain.persistence.media.MediaDB;
@@ -37,31 +39,49 @@ public class MediaDBImpl implements MediaDB {
}
@Override
public String insertMediaTrack(String videoTitle, String url, Date startTime, int durationInMillis, String mimeType) {
BasicDBObject dbVideo = new BasicDBObject();
dbVideo.put(DbNames.Fields.MEDIA_TITLE.name(), videoTitle);
dbVideo.put(DbNames.Fields.MEDIA_URL.name(), url);
dbVideo.put(DbNames.Fields.STARTTIME.name(), startTime);
dbVideo.put(DbNames.Fields.DURATION_IN_MILLIS.name(), durationInMillis);
dbVideo.put(DbNames.Fields.MIME_TYPE.name(), mimeType);
public String insertMediaTrack(String title, String url, Date startTime, int durationInMillis, String mimeType) {
BasicDBObject dbMediaTrack = new BasicDBObject();
dbMediaTrack.put(DbNames.Fields.MEDIA_TITLE.name(), title);
dbMediaTrack.put(DbNames.Fields.MEDIA_URL.name(), url);
dbMediaTrack.put(DbNames.Fields.STARTTIME.name(), startTime);
dbMediaTrack.put(DbNames.Fields.DURATION_IN_MILLIS.name(), durationInMillis);
dbMediaTrack.put(DbNames.Fields.MIME_TYPE.name(), mimeType);
DBCollection dbVideos = getVideoCollection();
dbVideos.insert(dbVideo);
return ((ObjectId) dbVideo.get(DbNames.Fields._id.name())).toString();
dbVideos.insert(dbMediaTrack);
return ((ObjectId) dbMediaTrack.get(DbNames.Fields._id.name())).toStringMongod();
}
@Override
public void insertMediaTrackWithId(String dbId, String title, String url, Date startTime, int durationInMillis, String mimeType) {
BasicDBObject dbMediaTrack = new BasicDBObject();
dbMediaTrack.put(DbNames.Fields._id.name(), new ObjectId(dbId));
dbMediaTrack.put(DbNames.Fields.MEDIA_TITLE.name(), title);
dbMediaTrack.put(DbNames.Fields.MEDIA_URL.name(), url);
dbMediaTrack.put(DbNames.Fields.STARTTIME.name(), startTime);
dbMediaTrack.put(DbNames.Fields.DURATION_IN_MILLIS.name(), durationInMillis);
dbMediaTrack.put(DbNames.Fields.MIME_TYPE.name(), mimeType);
DBCollection dbVideos = getVideoCollection();
try {
dbVideos.insert(dbMediaTrack);
} catch (MongoException.DuplicateKey e) {
throw new IllegalArgumentException(e);
}
}
private DBCollection getVideoCollection() {
try {
DBCollection dbVideos = database.getCollection(DbNames.Collections.VIDEOS.name());
dbVideos.setWriteConcern(WriteConcern.FSYNC_SAFE);
dbVideos.ensureIndex(DbNames.Collections.VIDEOS.name());
return dbVideos;
} catch (NullPointerException e) {
// sometimes, for reasons yet to be clarified, ensuring an index on the name field causes an NPE
throw new RuntimeException(e);
throw e;
}
}
private DBMediaTrack createMediaObjectFromDB(DBObject dbObject) {
String dbId = ((ObjectId) dbObject.get(DbNames.Fields._id.name())).toString();
String dbId = ((ObjectId) dbObject.get(DbNames.Fields._id.name())).toStringMongod();
String title = (String) dbObject.get(DbNames.Fields.MEDIA_TITLE.name());
String url = (String) dbObject.get(DbNames.Fields.MEDIA_URL.name());
Date startTime = (Date) dbObject.get(DbNames.Fields.STARTTIME.name());
@@ -93,10 +113,10 @@ public class MediaDBImpl implements MediaDB {
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append(DbNames.Fields._id.name(), new ObjectId(dbId));
BasicDBObject update = new BasicDBObject();
update.append("$set", new BasicDBObject(DbNames.Fields.MEDIA_TITLE.name(), title));
BasicDBObject updateCommand = new BasicDBObject();
updateCommand.append("$set", new BasicDBObject(DbNames.Fields.MEDIA_TITLE.name(), title));
getVideoCollection().update(updateQuery, update);
getVideoCollection().update(updateQuery, updateCommand);
}
@Override
@@ -104,10 +124,10 @@ public class MediaDBImpl implements MediaDB {
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append(DbNames.Fields._id.name(), new ObjectId(dbId));
BasicDBObject update = new BasicDBObject();
update.append("$set", new BasicDBObject(DbNames.Fields.MEDIA_URL.name(), url));
BasicDBObject updateCommand = new BasicDBObject();
updateCommand.append("$set", new BasicDBObject(DbNames.Fields.MEDIA_URL.name(), url));
getVideoCollection().update(updateQuery, update);
getVideoCollection().update(updateQuery, updateCommand);
}
@Override
@@ -115,10 +135,10 @@ public class MediaDBImpl implements MediaDB {
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append(DbNames.Fields._id.name(), new ObjectId(dbId));
BasicDBObject update = new BasicDBObject();
update.append("$set", new BasicDBObject(DbNames.Fields.STARTTIME.name(), startTime));
BasicDBObject updateCommand = new BasicDBObject();
updateCommand.append("$set", new BasicDBObject(DbNames.Fields.STARTTIME.name(), startTime));
getVideoCollection().update(updateQuery, update);
getVideoCollection().update(updateQuery, updateCommand);
}
@Override
@@ -126,10 +146,10 @@ public class MediaDBImpl implements MediaDB {
BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append(DbNames.Fields._id.name(), new ObjectId(dbId));
BasicDBObject update = new BasicDBObject();
update.append("$set", new BasicDBObject(DbNames.Fields.DURATION_IN_MILLIS.name(), durationInMillis));
BasicDBObject updateCommand = new BasicDBObject();
updateCommand.append("$set", new BasicDBObject(DbNames.Fields.DURATION_IN_MILLIS.name(), durationInMillis));
getVideoCollection().update(updateQuery, update);
getVideoCollection().update(updateQuery, updateCommand);
}
}