mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 14:12:11 +00:00
fixed broken tests by also matching exact boat class name (ignoring case)
This commit is contained in:
1 parent
6553c40c2c
commit
ceebdbf8d5
4 files changed
+83
-12
No files matched your search
+18
-5
@@ -42,17 +42,30 @@ public abstract class AbstractSailingServerResource {
|
||||
return resourceContext;
|
||||
}
|
||||
|
||||
public <T> T getService(Class<T> clazz) {
|
||||
BundleContext context = getBundleContext();
|
||||
ServiceTracker<T, T> tracker = new ServiceTracker<T, T>(context, clazz, null);
|
||||
tracker.open();
|
||||
protected <T> T getService(Class<T> clazz) {
|
||||
final ServiceTracker<T, T> tracker = getServiceTracker(clazz);
|
||||
T service = tracker.getService();
|
||||
tracker.close();
|
||||
return service;
|
||||
}
|
||||
|
||||
protected <T> T[] getServices(Class<T> clazz) {
|
||||
final ServiceTracker<T, T> tracker = getServiceTracker(clazz);
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] services = (T[]) tracker.getServices();
|
||||
tracker.close();
|
||||
return services;
|
||||
}
|
||||
|
||||
protected <T> ServiceTracker<T, T> getServiceTracker(Class<T> clazz) {
|
||||
final BundleContext context = getBundleContext();
|
||||
final ServiceTracker<T, T> tracker = new ServiceTracker<T, T>(context, clazz, null);
|
||||
tracker.open();
|
||||
return tracker;
|
||||
}
|
||||
|
||||
protected BundleContext getBundleContext() {
|
||||
BundleContext context = (BundleContext) servletContext
|
||||
final BundleContext context = (BundleContext) servletContext
|
||||
.getAttribute(RestServletContainer.OSGI_RFC66_WEBBUNDLE_BUNDLECONTEXT_NAME);
|
||||
return context;
|
||||
}
|
||||
|
||||
+47
-4
@@ -1,16 +1,19 @@
|
||||
package com.sap.sailing.server.gateway.jaxrs.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -77,6 +80,8 @@ import com.sap.sailing.domain.common.NoWindException;
|
||||
import com.sap.sailing.domain.common.NotFoundException;
|
||||
import com.sap.sailing.domain.common.PassingInstruction;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.domain.common.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.common.dto.CompetitorDTO;
|
||||
import com.sap.sailing.domain.common.dto.FleetDTO;
|
||||
@@ -165,7 +170,7 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
* or, respectively, after the finish line has been crossed.
|
||||
*/
|
||||
private static final Duration TIME_OFFSET_FOR_HEAD_AND_TAIL_OF_TRACK_FOR_LINE_INFERENCE = Duration.ONE_MINUTE;
|
||||
|
||||
|
||||
@GET
|
||||
@Produces("application/json;charset=UTF-8")
|
||||
public Response getLeaderboards() {
|
||||
@@ -1561,7 +1566,6 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
if (fleet == null) {
|
||||
throw new NotFoundException("fleet with name " + fleetName + " not found");
|
||||
}
|
||||
|
||||
boolean result = getRaceLogTrackingAdapter().denoteRaceForRaceLogTracking(getService(), leaderboard, raceColumn,
|
||||
fleet, raceName);
|
||||
return (result ? Response.ok() : Response.notModified()).build();
|
||||
@@ -1585,10 +1589,8 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
if (fleet == null) {
|
||||
throw new NotFoundException("fleet with name " + fleetName + " not found");
|
||||
}
|
||||
|
||||
final AbstractLogEventAuthor raceLogEventAuthorForRaceColumn = new LogEventAuthorImpl(
|
||||
AbstractRaceColumn.class.getName(), 0);
|
||||
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
RaceLog raceLog = raceColumn.getRaceLog(fleet);
|
||||
if (raceLog == null) {
|
||||
@@ -1618,4 +1620,45 @@ public class LeaderboardsResource extends AbstractLeaderboardsResource {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
private Iterable<ScoreCorrectionProvider> getScoreCorrectionProviders() {
|
||||
return Arrays.asList(getServices(ScoreCorrectionProvider.class));
|
||||
}
|
||||
|
||||
private Optional<ScoreCorrectionProvider> getScoreCorrectionProvider(final String scoreCorrectionProviderName) {
|
||||
return StreamSupport.stream(getScoreCorrectionProviders().spliterator(), /* parallel */ false).
|
||||
filter(scp->scp.getName().equals(scoreCorrectionProviderName)).findAny();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{name}/results")
|
||||
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response uploadResults(@PathParam("name") String leaderboardName,
|
||||
@QueryParam("scoreCorrectionProvider") String scoreCorrectionProviderName,
|
||||
InputStream inputStream) throws Exception {
|
||||
final Leaderboard leaderboard = getService().getLeaderboardByName(leaderboardName);
|
||||
if (leaderboard == null) {
|
||||
throw new NotFoundException("leaderboard with name " + leaderboardName + " not found");
|
||||
}
|
||||
getSecurityService().checkCurrentUserUpdatePermission(leaderboard);
|
||||
final Optional<ScoreCorrectionProvider> scoreCorrectionProvider = getScoreCorrectionProvider(scoreCorrectionProviderName);
|
||||
if (!scoreCorrectionProvider.isPresent()) {
|
||||
throw new NotFoundException("score correction provider with name " + scoreCorrectionProviderName + " not found");
|
||||
}
|
||||
final RegattaScoreCorrections scoreCorrection = scoreCorrectionProvider.get().getScoreCorrections(inputStream);
|
||||
return applyScoreCorrectionToLeaderboard(leaderboard, scoreCorrection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the matching specifications for race names/numbers and sail IDs/numbers, tries to apply the
|
||||
* {@code scoreCorrection} to the {@code leaderboard}. If everything works well, a simple {@link Status#OK} will
|
||||
* be returned with an empty JSON document. Otherwise, {@link Status#CONFLICT} will be the status of the response,
|
||||
* and the JSON document returned will tell which sail IDs/numbers and which race names/numbers could not be resolved.
|
||||
*/
|
||||
private Response applyScoreCorrectionToLeaderboard(Leaderboard leaderboard, RegattaScoreCorrections scoreCorrection) {
|
||||
final JSONObject result = new JSONObject();
|
||||
|
||||
// TODO Implement LeaderboardsResource.applyScoreCorrectionToLeaderboard(...)
|
||||
return Response.ok(result.toJSONString()).build();
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -4,15 +4,26 @@ import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
|
||||
import com.sap.sailing.domain.common.NotFoundException;
|
||||
|
||||
@Provider
|
||||
public class ExceptionManager implements ExceptionMapper<Exception> {
|
||||
public Response toResponse(Exception exception) {
|
||||
return Response.status(400).entity(exception.getMessage()).type("text/plain").build();
|
||||
Response result;
|
||||
try {
|
||||
throw exception;
|
||||
} catch (NotFoundException nfe) {
|
||||
result = Response.status(Status.NOT_FOUND).entity(nfe.getMessage()).type("text/plain").build();
|
||||
} catch (Exception e) {
|
||||
result = Response.status(Status.BAD_REQUEST).entity(e.getMessage()).type("text/plain").build();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String invalidDateFormatMsg(String date) {
|
||||
|
||||
+6
-2
@@ -113,11 +113,15 @@ public class ParserImpl implements Parser {
|
||||
if (eventO instanceof Division) {
|
||||
final Division division = (Division) eventO;
|
||||
final EventGender divisionGender = division.getGender();
|
||||
String divisionBoatClassAndGender = getBoatClassName(division);
|
||||
final String divisionBoatClass = getBoatClassName(division);
|
||||
final String divisionBoatClassAndGender;
|
||||
if (divisionGender != null) {
|
||||
divisionBoatClassAndGender += ", " + divisionGender.name();
|
||||
divisionBoatClassAndGender = divisionBoatClass + ", " + divisionGender.name();
|
||||
} else {
|
||||
divisionBoatClassAndGender = divisionBoatClass;
|
||||
}
|
||||
if (!boatClassNameFilter.isPresent()
|
||||
|| boatClassNameFilter.get().equalsIgnoreCase(divisionBoatClass)
|
||||
|| boatClassNameFilter.get().equalsIgnoreCase(divisionBoatClassAndGender)
|
||||
|| boatClassNameFilter.get().contains(divisionBoatClassAndGender)) {
|
||||
return new XRRRegattaResultsAsScoreCorrections(event, division, scoreCorrectionProvider, this);
|
||||
|
||||
Reference in new issue
Block a user