refactored SailingServiceImpl to use the RacingEventServiceOperations for ops requiring replication

This commit is contained in:
Axel Uhl
2012-04-20 16:00:14 +02:00
parent 6380d8709a
commit 34124bdd4c
40 changed files with 412 additions and 280 deletions
@@ -41,8 +41,8 @@ import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventNameAndRaceName;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.EventDisplayer;
@@ -846,7 +846,7 @@ public class LeaderboardConfigPanel extends FormPanel implements EventDisplayer,
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
// if no leaderboard column is selected, ignore the race selection change
RaceInLeaderboardDTO selectedRaceInLeaderboard = getSelectedRaceInLeaderboard();
if (selectedRaceInLeaderboard != null) {
@@ -859,7 +859,7 @@ public class LeaderboardConfigPanel extends FormPanel implements EventDisplayer,
}
private void linkTrackedRaceToSelectedRaceColumn(final RaceInLeaderboardDTO selectedRaceInLeaderboard,
final RaceIdentifier selectedRace) {
final EventAndRaceIdentifier selectedRace) {
sailingService.connectTrackedRaceToLeaderboardColumn(getSelectedLeaderboardName(), selectedRaceInLeaderboard
.getRaceColumnName(), selectedRace,
new AsyncCallback<Boolean>() {
@@ -15,6 +15,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.client.EventDisplayer;
import com.sap.sailing.gwt.ui.client.EventRefresher;
@@ -93,8 +94,8 @@ public class RacesListBoxPanel extends FormPanel implements EventDisplayer, Race
raceSelectionProvider.setSelection(getSelectedRaceIdentifiers(), this);
}
private List<RaceIdentifier> getSelectedRaceIdentifiers() {
List<RaceIdentifier> result = new ArrayList<RaceIdentifier>();
private List<EventAndRaceIdentifier> getSelectedRaceIdentifiers() {
List<EventAndRaceIdentifier> result = new ArrayList<EventAndRaceIdentifier>();
for (RaceDTO selectedRace : getSelectedRaces()) {
result.add(selectedRace.getRaceIdentifier());
}
@@ -118,7 +119,7 @@ public class RacesListBoxPanel extends FormPanel implements EventDisplayer, Race
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
if (selectedRaces != null && !selectedRaces.isEmpty()) {
RaceDTO newSelection = getRace(selectedRaces.iterator().next());
int index = raceList.indexOf(newSelection);
@@ -42,6 +42,7 @@ import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SelectionModel;
import com.google.gwt.view.client.SingleSelectionModel;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventNameAndRaceName;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
@@ -313,7 +314,7 @@ public class TrackedEventsComposite extends FormPanel implements EventDisplayer,
if (dontFireNextSelectionChangeEvent) {
dontFireNextSelectionChangeEvent = false;
} else {
List<RaceIdentifier> selectedRaceIdentifiers = new ArrayList<RaceIdentifier>();
List<EventAndRaceIdentifier> selectedRaceIdentifiers = new ArrayList<EventAndRaceIdentifier>();
for (RaceDTO selectedRace : selectedRaces) {
selectedRaceIdentifiers.add(selectedRace.getRaceIdentifier());
}
@@ -385,7 +386,7 @@ public class TrackedEventsComposite extends FormPanel implements EventDisplayer,
}
public void clearSelection() {
List<RaceIdentifier> emptySelection = Collections.emptyList();
List<EventAndRaceIdentifier> emptySelection = Collections.emptyList();
raceSelectionProvider.setSelection(emptySelection, /* listenersNotToNotify */ this);
if (raceList != null) {
for (RaceDTO race : raceList.getList()) {
@@ -410,7 +411,7 @@ public class TrackedEventsComposite extends FormPanel implements EventDisplayer,
noTrackedRacesLabel.setVisible(false);
}
List<RaceDTO> newAllRaces = new ArrayList<RaceDTO>();
List<RaceIdentifier> newAllRaceIdentifiers = new ArrayList<RaceIdentifier>();
List<EventAndRaceIdentifier> newAllRaceIdentifiers = new ArrayList<EventAndRaceIdentifier>();
for (EventDTO event : events) {
for (RegattaDTO regatta : event.regattas) {
for (RaceDTO race : regatta.races) {
@@ -500,7 +501,7 @@ public class TrackedEventsComposite extends FormPanel implements EventDisplayer,
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
for (RaceDTO raceFromAllRaces : raceList.getList()) {
selectionModel.setSelected(raceFromAllRaces, selectedRaces.contains(raceFromAllRaces.getRaceIdentifier()));
}
@@ -35,6 +35,7 @@ import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
@@ -493,7 +494,7 @@ public class WindChart extends SimpleChartPanel implements Component<WindChartSe
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
if (selectedRaces != null && !selectedRaces.isEmpty()) {
// show wind of first selected race
selectedRaceIdentifier = selectedRaces.iterator().next();
@@ -36,7 +36,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
@@ -96,8 +96,8 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
removeColumn = new IdentityColumn<WindDTO>(new ActionCell<WindDTO>(stringMessages.remove(), new Delegate<WindDTO>() {
@Override
public void execute(final WindDTO wind) {
List<RaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
final RaceIdentifier raceIdentifier = selectedRaces.get(selectedRaces.size()-1);
List<EventAndRaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
final EventAndRaceIdentifier raceIdentifier = selectedRaces.get(selectedRaces.size()-1);
sailingService.removeWind(raceIdentifier, wind, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
@@ -188,7 +188,7 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
this.setWidget(grid);
}
private void clearOrShowWindBasedOnRaceSelection(List<RaceIdentifier> selectedRaces) {
private void clearOrShowWindBasedOnRaceSelection(List<EventAndRaceIdentifier> selectedRaces) {
if (selectedRaces.isEmpty()) {
clearWindDisplay(); // no wind known for untracked race
} else {
@@ -202,7 +202,7 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
}
@Override
public void showWind(final RaceIdentifier raceIdentifier) {
public void showWind(final EventAndRaceIdentifier raceIdentifier) {
sailingService.getWindInfo(raceIdentifier,
// TODO Time interval should be determined by a selection in the chart but be at most 60s. See bug #121. Consider incremental updates for new data only.
null, null, // use race start and time of newest event as default time period
@@ -228,7 +228,7 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
});
}
private void updateWindSourcesToExclude(WindInfoForRaceDTO result, RaceIdentifier raceIdentifier) {
private void updateWindSourcesToExclude(WindInfoForRaceDTO result, EventAndRaceIdentifier raceIdentifier) {
windSourcesToExcludeSelector.update(raceIdentifier, result.windTrackInfoByWindSource.keySet(), result.windSourcesToExclude);
}
@@ -338,9 +338,9 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
}
private void setRaceIsKnownToStartUpwind(final Runnable runOnSuccess) {
List<RaceIdentifier> selection = raceSelectionProvider.getSelectedRaces();
List<EventAndRaceIdentifier> selection = raceSelectionProvider.getSelectedRaces();
if (selection != null && !selection.isEmpty()) {
final RaceIdentifier selectedRace = selection.get(0);
final EventAndRaceIdentifier selectedRace = selection.get(0);
sailingService.setRaceIsKnownToStartUpwind(selectedRace,
raceIsKnownToStartUpwindBox.getValue(), new AsyncCallback<Void>() {
@Override
@@ -359,7 +359,7 @@ public class WindPanel extends FormPanel implements EventDisplayer, WindShower,
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
clearOrShowWindBasedOnRaceSelection(selectedRaces);
}
}
@@ -10,7 +10,7 @@ import com.google.gwt.user.client.ui.DoubleBox;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.gwt.ui.client.AbstractEntryPoint;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.RaceSelectionProvider;
@@ -51,9 +51,9 @@ public class WindSettingPanel extends FormPanel {
if (latDegBox.getValue() != null && lngDegBox.getValue() != null) {
wind.position = new PositionDTO(latDegBox.getValue(), lngDegBox.getValue());
}
List<RaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
List<EventAndRaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
// Here we assume that single selection is enabled because the WindPanel creates a TrackedComposite with disabled multi selection.
final RaceIdentifier raceIdentifier = selectedRaces.get(selectedRaces.size()-1);
final EventAndRaceIdentifier raceIdentifier = selectedRaces.get(selectedRaces.size()-1);
sailingService.setWind(raceIdentifier, wind, new AsyncCallback<Void>() {
@Override
public void onSuccess(Void result) {
@@ -1,9 +1,7 @@
package com.sap.sailing.gwt.ui.adminconsole;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
public interface WindShower {
void showWind(RaceIdentifier race);
void showWind(EventAndRaceIdentifier race);
}
@@ -11,7 +11,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.SailingServiceAsync;
@@ -31,7 +31,7 @@ public class WindSourcesToExcludeSelector extends VerticalPanel {
private final StringMessages stringMessages;
private final SailingServiceAsync service;
private final ErrorReporter errorReporter;
private RaceIdentifier raceIdentifier;
private EventAndRaceIdentifier raceIdentifier;
public WindSourcesToExcludeSelector(SailingServiceAsync service,
StringMessages stringMessages, ErrorReporter errorReporter) {
@@ -42,7 +42,7 @@ public class WindSourcesToExcludeSelector extends VerticalPanel {
add(new Label(stringMessages.windSourcesUsed()));
}
public void update(RaceIdentifier raceIdentifier, Iterable<WindSource> allWindSources, Iterable<WindSource> windSourcesToExclude) {
public void update(EventAndRaceIdentifier raceIdentifier, Iterable<WindSource> allWindSources, Iterable<WindSource> windSourcesToExclude) {
this.raceIdentifier = raceIdentifier;
Set<WindSource> windSourcesToRemove = new HashSet<WindSource>(checkboxesByWindSource.keySet());
for (WindSource windSource : allWindSources) {
@@ -73,7 +73,7 @@ public class WindSourcesToExcludeSelector extends VerticalPanel {
}
}
private void onWindSourcesToExcludeChanged(final RaceIdentifier raceIdentifier) {
private void onWindSourcesToExcludeChanged(final EventAndRaceIdentifier raceIdentifier) {
service.setWindSourcesToExclude(raceIdentifier, getWindSourcesToExclude(), new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable e) {
@@ -2,7 +2,7 @@ package com.sap.sailing.gwt.ui.client;
import java.util.List;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
/**
@@ -18,6 +18,6 @@ public interface RaceSelectionChangeListener {
*
* @param selectedRaces a non-<code>null</code> list which is empty if nothing is selected
*/
void onRaceSelectionChange(List<RaceIdentifier> selectedRaces);
void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces);
}
@@ -8,23 +8,24 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
public class RaceSelectionModel implements RaceSelectionProvider {
private final List<RaceIdentifier> selection;
private final List<EventAndRaceIdentifier> selection;
private final List<RaceIdentifier> allRaces;
private final List<EventAndRaceIdentifier> allRaces;
private final Set<RaceSelectionChangeListener> listeners;
public RaceSelectionModel() {
this.selection = new ArrayList<RaceIdentifier>();
this.allRaces = new ArrayList<RaceIdentifier>();
this.selection = new ArrayList<EventAndRaceIdentifier>();
this.allRaces = new ArrayList<EventAndRaceIdentifier>();
listeners = new HashSet<RaceSelectionChangeListener>();
}
@Override
public List<RaceIdentifier> getSelectedRaces() {
public List<EventAndRaceIdentifier> getSelectedRaces() {
return Collections.unmodifiableList(selection);
}
@@ -39,7 +40,7 @@ public class RaceSelectionModel implements RaceSelectionProvider {
}
@Override
public void setSelection(List<RaceIdentifier> newSelection, RaceSelectionChangeListener... listenersNotToNotify) {
public void setSelection(List<EventAndRaceIdentifier> newSelection, RaceSelectionChangeListener... listenersNotToNotify) {
boolean notify = !selection.equals(newSelection);
selection.clear();
selection.addAll(newSelection);
@@ -49,7 +50,7 @@ public class RaceSelectionModel implements RaceSelectionProvider {
}
private void notifyListeners(RaceSelectionChangeListener[] listenersNotToNotify) {
List<RaceIdentifier> selectedRaces = getSelectedRaces();
List<EventAndRaceIdentifier> selectedRaces = getSelectedRaces();
for (RaceSelectionChangeListener listener : listeners) {
if (listenersNotToNotify == null || !Arrays.asList(listenersNotToNotify).contains(listener)) {
listener.onRaceSelectionChange(selectedRaces);
@@ -63,13 +64,13 @@ public class RaceSelectionModel implements RaceSelectionProvider {
* <code>newAllRaces</code> are removed from the selection. If this happens, the selection listeners are notified.
*/
@Override
public void setAllRaces(List<RaceIdentifier> newAllRaces, RaceSelectionChangeListener... listenersNotToNotify) {
public void setAllRaces(List<EventAndRaceIdentifier> newAllRaces, RaceSelectionChangeListener... listenersNotToNotify) {
allRaces.clear();
for (RaceIdentifier r : newAllRaces) {
for (EventAndRaceIdentifier r : newAllRaces) {
allRaces.add(r);
}
boolean notify = false;
for (Iterator<RaceIdentifier> i=selection.iterator(); i.hasNext(); ) {
for (Iterator<EventAndRaceIdentifier> i=selection.iterator(); i.hasNext(); ) {
RaceIdentifier selectedRace = i.next();
if (!allRaces.contains(selectedRace)) {
notify = true;
@@ -82,7 +83,7 @@ public class RaceSelectionModel implements RaceSelectionProvider {
}
@Override
public List<RaceIdentifier> getAllRaces() {
public List<EventAndRaceIdentifier> getAllRaces() {
return Collections.unmodifiableList(allRaces);
}
@@ -2,24 +2,24 @@ package com.sap.sailing.gwt.ui.client;
import java.util.List;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
public interface RaceSelectionProvider {
/**
* @return a non-<code>null</code> list which may be empty
*/
List<RaceIdentifier> getSelectedRaces();
List<EventAndRaceIdentifier> getSelectedRaces();
void addRaceSelectionChangeListener(RaceSelectionChangeListener listener);
void removeRaceSelectionChangeListener(RaceSelectionChangeListener listener);
void setSelection(List<RaceIdentifier> newSelection, RaceSelectionChangeListener... listenersNotToNotify);
void setSelection(List<EventAndRaceIdentifier> newSelection, RaceSelectionChangeListener... listenersNotToNotify);
/**
* @return a non-<code>null</code> list which may be empty
*/
List<RaceIdentifier> getAllRaces();
List<EventAndRaceIdentifier> getAllRaces();
void setAllRaces(List<RaceIdentifier> newAllRaces, RaceSelectionChangeListener... listenersNotToNotify);
void setAllRaces(List<EventAndRaceIdentifier> newAllRaces, RaceSelectionChangeListener... listenersNotToNotify);
}
@@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.client.Timer.PlayModes;
import com.sap.sailing.gwt.ui.client.Timer.PlayStates;
@@ -86,7 +87,7 @@ public class RaceTimePanel extends TimePanel<RaceTimePanelSettings> implements R
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
if (selectedRaces != null && !selectedRaces.isEmpty()) {
selectedRace = selectedRaces.iterator().next();
if (!raceTimesInfoProvider.containsRaceIdentifier(selectedRace)) {
@@ -11,6 +11,7 @@ import java.util.Set;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.RepeatingCommand;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.shared.RaceTimesInfoDTO;
@@ -29,7 +30,7 @@ public class RaceTimesInfoProvider {
/**
* The <code>raceIdentifiers</code> has to be <code>not-null</code>, but can be empty.
*/
public RaceTimesInfoProvider(SailingServiceAsync sailingService, ErrorReporter errorReporter, Collection<RaceIdentifier> raceIdentifiers, long requestInterval) {
public RaceTimesInfoProvider(SailingServiceAsync sailingService, ErrorReporter errorReporter, Collection<EventAndRaceIdentifier> raceIdentifiers, long requestInterval) {
this.sailingService = sailingService;
this.errorReporter = errorReporter;
this.raceIdentifiers = new HashSet<RaceIdentifier>(raceIdentifiers);
@@ -130,7 +130,7 @@ public interface SailingService extends RemoteService {
String raceColumnName, MaxPointsReason maxPointsReason, Date date) throws NoWindException;
Pair<Integer, Integer> updateLeaderboardScoreCorrection(String leaderboardName, String competitorIdAsString,
String raceName, Integer correctedScore, Date date) throws NoWindException;
String columnName, Integer correctedScore, Date date) throws NoWindException;
void updateCompetitorDisplayNameInLeaderboard(String leaderboardName, String competitorIdAsString, String displayName);
@@ -175,7 +175,7 @@ public interface SailingService extends RemoteService {
Date toDate, long stepSize, DetailType detailType)
throws NoWindException;
void setRaceIsKnownToStartUpwind(RaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind);
void setRaceIsKnownToStartUpwind(EventAndRaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind);
void setWindSourcesToExclude(RaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude);
void setWindSourcesToExclude(EventAndRaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude);
}
@@ -305,10 +305,10 @@ public interface SailingServiceAsync {
void getCompetitorsRaceData(RaceIdentifier race, List<Pair<Date,CompetitorDTO>> competitorsToLoad, Date toDate, long stepSize,
DetailType detailType, AsyncCallback<MultiCompetitorRaceDataDTO> callback);
void setRaceIsKnownToStartUpwind(RaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind,
void setRaceIsKnownToStartUpwind(EventAndRaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind,
AsyncCallback<Void> callback);
void setWindSourcesToExclude(RaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude,
void setWindSourcesToExclude(EventAndRaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude,
AsyncCallback<Void> callback);
void getRaceMapData(RaceIdentifier raceIdentifier, Date date, Map<CompetitorDTO, Date> from,
@@ -10,6 +10,7 @@ import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.common.WindSourceType;
@@ -147,7 +148,7 @@ public class SmallWindHistoryPanel extends FormPanel implements TimeListener, Ra
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
if (!selectedRaces.isEmpty()) {
race = selectedRaces.get(selectedRaces.size() - 1);
updateWindDisplay();
@@ -35,6 +35,7 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.DetailType;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.common.impl.Util.Triple;
@@ -136,7 +137,7 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
}
});
List<RaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
List<EventAndRaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
if(!selectedRaces.isEmpty()) {
loadData(true);
}
@@ -307,7 +308,7 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
private RaceIdentifier getSelectedRace() {
RaceIdentifier result = null;
List<RaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
List<EventAndRaceIdentifier> selectedRaces = raceSelectionProvider.getSelectedRaces();
if (selectedRaces != null && !selectedRaces.isEmpty()) {
result = selectedRaces.iterator().next();
}
@@ -565,7 +566,7 @@ implements CompetitorSelectionChangeListener, RaceSelectionChangeListener, TimeL
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
setChartData(null);
clearChart();
timeLineNeedsUpdate = true;
@@ -20,7 +20,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.client.CompetitorSelectionProvider;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
@@ -48,7 +48,7 @@ public class CompareCompetitorsChartDialog extends DialogBox {
private final CollapsablePanel collapsablePanel;
public CompareCompetitorsChartDialog(SailingServiceAsync sailingService,
List<RaceIdentifier> races, final CompetitorSelectionProvider competitorSelectionProvider, Timer timer,
List<EventAndRaceIdentifier> races, final CompetitorSelectionProvider competitorSelectionProvider, Timer timer,
StringMessages stringConstants, ErrorReporter errorReporter) {
super(false);
raceSelectionProvider = new RaceSelectionModel();
@@ -118,7 +118,7 @@ public class CompareCompetitorsChartDialog extends DialogBox {
HorizontalPanel raceChooserPanel = new HorizontalPanel();
raceChooserPanel.setSpacing(5);
boolean first = true;
for (final RaceIdentifier selectedRace : raceSelectionProvider.getAllRaces()) {
for (final EventAndRaceIdentifier selectedRace : raceSelectionProvider.getAllRaces()) {
RadioButton raceSelectionRadioButton = new RadioButton("chooseRace");
raceSelectionRadioButton.setText(selectedRace.toString());
raceChooserPanel.add(raceSelectionRadioButton);
@@ -138,7 +138,7 @@ public class CompareCompetitorsChartDialog extends DialogBox {
}
private void selectRace(final RaceIdentifier selectedRace) {
private void selectRace(final EventAndRaceIdentifier selectedRace) {
if(selectedRace != null)
collapsablePanel.getHeaderTextAccessor().setText(selectedRace.getRaceName());
else
@@ -45,6 +45,7 @@ import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SelectionModel;
import com.sap.sailing.domain.common.DetailType;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.actions.GetLeaderboardByNameAction;
@@ -1634,14 +1635,14 @@ public class LeaderboardPanel extends FormPanel implements TimeListener, PlaySta
}
private void compareCompetitors() {
List<RaceIdentifier> races = getTrackedRacesIdentifiers();
List<EventAndRaceIdentifier> races = getTrackedRacesIdentifiers();
CompareCompetitorsChartDialog chartDialog = new CompareCompetitorsChartDialog(sailingService, races,
competitorSelectionProvider, timer, stringMessages, errorReporter);
chartDialog.show();
}
private List<RaceIdentifier> getTrackedRacesIdentifiers() {
List<RaceIdentifier> result = new ArrayList<RaceIdentifier>();
private List<EventAndRaceIdentifier> getTrackedRacesIdentifiers() {
List<EventAndRaceIdentifier> result = new ArrayList<EventAndRaceIdentifier>();
for (RaceInLeaderboardDTO raceColumn : getLeaderboard().getRaceList()) {
if (raceColumn.getRaceIdentifier() != null) {
result.add(raceColumn.getRaceIdentifier());
@@ -11,6 +11,7 @@ import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
import com.sap.sailing.gwt.ui.client.CompetitorSelectionModel;
@@ -51,7 +52,7 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
private Label raceBoardHeader;
private RaceBoardPanel raceBoardPanel;
private FlowPanel timePanel;
private RaceIdentifier currentRace;
private EventAndRaceIdentifier currentRace;
private boolean raceBoardIsWidget;
public TVViewPanel(SailingServiceAsync sailingService, StringMessages stringMessages, ErrorReporter errorReporter,
@@ -72,7 +73,7 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
timePanel = null;
timer.play();
raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, errorReporter, new ArrayList<RaceIdentifier>(), 1000l);
raceTimesInfoProvider = new RaceTimesInfoProvider(sailingService, errorReporter, new ArrayList<EventAndRaceIdentifier>(), 1000l);
raceTimesInfoProvider.addRaceTimesInfoProviderListener(this);
leaderboardPanel = createLeaderboardPanel(leaderboardName);
@@ -112,9 +113,9 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
}
}
private RaceBoardPanel createRaceBoardPanel(String leaderboardName, RaceIdentifier raceToShow) {
private RaceBoardPanel createRaceBoardPanel(String leaderboardName, EventAndRaceIdentifier raceToShow) {
RaceSelectionModel raceSelectionModel = new RaceSelectionModel();
List<RaceIdentifier> singletonList = Collections.singletonList(raceToShow);
List<EventAndRaceIdentifier> singletonList = Collections.singletonList(raceToShow);
raceSelectionModel.setSelection(singletonList);
RaceBoardPanel raceBoardPanel = new RaceBoardPanel(sailingService, userDTO, timer, raceSelectionModel, leaderboardName, null,
errorReporter, stringMessages, userAgentType, RaceBoardViewModes.ONESCREEN, raceTimesInfoProvider);
@@ -216,11 +217,11 @@ public class TVViewPanel extends SimplePanel implements RaceTimesInfoProviderLis
}
}
private RaceIdentifier getFirstStartedAndUnfinishedRace() {
RaceIdentifier firstStartedAndUnfinishedRace = null;
private EventAndRaceIdentifier getFirstStartedAndUnfinishedRace() {
EventAndRaceIdentifier firstStartedAndUnfinishedRace = null;
Map<RaceIdentifier, RaceTimesInfoDTO> raceTimesInfos = raceTimesInfoProvider.getRaceTimesInfos();
for (RaceInLeaderboardDTO race : leaderboard.getRaceList()) {
RaceIdentifier raceIdentifier = race.getRaceIdentifier();
EventAndRaceIdentifier raceIdentifier = race.getRaceIdentifier();
RaceTimesInfoDTO raceTimes = raceTimesInfos.get(raceIdentifier);
if (raceIdentifier != null && raceTimes != null && raceTimes.startOfTracking != null
&& raceTimes.endOfRace == null) {
@@ -13,7 +13,7 @@ import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.DefaultLeaderboardName;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.gwt.ui.client.AbstractEntryPoint;
import com.sap.sailing.gwt.ui.client.LogoAndTitlePanel;
@@ -132,7 +132,7 @@ public class RaceBoardEntryPoint extends AbstractEntryPoint {
}
RaceSelectionModel raceSelectionModel = new RaceSelectionModel();
List<RaceIdentifier> singletonList = Collections.singletonList(selectedRace.getRaceIdentifier());
List<EventAndRaceIdentifier> singletonList = Collections.singletonList(selectedRace.getRaceIdentifier());
raceSelectionModel.setSelection(singletonList);
Timer timer = new Timer(PlayModes.Replay, 1000l);
RaceBoardPanel raceBoardPanel = new RaceBoardPanel(sailingService, user, timer, raceSelectionModel, leaderboardName, leaderboardGroupName,
@@ -20,6 +20,7 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.WindSourceType;
import com.sap.sailing.gwt.ui.actions.AsyncActionsExecutor;
@@ -87,7 +88,7 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
private final RaceSelectionProvider raceSelectionProvider;
private final UserAgentTypes userAgentType;
private final CompetitorSelectionModel competitorSelectionModel;
private final RaceIdentifier selectedRaceIdentifier;
private final EventAndRaceIdentifier selectedRaceIdentifier;
private LeaderboardPanel leaderboardPanel;
private WindChart windChart;
@@ -482,7 +483,7 @@ public class RaceBoardPanel extends FormPanel implements EventDisplayer, RaceSel
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
}
}
@@ -81,7 +81,6 @@ import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.Leaderboard.Entry;
import com.sap.sailing.domain.leaderboard.LeaderboardGroup;
import com.sap.sailing.domain.leaderboard.RaceInLeaderboard;
import com.sap.sailing.domain.leaderboard.impl.ResultDiscardingRuleImpl;
import com.sap.sailing.domain.persistence.DomainObjectFactory;
import com.sap.sailing.domain.persistence.MongoObjectFactory;
import com.sap.sailing.domain.persistence.MongoWindStoreFactory;
@@ -141,8 +140,29 @@ import com.sap.sailing.gwt.ui.shared.WindInfoForRaceDTO;
import com.sap.sailing.gwt.ui.shared.WindTrackInfoDTO;
import com.sap.sailing.server.RacingEventService;
import com.sap.sailing.server.operationaltransformation.AddColumnToLeaderboard;
import com.sap.sailing.server.operationaltransformation.ConnectTrackedRaceToLeaderboardColumn;
import com.sap.sailing.server.operationaltransformation.CreateLeaderboard;
import com.sap.sailing.server.operationaltransformation.CreateLeaderboardGroup;
import com.sap.sailing.server.operationaltransformation.DisconnectLeaderboardColumnFromTrackedRace;
import com.sap.sailing.server.operationaltransformation.MoveLeaderboardColumnDown;
import com.sap.sailing.server.operationaltransformation.MoveLeaderboardColumnUp;
import com.sap.sailing.server.operationaltransformation.RemoveAndUntrackRace;
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboard;
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboardColumn;
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboardGroup;
import com.sap.sailing.server.operationaltransformation.RenameLeaderboard;
import com.sap.sailing.server.operationaltransformation.RenameLeaderboardColumn;
import com.sap.sailing.server.operationaltransformation.RenameLeaderboardGroup;
import com.sap.sailing.server.operationaltransformation.SetRaceIsKnownToStartUpwind;
import com.sap.sailing.server.operationaltransformation.SetWindSourcesToExclude;
import com.sap.sailing.server.operationaltransformation.StopTrackingEvent;
import com.sap.sailing.server.operationaltransformation.UpdateCompetitorDisplayNameInLeaderboard;
import com.sap.sailing.server.operationaltransformation.UpdateIsMedalRace;
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboard;
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardCarryValue;
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardGroup;
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardMaxPointsReason;
import com.sap.sailing.server.operationaltransformation.UpdateLeaderboardScoreCorrection;
/**
* The server side implementation of the RPC service.
@@ -207,7 +227,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
result.name = leaderboard.getName();
result.competitorDisplayNames = new HashMap<CompetitorDTO, String>();
for (RaceInLeaderboard raceColumn : leaderboard.getRaceColumns()) {
RaceIdentifier raceIdentifier = null;
EventAndRaceIdentifier raceIdentifier = null;
if (raceColumn.getTrackedRace() != null) {
TrackedRace trackedRace = raceColumn.getTrackedRace();
raceIdentifier = new EventNameAndRaceName(trackedRace.getTrackedEvent().getEvent().getName(), trackedRace.getRace().getName());
@@ -497,10 +517,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public void stopTrackingEvent(EventIdentifier eventIdentifier) throws Exception {
Event event = getEvent(eventIdentifier);
if (event != null) {
getService().stopTracking(event);
}
getService().apply(new StopTrackingEvent(eventIdentifier));
}
private RaceDefinition getRaceByName(Event event, String raceName) {
@@ -513,24 +530,12 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public void stopTrackingRace(EventAndRaceIdentifier eventAndRaceIdentifier) throws Exception {
Event event = getEvent(eventAndRaceIdentifier);
if (event != null) {
RaceDefinition r = getRace(eventAndRaceIdentifier);
if (r != null) {
getService().stopTracking(event, r);
}
}
getService().apply(new StopTrackingEvent(eventAndRaceIdentifier));
}
@Override
public void removeAndUntrackRace(EventAndRaceIdentifier eventAndRaceidentifier) throws Exception{
Event event = getEvent(eventAndRaceidentifier);
if (event!= null) {
RaceDefinition race = getRace(eventAndRaceidentifier);
if (race != null) {
getService().removeRace(event, race);
}
}
public void removeAndUntrackRace(EventAndRaceIdentifier eventAndRaceidentifier) {
getService().apply(new RemoveAndUntrackRace(eventAndRaceidentifier));
}
/**
@@ -1046,19 +1051,13 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
}
@Override
public void setRaceIsKnownToStartUpwind(RaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind) {
DynamicTrackedRace trackedRace = (DynamicTrackedRace) getExistingTrackedRace(raceIdentifier);
if (trackedRace != null) {
trackedRace.setRaceIsKnownToStartUpwind(raceIsKnownToStartUpwind);
}
public void setRaceIsKnownToStartUpwind(EventAndRaceIdentifier raceIdentifier, boolean raceIsKnownToStartUpwind) {
getService().apply(new SetRaceIsKnownToStartUpwind(raceIdentifier, raceIsKnownToStartUpwind));
}
@Override
public void setWindSourcesToExclude(RaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude) {
DynamicTrackedRace trackedRace = (DynamicTrackedRace) getExistingTrackedRace(raceIdentifier);
if (trackedRace != null) {
trackedRace.setWindSourcesToExclude(windSourcesToExclude);
}
public void setWindSourcesToExclude(EventAndRaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude) {
getService().apply(new SetWindSourcesToExclude(raceIdentifier, windSourcesToExclude));
}
@Override
@@ -1109,7 +1108,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public LeaderboardDTO createLeaderboard(String leaderboardName, int[] discardThresholds) {
return createStrippedLeaderboardDTO(getService().addLeaderboard(leaderboardName, discardThresholds), false);
return createStrippedLeaderboardDTO(getService().apply(new CreateLeaderboard(leaderboardName, discardThresholds)), false);
}
@Override
@@ -1172,7 +1171,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
dto.name = leaderboard.getName();
dto.competitorDisplayNames = new HashMap<CompetitorDTO, String>();
for (RaceInLeaderboard raceColumn : leaderboard.getRaceColumns()) {
RaceIdentifier raceIdentifier = null;
EventAndRaceIdentifier raceIdentifier = null;
StrippedRaceDTO race = null;
if(raceColumn.getTrackedRace() != null) {
TrackedRace trackedRace = raceColumn.getTrackedRace();
@@ -1271,24 +1270,17 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public void updateLeaderboard(String leaderboardName, String newLeaderboardName, int[] newDiscardingThresholds) {
if (!leaderboardName.equals(newLeaderboardName)) {
getService().renameLeaderboard(leaderboardName, newLeaderboardName);
}
Leaderboard leaderboard = getService().getLeaderboardByName(newLeaderboardName);
if (!Arrays.equals(leaderboard.getResultDiscardingRule().getDiscardIndexResultsStartingWithHowManyRaces(), newDiscardingThresholds)) {
leaderboard.setResultDiscardingRule(new ResultDiscardingRuleImpl(newDiscardingThresholds));
}
getService().updateStoredLeaderboard(leaderboard);
getService().apply(new UpdateLeaderboard(leaderboardName, newLeaderboardName, newDiscardingThresholds));
}
@Override
public void removeLeaderboard(String leaderboardName) {
getService().removeLeaderboard(leaderboardName);
getService().apply(new RemoveLeaderboard(leaderboardName));
}
@Override
public void renameLeaderboard(String leaderboardName, String newLeaderboardName) {
getService().renameLeaderboard(leaderboardName, newLeaderboardName);
getService().apply(new RenameLeaderboard(leaderboardName, newLeaderboardName));
}
@Override
@@ -1308,21 +1300,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public boolean connectTrackedRaceToLeaderboardColumn(String leaderboardName, String raceColumnName, RaceIdentifier raceIdentifier) {
boolean success = false;
TrackedRace trackedRace = getExistingTrackedRace(raceIdentifier);
if (trackedRace != null) {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
if (leaderboard != null) {
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
if (raceColumn != null) {
raceColumn.setTrackedRace(trackedRace);
raceColumn.setRaceIdentifier(trackedRace.getRaceIdentifier());
success = true;
getService().updateStoredLeaderboard(leaderboard);
}
}
}
return success;
return getService().apply(new ConnectTrackedRaceToLeaderboardColumn(leaderboardName, raceColumnName, raceIdentifier));
}
@Override
@@ -1345,126 +1323,44 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public void disconnectLeaderboardColumnFromTrackedRace(String leaderboardName, String raceColumnName) {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
if (leaderboard != null) {
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
if (raceColumn != null) {
raceColumn.setTrackedRace(null);
raceColumn.setRaceIdentifier(null);
getService().updateStoredLeaderboard(leaderboard);
} else {
throw new IllegalArgumentException("Didn't find race "+raceColumnName+" in leaderboard "+leaderboardName);
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+leaderboardName);
}
getService().apply(new DisconnectLeaderboardColumnFromTrackedRace(leaderboardName, raceColumnName));
}
@Override
public void updateLeaderboardCarryValue(String leaderboardName, String competitorIdAsString, Integer carriedPoints) {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
if (leaderboard != null) {
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
if (competitor != null) {
if (carriedPoints == null) {
leaderboard.unsetCarriedPoints(competitor);
} else {
leaderboard.setCarriedPoints(competitor, carriedPoints);
}
getService().updateStoredLeaderboard(leaderboard);
} else {
throw new IllegalArgumentException("Didn't find competitor ID "+competitorIdAsString+" in leaderboard "+leaderboardName);
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+leaderboardName);
}
getService().apply(new UpdateLeaderboardCarryValue(leaderboardName, competitorIdAsString, carriedPoints));
}
@Override
public Pair<Integer, Integer> updateLeaderboardMaxPointsReason(String leaderboardName, String competitorIdAsString, String raceColumnName,
MaxPointsReason maxPointsReason, Date date) throws NoWindException {
TimePoint timePoint = new MillisecondsTimePoint(date);
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
if (leaderboard != null) {
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
if (competitor != null) {
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
if (raceColumn == null) {
throw new IllegalArgumentException("Didn't find race "+raceColumnName+" in leaderboard "+leaderboardName);
}
leaderboard.getScoreCorrection().setMaxPointsReason(competitor, raceColumn, maxPointsReason);
getService().updateStoredLeaderboard(leaderboard);
Entry updatedEntry = leaderboard.getEntry(competitor, raceColumn, timePoint);
return new Pair<Integer, Integer>(updatedEntry.getNetPoints(), updatedEntry.getTotalPoints());
} else {
throw new IllegalArgumentException("Didn't find competitor with ID "+competitorIdAsString+" in leaderboard "+leaderboardName);
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+leaderboardName);
}
return getService().apply(new UpdateLeaderboardMaxPointsReason(leaderboardName, raceColumnName, competitorIdAsString, maxPointsReason, date));
}
@Override
public Pair<Integer, Integer> updateLeaderboardScoreCorrection(String leaderboardName, String competitorIdAsString, String raceName,
public Pair<Integer, Integer> updateLeaderboardScoreCorrection(String leaderboardName, String competitorIdAsString, String columnName,
Integer correctedScore, Date date) throws NoWindException {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
int newNetPoints;
int newTotalPoints;
if (leaderboard != null) {
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
if (competitor != null) {
MillisecondsTimePoint timePoint = new MillisecondsTimePoint(date);
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(raceName);
if (raceColumn == null) {
throw new IllegalArgumentException("Didn't find race "+raceName+" in leaderboard "+leaderboardName);
}
if (correctedScore == null) {
leaderboard.getScoreCorrection().uncorrectScore(competitor, raceColumn);
newNetPoints = leaderboard.getNetPoints(competitor, raceColumn, timePoint);
} else {
leaderboard.getScoreCorrection().correctScore(competitor, raceColumn, correctedScore);
newNetPoints = correctedScore;
}
newTotalPoints = leaderboard.getEntry(competitor, raceColumn, timePoint).getTotalPoints();
} else {
throw new IllegalArgumentException("Didn't find competitor with ID "+competitorIdAsString+" in leaderboard "+leaderboardName);
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+leaderboardName);
}
getService().updateStoredLeaderboard(leaderboard);
return new Pair<Integer, Integer>(newNetPoints, newTotalPoints);
return getService().apply(new UpdateLeaderboardScoreCorrection(leaderboardName, columnName, competitorIdAsString, correctedScore, date));
}
@Override
public void updateCompetitorDisplayNameInLeaderboard(String leaderboardName, String competitorIdAsString, String displayName) {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
if (competitor != null) {
leaderboard.setDisplayName(competitor, displayName);
getService().updateStoredLeaderboard(leaderboard);
}
getService().apply(new UpdateCompetitorDisplayNameInLeaderboard(leaderboardName, competitorIdAsString, displayName));
}
@Override
public void moveLeaderboardColumnUp(String leaderboardName, String columnName) {
getService().moveLeaderboardColumnUp(leaderboardName, columnName);
getService().apply(new MoveLeaderboardColumnUp(leaderboardName, columnName));
}
@Override
public void moveLeaderboardColumnDown(String leaderboardName, String columnName) {
getService().moveLeaderboardColumnDown(leaderboardName, columnName);
getService().apply(new MoveLeaderboardColumnDown(leaderboardName, columnName));
}
@Override
public void updateIsMedalRace(String leaderboardName, String columnName, boolean isMedalRace) {
Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
if (leaderboard != null) {
leaderboard.updateIsMedalRace(columnName, isMedalRace);
getService().updateStoredLeaderboard(leaderboard);
} else {
throw new IllegalArgumentException("Leaderboard named " + leaderboardName + " not found");
}
getService().apply(new UpdateIsMedalRace(leaderboardName, columnName, isMedalRace));
}
@Override
@@ -1724,9 +1620,9 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
}
@Override
public RaceDefinition getRace(EventAndRaceIdentifier eventNameAndRaceName) {
Event event = getService().getEventByName(eventNameAndRaceName.getEventName());
RaceDefinition race = getRaceByName(event, eventNameAndRaceName.getRaceName());
public RaceDefinition getRace(EventAndRaceIdentifier raceIdentifier) {
Event event = getService().getEventByName(raceIdentifier.getEventName());
RaceDefinition race = getRaceByName(event, raceIdentifier.getRaceName());
return race;
}
@@ -1748,10 +1644,6 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
return getService().getEventByName(eventIdentifier.getEventName());
}
private Event getEvent(EventIdentifier eventIdentifier) {
return (Event) eventIdentifier.getEvent(this);
}
/**
* Returns a servlet context that, when asked for a resource, first tries the original servlet context's implementation. If that
* fails, it prepends "war/" to the request because the war/ folder contains all the resources exposed externally
@@ -1806,22 +1698,22 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
@Override
public void renameLeaderboardGroup(String oldName, String newName) {
getService().renameLeaderboardGroup(oldName, newName);
getService().apply(new RenameLeaderboardGroup(oldName, newName));
}
@Override
public void removeLeaderboardGroup(String groupName) {
getService().removeLeaderboardGroup(groupName);
getService().apply(new RemoveLeaderboardGroup(groupName));
}
@Override
public LeaderboardGroupDTO createLeaderboardGroup(String groupName, String description) {
return convertToLeaderboardGroupDTO(getService().addLeaderboardGroup(groupName, description, new ArrayList<String>()));
return convertToLeaderboardGroupDTO(getService().apply(new CreateLeaderboardGroup(groupName, description, new ArrayList<String>())));
}
@Override
public void updateLeaderboardGroup(String oldName, String newName, String description, List<String> leaderboardNames) {
getService().updateLeaderboardGroup(oldName, newName, description, leaderboardNames);
getService().apply(new UpdateLeaderboardGroup(oldName, newName, description, leaderboardNames));
}
}
@@ -9,7 +9,7 @@ import java.util.List;
import java.util.Map;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
/**
* Captures the serializable properties of a leaderboard which in particular has the competitors, any optional display
@@ -292,7 +292,7 @@ public class LeaderboardDTO implements IsSerializable {
return getRaceInLeaderboardByName(raceColumnName).isMedalRace();
}
public void addRace(String raceColumnName, boolean medalRace, RaceIdentifier trackedRaceIdentifier, StrippedRaceDTO race) {
public void addRace(String raceColumnName, boolean medalRace, EventAndRaceIdentifier trackedRaceIdentifier, StrippedRaceDTO race) {
RaceInLeaderboardDTO raceInLeaderboardDTO = new RaceInLeaderboardDTO();
raceInLeaderboardDTO.setRaceColumnName(raceColumnName);
raceInLeaderboardDTO.setMedalRace(medalRace);
@@ -301,7 +301,7 @@ public class LeaderboardDTO implements IsSerializable {
races.add(raceInLeaderboardDTO);
}
public void addRaceAt(String raceColumnName, boolean medalRace, RaceIdentifier trackedRaceIdentifier, int index) {
public void addRaceAt(String raceColumnName, boolean medalRace, EventAndRaceIdentifier trackedRaceIdentifier, int index) {
RaceInLeaderboardDTO raceInLeaderboardDTO = new RaceInLeaderboardDTO();
raceInLeaderboardDTO.setRaceColumnName(raceColumnName);
raceInLeaderboardDTO.setMedalRace(medalRace);
@@ -3,8 +3,10 @@ package com.sap.sailing.gwt.ui.shared;
import java.util.Date;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventNameAndRaceName;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tractracadapter.TracTracRaceTracker;
public class RaceDTO extends NamedDTO implements IsSerializable {
public Iterable<CompetitorDTO> competitors;
@@ -40,7 +42,7 @@ public class RaceDTO extends NamedDTO implements IsSerializable {
this.regatta = regatta;
}
public RaceIdentifier getRaceIdentifier() {
public EventAndRaceIdentifier getRaceIdentifier() {
return new EventNameAndRaceName(regatta.getEvent().name, name);
}
@@ -3,12 +3,12 @@ package com.sap.sailing.gwt.ui.shared;
import java.util.Date;
import com.google.gwt.user.client.rpc.IsSerializable;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
public class RaceInLeaderboardDTO implements IsSerializable {
private String raceColumnName;
private boolean medalRace;
private RaceIdentifier trackedRaceIdentifier;
private EventAndRaceIdentifier trackedRaceIdentifier;
private StrippedRaceDTO race;
public String getRaceColumnName() {
@@ -31,7 +31,7 @@ public class RaceInLeaderboardDTO implements IsSerializable {
return trackedRaceIdentifier != null;
}
public void setRaceIdentifier(RaceIdentifier raceIdentifier) {
public void setRaceIdentifier(EventAndRaceIdentifier raceIdentifier) {
this.trackedRaceIdentifier = raceIdentifier;
}
@@ -40,7 +40,7 @@ public class RaceInLeaderboardDTO implements IsSerializable {
* data can be obtained from the server in great detail, as opposed to non-tracked races for which only
* result points may have been entered manually.
*/
public RaceIdentifier getRaceIdentifier() {
public EventAndRaceIdentifier getRaceIdentifier() {
return trackedRaceIdentifier;
}
@@ -45,6 +45,7 @@ import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RequiresResize;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.ManeuverType;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.Tack;
@@ -165,7 +166,7 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
private CompetitorSelectionProvider competitorSelection;
private List<RaceIdentifier> selectedRaces;
private List<EventAndRaceIdentifier> selectedRaces;
/**
* Used to check if the first initial zoom to the buoy markers was already done.
@@ -308,7 +309,7 @@ public class RaceMap extends AbsolutePanel implements TimeListener, CompetitorSe
}
@Override
public void onRaceSelectionChange(List<RaceIdentifier> selectedRaces) {
public void onRaceSelectionChange(List<EventAndRaceIdentifier> selectedRaces) {
mapFirstZoomDone = false;
// TODO bug 494: reset zoom settings to user preferences
this.selectedRaces = selectedRaces;
@@ -16,7 +16,10 @@ import java.util.Map;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventFetcher;
import com.sap.sailing.domain.common.EventIdentifier;
import com.sap.sailing.domain.common.EventName;
import com.sap.sailing.domain.common.RaceFetcher;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.Util.Pair;
@@ -57,7 +60,7 @@ import com.sap.sailing.server.operationaltransformation.RacingEventServiceOperat
* @author Axel Uhl (d043530)
*
*/
public interface RacingEventService extends TrackedEventRegistry {
public interface RacingEventService extends TrackedEventRegistry, EventFetcher, RaceFetcher {
/**
* @return a thread-safe copy of the events currently known by the service; it's safe for callers to iterate over
* the iterable returned, and no risk of a {@link ConcurrentModificationException} exists
@@ -66,8 +69,14 @@ public interface RacingEventService extends TrackedEventRegistry {
Event getEventByName(String name);
@Override
Event getEvent(EventName eventName);
Event getEvent(EventIdentifier eventIdentifier);
@Override
RaceDefinition getRace(EventAndRaceIdentifier raceIdentifier);
TrackedRace getTrackedRace(Event event, RaceDefinition r);
TrackedRace getTrackedRace(RaceIdentifier raceIdentifier);
@@ -29,10 +29,8 @@ import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.base.impl.EventImpl;
import com.sap.sailing.domain.common.DefaultLeaderboardName;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.EventFetcher;
import com.sap.sailing.domain.common.EventIdentifier;
import com.sap.sailing.domain.common.EventName;
import com.sap.sailing.domain.common.RaceFetcher;
import com.sap.sailing.domain.common.RaceIdentifier;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.Util;
@@ -73,7 +71,7 @@ import com.sap.sailing.operationaltransformation.Operation;
import com.sap.sailing.server.RacingEventService;
import com.sap.sailing.server.operationaltransformation.RacingEventServiceOperation;
public class RacingEventServiceImpl implements RacingEventService, EventFetcher, RaceFetcher {
public class RacingEventServiceImpl implements RacingEventService {
private static final Logger logger = Logger.getLogger(RacingEventServiceImpl.class.getName());
/**
@@ -769,6 +767,11 @@ public class RacingEventServiceImpl implements RacingEventService, EventFetcher,
}
}
@Override
public Event getEvent(EventName eventName) {
return (Event) eventsByName.get(eventName.getEventName());
}
@Override
public Event getEvent(EventIdentifier eventIdentifier) {
return (Event) eventIdentifier.getEvent(this);
@@ -797,11 +800,6 @@ public class RacingEventServiceImpl implements RacingEventService, EventFetcher,
return result;
}
@Override
public Event getEvent(EventName eventIdentifier) {
return getEventByName(eventIdentifier.getEventName());
}
@Override
public Map<String, LeaderboardGroup> getLeaderboardGroups() {
synchronized (leaderboardGroupsByName) {
@@ -919,6 +917,10 @@ public class RacingEventServiceImpl implements RacingEventService, EventFetcher,
*/
@Override
public <T> T apply(RacingEventServiceOperation<T> operation) {
return operation.internalApplyTo(this);
try {
return operation.internalApplyTo(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@@ -20,8 +20,12 @@ public abstract class AbstractRacingEventServiceOperation<ResultType> implements
*/
@Override
public RacingEventService applyTo(RacingEventService toState) {
internalApplyTo(toState);
return toState;
try {
internalApplyTo(toState);
return toState;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
@@ -0,0 +1,46 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.RaceInLeaderboard;
import com.sap.sailing.server.RacingEventService;
public class DisconnectLeaderboardColumnFromTrackedRace extends AbstractLeaderboardColumnOperation<Void> {
private static final long serialVersionUID = -5822713961135743309L;
public DisconnectLeaderboardColumnFromTrackedRace(String leaderboardName, String columnName) {
super(leaderboardName, columnName);
// TODO Auto-generated constructor stub
}
@Override
public Void internalApplyTo(RacingEventService toState) {
Leaderboard leaderboard = toState.getLeaderboardByName(getLeaderboardName());
if (leaderboard != null) {
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(getColumnName());
if (raceColumn != null) {
raceColumn.setTrackedRace(null);
raceColumn.setRaceIdentifier(null);
toState.updateStoredLeaderboard(leaderboard);
} else {
throw new IllegalArgumentException("Didn't find race "+getColumnName()+" in leaderboard "+getLeaderboardName());
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+getLeaderboardName());
}
return null;
}
@Override
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
// TODO Auto-generated method stub
return null;
}
@Override
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
// TODO Auto-generated method stub
return null;
}
}
@@ -11,7 +11,7 @@ public interface RacingEventServiceOperation<ResultType> extends Operation<Racin
* Performs the actual operation, applying it to the <code>toState</code> service. The operation's result is
* returned.
*/
ResultType internalApplyTo(RacingEventService toState);
ResultType internalApplyTo(RacingEventService toState) throws Exception;
/**
* Implements the specific transformation rule for the implementing subclass for the set of possible peer operations
@@ -0,0 +1,35 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class RenameLeaderboard extends AbstractLeaderboardOperation<Void> {
private static final long serialVersionUID = 8874599127010526971L;
private final String newLeaderboardName;
public RenameLeaderboard(String leaderboardName, String newLeaderboardName) {
super(leaderboardName);
this.newLeaderboardName = newLeaderboardName;
}
@Override
public Void internalApplyTo(RacingEventService toState) {
if (!getLeaderboardName().equals(newLeaderboardName)) {
toState.renameLeaderboard(getLeaderboardName(), newLeaderboardName);
}
return null;
}
@Override
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
// TODO Auto-generated method stub
return null;
}
@Override
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
// TODO Auto-generated method stub
return null;
}
}
@@ -0,0 +1,34 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.server.RacingEventService;
public class RenameLeaderboardGroup extends AbstractLeaderboardGroupOperation<Void> {
private static final long serialVersionUID = -5007784579411727148L;
private final String newLeaderboardGroupName;
public RenameLeaderboardGroup(String leaderboardGroupName, String newLeaderboardGroupName) {
super(leaderboardGroupName);
this.newLeaderboardGroupName = newLeaderboardGroupName;
}
@Override
public Void internalApplyTo(RacingEventService toState) {
if (!getLeaderboardGroupName().equals(newLeaderboardGroupName)) {
toState.renameLeaderboardGroup(getLeaderboardGroupName(), newLeaderboardGroupName);
}
return null;
}
@Override
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
// TODO Auto-generated method stub
return null;
}
@Override
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
// TODO Auto-generated method stub
return null;
}
}
@@ -1,7 +1,5 @@
package com.sap.sailing.server.operationaltransformation;
import java.util.Set;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.domain.common.WindSource;
import com.sap.sailing.domain.tracking.DynamicTrackedRace;
@@ -9,9 +7,9 @@ import com.sap.sailing.server.RacingEventService;
public class SetWindSourcesToExclude extends AbstractRaceOperation<Void> {
private static final long serialVersionUID = 7639288885720509529L;
private final Set<WindSource> windSourcesToExclude;
private final Iterable<WindSource> windSourcesToExclude;
public SetWindSourcesToExclude(EventAndRaceIdentifier raceIdentifier, Set<WindSource> windSourcesToExclude) {
public SetWindSourcesToExclude(EventAndRaceIdentifier raceIdentifier, Iterable<WindSource> windSourcesToExclude) {
super(raceIdentifier);
this.windSourcesToExclude = windSourcesToExclude;
}
@@ -0,0 +1,40 @@
package com.sap.sailing.server.operationaltransformation;
import java.io.IOException;
import java.net.MalformedURLException;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.common.EventIdentifier;
import com.sap.sailing.server.RacingEventService;
public class StopTrackingEvent extends AbstractRacingEventServiceOperation<Void> {
private static final long serialVersionUID = -651066062098923320L;
private final EventIdentifier eventIdentifier;
public StopTrackingEvent(EventIdentifier eventIdentifier) {
super();
this.eventIdentifier = eventIdentifier;
}
@Override
public Void internalApplyTo(RacingEventService toState) throws MalformedURLException, IOException, InterruptedException {
Event event = toState.getEvent(eventIdentifier);
if (event != null) {
toState.stopTracking(event);
}
return null;
}
@Override
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
// TODO Auto-generated method stub
return null;
}
@Override
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
// TODO Auto-generated method stub
return null;
}
}
@@ -0,0 +1,39 @@
package com.sap.sailing.server.operationaltransformation;
import com.sap.sailing.domain.base.Event;
import com.sap.sailing.domain.base.RaceDefinition;
import com.sap.sailing.domain.common.EventAndRaceIdentifier;
import com.sap.sailing.server.RacingEventService;
public class StopTrackingRace extends AbstractRaceOperation<Void> {
private static final long serialVersionUID = -6074168525544219596L;
public StopTrackingRace(EventAndRaceIdentifier raceIdentifier) {
super(raceIdentifier);
}
@Override
public Void internalApplyTo(RacingEventService toState) throws Exception {
Event event = toState.getEvent(getRaceIdentifier());
if (event != null) {
RaceDefinition r = toState.getRace(getRaceIdentifier());
if (r != null) {
toState.stopTracking(event, r);
}
}
return null;
}
@Override
public RacingEventServiceOperation<?> transformClientOp(RacingEventServiceOperation<?> serverOp) {
// TODO Auto-generated method stub
return null;
}
@Override
public RacingEventServiceOperation<?> transformServerOp(RacingEventServiceOperation<?> clientOp) {
// TODO Auto-generated method stub
return null;
}
}
@@ -9,10 +9,10 @@ public class UpdateCompetitorDisplayNameInLeaderboard extends AbstractLeaderboar
private final String competitorIdAsString;
private final String newDisplayName;
public UpdateCompetitorDisplayNameInLeaderboard(String leaderboardName, String competitorIdAdString,
public UpdateCompetitorDisplayNameInLeaderboard(String leaderboardName, String competitorIdAsString,
String newDisplayName) {
super(leaderboardName);
this.competitorIdAsString = competitorIdAdString;
this.competitorIdAsString = competitorIdAsString;
this.newDisplayName = newDisplayName;
}
@@ -1,21 +1,30 @@
package com.sap.sailing.server.operationaltransformation;
import java.util.Date;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.MaxPointsReason;
import com.sap.sailing.domain.common.NoWindException;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.Leaderboard.Entry;
import com.sap.sailing.domain.leaderboard.RaceInLeaderboard;
import com.sap.sailing.server.RacingEventService;
public class UpdateLeaderboardMaxPointsReason extends AbstractLeaderboardColumnOperation<Void> {
public class UpdateLeaderboardMaxPointsReason extends AbstractLeaderboardColumnOperation<Pair<Integer, Integer>> {
private static final long serialVersionUID = -492130952256848047L;
private final String competitorIdAsString;
private final MaxPointsReason newMaxPointsReason;
private final Date date;
public UpdateLeaderboardMaxPointsReason(String leaderboardName, String columnName, String competitorIdAsString,
MaxPointsReason newMaxPointsReason) {
MaxPointsReason newMaxPointsReason, Date date) {
super(leaderboardName, columnName);
this.competitorIdAsString = competitorIdAsString;
this.newMaxPointsReason = newMaxPointsReason;
this.date = date;
}
@Override
@@ -31,7 +40,8 @@ public class UpdateLeaderboardMaxPointsReason extends AbstractLeaderboardColumnO
}
@Override
public Void internalApplyTo(RacingEventService toState) {
public Pair<Integer, Integer> internalApplyTo(RacingEventService toState) throws NoWindException {
TimePoint timePoint = new MillisecondsTimePoint(date);
Leaderboard leaderboard = toState.getLeaderboardByName(getLeaderboardName());
if (leaderboard != null) {
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
@@ -42,13 +52,14 @@ public class UpdateLeaderboardMaxPointsReason extends AbstractLeaderboardColumnO
}
leaderboard.getScoreCorrection().setMaxPointsReason(competitor, raceColumn, newMaxPointsReason);
toState.updateStoredLeaderboard(leaderboard);
Entry updatedEntry = leaderboard.getEntry(competitor, raceColumn, timePoint);
return new Pair<Integer, Integer>(updatedEntry.getNetPoints(), updatedEntry.getTotalPoints());
} else {
throw new IllegalArgumentException("Didn't find competitor with ID "+competitorIdAsString+" in leaderboard "+getLeaderboardName());
}
} else {
throw new IllegalArgumentException("Didn't find leaderboard "+getLeaderboardName());
}
return null;
}
}
@@ -1,20 +1,27 @@
package com.sap.sailing.server.operationaltransformation;
import java.util.Date;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.NoWindException;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.leaderboard.Leaderboard;
import com.sap.sailing.domain.leaderboard.RaceInLeaderboard;
import com.sap.sailing.server.RacingEventService;
public class UpdateLeaderboardScoreCorrection extends AbstractLeaderboardColumnOperation<Void> {
public class UpdateLeaderboardScoreCorrection extends AbstractLeaderboardColumnOperation<Pair<Integer, Integer>> {
private static final long serialVersionUID = -977025759476022993L;
private final String competitorIdAsString;
private final Integer correctedScore;
private final Date date;
public UpdateLeaderboardScoreCorrection(String leaderboardName, String columnName, String competitorIdAsString,
Integer correctedScore) {
Integer correctedScore, Date date) {
super(leaderboardName, columnName);
this.competitorIdAsString = competitorIdAsString;
this.correctedScore = correctedScore;
this.date = date;
}
@Override
@@ -30,20 +37,23 @@ public class UpdateLeaderboardScoreCorrection extends AbstractLeaderboardColumnO
}
@Override
public Void internalApplyTo(RacingEventService toState) {
public Pair<Integer, Integer> internalApplyTo(RacingEventService toState) throws NoWindException {
Leaderboard leaderboard = toState.getLeaderboardByName(getLeaderboardName());
int newNetPoints;
int newTotalPoints;
if (leaderboard != null) {
MillisecondsTimePoint timePoint = new MillisecondsTimePoint(date);
Competitor competitor = leaderboard.getCompetitorByIdAsString(competitorIdAsString);
if (competitor != null) {
RaceInLeaderboard raceColumn = leaderboard.getRaceColumnByName(getColumnName());
if (raceColumn == null) {
throw new IllegalArgumentException("Didn't find race "+getColumnName()+" in leaderboard "+getLeaderboardName());
}
if (correctedScore == null) {
leaderboard.getScoreCorrection().uncorrectScore(competitor, raceColumn);
newNetPoints = leaderboard.getNetPoints(competitor, raceColumn, timePoint);
} else {
leaderboard.getScoreCorrection().correctScore(competitor, raceColumn, correctedScore);
newNetPoints = correctedScore;
}
newTotalPoints = leaderboard.getEntry(competitor, raceColumn, timePoint).getTotalPoints();
} else {
throw new IllegalArgumentException("Didn't find competitor with ID "+competitorIdAsString+" in leaderboard "+getLeaderboardName());
}
@@ -51,7 +61,7 @@ public class UpdateLeaderboardScoreCorrection extends AbstractLeaderboardColumnO
throw new IllegalArgumentException("Didn't find leaderboard "+getLeaderboardName());
}
toState.updateStoredLeaderboard(leaderboard);
return null;
return new Pair<Integer, Integer>(newNetPoints, newTotalPoints);
}
}