use race ID instead of event ID to create the default regatta;

Event objects with the TracAPI now really contain multiple events, therefore having multiple different boat
classes. The regatta must have a single boat class.
This commit is contained in:
Axel Uhl committed 2014-04-08 17:05:40 +02:00
1 parent 3d09c1820d
commit 330778bd32
9 files changed
+23 -23

No files matched your search

@@ -76,7 +76,7 @@ public class CourseUpdateTest extends AbstractTracTracLiveTest {
public void setUp() throws MalformedURLException, IOException, InterruptedException, URISyntaxException, SubscriberInitializationException, ParseException, CreateModelException {
super.setUp();
domainFactory = new DomainFactoryImpl(new com.sap.sailing.domain.base.impl.DomainFactoryImpl());
domainRegatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null);
domainRegatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null);
trackedRegatta = new DynamicTrackedRegattaImpl(domainRegatta);
IRace tractracRace = SynchronizationUtil.getRaces(getTracTracEvent()).iterator().next();
ArrayList<Receiver> receivers = new ArrayList<Receiver>();
@@ -1,8 +1,8 @@
package com.sap.sailing.domain.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -15,8 +15,6 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.sap.sailing.domain.racelog.impl.EmptyRaceLogStore;
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
import com.sap.sailing.domain.tractracadapter.DomainFactory;
@@ -82,7 +80,7 @@ public class MultipleClassesInRegattaTest {
assertEquals("505", kiwotest2.getRegatta().getBoatClass().getName());
assertEquals("49er", kiwotest3.getRegatta().getBoatClass().getName());
assertEquals("STG", weym470may112014_2.getRegatta().getBoatClass().getName());
assertSame(weym470may112014_2.getRegatta(), kiwotest1.getRegatta());
assertNotSame(weym470may112014_2.getRegatta(), kiwotest1.getRegatta()); // expecting that each race gets a distinct default regatta
assertNotSame(kiwotest1.getRegatta(), kiwotest2.getRegatta());
assertNotSame(kiwotest1.getRegatta(), kiwotest3.getRegatta());
assertNotSame(kiwotest2.getRegatta(), kiwotest3.getRegatta());
@@ -183,7 +183,7 @@ public abstract class OnlineTracTracBasedTest extends AbstractTracTracLiveTest {
if (domainFactory == null) {
domainFactory = new DomainFactoryImpl(new com.sap.sailing.domain.base.impl.DomainFactoryImpl());
}
domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null);
domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null);
trackedRegatta = new DynamicTrackedRegattaImpl(domainEvent);
}
@@ -93,7 +93,7 @@ public class ReceiveMarkPassingDataTest extends AbstractTracTracLiveTest {
receivers.add(receiver);
for (Receiver r : DomainFactory.INSTANCE.getUpdateReceivers(
new DynamicTrackedRegattaImpl(DomainFactory.INSTANCE.getOrCreateDefaultRegatta(
EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */null)),
EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */null)),
SynchronizationUtil.getRaces(getTracTracEvent()).iterator().next(), EmptyWindStore.INSTANCE, /* delayToLiveInMillis */ 0l,
/* simulator */null,
new DynamicRaceDefinitionSet() {
@@ -62,7 +62,7 @@ public class ReceiveTrackingDataTest extends AbstractTracTracLiveTest {
}
}
};
Regatta regatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null);
Regatta regatta = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null);
DynamicTrackedRegatta trackedRegatta = new DynamicTrackedRegattaImpl(regatta);
trackedRegatta.addRaceListener(new RaceListener() {
@Override
@@ -100,7 +100,7 @@ public interface DomainFactory {
* boat class exists yet.
* @param trackedRegattaRegistry TODO
*/
com.sap.sailing.domain.base.Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IEvent event, TrackedRegattaRegistry trackedRegattaRegistry);
com.sap.sailing.domain.base.Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IRace race, TrackedRegattaRegistry trackedRegattaRegistry);
/**
* Creates a race tracked for the specified URL/URIs and starts receiving all available existing and future push
@@ -108,12 +108,11 @@ public class DomainFactoryImpl implements DomainFactory {
new HashMap<Pair<String, String>, com.sap.sailing.domain.base.Regatta>();
/**
* A cache based on weak references to the TracTrac event, allowing for quick Event lookup as long as the
* TracTrac event remains referenced. This is intended to reduce the number of times the dominant boat
* class needs to be determined for an regatta. Synchronization for additions / removals is tied to the
* A cache based on weak references to the TracTrac race, allowing for quick race lookup as long as the
* TracTrac race remains referenced. Synchronization for additions / removals is tied to the
* synchronization for {@link #regattaCache}.
*/
private final WeakIdentityHashMap<IEvent, Regatta> weakRegattaCache = new WeakIdentityHashMap<>();
private final WeakIdentityHashMap<IRace, Regatta> weakDefaultRegattaCache = new WeakIdentityHashMap<>();
/**
* Maps from the TracTrac race UUIDs to the domain model's {@link RaceDefinition} objects that represent the race
@@ -345,7 +344,7 @@ public class DomainFactoryImpl implements DomainFactory {
}
@Override
public Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IEvent event, TrackedRegattaRegistry trackedRegattaRegistry) {
public Regatta getOrCreateDefaultRegatta(RaceLogStore raceLogStore, IRace race, TrackedRegattaRegistry trackedRegattaRegistry) {
synchronized (regattaCache) {
// FIXME Dialog with Lasse by Skype on 2011-06-17:
// [6:20:04 PM] Axel Uhl: Lasse, can Event.getCompetitorClassList() ever produce more than one result?
@@ -360,22 +359,25 @@ public class DomainFactoryImpl implements DomainFactory {
// try a quick look-up in the weak cache using the TracTrac event as key; only if that delivers no result,
// compute the dominant boat class which requires a lot more effort
Regatta result = weakRegattaCache.get(event);
Regatta result = weakDefaultRegattaCache.get(race);
if (result == null) {
Collection<ICompetitorClass> competitorClassList = event.getCompetitorClasses();
Collection<ICompetitorClass> competitorClassList = new ArrayList<>();
for (IRaceCompetitor competitor : race.getRaceCompetitors()) {
competitorClassList.add(competitor.getCompetitor().getCompetitorClass());
}
BoatClass boatClass = getDominantBoatClass(competitorClassList);
Pair<String, String> key = new Pair<String, String>(event.getName(), boatClass == null ? null
Pair<String, String> key = new Pair<String, String>(race.getName(), boatClass == null ? null
: boatClass.getName());
result = regattaCache.get(key);
// FIXME When a Regatta is removed from RacingEventService, it isn't removed here. We use a "stale" regatta here.
// This is particularly bad if a persistent regatta was loaded but a default regatta was accidentally created.
// Then, there is no way but restart the server to get rid of this stale cache entry here.
if (result == null) {
result = new RegattaImpl(raceLogStore, event.getName(), boatClass, trackedRegattaRegistry,
result = new RegattaImpl(raceLogStore, race.getName(), boatClass, trackedRegattaRegistry,
// use the low-point system as the default scoring scheme
getBaseDomainFactory().createScoringScheme(ScoringSchemeType.LOW_POINT), event.getId(), null);
getBaseDomainFactory().createScoringScheme(ScoringSchemeType.LOW_POINT), race.getId(), null);
regattaCache.put(key, result);
weakRegattaCache.put(event, result);
weakDefaultRegattaCache.put(race, result);
logger.info("Created regatta "+result.getName()+" ("+result.hashCode()+") because none found for key "+key);
}
}
@@ -468,7 +470,7 @@ public class DomainFactoryImpl implements DomainFactory {
if (oldSize > 0 && Util.size(regatta.getAllRaces()) == 0) {
logger.info("Removing regatta "+regatta.getName()+" ("+regatta.hashCode()+") from TracTrac DomainFactoryImpl");
regattaCache.remove(key);
weakRegattaCache.remove(tractracEvent);
weakDefaultRegattaCache.remove(tractracRace);
}
TrackedRegatta trackedRegatta = trackedRegattaRegistry.getTrackedRegatta(regatta);
if (trackedRegatta != null) {
@@ -325,7 +325,7 @@ public class TracTracRaceTrackerImpl extends AbstractRaceTrackerImpl implements
// if regatta is still null, no previous assignment of any of the races in this TracTrac event to a Regatta was
// found;
// in this case, create a default regatta based on the TracTrac event data
this.regatta = effectiveRegatta == null ? domainFactory.getOrCreateDefaultRegatta(raceLogStore, tractracRace.getEvent(), trackedRegattaRegistry) : effectiveRegatta;
this.regatta = effectiveRegatta == null ? domainFactory.getOrCreateDefaultRegatta(raceLogStore, tractracRace, trackedRegattaRegistry) : effectiveRegatta;
trackedRegatta = trackedRegattaRegistry.getOrCreateTrackedRegatta(this.regatta);
receivers = new HashSet<Receiver>();
for (Receiver receiver : domainFactory.getUpdateReceivers(getTrackedRegatta(), delayToLiveInMillis,
@@ -75,7 +75,7 @@ public class TestStoringAndRetrievingWindTracksTest extends AbstractTracTracLive
@Test
public void testStoreAFewWindEntries() throws UnknownHostException, MongoException, InterruptedException {
DomainFactory domainFactory = DomainFactory.INSTANCE;
Regatta domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracEvent(), /* trackedRegattaRegistry */ null);
Regatta domainEvent = domainFactory.getOrCreateDefaultRegatta(EmptyRaceLogStore.INSTANCE, getTracTracRace(), /* trackedRegattaRegistry */ null);
DynamicTrackedRegatta trackedRegatta = new RacingEventServiceImpl().getOrCreateTrackedRegatta(domainEvent);
Iterable<Receiver> typeControllers = domainFactory.getUpdateReceivers(trackedRegatta, Util.get(SynchronizationUtil.getRaces(getTracTracEvent()), 0),
EmptyWindStore.INSTANCE,