Skip to content

Commit

Permalink
More Match Participant Precaution
Browse files Browse the repository at this point in the history
  • Loading branch information
Techno11 committed Dec 9, 2018
1 parent baf3a6e commit dadc6ef
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/org/theorangealliance/datasync/tabs/MatchesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public void checkMatchSchedule() {
matchesEndpoint.setCredentials(Config.TOA_API_KEY, Config.EVENT_ID);
matchesEndpoint.execute(((response, success) -> {
if (success) {
checkMatchParticipants();
uploadedMatches = new HashSet<>(Arrays.asList(matchesEndpoint.getGson().fromJson(response, MatchGeneralJSON[].class)));
if (uploadedMatches.size() > 0) {
this.controller.labelScheduleUploaded.setTextFill(Color.GREEN);
Expand Down Expand Up @@ -303,7 +304,7 @@ public void checkMatchDetails() {
matchesEndpoint.setCredentials(Config.TOA_API_KEY, Config.EVENT_ID);
matchesEndpoint.execute(((response, success) -> {
if (success) {
uploadedDetails = new HashSet<>(Arrays.asList(matchesEndpoint.getGson().fromJson(response, MatchDetail1819JSON[].class)));

TOALogger.log(Level.INFO, "Grabbed match details for " + uploadedDetails.size() + " matches.");
} else {
this.controller.sendError("Error: " + response);
Expand Down Expand Up @@ -1619,8 +1620,8 @@ public void postMatchSchedule() {

Optional<ButtonType> result = alert.showAndWait();
if (result.get() == okayButton) {
postMatchScheduleMatches();
postMatchScheduleTeams();
postMatchScheduleMatches();
//Do Dashboard Things
this.controller.cb_matches.setTextFill(Color.GREEN);
this.controller.cb_matches.setSelected(true);
Expand Down Expand Up @@ -1681,7 +1682,10 @@ private void postMatchScheduleTeams() {
matchParJSON.setStation(matchPar.getStation());
matchParJSON.setTeamKey(matchPar.getTeamKey() + "");
matchParJSON.setStationStatus(matchPar.getStationStatus());
requestBody.addValue(matchParJSON);
if(!matchParJSON.getTeamKey().equalsIgnoreCase("-1")) {
requestBody.addValue(matchParJSON);
}

}
}
}
Expand All @@ -1705,31 +1709,38 @@ private void postMatchScheduleMatches() {
scheduleEndpoint.setCredentials(Config.TOA_API_KEY, Config.EVENT_ID);
TOARequestBody requestBody = new TOARequestBody();
for (int i = 0; i < matchList.size(); i++) {
MatchGeneral match = matchList.get(i);

// TODO - Needs testing!
MatchGeneral match = matchList.get(i);

boolean uploaded = false;
if(uploadedMatches != null){
for (MatchGeneralJSON uploadedMatch : uploadedMatches) {
if (match.getMatchKey().equals(uploadedMatch.getMatchKey())) {
uploaded = true;
break;
}
boolean matchParExists = false;
for (MatchParticipantJSON mPj : uploadedMatchParticipants) {
if (mPj.getMatchKey().equalsIgnoreCase(match.getMatchKey())) {
matchParExists = true;
}
}
if (matchParExists) {
boolean uploaded = false;
if (uploadedMatches != null) {
for (MatchGeneralJSON uploadedMatch : uploadedMatches) {
if (match.getMatchKey().equals(uploadedMatch.getMatchKey())) {
uploaded = true;
break;
}
}
}

if (!uploaded) {
MatchGeneralJSON matchJSON = new MatchGeneralJSON();
matchJSON.setEventKey(Config.EVENT_ID);
matchJSON.setMatchKey(match.getMatchKey());
matchJSON.setTournamentLevel(match.getTournamentLevel());
matchJSON.setMatchName(match.getMatchName());
matchJSON.setPlayNumber(0);
matchJSON.setFieldNumber(match.getFieldNumber());
matchJSON.setScheduledTime(match.getScheduledTime());
matchJSON.setScoreNull();
requestBody.addValue(matchJSON);
if (!uploaded) {
MatchGeneralJSON matchJSON = new MatchGeneralJSON();
matchJSON.setEventKey(Config.EVENT_ID);
matchJSON.setMatchKey(match.getMatchKey());
matchJSON.setTournamentLevel(match.getTournamentLevel());
matchJSON.setMatchName(match.getMatchName());
matchJSON.setPlayNumber(0);
matchJSON.setFieldNumber(match.getFieldNumber());
matchJSON.setScheduledTime(match.getScheduledTime());
matchJSON.setScoreNull();
requestBody.addValue(matchJSON);
}
}
}
scheduleEndpoint.setBody(requestBody);
Expand Down

0 comments on commit dadc6ef

Please sign in to comment.