fir step towards a fix for bug 3270: change API to handle multiple course areas for addition/removal at once

This commit is contained in:
Axel Uhl committed 2015-09-16 18:12:59 +02:00
1 parent 5247877986
commit 6d192b56a9
12 files changed
+105 -91

No files matched your search

@@ -517,36 +517,40 @@ public class EventListComposite extends Composite implements EventsRefresher, Le
}
}
});
for (CourseAreaDTO courseArea : courseAreasToAdd) {
sailingService.createCourseArea(oldEvent.id, courseArea.getName(), new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable t) {
errorReporter.reportError("Error trying to add course area to sailing event " + oldEvent.getName()
+ ": " + t.getMessage());
}
@Override
public void onSuccess(Void result) {
fillEvents();
}
});
final String[] namesOfCourseAreasToAdd = new String[courseAreasToAdd.size()];
int i=0;
for (CourseAreaDTO courseAreaToAdd : courseAreasToAdd) {
namesOfCourseAreasToAdd[i++] = courseAreaToAdd.getName();
}
for (CourseAreaDTO courseArea : courseAreasToRemove) {
sailingService.removeCourseArea(oldEvent.id, courseArea.id, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable t) {
errorReporter.reportError("Error trying to remove course area from sailing event " + oldEvent.getName()
+ ": " + t.getMessage());
}
sailingService.createCourseAreas(oldEvent.id, namesOfCourseAreasToAdd, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable t) {
errorReporter.reportError("Error trying to add course area to sailing event " + oldEvent.getName()
+ ": " + t.getMessage());
}
@Override
public void onSuccess(Void result) {
fillEvents();
}
});
@Override
public void onSuccess(Void result) {
fillEvents();
}
});
final UUID[] idsOfCourseAreasToRemove = new UUID[courseAreasToRemove.size()];
int j=0;
for (CourseAreaDTO courseAreaToRemove : courseAreasToRemove) {
idsOfCourseAreasToRemove[j++] = courseAreaToRemove.id;
}
sailingService.removeCourseAreas(oldEvent.id, idsOfCourseAreasToRemove, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable t) {
errorReporter.reportError("Error trying to remove course area from sailing event " + oldEvent.getName()
+ ": " + t.getMessage());
}
@Override
public void onSuccess(Void result) {
fillEvents();
}
});
}
private Pair<List<CourseAreaDTO>, List<CourseAreaDTO>> getCourseAreasToAdd(final EventDTO oldEvent, final EventDTO updatedEvent) {
@@ -373,11 +373,11 @@ public interface SailingService extends RemoteService, FileStorageManagementGwtS
PolarSheetGenerationResponse generatePolarSheetForRaces(List<RegattaAndRaceIdentifier> selectedRaces,
PolarSheetGenerationSettings settings, String name) throws Exception;
void createCourseArea(UUID eventId, String courseAreaName);
void createCourseAreas(UUID eventId, String[] courseAreaNames);
List<String> getBoatClassNamesWithPolarSheetsAvailable();
void removeCourseArea(UUID eventId, UUID courseAreaId);
void removeCourseAreas(UUID eventId, UUID[] courseAreaIds);
List<Util.Pair<String, String>> getLeaderboardsNamesOfMetaLeaderboard(String metaLeaderboardName);
@@ -376,9 +376,9 @@ public interface SailingServiceAsync extends ServerInfoRetriever, FileStorageMan
VenueDTO venue, boolean isPublic, Iterable<UUID> leaderboardGroupIds, String officialWebsiteURL, String sailorsInfoWebsiteURL,
Iterable<ImageDTO> images, Iterable<VideoDTO> videos, AsyncCallback<EventDTO> callback);
void createCourseArea(UUID eventId, String courseAreaName, AsyncCallback<Void> callback);
void createCourseAreas(UUID eventId, String[] courseAreaNames, AsyncCallback<Void> callback);
void removeCourseArea(UUID eventId, UUID courseAreaId, AsyncCallback<Void> callback);
void removeCourseAreas(UUID eventId, UUID[] idsOfCourseAreasToRemove, AsyncCallback<Void> callback);
void removeRegatta(RegattaIdentifier regattaIdentifier, AsyncCallback<Void> callback);
@@ -364,7 +364,7 @@ import com.sap.sailing.server.RacingEventService;
import com.sap.sailing.server.masterdata.MasterDataImporter;
import com.sap.sailing.server.operationaltransformation.AddColumnToLeaderboard;
import com.sap.sailing.server.operationaltransformation.AddColumnToSeries;
import com.sap.sailing.server.operationaltransformation.AddCourseArea;
import com.sap.sailing.server.operationaltransformation.AddCourseAreas;
import com.sap.sailing.server.operationaltransformation.AddRemoteSailingServerReference;
import com.sap.sailing.server.operationaltransformation.AddSpecificRegatta;
import com.sap.sailing.server.operationaltransformation.AllowCompetitorResetToDefaults;
@@ -380,7 +380,7 @@ import com.sap.sailing.server.operationaltransformation.MoveLeaderboardColumnDow
import com.sap.sailing.server.operationaltransformation.MoveLeaderboardColumnUp;
import com.sap.sailing.server.operationaltransformation.RemoveAndUntrackRace;
import com.sap.sailing.server.operationaltransformation.RemoveColumnFromSeries;
import com.sap.sailing.server.operationaltransformation.RemoveCourseArea;
import com.sap.sailing.server.operationaltransformation.RemoveCourseAreas;
import com.sap.sailing.server.operationaltransformation.RemoveEvent;
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboard;
import com.sap.sailing.server.operationaltransformation.RemoveLeaderboardColumn;
@@ -3311,20 +3311,22 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
getService().apply(
new CreateEvent(eventName, eventDescription, startTimePoint, endTimePoint, venue, isPublic, eventUuid,
officialWebsiteURL, sailorsInfoWebsiteURL, eventImages, eventVideos));
for (String courseAreaName : courseAreaNames) {
createCourseArea(eventUuid, courseAreaName);
}
createCourseAreas(eventUuid, courseAreaNames.toArray(new String[courseAreaNames.size()]));
return getEventById(eventUuid, false);
}
@Override
public void createCourseArea(UUID eventId, String courseAreaName) {
getService().apply(new AddCourseArea(eventId, courseAreaName, UUID.randomUUID()));
public void createCourseAreas(UUID eventId, String[] courseAreaNames) {
final UUID[] courseAreaIDs = new UUID[courseAreaNames.length];
for (int i=0; i<courseAreaNames.length; i++) {
courseAreaIDs[i] = UUID.randomUUID();
}
getService().apply(new AddCourseAreas(eventId, courseAreaNames, courseAreaIDs));
}
@Override
public void removeCourseArea(UUID eventId, UUID courseAreaId) {
getService().apply(new RemoveCourseArea(eventId, courseAreaId));
public void removeCourseAreas(UUID eventId, UUID[] courseAreaIds) {
getService().apply(new RemoveCourseAreas(eventId, courseAreaIds));
}
@Override
@@ -98,7 +98,7 @@ public class EventReplicationTest extends AbstractServerReplicationTest {
final TimePoint eventStartDate = new MillisecondsTimePoint(new Date());
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
Event masterEvent = master.addEvent(eventName, /* eventDescription */ null, eventStartDate, eventEndDate, venueName, isPublic, UUID.randomUUID());
CourseArea masterCourseArea = master.addCourseArea(masterEvent.getId(), courseArea, UUID.randomUUID());
CourseArea masterCourseArea = master.addCourseAreas(masterEvent.getId(), new String[] {courseArea}, new UUID[] {UUID.randomUUID()})[0];
Thread.sleep(1000);
Event replicatedEvent = replica.getEvent(masterEvent.getId());
@@ -69,8 +69,8 @@ public class RegattaReplicationTest extends AbstractServerReplicationTest {
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
Event event = master.addEvent("Event", /* eventDescription */ null, eventStartDate, eventEndDate, "Venue", true, UUID.randomUUID());
master.addCourseArea(event.getId(), "Alpha", alphaCourseAreaId);
master.addCourseArea(event.getId(), "TV", tvCourseAreaId);
master.addCourseAreas(event.getId(), new String[] {"Alpha"}, new UUID[] {alphaCourseAreaId});
master.addCourseAreas(event.getId(), new String[] {"TV"}, new UUID[] {tvCourseAreaId});
UUID currentCourseAreaId = null;
Regatta masterRegatta = master.createRegatta(RegattaImpl.getDefaultName("Kiel Week 2012", "49er"), "49er",
@@ -119,8 +119,8 @@ public class RegattaReplicationTest extends AbstractServerReplicationTest {
final TimePoint eventStartDate = new MillisecondsTimePoint(new Date());
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
Event event = master.addEvent("Event", /* eventDescription */ null, eventStartDate, eventEndDate, "Venue", /*isPublic*/true, UUID.randomUUID());
master.addCourseArea(event.getId(), "TV", tvCourseAreaId);
master.addCourseArea(event.getId(), "Golf", golfCourseAreaId);
master.addCourseAreas(event.getId(), new String[] {"TV"}, new UUID[] {tvCourseAreaId});
master.addCourseAreas(event.getId(), new String[] {"Golf"}, new UUID[] {golfCourseAreaId});
final String regattaName = RegattaImpl.getDefaultName("Kiel Week 2012", "49er");
Regatta masterRegatta = master.createRegatta(regattaName, "49er", /*startDate*/ null, /*endDate*/ null, UUID.randomUUID(), Collections.<Series>emptyList(),
/* persistent */ true, DomainFactory.INSTANCE.createScoringScheme(ScoringSchemeType.LOW_POINT), tvCourseAreaId, /* useStartTimeInference */ true, OneDesignRankingMetric::new);
@@ -144,7 +144,7 @@ public class RegattaReplicationTest extends AbstractServerReplicationTest {
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
Event event = master.addEvent("Event", /* eventDescription */ null, eventStartDate, eventEndDate, "Venue", true, UUID.randomUUID());
master.addCourseArea(event.getId(), "Alpha", alphaCourseAreaId);
master.addCourseAreas(event.getId(), new String[] {"Alpha"}, new UUID[] {alphaCourseAreaId});
UUID currentCourseAreaId = null;
Regatta masterRegatta = master.createRegatta(RegattaImpl.getDefaultName("RR", "49er"), "49er", /*startDate*/ null, /*endDate*/ null, UUID.randomUUID(), Collections.<Series>emptyList(),
@@ -302,7 +302,7 @@ public class RegattaReplicationTest extends AbstractServerReplicationTest {
final TimePoint eventStartDate = new MillisecondsTimePoint(new Date());
final TimePoint eventEndDate = new MillisecondsTimePoint(new Date());
Event masterEvent = master.addEvent(eventName, /* eventDescription */ null, eventStartDate, eventEndDate, venueName, isPublic, UUID.randomUUID());
CourseArea masterCourseArea = master.addCourseArea(masterEvent.getId(), courseArea, UUID.randomUUID());
CourseArea masterCourseArea = master.addCourseAreas(masterEvent.getId(), new String[] {courseArea}, new UUID[] {UUID.randomUUID()})[0];
Regatta masterRegatta = master.createRegatta(RegattaImpl.getDefaultName(eventName, boatClassName), boatClassName, /*startDate*/ null, /*endDate*/ null, UUID.randomUUID(), series,
/* persistent */ true, DomainFactory.INSTANCE.createScoringScheme(ScoringSchemeType.LOW_POINT), masterCourseArea.getId(), /* useStartTimeInference */ true, OneDesignRankingMetric::new);
@@ -1344,7 +1344,7 @@ public class MasterDataImportTest {
new MillisecondsTimePoint(0), new MillisecondsTimePoint(10), "testvenue", false, UUID.randomUUID(),
/* officialWebsiteURL */ null, /* sailorsInfoWebsiteURL */ null,
/* images */Collections.<ImageDescriptor> emptyList(), /* videos */Collections.<VideoDescriptor> emptyList());
CourseArea defaultCourseArea = sourceService.addCourseArea(event.getId(), "ECHO", UUID.randomUUID());
CourseArea defaultCourseArea = sourceService.addCourseAreas(event.getId(), new String[] {"ECHO"}, new UUID[] {UUID.randomUUID()})[0];
Regatta regatta = sourceService.createRegatta(
RegattaImpl.getDefaultName(TEST_REGATTA_NAME, TEST_BOAT_CLASS_NAME), TEST_BOAT_CLASS_NAME, /*startDate*/ null, /*endDate*/ null,
@@ -1409,7 +1409,7 @@ public class MasterDataImportTest {
new MillisecondsTimePoint(0), new MillisecondsTimePoint(10), "testvenue", false, UUID.randomUUID(),
/* officialWebsiteURL */ null, /* sailorsInfoWebsiteURL */ null,
/* images */Collections.<ImageDescriptor> emptyList(), /* videos */Collections.<VideoDescriptor> emptyList());
CourseArea defaultCourseArea = sourceService.addCourseArea(event.getId(), "ECHO", UUID.randomUUID());
CourseArea defaultCourseArea = sourceService.addCourseAreas(event.getId(), new String[] {"ECHO"}, new UUID[] {UUID.randomUUID()})[0];
List<String> raceColumnNames = new ArrayList<String>();
String raceColumnName = "T1";
@@ -400,7 +400,7 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch
void removeRemoteSailingServerReference(String name);
CourseArea addCourseArea(UUID eventId, String courseAreaName, UUID courseAreaId);
CourseArea[] addCourseAreas(UUID eventId, String[] courseAreaNames, UUID[] courseAreaIds);
com.sap.sailing.domain.base.DomainFactory getBaseDomainFactory();
@@ -473,9 +473,9 @@ public interface RacingEventService extends TrackedRegattaRegistry, RegattaFetch
void setRegattaForRace(Regatta regatta, String raceIdAsString);
CourseArea addCourseAreaWithoutReplication(UUID eventId, UUID courseAreaId, String courseAreaName);
CourseArea[] addCourseAreasWithoutReplication(UUID eventId, UUID[] courseAreaIds, String[] courseAreaNames);
CourseArea removeCourseAreaWithoutReplication(UUID eventId, UUID courseAreaId);
CourseArea[] removeCourseAreaWithoutReplication(UUID eventId, UUID[] courseAreaIds);
/**
* Returns a mobile device's configuration.
@@ -171,7 +171,7 @@ import com.sap.sailing.server.gateway.deserialization.impl.LeaderboardGroupBaseJ
import com.sap.sailing.server.gateway.deserialization.impl.LeaderboardSearchResultBaseJsonDeserializer;
import com.sap.sailing.server.gateway.deserialization.impl.VenueJsonDeserializer;
import com.sap.sailing.server.masterdata.DataImportLockWithProgress;
import com.sap.sailing.server.operationaltransformation.AddCourseArea;
import com.sap.sailing.server.operationaltransformation.AddCourseAreas;
import com.sap.sailing.server.operationaltransformation.AddDefaultRegatta;
import com.sap.sailing.server.operationaltransformation.AddMediaTrackOperation;
import com.sap.sailing.server.operationaltransformation.AddRaceDefinition;
@@ -2771,38 +2771,46 @@ public class RacingEventServiceImpl implements RacingEventService, ClearStateTes
}
@Override
public CourseArea addCourseArea(UUID eventId, String courseAreaName, UUID courseAreaId) {
CourseArea courseArea = getBaseDomainFactory().getOrCreateCourseArea(courseAreaId, courseAreaName);
addCourseAreaWithoutReplication(eventId, courseAreaId, courseAreaName);
replicate(new AddCourseArea(eventId, courseAreaName, courseAreaId));
return courseArea;
public CourseArea[] addCourseAreas(UUID eventId, String[] courseAreaNames, UUID[] courseAreaIds) {
final CourseArea[] courseAreas = addCourseAreasWithoutReplication(eventId, courseAreaIds, courseAreaNames);
replicate(new AddCourseAreas(eventId, courseAreaNames, courseAreaIds));
return courseAreas;
}
@Override
public CourseArea addCourseAreaWithoutReplication(UUID eventId, UUID courseAreaId, String courseAreaName) {
final CourseArea courseArea = getBaseDomainFactory().getOrCreateCourseArea(courseAreaId, courseAreaName);
public CourseArea[] addCourseAreasWithoutReplication(UUID eventId, UUID[] courseAreaIds, String[] courseAreaNames) {
final CourseArea[] result = new CourseArea[courseAreaNames.length];
for (int i=0; i<courseAreaIds.length; i++) {
final CourseArea courseArea = getBaseDomainFactory().getOrCreateCourseArea(courseAreaIds[i], courseAreaNames[i]);
final Event event = eventsById.get(eventId);
if (event == null) {
throw new IllegalArgumentException("No sailing event with ID " + eventId + " found.");
}
event.getVenue().addCourseArea(courseArea);
mongoObjectFactory.storeEvent(event);
result[i] = courseArea;
}
return result;
}
@Override
public CourseArea[] removeCourseAreaWithoutReplication(UUID eventId, UUID[] courseAreaIds) {
final Event event = eventsById.get(eventId);
if (event == null) {
throw new IllegalArgumentException("No sailing event with ID " + eventId + " found.");
}
event.getVenue().addCourseArea(courseArea);
mongoObjectFactory.storeEvent(event);
return courseArea;
}
@Override
public CourseArea removeCourseAreaWithoutReplication(UUID eventId, UUID courseAreaId) {
final CourseArea courseArea = getBaseDomainFactory().getExistingCourseAreaById(courseAreaId);
if (courseArea == null) {
throw new IllegalArgumentException("No course area with ID " + courseAreaId + " found.");
final CourseArea[] courseAreasRemoved = new CourseArea[courseAreaIds.length];
int i=0;
for (final UUID courseAreaId : courseAreaIds) {
final CourseArea courseArea = getBaseDomainFactory().getExistingCourseAreaById(courseAreaId);
if (courseArea == null) {
throw new IllegalArgumentException("No course area with ID " + courseAreaId + " found.");
}
courseAreasRemoved[i++] = courseArea;
event.getVenue().removeCourseArea(courseArea);
mongoObjectFactory.storeEvent(event);
}
final Event event = eventsById.get(eventId);
if (event == null) {
throw new IllegalArgumentException("No sailing event with ID " + eventId + " found.");
}
event.getVenue().removeCourseArea(courseArea);
mongoObjectFactory.storeEvent(event);
return courseArea;
return courseAreasRemoved;
}
@Override
@@ -14,23 +14,23 @@ import com.sap.sailing.server.RacingEventServiceOperation;
* @author Axel Uhl (d043530)
*
*/
public class AddCourseArea extends AbstractRacingEventServiceOperation<CourseArea> {
public class AddCourseAreas extends AbstractRacingEventServiceOperation<CourseArea[]> {
private static final long serialVersionUID = -3650109848260363949L;
private final String courseAreaName;
private final UUID courseAreaId;
private final String[] courseAreaNames;
private final UUID[] courseAreaIds;
private final UUID eventId;
public AddCourseArea(UUID eventId, String courseAreaName, UUID courseAreaId) {
public AddCourseAreas(UUID eventId, String[] courseAreaNames, UUID[] courseAreaIds) {
super();
this.eventId = eventId;
this.courseAreaId = courseAreaId;
this.courseAreaName = courseAreaName;
this.courseAreaIds = courseAreaIds;
this.courseAreaNames = courseAreaNames;
}
@Override
public CourseArea internalApplyTo(RacingEventService toState) throws Exception {
return toState.addCourseAreaWithoutReplication(eventId, courseAreaId, courseAreaName);
public CourseArea[] internalApplyTo(RacingEventService toState) throws Exception {
return toState.addCourseAreasWithoutReplication(eventId, courseAreaIds, courseAreaNames);
}
@Override
@@ -12,7 +12,7 @@ import com.sap.sse.common.media.VideoDescriptor;
/**
* Creates an {@link Event} in the server, with a new venue and an empty course area list.
* See the {@link AddCourseArea} operation for adding course areas to the event's venue.
* See the {@link AddCourseAreas} operation for adding course areas to the event's venue.
*
* @author Axel Uhl (d043530)
*
@@ -13,20 +13,20 @@ import com.sap.sailing.server.RacingEventServiceOperation;
* @author Axel Uhl (d043530)
*
*/
public class RemoveCourseArea extends AbstractRacingEventServiceOperation<Void> {
public class RemoveCourseAreas extends AbstractRacingEventServiceOperation<Void> {
private static final long serialVersionUID = -3650109848260363949L;
private final UUID courseAreaId;
private final UUID[] courseAreaIds;
private final UUID eventId;
public RemoveCourseArea(UUID eventId, UUID courseAreaId) {
public RemoveCourseAreas(UUID eventId, UUID[] courseAreaIds) {
super();
this.eventId = eventId;
this.courseAreaId = courseAreaId;
this.courseAreaIds = courseAreaIds;
}
@Override
public Void internalApplyTo(RacingEventService toState) throws Exception {
toState.removeCourseAreaWithoutReplication(eventId, courseAreaId);
toState.removeCourseAreaWithoutReplication(eventId, courseAreaIds);
return null;
}