mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-22 03:53:56 +00:00
Merge commit 'd1b03bb576b58765444b4f0a44c5ab7f435a5740' into foiling2
This commit is contained in:
commit
40a79d8ded
301 files changed
+20250
-3126
No files matched your search
@@ -63,5 +63,8 @@ bearerToken = com.sap.sailing.server.security.BearerTokenOrBasicOrFormAuthentica
|
||||
# Uncomment the following to require the permission "event:view" in order to use /api/v1/events:
|
||||
#/api/v1/events = bearerToken
|
||||
|
||||
# Secure access to leaderboard race column factor updates; read access should require no permissions
|
||||
/api/v1/leaderboards/*/racecolumnfactors/** = bearerToken
|
||||
|
||||
# Secure the access (in particular the POST/write access) to posting race log events
|
||||
/rc/racelog = bearerToken
|
||||
+4
-1
@@ -58,9 +58,12 @@ public class CompetitorsResource extends AbstractSailingServerResource {
|
||||
json.put(CompetitorJsonConstants.FIELD_COUNTRY_CODE, nationality==null?null:nationality.getCountryCode().getTwoLetterISOCode());
|
||||
json.put(CompetitorJsonConstants.FIELD_BOAT_CLASS_NAME, competitor.getBoat().getBoatClass().getName());
|
||||
json.put(CompetitorJsonConstants.FIELD_COLOR, competitor.getColor() != null ? competitor.getColor().getAsHtml() : null);
|
||||
if(competitor.getFlagImage() != null) {
|
||||
if (competitor.getFlagImage() != null) {
|
||||
json.put(CompetitorJsonConstants.FIELD_FLAG_IMAGE, competitor.getFlagImage().toString());
|
||||
}
|
||||
if (competitor.getTeam().getImage() != null) {
|
||||
json.put(CompetitorJsonConstants.FIELD_TEAM_IMAGE_URI, competitor.getTeam().getImage().toString());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -35,13 +35,13 @@ public class EventsResource extends AbstractSailingServerResource {
|
||||
|
||||
@GET
|
||||
@Produces("application/json;charset=UTF-8")
|
||||
public Response getEvents() {
|
||||
public Response getEvents(@QueryParam("showNonPublic") String showNonPublic) {
|
||||
// TODO bug2589, bug3504: the following will require EVENT:READ permission; it requires cross-server links to be authentication aware...
|
||||
// SecurityUtils.getSubject().checkPermission(Permission.EVENT.getStringPermission(Permission.Mode.READ));
|
||||
JsonSerializer<EventBase> eventSerializer = new EventBaseJsonSerializer(new VenueJsonSerializer(new CourseAreaJsonSerializer()), new LeaderboardGroupBaseJsonSerializer());
|
||||
JSONArray result = new JSONArray();
|
||||
for (EventBase event : getService().getAllEvents()) {
|
||||
if (event.isPublic()) {
|
||||
if ((showNonPublic != null && Boolean.valueOf(showNonPublic)) || event.isPublic()) {
|
||||
result.add(eventSerializer.serialize(event));
|
||||
}
|
||||
}
|
||||
|
||||
+92
@@ -29,6 +29,7 @@ import javax.ws.rs.core.Response.Status;
|
||||
import javax.xml.ws.http.HTTPException;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
@@ -58,6 +59,8 @@ import com.sap.sailing.domain.common.dto.LeaderboardRowDTO;
|
||||
import com.sap.sailing.domain.common.dto.RaceColumnDTO;
|
||||
import com.sap.sailing.domain.common.racelog.RaceLogServletConstants;
|
||||
import com.sap.sailing.domain.common.racelog.tracking.DeviceMappingConstants;
|
||||
import com.sap.sailing.domain.common.security.Permission;
|
||||
import com.sap.sailing.domain.common.security.Permission.Mode;
|
||||
import com.sap.sailing.domain.common.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.leaderboard.Leaderboard;
|
||||
import com.sap.sailing.domain.leaderboard.SettableScoreCorrection;
|
||||
@@ -637,4 +640,93 @@ public class LeaderboardsResource extends AbstractSailingServerResource {
|
||||
adapter.pingMark(regattaLog, mark, fix, service);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param raceColumnName optional; if omitted, all race column factors in the leaderboard will be reported, otherwise only the one requested
|
||||
*/
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("{leaderboardName}/racecolumnfactors")
|
||||
public Response getRaceColumnFactors(@PathParam("leaderboardName") String leaderboardName, @QueryParam(RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME) String raceColumnName) {
|
||||
final Response response;
|
||||
final Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
|
||||
if (leaderboard == null) {
|
||||
response = Response.status(Status.NOT_FOUND)
|
||||
.entity("Could not find a leaderboard with name '" + StringEscapeUtils.escapeHtml(leaderboardName) + "'.")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
} else {
|
||||
final Iterable<RaceColumn> raceColumns;
|
||||
final RaceColumn raceColumn;
|
||||
if (raceColumnName == null) {
|
||||
raceColumns = leaderboard.getRaceColumns();
|
||||
raceColumn = null;
|
||||
} else {
|
||||
raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
|
||||
raceColumns = Collections.singleton(raceColumn);
|
||||
}
|
||||
if (raceColumnName != null && raceColumn == null) {
|
||||
response = Response.status(Status.NOT_FOUND)
|
||||
.entity("Could not find a race column named '"+StringEscapeUtils.escapeHtml(raceColumnName)+"' in leaderboard with name '" + StringEscapeUtils.escapeHtml(leaderboardName) + "'.")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
} else {
|
||||
final JSONObject json = getJsonForColumnFactors(leaderboard, raceColumns);
|
||||
response = Response.ok(json.toJSONString(), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private JSONObject getJsonForColumnFactors(final Leaderboard leaderboard, final Iterable<RaceColumn> raceColumns) {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("leaderboard_name", leaderboard.getName());
|
||||
json.put("leaderboard_display_name", leaderboard.getDisplayName());
|
||||
final JSONArray raceColumnsAsJson = new JSONArray();
|
||||
json.put("race_columns", raceColumnsAsJson);
|
||||
for (final RaceColumn rc : raceColumns) {
|
||||
final JSONObject raceColumnAsJson = new JSONObject();
|
||||
raceColumnsAsJson.add(raceColumnAsJson);
|
||||
raceColumnAsJson.put("race_column_name", rc.getName());
|
||||
raceColumnAsJson.put("explicit_factor", rc.getExplicitFactor());
|
||||
raceColumnAsJson.put("factor", rc.getFactor());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param raceColumnName
|
||||
* mandatory
|
||||
* @param explicitFactor
|
||||
* may be {@code null} which means resetting the explicit factor and letting the leaderboard determine
|
||||
* the column factor implicitly.
|
||||
* @see RaceColumn#setFactor(Double)
|
||||
* @return a document that contains the leaderboard "header" data and the factor data for the race column specified,
|
||||
* after the change. This may be useful to validate the impact the change had on the resulting column factor
|
||||
*/
|
||||
@POST
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Path("{leaderboardName}/racecolumnfactors")
|
||||
public Response setExplicitRaceColumnFactor(@PathParam("leaderboardName") String leaderboardName, @QueryParam(RaceLogServletConstants.PARAMS_RACE_COLUMN_NAME) String raceColumnName,
|
||||
@QueryParam("explicit_factor") Double explicitFactor) {
|
||||
final Response response;
|
||||
final Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
|
||||
if (leaderboard == null) {
|
||||
response = Response.status(Status.NOT_FOUND)
|
||||
.entity("Could not find a leaderboard with name '" + StringEscapeUtils.escapeHtml(leaderboardName) + "'.")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
} else {
|
||||
SecurityUtils.getSubject().checkPermission(Permission.LEADERBOARD.getStringPermissionForObjects(Mode.UPDATE, leaderboard.getName()));
|
||||
final RaceColumn raceColumn;
|
||||
raceColumn = leaderboard.getRaceColumnByName(raceColumnName);
|
||||
if (raceColumn == null) {
|
||||
response = Response.status(Status.NOT_FOUND)
|
||||
.entity("Could not find a race column named '"+StringEscapeUtils.escapeHtml(raceColumnName)+"' in leaderboard with name '" + StringEscapeUtils.escapeHtml(leaderboardName) + "'.")
|
||||
.type(MediaType.TEXT_PLAIN).build();
|
||||
} else {
|
||||
raceColumn.setFactor(explicitFactor);
|
||||
final JSONObject json = getJsonForColumnFactors(leaderboard, Collections.singleton(raceColumn));
|
||||
response = Response.ok(json.toJSONString(), MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<link href='../../../../fontface.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
|
||||
<link href='../../../main.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
|
||||
<link rel='icon' href='../../../../sap.ico' type='image/x-icon'>
|
||||
<title>SAP Sailing Analytics Webservices API Version 1.0 Beta</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SAP Sailing Analytics Webservices API Version 1.0 Beta</h1>
|
||||
<h2>URL: /api/v1/leaderboards/{name}/racecolumnfactors?race_column={racecolumnname}</h2>
|
||||
|
||||
<b>Description:</b>
|
||||
<p>Gets the scoring factor / multiplier for one or more race columns of a leaderboard.</p>
|
||||
<br/>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Webservice Type:</td>
|
||||
<td>REST</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Output format:</td>
|
||||
<td>Json</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Mandatory parameters:</td>
|
||||
<td>None</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Optional parameters:</td>
|
||||
<td>race_column: may specify the name of a single race column whose factor information to obtain;
|
||||
if omitted, information for all columns in the leaderboard will be returned</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Request method:</td>
|
||||
<td>GET</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example:</td>
|
||||
<td><a href="http://www.sapsailing.com/sailingserver/api/v1/leaderboards/Nacra%2017%20TracTrac%20Test/racecolumnfactors?race_column=R10">http://www.sapsailing.com/sailingserver/api/v1/leaderboards/Nacra%2017%20TracTrac%20Test/racecolumnfactors?race_column=R10</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example Output</td>
|
||||
<td><pre>
|
||||
{
|
||||
"leaderboard_name": "Nacra 17 TracTrac Test",
|
||||
"leaderboard_display_name": null,
|
||||
"race_columns": [
|
||||
{
|
||||
"race_column_name": "R10",
|
||||
"explicit_factor": 3.7,
|
||||
"factor": 3.7
|
||||
}
|
||||
]
|
||||
}
|
||||
</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="height: 1em;"></div>
|
||||
<a href="index.html">Back to Web Service Overview</a>
|
||||
</body>
|
||||
</html>
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<link href='../../../../fontface.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
|
||||
<link href='../../../main.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
|
||||
<link rel='icon' href='../../../../sap.ico' type='image/x-icon'>
|
||||
<title>SAP Sailing Analytics Webservices API Version 1.0 Beta</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SAP Sailing Analytics Webservices API Version 1.0 Beta</h1>
|
||||
<h2>URL: /api/v1/leaderboards/{name}/racecolumnfactors?race_column={racecolumnname}&explicit_factor=2.0</h2>
|
||||
|
||||
<b>Description:</b>
|
||||
<p>Sets the scoring factor / multiplier for a race columns of a leaderboard.</p>
|
||||
<br/>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Webservice Type:</td>
|
||||
<td>REST, method POST</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Output format:</td>
|
||||
<td>Json</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Mandatory parameters:</td>
|
||||
<td>race_column: specifies the name of a single race column whose factor information to update
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Optional parameters:</td>
|
||||
<td>explicit_factor: specifies the new factor to set; if <tt>null</tt> or empty, the column's factor
|
||||
goes back to the default as decided by the leaderboard, e.g., 1.0 for a regular column or 2.0 for
|
||||
a medal race column.
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Request method:</td>
|
||||
<td>POST</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example:</td>
|
||||
<td><a href="http://www.sapsailing.com/sailingserver/api/v1/leaderboards/Nacra%2017%20TracTrac%20Test/racecolumnfactors?race_column=R10&explicit_factor=2.0">http://www.sapsailing.com/sailingserver/api/v1/leaderboards/Nacra%2017%20TracTrac%20Test/racecolumnfactors?race_column=R10&explicit_factor=2.0</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Example Output</td>
|
||||
<td><pre>
|
||||
{
|
||||
"leaderboard_name": "Nacra 17 TracTrac Test",
|
||||
"leaderboard_display_name": null,
|
||||
"race_columns": [
|
||||
{
|
||||
"race_column_name": "R10",
|
||||
"explicit_factor": 3.7,
|
||||
"factor": 3.7
|
||||
}
|
||||
]
|
||||
}
|
||||
</pre></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="height: 1em;"></div>
|
||||
<a href="index.html">Back to Web Service Overview</a>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user