From 7f98b928bd275a17d65dff7cbc1f3ea8fc5daf48 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Sat, 31 Oct 2020 21:46:30 +0100 Subject: [PATCH] Add support for API Football config without result and placeholder as fallback --- .../jeyp91/tippliga/TLWMatchdaysCreator.java | 9 ++++----- .../tippliga/TLWMatchesCreatorFootball.java | 8 ++++---- .../tippliga/TLWMatchesUpdaterFootball.java | 5 +++++ .../TLWMatchesUpdaterFootballTest.java | 9 +++++++++ tokens/StoredCredential | Bin 1081 -> 1089 bytes 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java index c0d226c..129b02e 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysCreator.java @@ -59,13 +59,12 @@ public class TLWMatchdaysCreator { String deliveryDate2 = null; JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig"); - JSONObject matchesConfigOne = (JSONObject) matchesConfig.get(0); - if(matchesConfigOne.get("type").toString().equals("ToBeDefined")) { - deliveryDate1 = matchesConfigOne.get("placeholderDatetime").toString(); + JSONObject matchesConfigPlaceholder = (JSONObject) matchesConfig.get(matchesConfig.size() - 1); + ArrayList matchesOfMatchday = getMatchesForMatchday(matches, matchdayNumber); + if(matchesOfMatchday.size() == 0) { + deliveryDate1 = matchesConfigPlaceholder.get("placeholderDatetime").toString(); } else { - ArrayList matchesOfMatchday = getMatchesForMatchday(matches, matchdayNumber); - LocalDateTime firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(matchesOfMatchday); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); deliveryDate1 = firstMatchDate.format(formatter); diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java b/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java index 4c2487f..e79c239 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchesCreatorFootball.java @@ -88,12 +88,12 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase { // Add empty missing matches for(int j = matchdayMatchCounter; j < this.matchesPerMatchday; j++) { String matchDatetime = ""; - if(((JSONObject) matchesConfig.get(0)).get("type").toString().equals("ToBeDefined")) { - matchDatetime = ((JSONObject) matchesConfig.get(0)).get("placeholderDatetime").toString(); - } - else if(apiFootballMatchesForMatchday.size() > 0) { + if(apiFootballMatchesForMatchday.size() > 0) { matchDatetime = this.TLWMatches.get(this.TLWMatches.size() - 1).getMatchDateTime(); } + else { + matchDatetime = ((JSONObject) matchesConfig.get(matchesConfig.size() - 1)).get("placeholderDatetime").toString(); + } int matchNo = this.nextMatchNo; this.nextMatchNo++; this.TLWMatches.add(new TLWMatch(this.season, this.league, TLWMatchday, matchNo, matchDatetime, 0, this.ko)); diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java index 1fc96bd..7d66bc6 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java @@ -1,6 +1,7 @@ package de.jeyp91.tippliga; import de.jeyp91.App; +import de.jeyp91.StatusHolder; import de.jeyp91.TeamIDMatcher; import de.jeyp91.apifootball.APIFootballMatch; import de.jeyp91.apifootball.APIFootballMatchesProvider; @@ -170,6 +171,10 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { { for(APIFootballMatch apiFootballMatch : apiFootballMatches) { TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); + if(tlwMatch == null) { + StatusHolder.setError(); + logger.error("Did not find match to update"); + } tlwMatch.setMatchDateTime(apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19)); } } diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java index 82fdeeb..4a8ac6e 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootballTest.java @@ -21,4 +21,13 @@ public class TLWMatchesUpdaterFootballTest { System.out.println(sql); System.out.println(updater.getBeautifulInfo()); } + + @Test + public void getUpdateSqlTest48() { + TLWMatchesUpdaterFootball updater = new TLWMatchesUpdaterFootball(2021, 48, "WTL_Pokal.json"); + String sql = updater.getUpdateSQL(); + + System.out.println(sql); + System.out.println(updater.getBeautifulInfo()); + } } diff --git a/tokens/StoredCredential b/tokens/StoredCredential index 99ee11e8baa469d1384425df36a38117e60eb577..ab7d7b93c7c3b55ace7202784e4a201607172c52 100644 GIT binary patch delta 215 zcmdnVagbv|9^=J{`M2x0Rwf!*>Ny%Xrg@kJ`#MDi=H|LOItF4ru68~9lS znuhzkha`Dc#^;BWI)?ivr&t)~gq3F{=jM6^nfRwX849yg=B_XR>g-KBzyQ; zM)_3uM*8}Nn{4W6u1>9S{4Tv_!pT5`*`Q32bh`}n7bJJROAF16o-Vn zdL^2fTBi9{6(*LIx|n5Vq{l}Z6!-?@_?G8H803^^23Z!kIT=OznN9xA=)*oYTcWs# PL1XfNCXLNSOvf1kT8>Gd delta 199 zcmX@ev6Ev$9^=W0`M2xWRwf!*>LnUDrg@kJ`#L$5yLv|kxJ7z68|Iss2Ri2GI{WA3 zgho~-XNQ_NnOJ(I=X<;62l$&sd0M!chC2EdRU~E=n>z-Y`Z?!Y`leJ^dKy}m`Z_uX z88}6{_~n*``voK!nfhl1q?;EQXUA6-gjSW6dzu;*W;wYA8@uVHlx3B>gd1lWmXws3 z`g&#fn&){2mse!@rdgH*XO(5;yP0JK7e>bG8W@^aW=#Ii=))ZMf5m1$rq7H3bs0o>