mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 09:41:00 +00:00
Adding races affected by wind import to servlet response.
This commit is contained in:
1 parent
eb047e4c9e
commit
56e398a943
1 file changed
+55
-2
+55
-2
@@ -17,6 +17,8 @@ import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|||||||
|
|
||||||
import com.sap.sailing.domain.base.RaceDefinition;
|
import com.sap.sailing.domain.base.RaceDefinition;
|
||||||
import com.sap.sailing.domain.base.Regatta;
|
import com.sap.sailing.domain.base.Regatta;
|
||||||
|
import com.sap.sailing.domain.common.RegattaAndRaceIdentifier;
|
||||||
|
import com.sap.sailing.domain.common.RegattaIdentifier;
|
||||||
import com.sap.sailing.domain.common.WindSource;
|
import com.sap.sailing.domain.common.WindSource;
|
||||||
import com.sap.sailing.domain.common.WindSourceType;
|
import com.sap.sailing.domain.common.WindSourceType;
|
||||||
import com.sap.sailing.domain.common.impl.WindSourceImpl;
|
import com.sap.sailing.domain.common.impl.WindSourceImpl;
|
||||||
@@ -26,11 +28,56 @@ import com.sap.sailing.domain.tracking.Wind;
|
|||||||
import com.sap.sailing.server.gateway.SailingServerHttpServlet;
|
import com.sap.sailing.server.gateway.SailingServerHttpServlet;
|
||||||
|
|
||||||
public class WindImportServlet extends SailingServerHttpServlet {
|
public class WindImportServlet extends SailingServerHttpServlet {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private static final WindSource EXPEDITION_WIND_SOURCE = new WindSourceImpl(WindSourceType.EXPEDITION);
|
private static final WindSource EXPEDITION_WIND_SOURCE = new WindSourceImpl(WindSourceType.EXPEDITION);
|
||||||
|
|
||||||
|
static class WindImportResult {
|
||||||
|
|
||||||
|
private final RegattaIdentifier regattaIdentifier;
|
||||||
|
private final RegattaAndRaceIdentifier raceIdentifier;
|
||||||
|
private int count;
|
||||||
|
private Wind firstWind;
|
||||||
|
private Wind lastWind;
|
||||||
|
|
||||||
|
public void update(Wind newWind) {
|
||||||
|
count++;
|
||||||
|
if (firstWind == null || newWind.getTimePoint().before(firstWind.getTimePoint())) {
|
||||||
|
firstWind = newWind;
|
||||||
|
}
|
||||||
|
if (lastWind == null || newWind.getTimePoint().after(lastWind.getTimePoint())) {
|
||||||
|
lastWind = newWind;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegattaIdentifier getRegattaIdentifier() {
|
||||||
|
return regattaIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegattaAndRaceIdentifier getRaceIdentifier() {
|
||||||
|
return raceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindImportResult(RegattaIdentifier regattaIdentifier, RegattaAndRaceIdentifier raceIdentifier) {
|
||||||
|
this.regattaIdentifier = regattaIdentifier;
|
||||||
|
this.raceIdentifier = raceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Wind getFirstWind() {
|
||||||
|
return firstWind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Wind getLastWind() {
|
||||||
|
return lastWind;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
if (!ServletFileUpload.isMultipartContent(req)) {
|
if (!ServletFileUpload.isMultipartContent(req)) {
|
||||||
@@ -41,6 +88,8 @@ public class WindImportServlet extends SailingServerHttpServlet {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
List<WindImportResult> windImportResults = new ArrayList<WindImportResult>();
|
||||||
|
|
||||||
Iterable<Regatta> allRegattas = getService().getAllRegattas();
|
Iterable<Regatta> allRegattas = getService().getAllRegattas();
|
||||||
|
|
||||||
Collection<FileItem> files = readInput(req);
|
Collection<FileItem> files = readInput(req);
|
||||||
@@ -51,8 +100,12 @@ public class WindImportServlet extends SailingServerHttpServlet {
|
|||||||
Iterable<RaceDefinition> allRaceDefinitions = regatta.getAllRaces();
|
Iterable<RaceDefinition> allRaceDefinitions = regatta.getAllRaces();
|
||||||
for (RaceDefinition raceDefinition : allRaceDefinitions) {
|
for (RaceDefinition raceDefinition : allRaceDefinitions) {
|
||||||
DynamicTrackedRace trackedRace = trackedRegatta.getTrackedRace(raceDefinition);
|
DynamicTrackedRace trackedRace = trackedRegatta.getTrackedRace(raceDefinition);
|
||||||
|
WindImportResult windImportResult = new WindImportResult(regatta.getRegattaIdentifier(), trackedRace.getRaceIdentifier());
|
||||||
|
windImportResults.add(windImportResult);
|
||||||
for (Wind wind : windFixes) {
|
for (Wind wind : windFixes) {
|
||||||
trackedRace.recordWind(wind, EXPEDITION_WIND_SOURCE);
|
if (trackedRace.recordWind(wind, EXPEDITION_WIND_SOURCE)) {
|
||||||
|
windImportResult.update(wind);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user