mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
added storing of MigratableRegatta after migration
Change-Id: Ifa6d368b127924a1cb31455628c7f009ddea47a5
This commit is contained in:
1 parent
ec3969c869
commit
7bcd6f8aa9
4 files changed
+40
-25
No files matched your search
+5
-8
@@ -153,7 +153,6 @@ import com.sap.sailing.domain.base.configuration.impl.RegattaConfigurationImpl;
|
||||
import com.sap.sailing.domain.base.impl.CourseDataImpl;
|
||||
import com.sap.sailing.domain.base.impl.EventImpl;
|
||||
import com.sap.sailing.domain.base.impl.FleetImpl;
|
||||
import com.sap.sailing.domain.base.impl.MigratableRegattaImpl;
|
||||
import com.sap.sailing.domain.base.impl.RegattaImpl;
|
||||
import com.sap.sailing.domain.base.impl.RemoteSailingServerReferenceImpl;
|
||||
import com.sap.sailing.domain.base.impl.SailingServerConfigurationImpl;
|
||||
@@ -187,6 +186,7 @@ import com.sap.sailing.domain.common.racelog.Flags;
|
||||
import com.sap.sailing.domain.common.racelog.RaceLogRaceStatus;
|
||||
import com.sap.sailing.domain.common.racelog.RacingProcedureType;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.TransformationException;
|
||||
import com.sap.sailing.domain.common.tracking.impl.CompetitorJsonConstants;
|
||||
import com.sap.sailing.domain.leaderboard.DelayedLeaderboardCorrections;
|
||||
import com.sap.sailing.domain.leaderboard.EventResolver;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
@@ -1273,7 +1273,7 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
: buoyZoneRadiusInHullLengths,
|
||||
useStartTimeInference == null ? true : useStartTimeInference,
|
||||
controlTrackingFromStartAndFinishTimes == null ? false : controlTrackingFromStartAndFinishTimes,
|
||||
rankingMetricConstructor);
|
||||
rankingMetricConstructor, new MongoObjectFactoryImpl(database));
|
||||
} else {
|
||||
result = new RegattaImpl(getRaceLogStore(), getRegattaLogStore(), name, boatClass,
|
||||
canBoatsOfCompetitorsChangePerRace, startDate, endDate, series, /* persistent */true,
|
||||
@@ -2367,18 +2367,16 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
@Override
|
||||
public Collection<CompetitorWithBoat> migrateLegacyCompetitorsIfRequired() {
|
||||
Map<Serializable, CompetitorWithBoat> competitorsById = null;
|
||||
|
||||
boolean competitorsCollectionExist = database.collectionExists(CollectionNames.COMPETITORS.name());
|
||||
boolean boatsCollectionCollectionExist = database.collectionExists(CollectionNames.BOATS.name());
|
||||
DBCollection orginalCompetitorCollection = database.getCollection(CollectionNames.COMPETITORS.name());
|
||||
|
||||
// there is a corner case where tests can create just one competitor without boat
|
||||
// before we migrate we need to check if this case
|
||||
if (competitorsCollectionExist && !boatsCollectionCollectionExist) {
|
||||
long competitorCount = orginalCompetitorCollection.count();
|
||||
if (competitorCount > 0) {
|
||||
DBObject oneCompetitorDbObject = orginalCompetitorCollection.findOne();
|
||||
Object boatObject = oneCompetitorDbObject.get("boat");
|
||||
Object boatObject = oneCompetitorDbObject.get(CompetitorJsonConstants.FIELD_BOAT);
|
||||
// only in case such a boat object exist we need a migration, because the new type stores only a boatID or no boat at all
|
||||
if (boatObject != null) {
|
||||
competitorsById = new HashMap<>();
|
||||
@@ -2399,9 +2397,8 @@ public class DomainObjectFactoryImpl implements DomainObjectFactory {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return competitorsById.values();
|
||||
}
|
||||
return competitorsById==null?null:competitorsById.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+16
-6
@@ -1,33 +1,43 @@
|
||||
package com.sap.sailing.domain.base.impl;
|
||||
package com.sap.sailing.domain.persistence.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sap.sailing.domain.base.BoatClass;
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.MigratableRegatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.base.impl.RegattaImpl;
|
||||
import com.sap.sailing.domain.leaderboard.ScoringScheme;
|
||||
import com.sap.sailing.domain.persistence.MongoObjectFactory;
|
||||
import com.sap.sailing.domain.racelog.RaceLogStore;
|
||||
import com.sap.sailing.domain.ranking.RankingMetricConstructor;
|
||||
import com.sap.sailing.domain.regattalog.RegattaLogStore;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.Util;
|
||||
|
||||
public class MigratableRegattaImpl extends RegattaImpl {
|
||||
public class MigratableRegattaImpl extends RegattaImpl implements MigratableRegatta {
|
||||
private static final long serialVersionUID = -3545488249832218320L;
|
||||
|
||||
/**
|
||||
* To be used for storing a migrated regatta
|
||||
*/
|
||||
private final MongoObjectFactory mongoObjectFactory;
|
||||
|
||||
public <S extends Series> MigratableRegattaImpl(RaceLogStore raceLogStore, RegattaLogStore regattaLogStore, String name,
|
||||
BoatClass boatClass, boolean canBoatsOfCompetitorsChangePerRace, TimePoint startDate, TimePoint endDate,
|
||||
Iterable<S> series, boolean persistent, ScoringScheme scoringScheme, Serializable id, CourseArea courseArea,
|
||||
Double buoyZoneRadiusInHullLengths, boolean useStartTimeInference,
|
||||
boolean controlTrackingFromStartAndFinishTimes, RankingMetricConstructor rankingMetricConstructor) {
|
||||
boolean controlTrackingFromStartAndFinishTimes, RankingMetricConstructor rankingMetricConstructor, MongoObjectFactory mongoObjectFactory) {
|
||||
super(raceLogStore, regattaLogStore, name, boatClass, canBoatsOfCompetitorsChangePerRace, startDate, endDate, series,
|
||||
persistent, scoringScheme, id, courseArea, buoyZoneRadiusInHullLengths, useStartTimeInference,
|
||||
controlTrackingFromStartAndFinishTimes, rankingMetricConstructor);
|
||||
this.mongoObjectFactory = mongoObjectFactory;
|
||||
}
|
||||
|
||||
public void migrateCanBoatsOfCompetitorsChangePerRace(boolean canBoatsOfCompetitorsChangePerRace) {
|
||||
public synchronized void migrateCanBoatsOfCompetitorsChangePerRace() {
|
||||
// It should not be possible to call this after races have been already added to this regatta.
|
||||
assert Util.size(getAllRaces()) == 0;
|
||||
super.setCanBoatsOfCompetitorsChangePerRace(canBoatsOfCompetitorsChangePerRace);
|
||||
assert !canBoatsOfCompetitorsChangePerRace() && Util.size(getAllRaces()) == 0;
|
||||
super.setCanBoatsOfCompetitorsChangePerRace(true);
|
||||
mongoObjectFactory.storeRegatta(this);
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -34,6 +34,7 @@ import com.sap.sailing.domain.base.ControlPoint;
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.LeaderboardGroupBase;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.MigratableRegatta;
|
||||
import com.sap.sailing.domain.base.Nationality;
|
||||
import com.sap.sailing.domain.base.RaceDefinition;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
@@ -44,7 +45,6 @@ import com.sap.sailing.domain.base.impl.DynamicBoat;
|
||||
import com.sap.sailing.domain.base.impl.DynamicPerson;
|
||||
import com.sap.sailing.domain.base.impl.DynamicTeam;
|
||||
import com.sap.sailing.domain.base.impl.KilometersPerHourSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.base.impl.MigratableRegattaImpl;
|
||||
import com.sap.sailing.domain.base.impl.PersonImpl;
|
||||
import com.sap.sailing.domain.base.impl.RaceDefinitionImpl;
|
||||
import com.sap.sailing.domain.base.impl.RegattaImpl;
|
||||
@@ -697,16 +697,19 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
// As the attribute 'canBoatsOfCompetitorsChangePerRace' is new and 'false' is the default value
|
||||
// we need to set it's value to true for the regatta, but only if the regatta is of type MigratableRegattaImpl
|
||||
Regatta regatta = trackedRegatta.getRegatta();
|
||||
if (competitorBoatInfo != null && regatta.canBoatsOfCompetitorsChangePerRace() == false) {
|
||||
// we need to set this to true for the regatta to make it possible to create the boat/competitor mappings
|
||||
if (regatta instanceof MigratableRegattaImpl) {
|
||||
MigratableRegattaImpl migratableRegatta = (MigratableRegattaImpl) regatta;
|
||||
migratableRegatta.migrateCanBoatsOfCompetitorsChangePerRace(true);
|
||||
logger.log(Level.INFO, "Successful migration of regatta " + regatta.getName() +
|
||||
" to be of type 'canBoatsOfCompetitorsChangePerRace=true'");
|
||||
} else {
|
||||
logger.log(Level.SEVERE, "Regatta " + regatta.getName() +
|
||||
" has wrong type 'canBoatsOfCompetitorsChangePerRace' but can't be migrated because it is not of type MigratableRegattaImpl");
|
||||
// the check for migration needs to obtain the lock for check and possible migration
|
||||
synchronized (regatta) {
|
||||
if (competitorBoatInfo != null && regatta.canBoatsOfCompetitorsChangePerRace() == false) {
|
||||
// we need to set this to true for the regatta to make it possible to create the boat/competitor mappings
|
||||
if (regatta instanceof MigratableRegatta) {
|
||||
MigratableRegatta migratableRegatta = (MigratableRegatta) regatta;
|
||||
migratableRegatta.migrateCanBoatsOfCompetitorsChangePerRace();
|
||||
logger.log(Level.INFO, "Successful migration of regatta " + regatta.getName() +
|
||||
" to be of type 'canBoatsOfCompetitorsChangePerRace=true'");
|
||||
} else {
|
||||
logger.log(Level.SEVERE, "Regatta " + regatta.getName() +
|
||||
" has wrong type 'canBoatsOfCompetitorsChangePerRace' but can't be migrated because it is not of type MigratableRegattaImpl");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.sap.sailing.domain.base;
|
||||
|
||||
public interface MigratableRegatta extends Regatta {
|
||||
void migrateCanBoatsOfCompetitorsChangePerRace();
|
||||
}
|
||||
Reference in new issue
Block a user