mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
simplify events for RegattaLog replication
This commit is contained in:
1 parent
6d836fdfe4
commit
27f325e1cd
6 files changed
+64
-51
No files matched your search
+23
@@ -0,0 +1,23 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.domain.leaderboard.FlexibleLeaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public abstract class AbstractRegattaLogOnFlexibleLeaderboardOperation<T> extends AbstractRegattaLogOperation<T> {
|
||||
private static final long serialVersionUID = -1811293351556698801L;
|
||||
|
||||
public AbstractRegattaLogOnFlexibleLeaderboardOperation(String leaderboardName) {
|
||||
super(leaderboardName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RegattaLog getRegattaLog(RacingEventService toState) throws CouldNotResolveRegattaLogException {
|
||||
Leaderboard leaderboard = toState.getLeaderboardByName(regattaLikeParentName);
|
||||
if (! (leaderboard instanceof FlexibleLeaderboard)) {
|
||||
throw new CouldNotResolveRegattaLogException();
|
||||
}
|
||||
return ((FlexibleLeaderboard) leaderboard).getRegattaLog();
|
||||
}
|
||||
}
|
||||
+6
-10
@@ -1,21 +1,17 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public abstract class AbstractRegattaLogOnRegattaOperation<T> extends AbstractRegattaLogOperation<T> {
|
||||
private static final long serialVersionUID = -1811293351556698801L;
|
||||
private final String regattaName;
|
||||
|
||||
public AbstractRegattaLogOnRegattaOperation(String regattaName) {
|
||||
super();
|
||||
this.regattaName = regattaName;
|
||||
super(regattaName);
|
||||
}
|
||||
|
||||
protected String getRegattaName() {
|
||||
return regattaName;
|
||||
}
|
||||
protected Regatta getRegatta(RacingEventService toState) {
|
||||
return toState.getRegattaByName(regattaName);
|
||||
|
||||
@Override
|
||||
protected RegattaLog getRegattaLog(RacingEventService toState) {
|
||||
return toState.getRegattaByName(regattaLikeParentName).getRegattaLog();
|
||||
}
|
||||
}
|
||||
+12
-3
@@ -1,13 +1,22 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
|
||||
public abstract class AbstractRegattaLogOperation<T> extends AbstractRacingEventServiceOperation<T> {
|
||||
|
||||
private static final long serialVersionUID = 2748436647846774234L;
|
||||
|
||||
public AbstractRegattaLogOperation() {
|
||||
protected final String regattaLikeParentName;
|
||||
|
||||
public AbstractRegattaLogOperation(String regattaLikeParentName) {
|
||||
this.regattaLikeParentName = regattaLikeParentName;
|
||||
}
|
||||
|
||||
static final class CouldNotResolveRegattaLogException extends Exception {
|
||||
private static final long serialVersionUID = -634066450023913105L;
|
||||
}
|
||||
|
||||
protected abstract RegattaLog getRegattaLog(RacingEventService toState) throws CouldNotResolveRegattaLogException;
|
||||
|
||||
@Override
|
||||
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public class RecordRegattaLogEventOnFlexibleLeaderboard extends AbstractRegattaLogOnFlexibleLeaderboardOperation<RegattaLogEvent> {
|
||||
private static final long serialVersionUID = -6362628649889525333L;
|
||||
|
||||
private final RegattaLogEvent event;
|
||||
|
||||
public RecordRegattaLogEventOnFlexibleLeaderboard(String flexibleLeaderboardName, RegattaLogEvent event) {
|
||||
super(flexibleLeaderboardName);
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegattaLogEvent internalApplyTo(RacingEventService toState) throws Exception {
|
||||
getRegattaLog(toState).add(event);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
import com.sap.sailing.server.RacingEventService;
|
||||
|
||||
public class RecordRegattaLogEventOnRegatta extends AbstractRegattaLogOnRegattaOperation<RegattaLogEvent> {
|
||||
@@ -16,8 +15,8 @@ public class RecordRegattaLogEventOnRegatta extends AbstractRegattaLogOnRegattaO
|
||||
|
||||
@Override
|
||||
public RegattaLogEvent internalApplyTo(RacingEventService toState) throws Exception {
|
||||
Regatta regatta = getRegatta(toState);
|
||||
return new RegattaLogEventRecorder(event).addEventTo(regatta);
|
||||
getRegattaLog(toState).add(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.sap.sailing.server.operationaltransformation;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLog;
|
||||
import com.sap.sailing.domain.abstractlog.regatta.RegattaLogEvent;
|
||||
import com.sap.sailing.domain.base.Regatta;
|
||||
|
||||
public class RegattaLogEventRecorder implements Serializable {
|
||||
private static final long serialVersionUID = -7097222052117730898L;
|
||||
private final RegattaLogEvent event;
|
||||
|
||||
public RegattaLogEventRecorder(RegattaLogEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
private RegattaLogEvent getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the stored event to the regatta's regattalog.
|
||||
*
|
||||
* @param regatta
|
||||
* to add to.
|
||||
* @return <code>true</code> if add was successful.
|
||||
*/
|
||||
RegattaLogEvent addEventTo(Regatta regatta) {
|
||||
if (regatta != null) {
|
||||
RegattaLog regattaLog = regatta.getRegattaLog();
|
||||
regattaLog.add(getEvent());
|
||||
}
|
||||
return getEvent();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user