mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 03:13:49 +00:00
include boat class in CompetitorDescriptor and fill properly from Manage2Sail import
Change-Id: Id63e9f819a1b098d869e8f4795184cfdc1c2ceed
This commit is contained in:
1 parent
0dc36b4758
commit
e2784e3a53
6 files changed
+65
-22
No files matched your search
+10
-4
@@ -7,6 +7,7 @@ import com.sap.sse.common.CountryCode;
|
||||
public class CompetitorDescriptor {
|
||||
private final String eventName;
|
||||
private final String regattaName;
|
||||
private final String boatClassName;
|
||||
private final String raceName;
|
||||
private final String fleetName;
|
||||
private final String sailNumber;
|
||||
@@ -14,11 +15,12 @@ public class CompetitorDescriptor {
|
||||
private final CountryCode countryCode;
|
||||
private final Iterable<Person> persons;
|
||||
|
||||
public CompetitorDescriptor(String eventName, String regattaName, String raceName, String fleetName,
|
||||
String sailNumber, String competitorName, CountryCode countryCode, Iterable<Person> persons) {
|
||||
public CompetitorDescriptor(String eventName, String regattaName, String boatClassName, String raceName,
|
||||
String fleetName, String sailNumber, String competitorName, CountryCode countryCode, Iterable<Person> persons) {
|
||||
super();
|
||||
this.eventName = eventName;
|
||||
this.regattaName = regattaName;
|
||||
this.boatClassName = boatClassName;
|
||||
this.raceName = raceName;
|
||||
this.fleetName = fleetName;
|
||||
this.sailNumber = sailNumber;
|
||||
@@ -35,6 +37,10 @@ public class CompetitorDescriptor {
|
||||
return regattaName;
|
||||
}
|
||||
|
||||
public String getBoatClassName() {
|
||||
return boatClassName;
|
||||
}
|
||||
|
||||
public String getRaceName() {
|
||||
return raceName;
|
||||
}
|
||||
@@ -61,7 +67,7 @@ public class CompetitorDescriptor {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ""+countryCode+" "+sailNumber+" "+getCompetitorName()+" at event: "+eventName+", regatta: "+regattaName+", race: "+raceName+
|
||||
", fleet: "+fleetName+", "+persons;
|
||||
return ""+countryCode+" "+sailNumber+" "+getCompetitorName()+" at event: "+eventName+", regatta: "+regattaName+
|
||||
", boat class: "+boatClassName+", race: "+raceName+", fleet: "+fleetName+", "+persons;
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -7,6 +7,7 @@ public class CompetitorDescriptorDTO extends NamedDTO {
|
||||
private static final long serialVersionUID = 4855053239521181610L;
|
||||
private String eventName;
|
||||
private String regattaName;
|
||||
private String boatClassName;
|
||||
private String raceName;
|
||||
private String fleetName;
|
||||
private String sailNumber;
|
||||
@@ -19,12 +20,13 @@ public class CompetitorDescriptorDTO extends NamedDTO {
|
||||
|
||||
CompetitorDescriptorDTO() {} // for GWT de-serialization only
|
||||
|
||||
public CompetitorDescriptorDTO(String eventName, String regattaName, String raceName, String fleetName,
|
||||
String sailNumber, String competitorName, String countryName, String twoLetterIsoCountryCode,
|
||||
String threeLetterIocCountryCode, Set<PersonDTO> persons) {
|
||||
public CompetitorDescriptorDTO(String eventName, String regattaName, String boatClassName, String raceName,
|
||||
String fleetName, String sailNumber, String competitorName, String countryName,
|
||||
String twoLetterIsoCountryCode, String threeLetterIocCountryCode, Set<PersonDTO> persons) {
|
||||
super(competitorName);
|
||||
this.eventName = eventName;
|
||||
this.regattaName = regattaName;
|
||||
this.boatClassName = boatClassName;
|
||||
this.raceName = raceName;
|
||||
this.fleetName = fleetName;
|
||||
this.sailNumber = sailNumber;
|
||||
@@ -42,6 +44,10 @@ public class CompetitorDescriptorDTO extends NamedDTO {
|
||||
return regattaName;
|
||||
}
|
||||
|
||||
public String getBoatClassName() {
|
||||
return boatClassName;
|
||||
}
|
||||
|
||||
public String getRaceName() {
|
||||
return raceName;
|
||||
}
|
||||
@@ -74,7 +80,7 @@ public class CompetitorDescriptorDTO extends NamedDTO {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + Objects.hash(eventName, regattaName, raceName, fleetName, sailNumber, persons,
|
||||
result = prime * result + Objects.hash(eventName, regattaName, boatClassName, raceName, fleetName, sailNumber, persons,
|
||||
countryName, twoLetterIsoCountryCode, threeLetterIocCountryCode);
|
||||
return result;
|
||||
}
|
||||
@@ -93,6 +99,7 @@ public class CompetitorDescriptorDTO extends NamedDTO {
|
||||
CompetitorDescriptorDTO other = (CompetitorDescriptorDTO) obj;
|
||||
return Objects.equals(countryName, other.countryName) && Objects.equals(eventName, other.eventName)
|
||||
&& Objects.equals(fleetName, other.fleetName) && Objects.deepEquals(persons, other.persons)
|
||||
&& Objects.equals(boatClassName, other.boatClassName)
|
||||
&& Objects.equals(raceName, other.raceName) && Objects.equals(regattaName, other.regattaName)
|
||||
&& Objects.equals(sailNumber, other.sailNumber)
|
||||
&& Objects.equals(threeLetterIocCountryCode, other.threeLetterIocCountryCode)
|
||||
|
||||
+10
-2
@@ -57,6 +57,7 @@ public class CompetitorDescriptorTableWrapper<S extends RefreshableSelectionMode
|
||||
List<String> string = new ArrayList<String>();
|
||||
string.add(competitorDescriptor.getName());
|
||||
string.add(competitorDescriptor.getSailNumber());
|
||||
string.add(competitorDescriptor.getBoatClassName());
|
||||
string.add(competitorDescriptor.getRaceName());
|
||||
string.add(competitorDescriptor.getFleetName());
|
||||
return string;
|
||||
@@ -97,6 +98,14 @@ public class CompetitorDescriptorTableWrapper<S extends RefreshableSelectionMode
|
||||
};
|
||||
sailIdColumn.setSortable(true);
|
||||
|
||||
TextColumn<CompetitorDescriptorDTO> boatClassNameColumn = new TextColumn<CompetitorDescriptorDTO>() {
|
||||
@Override
|
||||
public String getValue(CompetitorDescriptorDTO competitorDescriptor) {
|
||||
return competitorDescriptor.getBoatClassName();
|
||||
}
|
||||
};
|
||||
boatClassNameColumn.setSortable(true);
|
||||
|
||||
TextColumn<CompetitorDescriptorDTO> raceNameColumn = new TextColumn<CompetitorDescriptorDTO>() {
|
||||
@Override
|
||||
public String getValue(CompetitorDescriptorDTO competitorDescriptor) {
|
||||
@@ -121,14 +130,13 @@ public class CompetitorDescriptorTableWrapper<S extends RefreshableSelectionMode
|
||||
}
|
||||
};
|
||||
isHasMatchesColumn.setSortable(true);
|
||||
|
||||
mainPanel.insert(filterablePanelCompetitorDescriptor, 0);
|
||||
table.addColumn(sailIdColumn, stringMessages.sailNumber());
|
||||
table.addColumn(competitorNameColumn, stringMessages.name());
|
||||
table.addColumn(boatClassNameColumn, stringMessages.boatClass());
|
||||
table.addColumn(raceNameColumn, stringMessages.race());
|
||||
table.addColumn(fleetNameColumn, stringMessages.fleet());
|
||||
table.addColumn(isHasMatchesColumn, stringMessages.hasMatches());
|
||||
|
||||
table.addColumnSortHandler(getCompetitorDescriptorTableColumnListSortHandler(competitorNameColumn, sailIdColumn,
|
||||
raceNameColumn, fleetNameColumn, isHasMatchesColumn));
|
||||
}
|
||||
|
||||
+4
-4
@@ -128,7 +128,6 @@ public class MatchImportedCompetitorsDialog extends DataEntryDialog<Set<Competit
|
||||
existingCompetitorsTable.getFilterField().removeAll();
|
||||
return;
|
||||
}
|
||||
|
||||
CompetitorDescriptorDTO selectedCompetitorDescriptor = selectedCompetitorDescriptors.isEmpty() ? null
|
||||
: importedCompetitorSelectionModel.getSelectedSet().iterator().next();
|
||||
existingCompetitorsTable.refreshCompetitorList(
|
||||
@@ -144,8 +143,7 @@ public class MatchImportedCompetitorsDialog extends DataEntryDialog<Set<Competit
|
||||
@Override
|
||||
protected Set<CompetitorDTO> getResult() {
|
||||
final Set<CompetitorDTO> competitorsForSave = new HashSet<>();
|
||||
for (CompetitorDescriptorDTO competitorDescriptor : importedCompetitorsTable.getSelectionModel()
|
||||
.getSelectedSet()) {
|
||||
for (CompetitorDescriptorDTO competitorDescriptor : importedCompetitorsTable.getSelectionModel().getSelectedSet()) {
|
||||
CompetitorDTO existingCompetitor = existingCompetitorsByImported.get(competitorDescriptor);
|
||||
if (existingCompetitor != null) {
|
||||
competitorsForSave.add(existingCompetitor);
|
||||
@@ -158,7 +156,9 @@ public class MatchImportedCompetitorsDialog extends DataEntryDialog<Set<Competit
|
||||
|
||||
private CompetitorDTO convertCompetitorDescriptorToCompetitorDTO(CompetitorDescriptorDTO competitorDescriptor) {
|
||||
BoatDTO defaultBoat = new BoatDTO(null, competitorDescriptor.getSailNumber());
|
||||
BoatClassDTO defaultBoatClass = new BoatClassDTO(BoatClassDTO.DEFAULT_NAME, /* hull length */ new MeterDistance(5));
|
||||
BoatClassDTO defaultBoatClass = new BoatClassDTO(competitorDescriptor.getBoatClassName() == null
|
||||
? BoatClassDTO.DEFAULT_NAME : competitorDescriptor.getBoatClassName(),
|
||||
/* some default hull length; not used if boat class name can be resolved on the server */ new MeterDistance(5));
|
||||
return new CompetitorDTOImpl(competitorDescriptor.getName(), null, null,
|
||||
competitorDescriptor.getTwoLetterIsoCountryCode(), competitorDescriptor.getThreeLetterIocCountryCode(),
|
||||
competitorDescriptor.getCountryName(), null, null, null, defaultBoat, defaultBoatClass, null, null, null);
|
||||
|
||||
+3
-3
@@ -767,9 +767,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
|
||||
CompetitorDescriptorDTO competitorDescriptorDTO = new CompetitorDescriptorDTO(
|
||||
competitorDescriptor.getEventName(), competitorDescriptor.getRegattaName(),
|
||||
competitorDescriptor.getRaceName(), competitorDescriptor.getFleetName(),
|
||||
competitorDescriptor.getSailNumber(), competitorDescriptor.getCompetitorName(), countryName,
|
||||
twoLetterIsoCountryCode, threeLetterIocCountryCode, persons);
|
||||
competitorDescriptor.getBoatClassName(), competitorDescriptor.getRaceName(),
|
||||
competitorDescriptor.getFleetName(), competitorDescriptor.getSailNumber(), competitorDescriptor.getCompetitorName(),
|
||||
countryName, twoLetterIsoCountryCode, threeLetterIocCountryCode, persons);
|
||||
|
||||
return competitorDescriptorDTO;
|
||||
}
|
||||
|
||||
+27
-5
@@ -67,23 +67,31 @@ public class CompetitorImporter extends AbstractManage2SailProvider implements C
|
||||
public Iterable<CompetitorDescriptor> getCompetitorDescriptors(String eventName, String regattaName) throws JAXBException, IOException {
|
||||
final List<CompetitorDescriptor> result = new ArrayList<>();
|
||||
final Map<String, CompetitorDescriptor> resultsByTeamID = new HashMap<>();
|
||||
final Map<String, CompetitorDescriptor> teamsWithoutRaceAssignments = new HashMap<>();
|
||||
final Map<String, CompetitorDescriptor> teamsWithoutRaceAssignments = new HashMap<>(); // keys are the teamID
|
||||
for (ResultDocumentDescriptor resultDocDescr : getDocumentProvider().getResultDocumentDescriptors()) {
|
||||
if (resultDocDescr.getEventName().equals(eventName) &&
|
||||
(regattaName == null || regattaName.equals(resultDocDescr.getRegattaName()))) {
|
||||
final Parser parser = getParserFactory().createParser(resultDocDescr.getInputStream(), resultDocDescr.getEventName());
|
||||
try {
|
||||
final RegattaResults regattaResults = parser.parse();
|
||||
// If teams are found outside of a Division context then no boat class would be assigned to the
|
||||
// competitor. However, if only one Division exists it can be used as default and the boat class
|
||||
// can therefore be derived from it. This, however, is not clear until the document has been fully
|
||||
// consumed. So we keep track of the teams found outside of Divisions, and if exactly one division
|
||||
// is found we create the CompetitorDescriptors as if they were part of that Division; otherwise
|
||||
// we need to come up with a default boat class instead.
|
||||
final Set<Team> teamsOutsideOfDivision = new HashSet<>();
|
||||
Map<Division, Event> divisions = new HashMap<>();
|
||||
for (Object o : regattaResults.getPersonOrBoatOrTeam()) {
|
||||
if (o instanceof Team) {
|
||||
final Team team = (Team) o;
|
||||
teamsWithoutRaceAssignments.put(team.getTeamID(),
|
||||
createCompetitorDescriptor(team, parser, /* event */ null, /* division */ null, /* raceID */ null));
|
||||
teamsOutsideOfDivision.add(team);
|
||||
} else if (o instanceof Event) {
|
||||
Event event = (Event) o;
|
||||
for (Object eventO : event.getRaceOrDivisionOrRegattaSeriesResult()) {
|
||||
if (eventO instanceof Division) {
|
||||
Division division = (Division) eventO;
|
||||
divisions.put(division, event);
|
||||
if (regattaName == null || regattaName.equals(division.getTitle())) {
|
||||
for (Object divisionO : division.getSeriesResultOrRaceResultOrTRResult()) {
|
||||
String raceID = null;
|
||||
@@ -108,6 +116,19 @@ public class CompetitorImporter extends AbstractManage2SailProvider implements C
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Team teamOutsideOfDivision : teamsOutsideOfDivision) {
|
||||
if (divisions.size() == 1) { // exactly one Division; use as default for teams outside of division that were not assigned to a division later
|
||||
if (!resultsByTeamID.containsKey(teamOutsideOfDivision.getTeamID())) {
|
||||
final CompetitorDescriptor competitorDescriptor = createCompetitorDescriptor(
|
||||
teamOutsideOfDivision, parser, divisions.values().iterator().next(), divisions.keySet().iterator().next(), /* raceID */ null);
|
||||
resultsByTeamID.put(teamOutsideOfDivision.getTeamID(), competitorDescriptor);
|
||||
result.add(competitorDescriptor);
|
||||
}
|
||||
} else {
|
||||
teamsWithoutRaceAssignments.put(teamOutsideOfDivision.getTeamID(),
|
||||
createCompetitorDescriptor(teamOutsideOfDivision, parser, /* event */ null, /* division */ null, /* raceID */ null));
|
||||
}
|
||||
}
|
||||
} catch (JAXBException e) {
|
||||
logger.log(Level.WARNING, "Exception trying to read competitors for event "+resultDocDescr.getEventName()+
|
||||
", regatta "+resultDocDescr.getRegattaName()+" from document "+resultDocDescr.getDocumentName(), e);
|
||||
@@ -131,6 +152,7 @@ public class CompetitorImporter extends AbstractManage2SailProvider implements C
|
||||
// use that of team; if not defined for team, use first nationality of a team member that has one defined
|
||||
team.getNOC() == null ? null : new NationalityImpl(team.getNOC().name())
|
||||
};
|
||||
final String boatClassName = parser.getBoatClassName(division);
|
||||
List<com.sap.sailing.domain.base.Person> persons = team.getCrew().stream().sorted((c1, c2) -> -c1.getPosition().name().compareTo(c2.getPosition().name())).map((crew)->{
|
||||
Person xrrPerson = parser.getPerson(crew.getPersonID());
|
||||
String name = xrrPerson.getGivenName()+" "+xrrPerson.getFamilyName();
|
||||
@@ -149,8 +171,8 @@ public class CompetitorImporter extends AbstractManage2SailProvider implements C
|
||||
final CompetitorDescriptor competitorDescriptor = new CompetitorDescriptor(
|
||||
event==null?null:event.getTitle(),
|
||||
division==null?null:(division.getTitle() + (division.getGender() == null ? "" : division.getGender().name())),
|
||||
race != null ? race.getRaceName() : null, /* fleetName */ null, sailNumber, team.getTeamName(),
|
||||
teamNationality[0] == null ? null : teamNationality[0].getCountryCode(), persons);
|
||||
boatClassName, race != null ? race.getRaceName() : null, /* fleetName */ null, sailNumber,
|
||||
team.getTeamName(), teamNationality[0] == null ? null : teamNationality[0].getCountryCode(), persons);
|
||||
return competitorDescriptor;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user