Merge branch 'master' of ssh://kielweek.web4sap.com/home/trac/git

This commit is contained in:
Marcus Kammer committed 2012-06-09 22:19:23 +02:00
commit 67a9af3ce0
40 files changed
+712 -305

No files matched your search

@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.SafeHtmlCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
@@ -18,6 +19,7 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CaptionPanel;
@@ -215,12 +217,28 @@ public class EventStructureManagementPanel extends SimplePanel implements Regatt
}
};
ImagesBarColumn<RegattaDTO, RegattaConfigImagesBarCell> regattaActionColumn = new ImagesBarColumn<RegattaDTO, RegattaConfigImagesBarCell>(
new RegattaConfigImagesBarCell(stringMessages));
regattaActionColumn.setFieldUpdater(new FieldUpdater<RegattaDTO, String>() {
@Override
public void update(int index, RegattaDTO regatta, String value) {
if ("ACTION_REMOVE".equals(value)) {
if (Window.confirm("Do you really want to remove the regatta: '" + regatta.name + "' ?")) {
removeRegatta(regatta);
}
} else if ("ACTION_EDIT".equals(value)) {
} else if ("ACTION_EDIT_RACES".equals(value)) {
}
}
});
regattaTable = new CellTable<RegattaDTO>(200, tableRes);
regattaTable.setWidth("100%");
regattaTable.addColumn(regattaNameColumn, stringMessages.regattaName());
regattaTable.addColumn(regattaBoatClassColumn, stringMessages.boatClass());
regattaTable.addColumn(regattaSeriesColumn, stringMessages.series());
regattaTable.addColumn(regattaFleetsColumn, stringMessages.fleets());
regattaTable.addColumn(regattaActionColumn, stringMessages.actions());
regattaSelectionModel = new SingleSelectionModel<RegattaDTO>();
regattaSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@@ -236,6 +254,10 @@ public class EventStructureManagementPanel extends SimplePanel implements Regatt
parentPanel.add(regattaTable);
}
private void removeRegatta(RegattaDTO regatta) {
}
private void onEventSelectionChanged() {
int selIndex = eventsComboBox.getSelectedIndex();
String selItemText = eventsComboBox.getItemText(selIndex);
@@ -6,6 +6,8 @@ import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.EventTarget;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;
@@ -13,6 +15,11 @@ import com.google.gwt.user.client.ui.AbstractImagePrototype;
public abstract class ImagesBarCell extends AbstractSafeHtmlCell<String> {
interface ImagesBarTemplates extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div name=\"{0}\" style=\"{1}\" title=\"{2}\">{3}</div>")
SafeHtml cell(String name, SafeStyles styles, String title, SafeHtml value);
}
public ImagesBarCell() {
super(SimpleSafeHtmlRenderer.getInstance(), "click", "keydown");
}
@@ -3,7 +3,6 @@ package com.sap.sailing.gwt.ui.adminconsole;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safecss.shared.SafeStylesUtils;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
@@ -11,11 +10,6 @@ import com.sap.sailing.gwt.ui.client.StringMessages;
public class LeaderboardConfigImagesBarCell extends ImagesBarCell {
interface ImagesBarTemplates extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div name=\"{0}\" style=\"{1}\" title=\"{2}\">{3}</div>")
SafeHtml cell(String name, SafeStyles styles, String title, SafeHtml value);
}
public LeaderboardConfigImagesBarCell(StringMessages stringConstants) {
super();
this.stringConstants = stringConstants;
@@ -3,7 +3,6 @@ package com.sap.sailing.gwt.ui.adminconsole;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safecss.shared.SafeStylesUtils;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
@@ -11,11 +10,6 @@ import com.sap.sailing.gwt.ui.client.StringMessages;
public class LeaderboardGroupConfigImagesBarCell extends ImagesBarCell {
interface ImagesBarTemplates extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div name=\"{0}\" style=\"{1}\" title=\"{2}\">{3}</div>")
SafeHtml cell(String name, SafeStyles styles, String title, SafeHtml value);
}
public LeaderboardGroupConfigImagesBarCell(StringMessages stringConstants) {
super();
this.stringConstants = stringConstants;
@@ -3,7 +3,6 @@ package com.sap.sailing.gwt.ui.adminconsole;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safecss.shared.SafeStylesUtils;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
@@ -13,11 +12,6 @@ public class LeaderboardRaceConfigImagesBarCell extends ImagesBarCell {
private StringMessages stringConstants;
interface ImagesBarTemplates extends SafeHtmlTemplates {
@SafeHtmlTemplates.Template("<div name=\"{0}\" style=\"{1}\" title=\"{2}\">{3}</div>")
SafeHtml cell(String name, SafeStyles styles, String title, SafeHtml value);
}
public LeaderboardRaceConfigImagesBarCell(StringMessages stringConstants) {
super();
this.stringConstants = stringConstants;
@@ -0,0 +1,57 @@
package com.sap.sailing.gwt.ui.adminconsole;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safecss.shared.SafeStylesUtils;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.sap.sailing.gwt.ui.client.StringMessages;
public class RegattaConfigImagesBarCell extends ImagesBarCell {
public RegattaConfigImagesBarCell(StringMessages stringConstants) {
super();
this.stringConstants = stringConstants;
}
public RegattaConfigImagesBarCell(SafeHtmlRenderer<String> renderer, StringMessages stringConstants) {
super();
this.stringConstants = stringConstants;
}
private static ImagesBarTemplates templates = GWT.create(ImagesBarTemplates.class);
private static AdminConsoleResources resources = GWT.create(AdminConsoleResources.class);
private static final SafeHtml ICON_EDIT = makeImage(resources.editIcon());
private static final SafeHtml ICON_REMOVE = makeImage(resources.removeIcon());
private static final SafeHtml ICON_EDIT_RACES = makeImage(resources.linkIcon());
private StringMessages stringConstants;
@Override
protected void render(com.google.gwt.cell.client.Cell.Context context, SafeHtml data, SafeHtmlBuilder sb) {
/*
* Always do a null check on the value. Cell widgets can pass null to
* cells if the underlying data contains a null, or if the data arrives
* out of order.
*/
if (data == null) {
return;
}
SafeStyles imgStyle = SafeStylesUtils.fromTrustedString("float:left;cursor:hand;cursor:pointer;padding-right:5px;");
SafeHtml rendered = templates.cell("ACTION_EDIT", imgStyle, stringConstants.actionEdit(), ICON_EDIT);
sb.append(rendered);
rendered = templates.cell("ACTION_EDIT_RACES", imgStyle, stringConstants.actionRaceEdit(), ICON_EDIT_RACES);
sb.append(rendered);
rendered = templates.cell("ACTION_REMOVE", imgStyle, stringConstants.actionRemove(), ICON_REMOVE);
sb.append(rendered);
}
}
@@ -28,13 +28,13 @@ import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.Crewmember;
import com.sap.sailing.kiworesultimport.ParserFactory;
import com.sap.sailing.kiworesultimport.Race;
import com.sap.sailing.kiworesultimport.Races;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
import com.sap.sailing.kiworesultimport.ResultList;
import com.sap.sailing.kiworesultimport.ResultListParser;
import com.sap.sailing.kiworesultimport.Skipper;
public class ParserTest {
private static final String SAMPLE_INPUT_NAME = "2011-06-18_49er_Wettfahrt_2_Extra.xml";
private static final String RESOURCES = "resources/";
private InputStream getInputStream(String filename) throws FileNotFoundException, IOException {
@@ -55,13 +55,13 @@ public class ParserTest {
}
private InputStream getSampleInputStream() throws FileNotFoundException, IOException {
return getInputStream("2011-06-18_49er_Wettfahrt_2_Extra.xml");
return getInputStream(SAMPLE_INPUT_NAME);
}
@Test
public void testEmptyIsafID() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
ResultListParser parser = ParserFactory.INSTANCE.createResultListParser();
ResultList resultList = parser.parse(getSampleInputStream());
ResultList resultList = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
assertNotNull(resultList);
assertNull(resultList.getBoatBySailID("SWE 1196").getCrew().getSkipper().getIsaf());
}
@@ -69,36 +69,40 @@ public class ParserTest {
@Test
public void testEmptyStatus() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
ResultListParser parser = ParserFactory.INSTANCE.createResultListParser();
ResultList resultList = parser.parse(getSampleInputStream());
ResultList resultList = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
assertNotNull(resultList);
assertNull(resultList.getBoatBySailID("SWE 1196").getRaces().getRaces().iterator().next().getStatus());
assertEquals(MaxPointsReason.NONE, resultList.getBoatBySailID("SWE 1196").getRaces().getRaces()
assertNull(resultList.getBoatBySailID("SWE 1196").getResultsInRaces().iterator().next().getStatus());
assertEquals(MaxPointsReason.NONE, resultList.getBoatBySailID("SWE 1196").getResultsInRaces()
.iterator().next().getMaxPointsReason());
}
@Test
public void testNonEmptyStatus() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
ResultListParser parser = ParserFactory.INSTANCE.createResultListParser();
ResultList resultList = parser.parse(getSampleInputStream());
ResultList resultList = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
assertNotNull(resultList);
assertEquals("DNC", resultList.getBoatBySailID("GER 1199").getRaces().getRaces().iterator().next().getStatus());
assertEquals(MaxPointsReason.DNC, resultList.getBoatBySailID("GER 1199").getRaces().getRaces()
final Boat GER1199 = resultList.getBoatBySailID("GER 1199");
assertEquals("DNC", GER1199.getResultsInRaces().iterator().next().getStatus());
assertEquals(MaxPointsReason.DNC, GER1199.getResultsInRaces()
.iterator().next().getMaxPointsReason());
assertEquals(47, (int) GER1199.getRank());
assertEquals(25.00, GER1199.getResultsInRace(1).getPoints(), 0.00000001);
assertEquals(25.00, GER1199.getResultsInRace(2).getPoints(), 0.00000001);
}
@Test
public void testObtainingResultList() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
ResultListParser parser = ParserFactory.INSTANCE.createResultListParser();
ResultList resultList = parser.parse(getSampleInputStream());
ResultList resultList = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
assertNotNull(resultList);
assertEquals("D:\\Programme\\KWSailing\\eventlogos\\KielerWoche_Ergebnislistenkopf_2011.jpg", resultList.getImagePfad());
assertEquals(new String(new byte[] { (byte) 160 /* non-breaking space */}), resultList.getLegende());
assertEquals("D:\\Programme\\KWSailing\\eventlogos\\KielerWoche_Ergebnislistenkopf_2011.jpg", resultList.getImagePath());
assertEquals(new String(new byte[] { (byte) 160 /* non-breaking space */}), resultList.getLegend());
Iterable<Boat> boats = resultList.getBoats();
assertFalse(Util.isEmpty(boats));
assertEquals(48, Util.size(boats));
Boat DEN9 = resultList.getBoatBySailID("DEN 9");
assertNotNull(DEN9);
assertEquals(7, (int) DEN9.getPosition());
assertEquals(7, (int) DEN9.getRank());
Skipper DEN9Skipper = DEN9.getCrew().getSkipper();
assertEquals("Norregaard, Allan (1981) Kolding", DEN9Skipper.getName());
assertEquals(new URL("http://www.sailing.org/biog.php?id=DENAN1"), DEN9Skipper.getIsaf());
@@ -106,16 +110,16 @@ public class ParserTest {
assertEquals(1, Util.size(DEN9Crewmembers));
Crewmember DEN9Crewmember = DEN9Crewmembers.iterator().next();
assertEquals("Lang, Peter (1989) Kolding Sejlklub", DEN9Crewmember.getName());
Races DEN9Races = DEN9.getRaces();
Iterable<BoatResultInRace> DEN9Races = DEN9.getResultsInRaces();
assertNotNull(DEN9Races);
assertEquals(2, Util.size(DEN9Races.getRaces()));
Iterator<Race> i = DEN9Races.getRaces().iterator();
Race r1 = i.next();
assertEquals(2, Util.size(DEN9Races));
Iterator<BoatResultInRace> i = DEN9Races.iterator();
BoatResultInRace r1 = i.next();
assertEquals(9.00, r1.getPoints(), 0.0000000001);
assertEquals(1, (int) r1.getNumber());
Race r2 = i.next();
assertEquals(1, (int) r1.getRaceNumber());
BoatResultInRace r2 = i.next();
assertEquals(1.00, r2.getPoints(), 0.0000000001);
assertEquals(2, (int) r2.getNumber());
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 18, 16, 26).getTime()), resultList.getTimePoint());
assertEquals(2, (int) r2.getRaceNumber());
assertEquals(new MillisecondsTimePoint(new GregorianCalendar(2011, 05, 18, 16, 26).getTime()), resultList.getTimePointPublished());
}
}
@@ -1,13 +1,24 @@
package com.sap.sailing.kiworesultimport.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Test;
import org.xml.sax.SAXException;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.kiworesultimport.ParserFactory;
import com.sap.sailing.kiworesultimport.RegattaSummary;
import com.sap.sailing.kiworesultimport.ZipFile;
public class ZipStreamTest {
private final static String ZIP_EXAMPLE_FILE = "resources/Kieler_Woche_2011_Export.zip";
@@ -26,4 +37,13 @@ public class ZipStreamTest {
zis.close();
assertTrue(foundStartberichteDir);
}
@Test
public void testZipParser() throws FileNotFoundException, IOException, SAXException, ParserConfigurationException {
ZipFile zipFile = ParserFactory.INSTANCE.createZipFileParser().parse(new FileInputStream(ZIP_EXAMPLE_FILE));
assertNotNull(zipFile);
Util.contains(zipFile.getBoatClassNames(), "Laser");
RegattaSummary laser = zipFile.getRegattaSummary("Laser");
assertEquals(9, Util.size(laser.getRaces()));
}
}
@@ -3,11 +3,15 @@ package com.sap.sailing.kiworesultimport;
public interface Boat extends Named {
String getSailingNumber();
Integer getPosition();
Integer getRank();
String getPreis();
String getPrice();
Crew getCrew();
Races getRaces();
Iterable<BoatResultInRace> getResultsInRaces();
BoatResultInRace getResultsInRace(int raceNumberOneBased);
Double getTotalPoints();
}
@@ -2,12 +2,14 @@ package com.sap.sailing.kiworesultimport;
import com.sap.sailing.domain.common.MaxPointsReason;
public interface Race {
public interface BoatResultInRace {
String getStatus();
Double getPoints();
Integer getNumber();
Integer getRaceNumber();
MaxPointsReason getMaxPointsReason();
boolean isDiscarded();
}
@@ -7,7 +7,7 @@ public interface ParserFactory {
ResultListParser createResultListParser();
StartberichtParser createStartberichtParser();
StartReportParser createStartReportParser();
ZipFileParser createZipFileParser();
}
@@ -0,0 +1,25 @@
package com.sap.sailing.kiworesultimport;
/**
* Derived object, providing a view onto the data parsed from the result ZIP
*
* @author Axel Uhl (D043530)
*
*/
public interface RaceSummary {
String getBoatClassName();
int getRaceNumber();
Iterable<String> getFleetNames();
/**
* The {@link Boat} objects
*/
Iterable<Boat> getBoats();
/**
* Retrieves the {@link BoatResultInRace} data that <code>boat</code> achieved in the race summarized by this object
*/
BoatResultInRace getBoatResults(Boat boat);
}
@@ -1,7 +0,0 @@
package com.sap.sailing.kiworesultimport;
public interface Races {
Double getTotalPoints();
Iterable<Race> getRaces();
}
@@ -0,0 +1,24 @@
package com.sap.sailing.kiworesultimport;
import com.sap.sailing.domain.common.TimePoint;
/**
* Derived object, providing a view onto the data parsed from the result ZIP
*
* @author Axel Uhl (D043530)
*
*/
public interface RegattaSummary {
TimePoint getTimePointPublished();
String getBoatClassName();
Iterable<RaceSummary> getRaces();
RaceSummary getRace(int raceNumberOneBased);
/**
* All {@link Boat} objects that participated in this regatta
*/
Iterable<Boat> getBoats();
}
@@ -3,13 +3,13 @@ package com.sap.sailing.kiworesultimport;
import com.sap.sailing.domain.common.TimePoint;
public interface ResultList {
String getLegende();
String getLegend();
String getImagePfad();
String getImagePath();
String getStatus();
String getBoatClass();
String getBoatClassName();
String getEvent();
@@ -20,7 +20,7 @@ public interface ResultList {
/**
* Point in time when this result list was published
*/
TimePoint getTimePoint();
TimePoint getTimePointPublished();
Iterable<Boat> getBoats();
@@ -30,4 +30,8 @@ public interface ResultList {
* @return <code>null</code> if no such {@link Boat} is found in {@link #getBoats}, or the boat found otherwise.
*/
Boat getBoatBySailID(String sailID);
String getSourceName();
Iterable<Integer> getRaceNumbers();
}
@@ -8,5 +8,5 @@ import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public interface ResultListParser {
ResultList parse(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException;
ResultList parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException;
}
@@ -11,17 +11,17 @@ public interface Start {
String getFleetName();
String getKurs();
String getCourseName();
String getStartzeit();
String getStartTimeAsString();
TimePoint getTimePoint() throws ParseException;
String getStartflagge();
String getStartFlag();
String getBemerkung();
String getComment();
Boolean getDoppelteWertung();
Boolean isDoubleScore();
Boolean getStreichbar();
Boolean isDiscardable();
}
@@ -0,0 +1,23 @@
package com.sap.sailing.kiworesultimport;
import java.text.ParseException;
import com.sap.sailing.domain.common.TimePoint;
public interface StartReport {
String getDateAsString();
TimePoint getTimePoint() throws ParseException;
String getCourseAreaName();
String getStartBearingAsString();
String getWindSpeedAsString();
String getWindDirectionAsString();
Iterable<Start> getStarts();
String getSourceName();
}
@@ -0,0 +1,12 @@
package com.sap.sailing.kiworesultimport;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public interface StartReportParser {
StartReport parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException;
}
@@ -1,21 +0,0 @@
package com.sap.sailing.kiworesultimport;
import java.text.ParseException;
import com.sap.sailing.domain.common.TimePoint;
public interface Startbericht {
String getDatum();
TimePoint getTimePoint() throws ParseException;
String getRegattabahn();
String getKompasskurs();
String getWindstaerke();
String getWindrichtung();
Iterable<Start> getStarts();
}
@@ -1,7 +0,0 @@
package com.sap.sailing.kiworesultimport;
import java.io.InputStream;
public interface StartberichtParser {
Startbericht parse(InputStream inputStream);
}
@@ -1,7 +1,13 @@
package com.sap.sailing.kiworesultimport;
public interface ZipFile {
Iterable<Startbericht> getStartberichte();
Iterable<StartReport> getStartReports();
Iterable<ResultList> getResultLists();
RegattaSummary getRegattaSummary(String boatClassName);
Iterable<String> getBoatClassNames();
Iterable<RegattaSummary> getRegattaSummaries();
}
@@ -1,7 +1,12 @@
package com.sap.sailing.kiworesultimport;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
public interface ZipFileParser {
ZipFile parse(InputStream inputStream);
ZipFile parse(InputStream inputStream) throws IOException, SAXException, ParserConfigurationException;
}
@@ -1,12 +1,15 @@
package com.sap.sailing.kiworesultimport.impl;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.Crew;
import com.sap.sailing.kiworesultimport.Races;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
public class BoatImpl extends NamedImpl implements Boat {
@@ -20,12 +23,12 @@ public class BoatImpl extends NamedImpl implements Boat {
}
@Override
public Integer getPosition() {
public Integer getRank() {
return Integer.valueOf(getNode().getAttributes().getNamedItem("position").getNodeValue());
}
@Override
public String getPreis() {
public String getPrice() {
return getNode().getAttributes().getNamedItem("preis").getNodeValue();
}
@@ -34,11 +37,35 @@ public class BoatImpl extends NamedImpl implements Boat {
final NodeList crew = ((Element) getNode()).getElementsByTagName("Crew");
return new CrewImpl(crew.item(0));
}
@Override
public Races getRaces() {
final NodeList races = ((Element) getNode()).getElementsByTagName("Races");
return new RacesImpl(races.item(0));
public Double getTotalPoints() {
return Double.valueOf(((Element) getNode()).getElementsByTagName("Races").item(0).getAttributes()
.getNamedItem("totalpoints").getNodeValue().replace(',', '.'));
}
@Override
public Iterable<BoatResultInRace> getResultsInRaces() {
List<BoatResultInRace> result = new ArrayList<BoatResultInRace>();
final NodeList races = ((Element) ((Element) getNode()).getElementsByTagName("Races").item(0)).getElementsByTagName("Race");
for (int i=0; i<races.getLength(); i++) {
result.add(new BoatResultsInRaceImpl(races.item(i)));
}
return result;
}
@Override
public BoatResultInRace getResultsInRace(int raceNumberOneBased) {
for (BoatResultInRace race : getResultsInRaces()) {
if (race.getRaceNumber() == raceNumberOneBased) {
return race;
}
}
return null;
}
@Override
public String toString() {
return getSailingNumber();
}
}
@@ -0,0 +1,55 @@
package com.sap.sailing.kiworesultimport.impl;
import org.w3c.dom.Node;
import com.sap.sailing.domain.common.MaxPointsReason;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
public class BoatResultsInRaceImpl extends AbstractNodeWrapper implements BoatResultInRace {
public BoatResultsInRaceImpl(Node node) {
super(node);
}
@Override
public boolean isDiscarded() {
final String pointsAsString = getNode().getAttributes().getNamedItem("points").getNodeValue().trim();
return pointsAsString.startsWith("(") && pointsAsString.endsWith(")");
}
@Override
public Double getPoints() {
final String pointsAsString = getNode().getAttributes().getNamedItem("points").getNodeValue().replace('(', ' ')
.replace(')', ' ').replace(',', '.').trim();
return Double.valueOf(pointsAsString);
}
@Override
public Integer getRaceNumber() {
return Integer.valueOf(getNode().getAttributes().getNamedItem("number").getNodeValue());
}
@Override
public String getStatus() {
final Node namedItem = getNode().getAttributes().getNamedItem("status");
return namedItem == null || namedItem.getNodeValue() == null || namedItem.getNodeValue().trim().length() == 0 ? null
: namedItem.getNodeValue();
}
@Override
public MaxPointsReason getMaxPointsReason() {
MaxPointsReason result;
String status = getStatus();
if (status != null) {
result = MaxPointsReason.valueOf(status.substring(0, 3));
} else {
result = MaxPointsReason.NONE;
}
return result;
}
@Override
public String toString() {
return "{" + getRaceNumber() + ": " + getMaxPointsReason() + ", " + getPoints() + (isDiscarded()?", discarded":"")+"}";
}
}
@@ -15,4 +15,8 @@ public class NamedImpl extends AbstractNodeWrapper implements Named {
return getNode().getAttributes().getNamedItem("name").getNodeValue();
}
@Override
public String toString() {
return getName();
}
}
@@ -2,7 +2,7 @@ package com.sap.sailing.kiworesultimport.impl;
import com.sap.sailing.kiworesultimport.ParserFactory;
import com.sap.sailing.kiworesultimport.ResultListParser;
import com.sap.sailing.kiworesultimport.StartberichtParser;
import com.sap.sailing.kiworesultimport.StartReportParser;
import com.sap.sailing.kiworesultimport.ZipFileParser;
public class ParserFactoryImpl implements ParserFactory {
@@ -13,12 +13,12 @@ public class ParserFactoryImpl implements ParserFactory {
}
@Override
public StartberichtParser createStartberichtParser() {
return new StartberichtParserImpl();
public StartReportParser createStartReportParser() {
return new StartReportParserImpl();
}
@Override
public ZipFileParser createZipFileParser() {
return new ZipFileParserImpl();
return new ZipFileParserImpl(this);
}
}
@@ -1,41 +0,0 @@
package com.sap.sailing.kiworesultimport.impl;
import org.w3c.dom.Node;
import com.sap.sailing.domain.common.MaxPointsReason;
import com.sap.sailing.kiworesultimport.Race;
public class RaceImpl extends AbstractNodeWrapper implements Race {
public RaceImpl(Node node) {
super(node);
}
@Override
public Double getPoints() {
return Double.valueOf(getNode().getAttributes().getNamedItem("points").getNodeValue().replace(',', '.'));
}
@Override
public Integer getNumber() {
return Integer.valueOf(getNode().getAttributes().getNamedItem("number").getNodeValue());
}
@Override
public String getStatus() {
final Node namedItem = getNode().getAttributes().getNamedItem("status");
return namedItem == null || namedItem.getNodeValue() == null || namedItem.getNodeValue().trim().length() == 0 ? null : namedItem.getNodeValue();
}
@Override
public MaxPointsReason getMaxPointsReason() {
MaxPointsReason result;
String status = getStatus();
if (status != null) {
result = MaxPointsReason.valueOf(status);
} else {
result = MaxPointsReason.NONE;
}
return result;
}
}
@@ -0,0 +1,47 @@
package com.sap.sailing.kiworesultimport.impl;
import java.util.Map;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
import com.sap.sailing.kiworesultimport.RaceSummary;
public class RaceSummaryImpl implements RaceSummary {
private final String boatClassName;
private final Map<Boat, BoatResultInRace> boatResults;
private final Iterable<String> fleetNames;
private final int raceNumber;
public RaceSummaryImpl(String boatClassName, Map<Boat, BoatResultInRace> boatResults, Iterable<String> fleetNames, int raceNumber) {
super();
this.boatClassName = boatClassName;
this.boatResults = boatResults;
this.raceNumber = raceNumber;
this.fleetNames = fleetNames;
}
@Override
public String getBoatClassName() {
return boatClassName;
}
@Override
public int getRaceNumber() {
return raceNumber;
}
@Override
public Iterable<Boat> getBoats() {
return boatResults.keySet();
}
@Override
public BoatResultInRace getBoatResults(Boat boat) {
return boatResults.get(boat);
}
@Override
public Iterable<String> getFleetNames() {
return fleetNames;
}
}
@@ -1,34 +0,0 @@
package com.sap.sailing.kiworesultimport.impl;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.sailing.kiworesultimport.Race;
import com.sap.sailing.kiworesultimport.Races;
public class RacesImpl extends AbstractNodeWrapper implements Races {
public RacesImpl(Node node) {
super(node);
}
@Override
public Double getTotalPoints() {
return Double.valueOf(getNode().getAttributes().getNamedItem("totalpoints").getNodeValue().replace(',', '.'));
}
@Override
public Iterable<Race> getRaces() {
List<Race> result = new ArrayList<Race>();
final NodeList races = ((Element) getNode()).getElementsByTagName("Race");
for (int i=0; i<races.getLength(); i++) {
result.add(new RaceImpl(races.item(i)));
}
return result;
}
}
@@ -0,0 +1,52 @@
package com.sap.sailing.kiworesultimport.impl;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.RaceSummary;
import com.sap.sailing.kiworesultimport.RegattaSummary;
public class RegattaSummaryImpl implements RegattaSummary {
private final Iterable<RaceSummary> races;
private final String boatClassName;
private final Iterable<Boat> boats;
private final TimePoint timePointPublished;
public RegattaSummaryImpl(Iterable<RaceSummary> races, String boatClassName, Iterable<Boat> boats, TimePoint timePointPublished) {
super();
this.races = races;
this.boatClassName = boatClassName;
this.boats = boats;
this.timePointPublished = timePointPublished;
}
@Override
public TimePoint getTimePointPublished() {
return timePointPublished;
}
@Override
public String getBoatClassName() {
return boatClassName;
}
@Override
public Iterable<RaceSummary> getRaces() {
return races;
}
@Override
public RaceSummary getRace(int raceNumberOneBased) {
for (RaceSummary race : getRaces()) {
if (race.getRaceNumber() == raceNumberOneBased) {
return race;
}
}
return null;
}
@Override
public Iterable<Boat> getBoats() {
return boats;
}
}
@@ -4,6 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;
@@ -15,24 +16,33 @@ import org.w3c.dom.NodeList;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
import com.sap.sailing.kiworesultimport.ResultList;
public class ResultListImpl extends AbstractNodeWrapper implements ResultList {
private static final Logger logger = Logger.getLogger(ResultListImpl.class.getName());
private final String sourceName;
private static final SimpleDateFormat df = new SimpleDateFormat("dd. MMM yyyy hh:mm", Locale.GERMAN);
public ResultListImpl(Node node) {
public ResultListImpl(Node node, String sourceName) {
super(node);
this.sourceName = sourceName;
}
@Override
public String getSourceName() {
return sourceName;
}
@Override
public String getLegende() {
public String getLegend() {
return getNode().getAttributes().getNamedItem("legende").getNodeValue();
}
@Override
public String getImagePfad() {
public String getImagePath() {
return getNode().getAttributes().getNamedItem("imagePfad").getNodeValue();
}
@@ -42,7 +52,7 @@ public class ResultListImpl extends AbstractNodeWrapper implements ResultList {
}
@Override
public String getBoatClass() {
public String getBoatClassName() {
return getNode().getAttributes().getNamedItem("class").getNodeValue();
}
@@ -62,7 +72,7 @@ public class ResultListImpl extends AbstractNodeWrapper implements ResultList {
}
@Override
public TimePoint getTimePoint() {
public TimePoint getTimePointPublished() {
TimePoint result = null;
String dateTime = getDate()+" "+getTime();
try {
@@ -93,4 +103,15 @@ public class ResultListImpl extends AbstractNodeWrapper implements ResultList {
}
return null;
}
@Override
public Iterable<Integer> getRaceNumbers() {
LinkedHashSet<Integer> result = new LinkedHashSet<Integer>();
for (Boat boat : getBoats()) {
for (BoatResultInRace results : boat.getResultsInRaces()) {
result.add(results.getRaceNumber());
}
}
return result;
}
}
@@ -18,9 +18,9 @@ public class ResultListParserImpl implements ResultListParser {
}
@Override
public ResultList parse(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException {
public ResultList parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException {
Document doc = parseDocument(inputStream);
ResultList result = new ResultListImpl(doc.getElementsByTagName("ResultList").item(0));
ResultList result = new ResultListImpl(doc.getElementsByTagName("ResultList").item(0), sourceName);
return result;
}
@@ -4,6 +4,7 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
@@ -19,52 +20,53 @@ public class StartImpl extends AbstractNodeWrapper implements Start {
@Override
public String getBoatClass() {
return getNode().getAttributes().getNamedItem("bootsklasse").getNodeValue();
final Node item = ((Element) getNode()).getElementsByTagName("bootsklasse").item(0);
return item == null ? null : item.getFirstChild().getNodeValue();
}
@Override
public Integer getRaceNumber() {
return Integer.valueOf(getNode().getAttributes().getNamedItem("wettfahrt").getNodeValue());
return Integer.valueOf(((Element) getNode()).getElementsByTagName("wettfahrt").item(0).getFirstChild().getNodeValue());
}
@Override
public String getFleetName() {
return getNode().getAttributes().getNamedItem("startgruppe").getNodeValue();
return ((Element) getNode()).getElementsByTagName("startgruppe").item(0).getFirstChild().getNodeValue();
}
@Override
public String getKurs() {
return getNode().getAttributes().getNamedItem("kurs").getNodeValue();
public String getCourseName() {
return ((Element) getNode()).getElementsByTagName("kurs").item(0).getFirstChild().getNodeValue();
}
@Override
public String getStartzeit() {
return getNode().getAttributes().getNamedItem("startzeit").getNodeValue();
public String getStartTimeAsString() {
return ((Element) getNode()).getElementsByTagName("startzeit").item(0).getFirstChild().getNodeValue();
}
@Override
public TimePoint getTimePoint() throws ParseException {
return new MillisecondsTimePoint(df.parse(getStartzeit()));
return new MillisecondsTimePoint(df.parse(getStartTimeAsString()));
}
@Override
public String getStartflagge() {
return getNode().getAttributes().getNamedItem("startflagge").getNodeValue();
public String getStartFlag() {
return ((Element) getNode()).getElementsByTagName("startflagge").item(0).getFirstChild().getNodeValue();
}
@Override
public String getBemerkung() {
return getNode().getAttributes().getNamedItem("bemerkung").getNodeValue();
public String getComment() {
return ((Element) getNode()).getElementsByTagName("bemerkung").item(0).getFirstChild().getNodeValue();
}
@Override
public Boolean getDoppelteWertung() {
return Boolean.valueOf(getNode().getAttributes().getNamedItem("doppelte_Wertung").getNodeValue());
public Boolean isDoubleScore() {
return Boolean.valueOf(((Element) getNode()).getElementsByTagName("doppelte_Wertung").item(0).getFirstChild().getNodeValue());
}
@Override
public Boolean getStreichbar() {
return Boolean.valueOf(getNode().getAttributes().getNamedItem("streichbar").getNodeValue());
public Boolean isDiscardable() {
return Boolean.valueOf(((Element) getNode()).getElementsByTagName("streichbar").item(0).getFirstChild().getNodeValue());
}
}
@@ -0,0 +1,78 @@
package com.sap.sailing.kiworesultimport.impl;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.kiworesultimport.Start;
import com.sap.sailing.kiworesultimport.StartReport;
public class StartReportImpl extends AbstractNodeWrapper implements StartReport {
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-ddX");
private final String sourceName;
public StartReportImpl(Node node, String sourceName) {
super(node);
this.sourceName = sourceName;
}
@Override
public String getSourceName() {
return sourceName;
}
@Override
public String getDateAsString() {
return ((Element) getNode()).getElementsByTagName("datum").item(0).getNodeValue();
}
@Override
public TimePoint getTimePoint() throws ParseException {
String datum = getDateAsString();
return datum == null || datum.trim().length() == 0 ? null : new MillisecondsTimePoint(df.parse(datum));
}
@Override
public String getCourseAreaName() {
return ((Element) getNode()).getElementsByTagName("regattabahn").item(0).getNodeValue();
}
@Override
public String getStartBearingAsString() {
return ((Element) getNode()).getElementsByTagName("kompasskurs").item(0).getNodeValue();
}
@Override
public String getWindSpeedAsString() {
return ((Element) getNode()).getElementsByTagName("windstaerke").item(0).getNodeValue();
}
@Override
public String getWindDirectionAsString() {
return ((Element) getNode()).getElementsByTagName("windrichtung").item(0).getNodeValue();
}
@Override
public Iterable<Start> getStarts() {
List<Start> result = new ArrayList<Start>();
final NodeList starts = ((Element) getNode()).getElementsByTagName("start");
for (int i=0; i<starts.getLength(); i++) {
final Element startNode = (Element) starts.item(i);
final StartImpl start = new StartImpl(startNode);
if (start.getBoatClass() != null) {
result.add(start);
}
}
return result;
}
}
@@ -0,0 +1,28 @@
package com.sap.sailing.kiworesultimport.impl;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import com.sap.sailing.kiworesultimport.StartReport;
import com.sap.sailing.kiworesultimport.StartReportParser;
public class StartReportParserImpl implements StartReportParser {
private Document parseDocument(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
}
@Override
public StartReport parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException {
Document doc = parseDocument(inputStream);
StartReport result = new StartReportImpl(doc.getElementsByTagName("star:startbericht").item(0), sourceName);
return result;
}
}
@@ -1,66 +0,0 @@
package com.sap.sailing.kiworesultimport.impl;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.kiworesultimport.Start;
import com.sap.sailing.kiworesultimport.Startbericht;
public class StartberichtImpl extends AbstractNodeWrapper implements Startbericht {
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-ddX");
public StartberichtImpl(Node node) {
super(node);
}
@Override
public String getDatum() {
return getNode().getAttributes().getNamedItem("datum").getNodeValue();
}
@Override
public TimePoint getTimePoint() throws ParseException {
String datum = getDatum();
return datum == null || datum.trim().length() == 0 ? null : new MillisecondsTimePoint(df.parse(datum));
}
@Override
public String getRegattabahn() {
return getNode().getAttributes().getNamedItem("regattabahn").getNodeValue();
}
@Override
public String getKompasskurs() {
return getNode().getAttributes().getNamedItem("kompasskurs").getNodeValue();
}
@Override
public String getWindstaerke() {
return getNode().getAttributes().getNamedItem("windstaerke").getNodeValue();
}
@Override
public String getWindrichtung() {
return getNode().getAttributes().getNamedItem("windrichtung").getNodeValue();
}
@Override
public Iterable<Start> getStarts() {
List<Start> result = new ArrayList<Start>();
final NodeList starts = ((Element) getNode()).getElementsByTagName("start");
for (int i=0; i<starts.getLength(); i++) {
result.add(new StartImpl(starts.item(i)));
}
return result;
}
}
@@ -1,16 +0,0 @@
package com.sap.sailing.kiworesultimport.impl;
import java.io.InputStream;
import com.sap.sailing.kiworesultimport.Startbericht;
import com.sap.sailing.kiworesultimport.StartberichtParser;
public class StartberichtParserImpl implements StartberichtParser {
@Override
public Startbericht parse(InputStream inputStream) {
// TODO Auto-generated method stub
return null;
}
}
@@ -8,31 +8,37 @@ import java.util.Map;
import java.util.Set;
import com.sap.sailing.domain.common.impl.Util.Triple;
import com.sap.sailing.kiworesultimport.Boat;
import com.sap.sailing.kiworesultimport.BoatResultInRace;
import com.sap.sailing.kiworesultimport.RaceSummary;
import com.sap.sailing.kiworesultimport.RegattaSummary;
import com.sap.sailing.kiworesultimport.ResultList;
import com.sap.sailing.kiworesultimport.Start;
import com.sap.sailing.kiworesultimport.Startbericht;
import com.sap.sailing.kiworesultimport.StartReport;
import com.sap.sailing.kiworesultimport.ZipFile;
public class ZipFileImpl implements ZipFile {
private final Iterable<Startbericht> startberichte;
private final Map<Triple<String, Integer, String>, Start> startsByBoatclassAndWettfahrtAndFleet;
private final List<ResultList> resultLists;
private final Map<String, Map<Integer, Set<String>>> fleetsPerBoatClassAndRace;
private final Iterable<StartReport> startReports;
private final Map<Triple<String, Integer, String>, Start> startsByBoatclassAndRaceNumberAndFleetName;
private final Iterable<ResultList> resultLists;
private final Map<String, RegattaSummary> regattaSummaryByBoatClass;
public ZipFileImpl(Iterable<Startbericht> startberichte, Iterable<ResultList> resultLists) {
this.fleetsPerBoatClassAndRace = new HashMap<String, Map<Integer, Set<String>>>();
this.startberichte = new ArrayList<Startbericht>();
this.startsByBoatclassAndWettfahrtAndFleet = new HashMap<Triple<String, Integer, String>, Start>();
this.resultLists = new ArrayList<ResultList>();
for (Startbericht startbericht : startberichte) {
for (Start start : startbericht.getStarts()) {
startsByBoatclassAndWettfahrtAndFleet.put(
public ZipFileImpl(Iterable<StartReport> startReports, Iterable<ResultList> resultLists) {
this.regattaSummaryByBoatClass = new HashMap<>();
Map<String, ResultList> latestResultListForBoatClass = new HashMap<>();
HashMap<String, Map<Integer, Set<String>>> fleetNamesPerBoatClassAndRaceNumber = new HashMap<String, Map<Integer, Set<String>>>();
this.startReports = startReports;
this.startsByBoatclassAndRaceNumberAndFleetName = new HashMap<Triple<String, Integer, String>, Start>();
this.resultLists = resultLists;
for (StartReport startReport : startReports) {
for (Start start : startReport.getStarts()) {
startsByBoatclassAndRaceNumberAndFleetName.put(
new Triple<String, Integer, String>(start.getBoatClass(), start.getRaceNumber(), start
.getFleetName()), start);
Map<Integer, Set<String>> fleetsForBoatClass = fleetsPerBoatClassAndRace.get(start.getBoatClass());
Map<Integer, Set<String>> fleetsForBoatClass = fleetNamesPerBoatClassAndRaceNumber.get(start.getBoatClass());
if (fleetsForBoatClass == null) {
fleetsForBoatClass = new HashMap<Integer, Set<String>>();
fleetsPerBoatClassAndRace.put(start.getBoatClass(), fleetsForBoatClass);
fleetNamesPerBoatClassAndRaceNumber.put(start.getBoatClass(), fleetsForBoatClass);
}
Set<String> fleetsForTheBoatClassAndRace = fleetsForBoatClass.get(start.getRaceNumber());
if (fleetsForTheBoatClassAndRace == null) {
@@ -42,16 +48,53 @@ public class ZipFileImpl implements ZipFile {
fleetsForTheBoatClassAndRace.add(start.getFleetName());
}
}
// use the latest result lists per boat class only to construct RegattaSummary objects
for (ResultList resultList : resultLists) {
ResultList latestSoFar = latestResultListForBoatClass.get(resultList.getBoatClassName());
if (latestSoFar == null || latestSoFar.getTimePointPublished().compareTo(resultList.getTimePointPublished()) < 0) {
latestResultListForBoatClass.put(resultList.getBoatClassName(), resultList);
}
}
for (Map.Entry<String, ResultList> boatClassNameAndLatestResultList : latestResultListForBoatClass.entrySet()) {
ResultList resultList = boatClassNameAndLatestResultList.getValue();
List<RaceSummary> raceSummaries = new ArrayList<RaceSummary>();
for (Integer raceNumber : resultList.getRaceNumbers()) {
Map<Boat, BoatResultInRace> resultsPerBoat = new HashMap<>();
for (Boat boat : resultList.getBoats()) {
resultsPerBoat.put(boat, boat.getResultsInRace(raceNumber));
}
raceSummaries.add(new RaceSummaryImpl(boatClassNameAndLatestResultList.getKey(), resultsPerBoat,
fleetNamesPerBoatClassAndRaceNumber.get(boatClassNameAndLatestResultList.getKey()).get(raceNumber), raceNumber));
}
RegattaSummary regattaSummary = new RegattaSummaryImpl(raceSummaries, boatClassNameAndLatestResultList.getKey(), resultList.getBoats(),
resultList.getTimePointPublished());
regattaSummaryByBoatClass.put(regattaSummary.getBoatClassName(), regattaSummary);
}
}
@Override
public Iterable<Startbericht> getStartberichte() {
return startberichte;
public Iterable<StartReport> getStartReports() {
return startReports;
}
@Override
public Iterable<ResultList> getResultLists() {
return resultLists;
}
@Override
public RegattaSummary getRegattaSummary(String boatClassName) {
return regattaSummaryByBoatClass.get(boatClassName);
}
@Override
public Iterable<String> getBoatClassNames() {
return regattaSummaryByBoatClass.keySet();
}
@Override
public Iterable<RegattaSummary> getRegattaSummaries() {
return regattaSummaryByBoatClass.values();
}
}
@@ -1,16 +1,61 @@
package com.sap.sailing.kiworesultimport.impl;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
import com.sap.sailing.kiworesultimport.ParserFactory;
import com.sap.sailing.kiworesultimport.ResultList;
import com.sap.sailing.kiworesultimport.StartReport;
import com.sap.sailing.kiworesultimport.ZipFile;
import com.sap.sailing.kiworesultimport.ZipFileParser;
public class ZipFileParserImpl implements ZipFileParser {
private final ParserFactory parserFactory;
public ZipFileParserImpl(ParserFactory parserFactory) {
super();
this.parserFactory = parserFactory;
}
@Override
public ZipFile parse(InputStream inputStream) {
// TODO Auto-generated method stub
return null;
public ZipFile parse(InputStream inputStream) throws IOException, SAXException, ParserConfigurationException {
ZipInputStream zis = new ZipInputStream(inputStream);
List<StartReport> startReports = new ArrayList<StartReport>();
List<ResultList> resultLists = new ArrayList<ResultList>();
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
if (isStartReport(entry)) {
startReports.add(parserFactory.createStartReportParser().parse(getNonClosableInputStream(zis), entry.getName()));
} else if (isResultList(entry)) {
resultLists.add(parserFactory.createResultListParser().parse(getNonClosableInputStream(zis), entry.getName()));
}
entry = zis.getNextEntry();
}
return new ZipFileImpl(startReports, resultLists);
}
private InputStream getNonClosableInputStream(ZipInputStream zis) {
return new FilterInputStream(zis) {
@Override
public void close() { }
};
}
private boolean isResultList(ZipEntry entry) {
return entry.getName().endsWith("_Extra.xml");
}
private boolean isStartReport(ZipEntry entry) {
return entry.getName().startsWith("Startberichte\\");
}
}