Merge branch 'main' into bug6031

This commit is contained in:
Axel Uhl
2024-06-19 13:52:16 +02:00
5 changed files with 45 additions and 28 deletions
@@ -16,6 +16,7 @@ import com.sap.sailing.domain.base.Fleet;
import com.sap.sailing.domain.base.Nationality;
import com.sap.sailing.domain.base.RaceColumn;
import com.sap.sailing.domain.base.Waypoint;
import com.sap.sailing.domain.common.LeaderboardNameConstants;
import com.sap.sailing.domain.common.NoWindException;
import com.sap.sailing.domain.common.dto.BoatDTO;
import com.sap.sailing.domain.common.dto.CompetitorDTO;
@@ -128,25 +129,35 @@ public abstract class AbstractLeaderboardsResource extends AbstractSailingServer
}
}
static JSONArray getDiscardingRuleAsJson(Leaderboard leaderboard) {
final JSONArray discardIndices;
final ResultDiscardingRule resultDiscardingRule = leaderboard.getResultDiscardingRule();
if (resultDiscardingRule instanceof ThresholdBasedResultDiscardingRule) {
final ThresholdBasedResultDiscardingRule thresholdBasedResultDiscardingRule = (ThresholdBasedResultDiscardingRule) resultDiscardingRule;
discardIndices = new JSONArray();
for (int index : thresholdBasedResultDiscardingRule.getDiscardIndexResultsStartingWithHowManyRaces()) {
discardIndices.add(index);
}
} else {
discardIndices = null;
}
return discardIndices;
}
protected void writeCommonLeaderboardData(JSONObject jsonLeaderboard, Leaderboard leaderboard,
ResultStates resultState, Date resultTimePoint, Integer maxCompetitorsCount) {
jsonLeaderboard.put("name", leaderboard.getName());
jsonLeaderboard.put(LeaderboardNameConstants.NAME, leaderboard.getName());
final String displayName = leaderboard.getDisplayName();
jsonLeaderboard.put("displayName", displayName == null ? leaderboard.getName() : displayName);
jsonLeaderboard.put(LeaderboardNameConstants.DISPLAYNAME, displayName == null ? leaderboard.getName() : displayName);
jsonLeaderboard.put("boatClass", leaderboard.getBoatClass() == null ? null : leaderboard.getBoatClass().getName());
jsonLeaderboard.put("resultTimepoint", resultTimePoint != null ? resultTimePoint.getTime() : null);
jsonLeaderboard.put("delayToLiveInMillis", leaderboard.getDelayToLiveInMillis());
jsonLeaderboard.put("resultState", resultState.name());
jsonLeaderboard.put("type", leaderboard.getLeaderboardType().name());
jsonLeaderboard.put("shardingLeaderboardName", ShardingType.LEADERBOARDNAME.encodeShardingInfo(leaderboard.getName()));
final ResultDiscardingRule resultDiscardingRule = leaderboard.getResultDiscardingRule();
if (resultDiscardingRule instanceof ThresholdBasedResultDiscardingRule) {
final ThresholdBasedResultDiscardingRule thresholdBasedResultDiscardingRule = (ThresholdBasedResultDiscardingRule) resultDiscardingRule;
final JSONArray discardIndices = new JSONArray();
jsonLeaderboard.put("discardIndexResultsStartingWithHowManyRaces", discardIndices);
for (int index : thresholdBasedResultDiscardingRule.getDiscardIndexResultsStartingWithHowManyRaces()) {
discardIndices.add(index);
}
final JSONArray discardIndices = getDiscardingRuleAsJson(leaderboard);
if (discardIndices != null) {
jsonLeaderboard.put(LeaderboardNameConstants.DISCARDS, discardIndices);
}
if (leaderboard instanceof RegattaLeaderboard) {
final RegattaLeaderboard regattaLeaderboard = (RegattaLeaderboard) leaderboard;
@@ -157,12 +168,12 @@ public abstract class AbstractLeaderboardsResource extends AbstractSailingServer
jsonLeaderboard.put("maxCompetitorsCount", maxCompetitorsCount);
final SettableScoreCorrection scoreCorrection = leaderboard.getScoreCorrection();
if (scoreCorrection != null) {
jsonLeaderboard.put("scoringComment", scoreCorrection.getComment());
jsonLeaderboard.put(LeaderboardNameConstants.SCORINGCOMMENT, scoreCorrection.getComment());
TimePoint lastUpdateTimepoint = scoreCorrection.getTimePointOfLastCorrectionsValidity();
jsonLeaderboard.put("lastScoringUpdate", lastUpdateTimepoint != null ? lastUpdateTimepoint.asMillis() : null);
jsonLeaderboard.put(LeaderboardNameConstants.LASTSCORINGUPDATE, lastUpdateTimepoint != null ? lastUpdateTimepoint.asMillis() : null);
} else {
jsonLeaderboard.put("scoringComment", null);
jsonLeaderboard.put("lastScoringUpdate", null);
jsonLeaderboard.put(LeaderboardNameConstants.SCORINGCOMMENT, null);
jsonLeaderboard.put(LeaderboardNameConstants.LASTSCORINGUPDATE, null);
}
final JSONArray jsonColumnNames = new JSONArray();
final JSONArray trackedRacesInfo = new JSONArray();
@@ -174,7 +185,7 @@ public abstract class AbstractLeaderboardsResource extends AbstractSailingServer
trackedRacesInfo.add(raceColumnJson);
raceColumnJson.put("raceColumnName", raceColumn.getName());
final JSONArray fleetsJson = new JSONArray();
raceColumnJson.put("fleets", fleetsJson);
raceColumnJson.put(LeaderboardNameConstants.FLEETS, fleetsJson);
for (final Fleet fleet : raceColumn.getFleets()) {
final JSONObject fleetJson = new JSONObject();
fleetsJson.add(fleetJson);
@@ -27,6 +27,7 @@ import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.json.simple.JSONArray;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.JSONParser;
@@ -67,6 +68,7 @@ public class CompareServersResource extends AbstractSailingServerResource {
LeaderboardNameConstants.ISMETALEADERBOARD, LeaderboardNameConstants.ISREGATTALEADERBOARD,
LeaderboardNameConstants.SCORINGCOMMENT, LeaderboardNameConstants.LASTSCORINGUPDATE,
LeaderboardNameConstants.SCORINGSCHEME, LeaderboardNameConstants.REGATTANAME,
LeaderboardNameConstants.DISCARDS,
LeaderboardNameConstants.SERIES, LeaderboardNameConstants.ISMEDALSERIES, LeaderboardNameConstants.FLEETS,
LeaderboardNameConstants.COLOR, LeaderboardNameConstants.ORDERING, LeaderboardNameConstants.RACES,
LeaderboardNameConstants.ISMEDALRACE, LeaderboardNameConstants.ISTRACKED,
@@ -244,13 +246,13 @@ public class CompareServersResource extends AbstractSailingServerResource {
*/
private Pair<Object, Object> fetchLeaderboardgroupDetailsAndRemoveDuplicates(String server1, String server2,
String leaderboardgroupId, String bearer1, String bearer2) throws Exception {
Object lgdetail1 = getLeaderboardgroupDetailsById(leaderboardgroupId, RemoteServerUtil.createBaseUrl(server1), bearer1);
Object lgdetail2 = getLeaderboardgroupDetailsById(leaderboardgroupId, RemoteServerUtil.createBaseUrl(server2), bearer2);
Pair<Object, Object> result = removeUnnecessaryAndDuplicateFields(lgdetail1, lgdetail2);
final JSONObject lgdetail1 = getLeaderboardgroupDetailsById(leaderboardgroupId, RemoteServerUtil.createBaseUrl(server1), bearer1);
final JSONObject lgdetail2 = getLeaderboardgroupDetailsById(leaderboardgroupId, RemoteServerUtil.createBaseUrl(server2), bearer2);
final Pair<Object, Object> result = removeUnnecessaryAndDuplicateFields(lgdetail1, lgdetail2);
return result;
}
Pair<Object, Object> removeUnnecessaryAndDuplicateFields(Object lgdetail1, Object lgdetail2) {
Pair<Object, Object> removeUnnecessaryAndDuplicateFields(JSONAware lgdetail1, JSONAware lgdetail2) {
removeUnnecessaryFields(lgdetail1);
removeUnnecessaryFields(lgdetail2);
Pair<Object, Object> result = removeDuplicateEntries(lgdetail1, lgdetail2);
@@ -275,10 +277,10 @@ public class CompareServersResource extends AbstractSailingServerResource {
/**
* Fetches the JSON for a given leaderboardgroup UUID.
*/
private Object getLeaderboardgroupDetailsById(String leaderboardgroupId, URL baseUrl, String bearer) throws Exception {
final URLConnection lgdetailc = HttpUrlConnectionHelper.redirectConnectionWithBearerToken(
private JSONObject getLeaderboardgroupDetailsById(String leaderboardgroupId, URL baseUrl, String bearer) throws Exception {
final URLConnection lgdetails = HttpUrlConnectionHelper.redirectConnectionWithBearerToken(
RemoteServerUtil.createRemoteServerUrl(baseUrl, createLgDetailPath(leaderboardgroupId), null), bearer);
Object result = JSONValue.parse(new InputStreamReader(lgdetailc.getInputStream(), "UTF-8"));
JSONObject result = (JSONObject) JSONValue.parse(new InputStreamReader(lgdetails.getInputStream(), "UTF-8"));
return result;
}
@@ -296,7 +298,7 @@ public class CompareServersResource extends AbstractSailingServerResource {
* empty path string to start with, removing fields to be ignored or not to be compared in-place, modifying
* the {@code json} object.
*/
private void removeUnnecessaryFields(Object json) {
private void removeUnnecessaryFields(JSONAware json) {
removeUnnecessaryFields(json, "");
}
@@ -171,6 +171,10 @@ public class LeaderboardGroupsResource extends AbstractSailingServerResource {
jsonLeaderboard.put(LeaderboardNameConstants.DISPLAYNAME, leaderboard.getDisplayName());
jsonLeaderboard.put(LeaderboardNameConstants.ISMETALEADERBOARD, isMetaLeaderboard);
jsonLeaderboard.put(LeaderboardNameConstants.ISREGATTALEADERBOARD, isRegattaLeaderboard);
final JSONArray discardIndices = AbstractLeaderboardsResource.getDiscardingRuleAsJson(leaderboard);
if (discardIndices != null) {
jsonLeaderboard.put(LeaderboardNameConstants.DISCARDS, discardIndices);
}
jsonLeaderboardEntries.add(jsonLeaderboard);
SettableScoreCorrection scoreCorrection = leaderboard.getScoreCorrection();
if (scoreCorrection != null) {