mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 22:15:26 +00:00
fixed replication of creation of CompetitorWithBoat, now transmitting the boat ID and instantiating the right type
Change-Id: I65e8613b7a9e27259095b999fde56fd96e0b6e9b
This commit is contained in:
1 parent
174a47e1d1
commit
ec80cd48e5
5 files changed
+33
-59
No files matched your search
-12
@@ -130,18 +130,6 @@ public interface CompetitorAndBoatStore extends CompetitorFactory, BoatFactory {
|
||||
|
||||
void removeCompetitorUpdateListener(CompetitorUpdateListener listener);
|
||||
|
||||
/**
|
||||
* Updates the competitor with {@link Competitor#getId() ID} <code>id</code> by setting the name, sail ID and nationality to
|
||||
* the values provided. Doing so will not fire any events nor will it replicate this change from a master to any replicas.
|
||||
* The calling client has to make sure that the changes applied will reach replicas and all other interested clients. It will
|
||||
* be sufficient to ensure that subsequent DTOs produced from the competitor modified will reflect the changes.<p>
|
||||
*
|
||||
* If no competitor with the ID requested is found, the call is a no-op, doing nothing, not even throwing an exception.
|
||||
*/
|
||||
CompetitorWithBoat updateCompetitorWithBoat(String idAsString, String newName, String newShortName, Color newDisplayColor, String newEmail,
|
||||
Nationality newNationality, URI newTeamImageUri, URI newFlagImageUri,
|
||||
Double timeOnTimeFactor, Duration timeOnDistanceAllowancePerNauticalMile, String searchTag);
|
||||
|
||||
/**
|
||||
* If a valid boat is returned and the caller has information available that could be used to update the boat,
|
||||
* the caller must check the result of {@link #isBoatToUpdateDuringGetOrCreate(Competitor)}, and if <code>true</code>,
|
||||
|
||||
+1
-32
@@ -441,43 +441,12 @@ public class TransientCompetitorAndBoatStoreImpl implements CompetitorAndBoatSto
|
||||
}
|
||||
} else if (isCompetitorToUpdateDuringGetOrCreate(result)) {
|
||||
assert result.getBoat() == boat;
|
||||
updateCompetitorWithBoat(result.getId().toString(), name, shortName, displayColor, email, team.getNationality(),
|
||||
updateCompetitor(result.getId().toString(), name, shortName, displayColor, email, team.getNationality(),
|
||||
team.getImage(), flagImage, timeOnTimeFactor, timeOnDistanceAllowancePerNauticalMile, searchTag);
|
||||
competitorNoLongerToUpdateDuringGetOrCreate(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitorWithBoat updateCompetitorWithBoat(String idAsString, String newName, String newShortName, Color newDisplayColor, String newEmail,
|
||||
Nationality newNationality, URI newTeamImageUri, URI newFlagImageUri,
|
||||
Double timeOnTimeFactor, Duration timeOnDistanceAllowancePerNauticalMile, String newSearchTag) {
|
||||
DynamicCompetitorWithBoat competitor = (DynamicCompetitorWithBoat) getExistingCompetitorByIdAsString(idAsString);
|
||||
if (competitor != null) {
|
||||
LockUtil.lockForWrite(lock);
|
||||
try {
|
||||
competitor.setName(newName);
|
||||
competitor.setShortName(newShortName);
|
||||
competitor.setColor(newDisplayColor);
|
||||
competitor.setEmail(newEmail);
|
||||
competitor.setFlagImage(newFlagImageUri);
|
||||
competitor.getTeam().setNationality(newNationality);
|
||||
competitor.getTeam().setImage(newTeamImageUri);
|
||||
competitor.setTimeOnTimeFactor(timeOnTimeFactor);
|
||||
competitor.setTimeOnDistanceAllowancePerNauticalMile(timeOnDistanceAllowancePerNauticalMile);
|
||||
competitor.setSearchTag(newSearchTag);
|
||||
weakCompetitorDTOCache.remove(competitor);
|
||||
} finally {
|
||||
LockUtil.unlockAfterWrite(lock);
|
||||
}
|
||||
}
|
||||
synchronized (competitorUpdateListeners) {
|
||||
for (CompetitorUpdateListener listener : competitorUpdateListeners) {
|
||||
listener.competitorUpdated(competitor);
|
||||
}
|
||||
}
|
||||
return (CompetitorWithBoat) competitor;
|
||||
}
|
||||
|
||||
/** Boat stuff starts here */
|
||||
|
||||
|
||||
-10
@@ -162,16 +162,6 @@ public class PersistentCompetitorAndBoatStore extends TransientCompetitorAndBoat
|
||||
super.addNewCompetitors(competitors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitorWithBoat updateCompetitorWithBoat(String idAsString, String newName, String newShortName, Color newRgbDisplayColor, String newEmail,
|
||||
Nationality newNationality, URI newTeamImageUri, URI newFlagImageUri, Double timeOnTimeFactor, Duration timeOnDistanceAllowancePerNauticalMile,
|
||||
String searchTag) {
|
||||
CompetitorWithBoat result = super.updateCompetitorWithBoat(idAsString, newName, newShortName, newRgbDisplayColor, newEmail, newNationality,
|
||||
newTeamImageUri, newFlagImageUri, timeOnTimeFactor, timeOnDistanceAllowancePerNauticalMile, searchTag);
|
||||
storeTo.storeCompetitor(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addNewBoat(DynamicBoat boat) {
|
||||
storeTo.storeBoat(boat);
|
||||
|
||||
+2
-3
@@ -724,7 +724,8 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
competitor.getColor(), competitor.getEmail(), competitor.getFlagImage(),
|
||||
competitor.getTeam()==null?null:competitor.getTeam().getNationality(),
|
||||
competitor.getTimeOnTimeFactor(),
|
||||
competitor.getTimeOnDistanceAllowancePerNauticalMile(), competitor.getSearchTag()));
|
||||
competitor.getTimeOnDistanceAllowancePerNauticalMile(), competitor.getSearchTag(),
|
||||
competitor.hasBoat() ? ((CompetitorWithBoat) competitor).getBoat().getId() : null));
|
||||
}
|
||||
});
|
||||
this.competitorAndBoatStore.addBoatUpdateListener(new BoatUpdateListener() {
|
||||
@@ -2608,7 +2609,6 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
replicate(new TrackRegatta(regatta.getRegattaIdentifier()));
|
||||
regattaTrackingCache.put(regatta, result);
|
||||
ensureRegattaIsObservedForDefaultLeaderboardAndAutoLeaderboardLinking(result);
|
||||
|
||||
trackedRegattaListener.regattaAdded(result);
|
||||
}
|
||||
return result;
|
||||
@@ -2995,7 +2995,6 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
|
||||
regatta.addRegattaListener(this);
|
||||
logoutput.append(String.format("%3s\n", regatta.toString()));
|
||||
}
|
||||
|
||||
logger.info("Reading all events...");
|
||||
eventsById.putAll((Map<Serializable, Event>) ois.readObject());
|
||||
logoutput.append("\nReceived " + eventsById.size() + " NEW events\n");
|
||||
|
||||
+30
-2
@@ -5,8 +5,11 @@ import java.net.URI;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.CompetitorAndBoatStore;
|
||||
import com.sap.sailing.domain.base.CompetitorAndBoatStore.CompetitorUpdateListener;
|
||||
import com.sap.sailing.domain.base.CompetitorWithBoat;
|
||||
import com.sap.sailing.domain.base.Nationality;
|
||||
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.PersonImpl;
|
||||
@@ -17,6 +20,18 @@ import com.sap.sailing.server.impl.RacingEventServiceImpl;
|
||||
import com.sap.sse.common.Color;
|
||||
import com.sap.sse.common.Duration;
|
||||
|
||||
/**
|
||||
* Creates a {@link Competitor} if {@link #boatId} is {@code null}, or a {@link CompetitorWithBoat} otherwise. See also
|
||||
* {@link CompetitorAndBoatStore#getOrCreateCompetitor(Serializable, String, String, Color, String, URI, DynamicTeam, Double, Duration, String)}
|
||||
* and
|
||||
* {@link CompetitorAndBoatStore#getOrCreateCompetitorWithBoat(Serializable, String, String, Color, String, URI, DynamicTeam, Double, Duration, String, com.sap.sailing.domain.base.impl.DynamicBoat)},
|
||||
* respectively. This operation assumes that the boat creation has been replicated before the competitor creation in
|
||||
* case a non-{@code null} boat ID has been provided, so the boat is expected to be found by a
|
||||
* {@link CompetitorAndBoatStore#getExistingBoatById(Serializable) lookup by ID}.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class CreateCompetitor extends AbstractRacingEventServiceOperation<Competitor> {
|
||||
private static final long serialVersionUID = 1172181354320184263L;
|
||||
private final Serializable competitorId;
|
||||
@@ -29,10 +44,11 @@ public class CreateCompetitor extends AbstractRacingEventServiceOperation<Compet
|
||||
private final Double timeOnTimeFactor;
|
||||
private final Duration timeOnDistanceAllowancePerNauticalMile;
|
||||
private final String searchTag;
|
||||
private final Serializable boatId;
|
||||
|
||||
public CreateCompetitor(Serializable competitorId, String name, String shortName, Color displayColor,
|
||||
String email, URI flagImageUri, Nationality nationality,
|
||||
Double timeOnTimeFactor, Duration timeOnDistanceAllowancePerNauticalMile, String searchTag) {
|
||||
Double timeOnTimeFactor, Duration timeOnDistanceAllowancePerNauticalMile, String searchTag, Serializable boatId) {
|
||||
super();
|
||||
this.competitorId = competitorId;
|
||||
this.name = name;
|
||||
@@ -44,6 +60,7 @@ public class CreateCompetitor extends AbstractRacingEventServiceOperation<Compet
|
||||
this.timeOnTimeFactor = timeOnTimeFactor;
|
||||
this.timeOnDistanceAllowancePerNauticalMile = timeOnDistanceAllowancePerNauticalMile;
|
||||
this.searchTag = searchTag;
|
||||
this.boatId = boatId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,9 +76,20 @@ public class CreateCompetitor extends AbstractRacingEventServiceOperation<Compet
|
||||
public Competitor internalApplyTo(RacingEventService toState) throws Exception {
|
||||
DynamicPerson sailor = new PersonImpl(name, nationality, null, null);
|
||||
DynamicTeam team = new TeamImpl(name + " team", Collections.singleton(sailor), null);
|
||||
final Competitor result = toState.getBaseDomainFactory().getCompetitorAndBoatStore()
|
||||
final Competitor result;
|
||||
if (boatId == null) {
|
||||
result = toState.getBaseDomainFactory().getCompetitorAndBoatStore()
|
||||
.getOrCreateCompetitor(competitorId, name, shortName, displayColor, email, flagImageUri,
|
||||
team, timeOnTimeFactor, timeOnDistanceAllowancePerNauticalMile, searchTag);
|
||||
} else {
|
||||
final DynamicBoat boat = toState.getBaseDomainFactory().getCompetitorAndBoatStore().getExistingBoatById(boatId);
|
||||
if (boat == null) {
|
||||
throw new IllegalStateException("Boat with ID "+boatId+" not found");
|
||||
}
|
||||
result = toState.getBaseDomainFactory().getCompetitorAndBoatStore()
|
||||
.getOrCreateCompetitorWithBoat(competitorId, name, shortName, displayColor, email, flagImageUri,
|
||||
team, timeOnTimeFactor, timeOnDistanceAllowancePerNauticalMile, searchTag, boat);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user