mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 14:56:41 +00:00
added competitorAndBoatIdsOnly to both leaderboard end points
Change-Id: I4950bfbd49d2a8c0cb7d33bd3ef58bcb02f4c2ad
This commit is contained in:
1 parent
6c5aee84f3
commit
6facaa1745
7 files changed
+77
-39
No files matched your search
+2
-1
@@ -148,7 +148,8 @@ public class EventResourceTest extends AbstractJaxRsApiTest {
|
||||
}
|
||||
|
||||
private Response getLeaderboard(String name) {
|
||||
return leaderboardsResource.getLeaderboard(name, AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
return leaderboardsResource.getLeaderboard(name, AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
}
|
||||
|
||||
private boolean hasAtLeastOneCourseArea(JSONObject objEvent) {
|
||||
|
||||
+20
-10
@@ -86,7 +86,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
dropAndCreateRegatta();
|
||||
|
||||
Response leaderboardReponse = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString = (String) leaderboardReponse.getEntity();
|
||||
Object obj= JSONValue.parse(jsonString);
|
||||
@@ -111,7 +112,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
dropAndCreateRegatta();
|
||||
|
||||
Response leaderboardReponse = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString = (String) leaderboardReponse.getEntity();
|
||||
Object obj= JSONValue.parse(jsonString);
|
||||
@@ -129,7 +131,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
regattaLeaderboard.getScoreCorrection().setTimePointOfLastCorrectionsValidity(MillisecondsTimePoint.now());
|
||||
|
||||
Response leaderboardReponse2 = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString2 = (String) leaderboardReponse2.getEntity();
|
||||
obj= JSONValue.parse(jsonString2);
|
||||
@@ -143,7 +146,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
public void testExportLeaderboardWithLiveResultStateAsJson() throws Exception {
|
||||
dropAndCreateRegatta();
|
||||
Response leaderboardReponse = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Live, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Live, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
String jsonString = (String) leaderboardReponse.getEntity();
|
||||
Object obj= JSONValue.parse(jsonString);
|
||||
JSONObject jsonObject = (JSONObject) obj;
|
||||
@@ -168,7 +172,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
|
||||
// call the servlet for the first time
|
||||
Response leaderboardReponse = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString = (String) leaderboardReponse.getEntity();
|
||||
Object obj= JSONValue.parse(jsonString);
|
||||
@@ -187,7 +192,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
Thread.sleep(100);
|
||||
|
||||
Response leaderboardReponse2 = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString2 = (String) leaderboardReponse2.getEntity();
|
||||
Object obj2= JSONValue.parse(jsonString2);
|
||||
@@ -210,7 +216,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
Integer maxCompetitorsCount = 2;
|
||||
|
||||
Response leaderboardReponse = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
String jsonString = (String) leaderboardReponse.getEntity();
|
||||
Object obj= JSONValue.parse(jsonString);
|
||||
@@ -229,7 +236,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
|
||||
// first call for 'all' competitors
|
||||
Response leaderboardReponse2 = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
jsonString = (String) leaderboardReponse2.getEntity();
|
||||
obj= JSONValue.parse(jsonString);
|
||||
@@ -241,7 +249,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
|
||||
// second call with maxCompetitorsCount set
|
||||
Response leaderboardReponse3 = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, maxCompetitorsCount, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, maxCompetitorsCount, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
jsonString = (String) leaderboardReponse3.getEntity();
|
||||
obj= JSONValue.parse(jsonString);
|
||||
@@ -253,7 +262,8 @@ public class LeaderboardsResourceTest extends AbstractJaxRsApiTest {
|
||||
|
||||
// third call for 'all' competitors
|
||||
Response leaderboardReponse4 = leaderboardsResource.getLeaderboard(regatta.getName(),
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null);
|
||||
AbstractLeaderboardsResource.ResultStates.Final, null, null,
|
||||
/* competitorAndBoatIdsOnly */ false);
|
||||
|
||||
jsonString = (String) leaderboardReponse4.getEntity();
|
||||
obj= JSONValue.parse(jsonString);
|
||||
|
||||
+21
-17
@@ -92,24 +92,28 @@ public abstract class AbstractLeaderboardsResource extends AbstractSailingServer
|
||||
return jsonLeaderboard;
|
||||
}
|
||||
|
||||
protected void writeCompetitorBaseData(JSONObject jsonCompetitor, CompetitorDTO competitor, LeaderboardDTO leaderboard) {
|
||||
jsonCompetitor.put("name", competitor.getName());
|
||||
jsonCompetitor.put("shortName", competitor.getShortName());
|
||||
final String displayName = leaderboard.getDisplayName(competitor);
|
||||
jsonCompetitor.put("displayName", displayName == null ? competitor.getName() : displayName);
|
||||
protected void writeCompetitorBaseData(JSONObject jsonCompetitor, CompetitorDTO competitor, LeaderboardDTO leaderboard, boolean competitorAndBoatIdsOnly) {
|
||||
jsonCompetitor.put("id", competitor.getIdAsString());
|
||||
jsonCompetitor.put("sailID", competitor.hasBoat() ? ((CompetitorWithBoatDTO) competitor).getSailID() : null); // only for backward compatibility
|
||||
jsonCompetitor.put("nationality", competitor.getThreeLetterIocCountryCode());
|
||||
jsonCompetitor.put("countryCode", competitor.getTwoLetterIsoCountryCode());
|
||||
if (!competitorAndBoatIdsOnly) {
|
||||
jsonCompetitor.put("name", competitor.getName());
|
||||
jsonCompetitor.put("shortName", competitor.getShortName());
|
||||
final String displayName = leaderboard.getDisplayName(competitor);
|
||||
jsonCompetitor.put("displayName", displayName == null ? competitor.getName() : displayName);
|
||||
jsonCompetitor.put("sailID", competitor.hasBoat() ? ((CompetitorWithBoatDTO) competitor).getSailID() : null); // only for backward compatibility
|
||||
jsonCompetitor.put("nationality", competitor.getThreeLetterIocCountryCode());
|
||||
jsonCompetitor.put("countryCode", competitor.getTwoLetterIsoCountryCode());
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeBoatData(JSONObject jsonBoat, BoatDTO boat) {
|
||||
jsonBoat.put("name", boat.getName());
|
||||
jsonBoat.put("displayName", boat.getDisplayName());
|
||||
protected void writeBoatData(JSONObject jsonBoat, BoatDTO boat, boolean competitorAndBoatIdsOnly) {
|
||||
jsonBoat.put("id", boat.getIdAsString());
|
||||
jsonBoat.put("sailId", boat.getSailId());
|
||||
jsonBoat.put("boatClass", boat.getBoatClass().getName());
|
||||
jsonBoat.put("color", boat.getColor() != null ? boat.getColor().toString() : null);
|
||||
if (!competitorAndBoatIdsOnly) {
|
||||
jsonBoat.put("name", boat.getName());
|
||||
jsonBoat.put("displayName", boat.getDisplayName());
|
||||
jsonBoat.put("sailId", boat.getSailId());
|
||||
jsonBoat.put("boatClass", boat.getBoatClass().getName());
|
||||
jsonBoat.put("color", boat.getColor() != null ? boat.getColor().toString() : null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeCommonLeaderboardData(JSONObject jsonLeaderboard, Leaderboard leaderboard,
|
||||
@@ -192,15 +196,15 @@ public abstract class AbstractLeaderboardsResource extends AbstractSailingServer
|
||||
|
||||
protected abstract JSONObject getLeaderboardJson(Leaderboard leaderboard, TimePoint resultTimePoint,
|
||||
ResultStates resultState, Integer maxCompetitorsCount, List<String> raceColumnNames,
|
||||
List<String> raceDetailNames) throws NoWindException, InterruptedException, ExecutionException;
|
||||
List<String> raceDetailNames, boolean competitorAndBoatIdsOnly) throws NoWindException, InterruptedException, ExecutionException;
|
||||
|
||||
protected JSONObject getLeaderboardJson(ResultStates resultState, Integer maxCompetitorsCount,
|
||||
TimePoint requestTimePoint, Leaderboard leaderboard, TimePoint timePoint, List<String> raceColumnNames,
|
||||
List<String> raceDetailNames) throws NoWindException, InterruptedException, ExecutionException {
|
||||
List<String> raceDetailNames, boolean competitorAndBoatIdsOnly) throws NoWindException, InterruptedException, ExecutionException {
|
||||
final JSONObject jsonLeaderboard;
|
||||
if (timePoint != null || resultState == ResultStates.Live) {
|
||||
jsonLeaderboard = getLeaderboardJson(leaderboard, timePoint, resultState, maxCompetitorsCount,
|
||||
raceColumnNames, raceDetailNames);
|
||||
raceColumnNames, raceDetailNames, competitorAndBoatIdsOnly);
|
||||
} else {
|
||||
jsonLeaderboard = createEmptyLeaderboardJson(leaderboard, resultState, maxCompetitorsCount);
|
||||
}
|
||||
|
||||
+5
-5
@@ -180,9 +180,9 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
public Response getLeaderboard(@PathParam("name") String leaderboardName,
|
||||
@DefaultValue("Live") @QueryParam("resultState") ResultStates resultState,
|
||||
@QueryParam("maxCompetitorsCount") Integer maxCompetitorsCount,
|
||||
@QueryParam("secret") String regattaSecret) {
|
||||
@QueryParam("secret") String regattaSecret,
|
||||
@DefaultValue("false") @QueryParam("competitorAndBoatIdsOnly") boolean competitorAndBoatIdsOnly) {
|
||||
ShardingContext.setShardingConstraint(ShardingType.LEADERBOARDNAME, leaderboardName);
|
||||
|
||||
try {
|
||||
Response response;
|
||||
TimePoint requestTimePoint = MillisecondsTimePoint.now();
|
||||
@@ -200,7 +200,7 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
TimePoint timePoint = calculateTimePointForResultState(leaderboard, resultState);
|
||||
JSONObject jsonLeaderboard;
|
||||
jsonLeaderboard = getLeaderboardJson(resultState, maxCompetitorsCount, requestTimePoint,
|
||||
leaderboard, timePoint, /* race column names */ null, /* race detail names */ null);
|
||||
leaderboard, timePoint, /* race column names */ null, /* race detail names */ null, competitorAndBoatIdsOnly);
|
||||
StringWriter sw = new StringWriter();
|
||||
jsonLeaderboard.writeJSONString(sw);
|
||||
String json = sw.getBuffer().toString();
|
||||
@@ -220,7 +220,7 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
@Override
|
||||
protected JSONObject getLeaderboardJson(Leaderboard leaderboard,
|
||||
TimePoint resultTimePoint, ResultStates resultState, Integer maxCompetitorsCount, List<String> raceColumnNames,
|
||||
List<String> raceDetailNames)
|
||||
List<String> raceDetailNames, boolean competitorIdsOnly)
|
||||
throws NoWindException, InterruptedException, ExecutionException {
|
||||
LeaderboardDTO leaderboardDTO = leaderboard.getLeaderboardDTO(
|
||||
resultTimePoint, Collections.<String> emptyList(), /* addOverallDetails */
|
||||
@@ -238,7 +238,7 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
break;
|
||||
}
|
||||
JSONObject jsonCompetitor = new JSONObject();
|
||||
writeCompetitorBaseData(jsonCompetitor, competitor, leaderboardDTO);
|
||||
writeCompetitorBaseData(jsonCompetitor, competitor, leaderboardDTO, competitorIdsOnly);
|
||||
jsonCompetitor.put("rank", counter);
|
||||
jsonCompetitor.put("carriedPoints", leaderboardRowDTO.carriedPoints);
|
||||
jsonCompetitor.put("netPoints", leaderboardRowDTO.netPoints);
|
||||
|
||||
+7
-6
@@ -62,7 +62,8 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
|
||||
@QueryParam("raceDetails") final List<String> raceDetails,
|
||||
@QueryParam("time") String time, @QueryParam("timeasmillis") Long timeasmillis,
|
||||
@QueryParam("maxCompetitorsCount") Integer maxCompetitorsCount,
|
||||
@QueryParam("secret") String regattaSecret) {
|
||||
@QueryParam("secret") String regattaSecret,
|
||||
@DefaultValue("false") @QueryParam("competitorAndBoatIdsOnly") boolean competitorAndBoatIdsOnly) {
|
||||
ShardingContext.setShardingConstraint(ShardingType.LEADERBOARDNAME, leaderboardName);
|
||||
try {
|
||||
Response response;
|
||||
@@ -86,7 +87,7 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
|
||||
}
|
||||
JSONObject jsonLeaderboard;
|
||||
if (timePoint != null || resultState == ResultStates.Live) {
|
||||
jsonLeaderboard = getLeaderboardJson(leaderboard, timePoint, resultState, maxCompetitorsCount, raceColumnNames, raceDetails);
|
||||
jsonLeaderboard = getLeaderboardJson(leaderboard, timePoint, resultState, maxCompetitorsCount, raceColumnNames, raceDetails, competitorAndBoatIdsOnly);
|
||||
} else {
|
||||
jsonLeaderboard = createEmptyLeaderboardJson(leaderboard, resultState, maxCompetitorsCount);
|
||||
}
|
||||
@@ -108,7 +109,7 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
|
||||
@Override
|
||||
protected JSONObject getLeaderboardJson(Leaderboard leaderboard,
|
||||
TimePoint resultTimePoint, ResultStates resultState, Integer maxCompetitorsCount,
|
||||
List<String> raceColumnNames, List<String> raceDetailNames)
|
||||
List<String> raceColumnNames, List<String> raceDetailNames, boolean competitorAndBoatIdsOnly)
|
||||
throws NoWindException, InterruptedException, ExecutionException {
|
||||
List<String> raceColumnsToShow = calculateRaceColumnsToShow(raceColumnNames, leaderboard.getRaceColumns());
|
||||
List<DetailType> raceDetailsToShow = calculateRaceDetailTypesToShow(raceDetailNames);
|
||||
@@ -171,11 +172,11 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
|
||||
break;
|
||||
}
|
||||
JSONObject jsonCompetitor = new JSONObject();
|
||||
writeCompetitorBaseData(jsonCompetitor, competitor, leaderboardDTO);
|
||||
writeCompetitorBaseData(jsonCompetitor, competitor, leaderboardDTO, competitorAndBoatIdsOnly);
|
||||
BoatDTO rowBoatDTO = leaderboardRowDTO.boat;
|
||||
if (rowBoatDTO != null) {
|
||||
JSONObject jsonBoat = new JSONObject();
|
||||
writeBoatData(jsonBoat, rowBoatDTO);
|
||||
writeBoatData(jsonBoat, rowBoatDTO, competitorAndBoatIdsOnly);
|
||||
jsonCompetitor.put("boat", jsonBoat);
|
||||
}
|
||||
jsonCompetitor.put("rank", ranks.get(competitor));
|
||||
@@ -192,7 +193,7 @@ public class LeaderboardsResourceV2 extends AbstractLeaderboardsResource {
|
||||
BoatDTO entryBoatDTO = leaderboardEntry.boat;
|
||||
if (entryBoatDTO != null) {
|
||||
JSONObject jsonBoat = new JSONObject();
|
||||
writeBoatData(jsonBoat, entryBoatDTO);
|
||||
writeBoatData(jsonBoat, entryBoatDTO, competitorAndBoatIdsOnly);
|
||||
jsonEntry.put("boat", jsonBoat);
|
||||
}
|
||||
final FleetDTO fleetOfCompetitor = leaderboardEntry.fleet;
|
||||
|
||||
@@ -36,6 +36,17 @@
|
||||
<td> </td>
|
||||
<td>maxCompetitorsCount [1000 = Default]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<div>competitorAndBoatIdsOnly [Default = false, true] if true, only IDs and no further attributes
|
||||
will be delivered for competitor and boat JSON objects in the result document. This can help
|
||||
save bandwidth if the competitor and boat data have been received already during previous calls
|
||||
and the current call is only an update. Note, however, that competitor and boat data may change,
|
||||
so every now and then it is advisable to still set this to false to obtain the full up-to-date
|
||||
fields for all competitors and boats again.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Request method:</td>
|
||||
<td>GET</td>
|
||||
|
||||
@@ -52,6 +52,17 @@ There is also the 'ALL' shortcut constant which can be used to get all available
|
||||
<td> </td>
|
||||
<td>raceDetails [Default = RACE_GAP_TO_LEADER_IN_SECONDS, RACE_AVERAGE_SPEED_OVER_GROUND_IN_KNOTS, RACE_CURRENT_SPEED_OVER_GROUND_IN_KNOTS, RACE_DISTANCE_TO_COMPETITOR_FARTHEST_AHEAD_IN_METERS, CURRENT_LEG]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<div>competitorAndBoatIdsOnly [Default = false, true] if true, only IDs and no further attributes
|
||||
will be delivered for competitor and boat JSON objects in the result document. This can help
|
||||
save bandwidth if the competitor and boat data have been received already during previous calls
|
||||
and the current call is only an update. Note, however, that competitor and boat data may change,
|
||||
so every now and then it is advisable to still set this to false to obtain the full up-to-date
|
||||
fields for all competitors and boats again.</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
|
||||
Reference in new issue
Block a user