mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-25 21:43:49 +00:00
refactored race log replication operations such that now it should be straightforward to introduce a race log reloaded operation
This commit is contained in:
1 parent
79934c22c5
commit
beef855a02
9 files changed
+174
-82
No files matched your search
+12
-7
@@ -9,29 +9,34 @@ import com.sap.sailing.domain.base.Fleet;
|
||||
* <p>
|
||||
* {LeaderboardName / RegattaName} + RaceColumnName + FleetName
|
||||
* <p>
|
||||
* As the components of the RaceLogIdentifier are not available on RaceColumn level, we have to propagate the
|
||||
* As the components of the RaceLogIdentifier are not available on RaceColumn level, we have to propagate the
|
||||
* information in this template data object.
|
||||
*
|
||||
*/
|
||||
public interface RaceLogIdentifierTemplate extends Serializable {
|
||||
|
||||
/**
|
||||
* This method returns the name of parent object of the {@link RaceColumn}. This can be a {@link FlexibleLeaderboard} or a {@link Regatta}.
|
||||
* This method returns the name of parent object of the {@link RaceColumn}. This can be a
|
||||
* {@link FlexibleLeaderboard} or a {@link Regatta}.
|
||||
*
|
||||
* @return the name of the parent object
|
||||
*/
|
||||
String getParentObjectName();
|
||||
|
||||
/**
|
||||
* Compiles the template with giving the last component, the {@link Fleet}, to a RaceLogIdentifier that is used to retrieve the
|
||||
* {@link RaceLogEvent}s from a RaceLogStore
|
||||
* @param fleet the fleet of the race
|
||||
* Compiles the template with giving the last component, the {@link Fleet}, to a RaceLogIdentifier that is used to
|
||||
* retrieve the {@link RaceLogEvent}s from a RaceLogStore
|
||||
*
|
||||
* @param fleet
|
||||
* the fleet of the race
|
||||
* @return the RaceLogIdentifier
|
||||
*/
|
||||
RaceLogIdentifier compileRaceLogIdentifier(Fleet fleet);
|
||||
|
||||
/**
|
||||
* Resolves this RaceLogIdentifier template for replication with the help of the given resolver.
|
||||
* @param resolver the resolver that resolves this template, either for {@link Leaderboard} or for {@link Regatta}.
|
||||
*
|
||||
* @param resolver
|
||||
* the resolver that resolves this template, either for {@link Leaderboard} or for {@link Regatta}.
|
||||
*/
|
||||
void resolve(RaceLogIdentifierTemplateResolver resolver);
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ public class RaceLogReplicator implements RaceColumnListener {
|
||||
@Override
|
||||
public void raceLogEventAdded(final RaceColumn raceColumn, final RaceLogIdentifier identifier, final RaceLogEvent event) {
|
||||
identifier.getTemplate().resolve(new RaceLogIdentifierTemplateResolver() {
|
||||
|
||||
@Override
|
||||
public void resolveOnRegattaIdentifierAndReplicate(RaceLogOnRegattaIdentifier identifierTemplate) {
|
||||
RacingEventServiceOperation<?> operation = new RecordRaceLogEventOnRegatta(
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public abstract class AbstractRaceLogOnLeaderboardOperation extends AbstractRaceLogOperation {
|
||||
private static final long serialVersionUID = -5649159437859782663L;
|
||||
private final String leaderboardName;
|
||||
|
||||
public AbstractRaceLogOnLeaderboardOperation(String leaderboardName, String raceColumnName,
|
||||
String fleetName, RaceLogEvent event) {
|
||||
super(raceColumnName, fleetName, event);
|
||||
this.leaderboardName = leaderboardName;
|
||||
}
|
||||
|
||||
protected RaceColumn getRaceColumn(RacingEventService toState) {
|
||||
Leaderboard leaderboard = toState.getLeaderboardByName(leaderboardName);
|
||||
RaceColumn raceColumn = leaderboard.getRaceColumnByName(getRaceColumnName());
|
||||
return raceColumn;
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public abstract class AbstractRaceLogOnRegattaOperation extends AbstractRaceLogOperation {
|
||||
private static final long serialVersionUID = -7174569054572099191L;
|
||||
private final String regattaName;
|
||||
|
||||
public AbstractRaceLogOnRegattaOperation(String regattaName, String raceColumnName,
|
||||
String fleetName, RaceLogEvent event) {
|
||||
super(raceColumnName, fleetName, event);
|
||||
this.regattaName = regattaName;
|
||||
}
|
||||
|
||||
protected String getRegattaName() {
|
||||
return regattaName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RaceColumn getRaceColumn(RacingEventService toState) {
|
||||
Regatta regatta = toState.getRegattaByName(regattaName);
|
||||
RaceColumn raceColumn = null;
|
||||
for (Series series : regatta.getSeries()) {
|
||||
raceColumn = series.getRaceColumnByName(getRaceColumnName());
|
||||
if (raceColumn != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return raceColumn;
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public abstract class AbstractRaceLogOperation extends AbstractRacingEventServiceOperation<RaceLogEvent> {
|
||||
private static final long serialVersionUID = 2140858355670664173L;
|
||||
|
||||
private final String raceColumnName;
|
||||
private final String fleetName;
|
||||
private final RaceLogEvent event;
|
||||
|
||||
public AbstractRaceLogOperation(String raceColumnName, String fleetName, RaceLogEvent event) {
|
||||
this.raceColumnName = raceColumnName;
|
||||
this.fleetName = fleetName;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected String getRaceColumnName() {
|
||||
return raceColumnName;
|
||||
}
|
||||
|
||||
protected String getFleetName() {
|
||||
return fleetName;
|
||||
}
|
||||
|
||||
protected RaceLogEvent getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
abstract protected RaceColumn getRaceColumn(RacingEventService toState);
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.racelog.RaceLog;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
|
||||
public abstract class AbstractRecordRaceLogEvent extends AbstractRacingEventServiceOperation<RaceLogEvent> {
|
||||
private static final long serialVersionUID = 2140858355670664173L;
|
||||
|
||||
protected final String raceColumnName;
|
||||
private final String fleetName;
|
||||
private final RaceLogEvent event;
|
||||
|
||||
public AbstractRecordRaceLogEvent(String raceColumnName, String fleetName, RaceLogEvent event) {
|
||||
this.raceColumnName = raceColumnName;
|
||||
this.fleetName = fleetName;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the stored event to the race column's race log.
|
||||
* @param raceColumn to add to.
|
||||
* @param fleetName to resolve correct {@link RaceLog}.
|
||||
* @return <code>true</code> if add was successful.
|
||||
*/
|
||||
protected RaceLogEvent addEventTo(RaceColumn raceColumn) {
|
||||
if (raceColumn != null) {
|
||||
Fleet fleet = raceColumn.getFleetByName(fleetName);
|
||||
RaceLog raceLog = raceColumn.getRaceLog(fleet);
|
||||
raceLog.add(event);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sap.sailing.domain.base.Fleet;
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.racelog.RaceLog;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
|
||||
public class RaceLogEventRecorder implements Serializable {
|
||||
private static final long serialVersionUID = -5426128599743917274L;
|
||||
private final String fleetName;
|
||||
private final RaceLogEvent event;
|
||||
|
||||
public RaceLogEventRecorder(String fleetName, RaceLogEvent event) {
|
||||
this.fleetName = fleetName;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
private String getFleetName() {
|
||||
return fleetName;
|
||||
}
|
||||
|
||||
private RaceLogEvent getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the stored event to the race column's race log.
|
||||
*
|
||||
* @param raceColumn
|
||||
* to add to.
|
||||
* @param fleetName
|
||||
* to resolve correct {@link RaceLog}.
|
||||
* @return <code>true</code> if add was successful.
|
||||
*/
|
||||
RaceLogEvent addEventTo(RaceColumn raceColumn) {
|
||||
if (raceColumn != null) {
|
||||
Fleet fleet = raceColumn.getFleetByName(getFleetName());
|
||||
RaceLog raceLog = raceColumn.getRaceLog(fleet);
|
||||
raceLog.add(getEvent());
|
||||
}
|
||||
return getEvent();
|
||||
}
|
||||
}
|
||||
+4
-21
@@ -1,37 +1,20 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.RaceColumn;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public class RecordRaceLogEventOnLeaderboard extends AbstractRecordRaceLogEvent {
|
||||
public class RecordRaceLogEventOnLeaderboard extends AbstractRaceLogOnLeaderboardOperation {
|
||||
private static final long serialVersionUID = 1008913415922358665L;
|
||||
|
||||
private final String leaderboardName;
|
||||
|
||||
public RecordRaceLogEventOnLeaderboard(String leaderboardName, String raceColumnName,
|
||||
String fleetName, RaceLogEvent event) {
|
||||
super(raceColumnName, fleetName, event);
|
||||
this.leaderboardName = leaderboardName;
|
||||
super(leaderboardName, raceColumnName, fleetName, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceLogEvent internalApplyTo(RacingEventService toState) throws Exception {
|
||||
Leaderboard leaderboard = toState.getLeaderboardByName(leaderboardName);
|
||||
RaceColumn raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
|
||||
return addEventTo(raceColumn);
|
||||
RaceColumn raceColumn = getRaceColumn(toState);
|
||||
return new RaceLogEventRecorder(getFleetName(), getEvent()).addEventTo(raceColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+9
-17
@@ -5,40 +5,32 @@ import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.base.Series;
|
||||
import com.sap.sailing.domain.racelog.RaceLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public class RecordRaceLogEventOnRegatta extends AbstractRecordRaceLogEvent {
|
||||
public class RecordRaceLogEventOnRegatta extends AbstractRaceLogOnRegattaOperation {
|
||||
private static final long serialVersionUID = 8092146834280389864L;
|
||||
|
||||
private final String regattaName;
|
||||
|
||||
public RecordRaceLogEventOnRegatta(String regattaName, String raceColumnName,
|
||||
String fleetName, RaceLogEvent event) {
|
||||
super(raceColumnName, fleetName, event);
|
||||
this.regattaName = regattaName;
|
||||
super(regattaName, raceColumnName, fleetName, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceLogEvent internalApplyTo(RacingEventService toState) throws Exception {
|
||||
Regatta regatta = toState.getRegattaByName(regattaName);
|
||||
protected RaceColumn getRaceColumn(RacingEventService toState) {
|
||||
Regatta regatta = toState.getRegattaByName(getRegattaName());
|
||||
RaceColumn raceColumn = null;
|
||||
for (Series series : regatta.getSeries()) {
|
||||
raceColumn = series.getRaceColumnByName(raceColumnName);
|
||||
raceColumn = series.getRaceColumnByName(getRaceColumnName());
|
||||
if (raceColumn != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return addEventTo(raceColumn);
|
||||
return raceColumn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
|
||||
return null;
|
||||
public RaceLogEvent internalApplyTo(RacingEventService toState) throws Exception {
|
||||
RaceColumn raceColumn = getRaceColumn(toState);
|
||||
return new RaceLogEventRecorder(getFleetName(), getEvent()).addEventTo(raceColumn);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user