Add ability for additional delivery dates
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package de.jeyp91.apifootball;
|
package de.jeyp91.apifootball;
|
||||||
|
|
||||||
import de.jeyp91.S3Provider;
|
import de.jeyp91.S3Provider;
|
||||||
import de.jeyp91.tippliga.TLWMatchesUpdaterFootball;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.jeyp91.tippliga;
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
|
import de.jeyp91.apifootball.APIFootballConnector;
|
||||||
|
import de.jeyp91.apifootball.APIFootballMatch;
|
||||||
import de.jeyp91.tippligaforum.TippligaConfigProvider;
|
import de.jeyp91.tippligaforum.TippligaConfigProvider;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
@@ -45,34 +47,91 @@ public class TLWMatchdaysCreator {
|
|||||||
numberOfMatches = Integer.parseInt(matchdayConfigJson.get("numberOfMatches").toString());
|
numberOfMatches = Integer.parseInt(matchdayConfigJson.get("numberOfMatches").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
String deliveryDate1;
|
ArrayList<String> deliveryDates = getDeliveryDates(matchdayConfigJson, matchdayNumber);
|
||||||
String deliveryDate2 = null;
|
|
||||||
|
|
||||||
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");
|
TLWMatchday matchday = new TLWMatchday(this.season, this.league, matchdayNumber, 0, deliveryDates.get(0), deliveryDates.get(1), deliveryDates.get(2), matchdayName, numberOfMatches);
|
||||||
JSONObject matchesConfigPlaceholder = (JSONObject) matchesConfig.get(matchesConfig.size() - 1);
|
|
||||||
ArrayList<TLWMatch> matchesOfMatchday = getMatchesForMatchday(matches, matchdayNumber);
|
|
||||||
if(matchesOfMatchday.size() == 0) {
|
|
||||||
deliveryDate1 = matchesConfigPlaceholder.get("placeholderDatetime").toString();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LocalDateTime firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(matchesOfMatchday);
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
deliveryDate1 = firstMatchDate.format(formatter);
|
|
||||||
|
|
||||||
ArrayList<TLWMatch> remainingMatches = TLWMatchesManagerBase.getMatchesStartingFromSecondDay(matchesOfMatchday);
|
|
||||||
if(remainingMatches.size() > 0) {
|
|
||||||
firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(remainingMatches);
|
|
||||||
deliveryDate2 = firstMatchDate.format(formatter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TLWMatchday matchday = new TLWMatchday(this.season, this.league, matchdayNumber, 0, deliveryDate1, deliveryDate2, "", matchdayName, numberOfMatches);
|
|
||||||
matchdays.add(matchday);
|
matchdays.add(matchday);
|
||||||
}
|
}
|
||||||
|
|
||||||
return matchdays;
|
return matchdays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayList<TLWMatch> getMatchesForMatchday(ArrayList<TLWMatch> matches, int matchday) {
|
||||||
|
ArrayList<TLWMatch> matchesOfMatchday = new ArrayList<>();
|
||||||
|
for(TLWMatch match : matches) {
|
||||||
|
if(match.getMatchday() == matchday) {
|
||||||
|
matchesOfMatchday.add(match);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchesOfMatchday;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMatchdayNameFromConfig(int matchday) {
|
||||||
|
String matchdayName = "";
|
||||||
|
JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig");
|
||||||
|
for (Object matchdayConfig : matchdaysConfig) {
|
||||||
|
if(((JSONObject) matchdayConfig).get("TLWMatchday").toString().equals(String.valueOf(matchday))
|
||||||
|
&& ((JSONObject) matchdayConfig).containsKey("matchdayName")) {
|
||||||
|
matchdayName = ((JSONObject) matchdayConfig).get("matchdayName").toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matchdayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> getDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||||
|
ArrayList<String> deliveryDates = getDefaultDeliveryDates(matchdayConfigJson, matchdayNumber);
|
||||||
|
deliveryDates.addAll(getAdditionalDeliveryDates(matchdayConfigJson, matchdayNumber));
|
||||||
|
deliveryDates = removeDuplicates(deliveryDates);
|
||||||
|
while(deliveryDates.size() < 3) {
|
||||||
|
deliveryDates.add("");
|
||||||
|
}
|
||||||
|
return deliveryDates;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> getDefaultDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||||
|
ArrayList<String> deliveryDates = new ArrayList<>();
|
||||||
|
|
||||||
|
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");
|
||||||
|
JSONObject matchesConfigPlaceholder = (JSONObject) matchesConfig.get(matchesConfig.size() - 1);
|
||||||
|
ArrayList<TLWMatch> matchesOfMatchday = getMatchesForMatchday(matches, matchdayNumber);
|
||||||
|
if(matchesOfMatchday.size() == 0) {
|
||||||
|
deliveryDates.add(matchesConfigPlaceholder.get("placeholderDatetime").toString());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LocalDateTime firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(matchesOfMatchday);
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
deliveryDates.add(firstMatchDate.format(formatter));
|
||||||
|
|
||||||
|
ArrayList<TLWMatch> remainingMatches = TLWMatchesManagerBase.getMatchesStartingFromSecondDay(matchesOfMatchday);
|
||||||
|
if(remainingMatches.size() > 0) {
|
||||||
|
firstMatchDate = TLWMatchesManagerBase.getFirstMatchtimeTLW(remainingMatches);
|
||||||
|
deliveryDates.add(firstMatchDate.format(formatter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deliveryDates;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> getAdditionalDeliveryDates(JSONObject matchdayConfigJson, int matchdayNumber) {
|
||||||
|
ArrayList<String> deliveryDates = new ArrayList<>();
|
||||||
|
JSONArray matchesConfig = (JSONArray) matchdayConfigJson.get("matchesConfig");
|
||||||
|
|
||||||
|
APIFootballConnector conn = APIFootballConnector.getAPIFootballConnectorInstance(this.season);
|
||||||
|
for(Object config: matchesConfig) {
|
||||||
|
JSONObject jsonConfig = (JSONObject) config;
|
||||||
|
if(jsonConfig.containsKey("additionalDeliveryDate") &&
|
||||||
|
((Boolean) jsonConfig.get("additionalDeliveryDate"))) {
|
||||||
|
ArrayList<APIFootballMatch> matches = TLWMatchesCreatorFootball.getAPIFootballMatchesForConfig(conn, jsonConfig);
|
||||||
|
if(matches.size() > 0) {
|
||||||
|
LocalDateTime firstDate = TLWMatchesManagerBase.getFirstMatchtimeAPIFootball(matches);
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
deliveryDates.add(firstDate.format(formatter));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deliveryDates;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMatchdaysSQL() {
|
public String getMatchdaysSQL() {
|
||||||
String matchdaySql = "";
|
String matchdaySql = "";
|
||||||
for (TLWMatchday matchday : getMatchdays()) {
|
for (TLWMatchday matchday : getMatchdays()) {
|
||||||
@@ -99,25 +158,14 @@ public class TLWMatchdaysCreator {
|
|||||||
return matchdaySql;
|
return matchdaySql;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<TLWMatch> getMatchesForMatchday(ArrayList<TLWMatch> matches, int matchday) {
|
public static <T> ArrayList<T> removeDuplicates(ArrayList<T> list)
|
||||||
ArrayList<TLWMatch> matchesOfMatchday = new ArrayList<>();
|
{
|
||||||
for(TLWMatch match : matches) {
|
ArrayList<T> newList = new ArrayList<T>();
|
||||||
if(match.getMatchday() == matchday) {
|
for (T element : list) {
|
||||||
matchesOfMatchday.add(match);
|
if (!newList.contains(element)) {
|
||||||
|
newList.add(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matchesOfMatchday;
|
return newList;
|
||||||
}
|
|
||||||
|
|
||||||
private String getMatchdayNameFromConfig(int matchday) {
|
|
||||||
String matchdayName = "";
|
|
||||||
JSONArray matchdaysConfig = (JSONArray) this.configObject.get("matchdayConfig");
|
|
||||||
for (Object matchdayConfig : matchdaysConfig) {
|
|
||||||
if(((JSONObject) matchdayConfig).get("TLWMatchday").toString().equals(String.valueOf(matchday))
|
|
||||||
&& ((JSONObject) matchdayConfig).containsKey("matchdayName")) {
|
|
||||||
matchdayName = ((JSONObject) matchdayConfig).get("matchdayName").toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return matchdayName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,19 +93,25 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
|||||||
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
||||||
for (Object singleConfigObject : config) {
|
for (Object singleConfigObject : config) {
|
||||||
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
||||||
String type = (String) singleConfig.get("type");
|
apiFootballMatches.addAll(getAPIFootballMatchesForConfig(this.conn, singleConfig));
|
||||||
switch (type) {
|
}
|
||||||
case "AllMatchesOfMatchday":
|
return apiFootballMatches;
|
||||||
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
}
|
||||||
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
|
||||||
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
public static ArrayList<APIFootballMatch> getAPIFootballMatchesForConfig(APIFootballConnector conn, JSONObject singleConfig) {
|
||||||
break;
|
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
||||||
case "SingleMatch":
|
String type = (String) singleConfig.get("type");
|
||||||
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
switch (type) {
|
||||||
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
case "AllMatchesOfMatchday":
|
||||||
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
||||||
break;
|
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
||||||
}
|
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
||||||
|
break;
|
||||||
|
case "SingleMatch":
|
||||||
|
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
||||||
|
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
||||||
|
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return apiFootballMatches;
|
return apiFootballMatches;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class TLWMatchdaysCreatorTest {
|
public class TLWMatchdaysCreatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysTippligaTest() throws ParseException {
|
public void getMatchdaysTippligaTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");
|
||||||
ArrayList<TLWMatchday> matchdays = matchdaysCreator.getMatchdays();
|
ArrayList<TLWMatchday> matchdays = matchdaysCreator.getMatchdays();
|
||||||
@@ -19,7 +19,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysWTLPokalTest() throws ParseException {
|
public void getMatchdaysWTLPokalTest() {
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "WTL-Pokal");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "WTL-Pokal");
|
||||||
ArrayList<TLWMatchday> matchdays = matchdaysCreator.getMatchdays();
|
ArrayList<TLWMatchday> matchdays = matchdaysCreator.getMatchdays();
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysTippliga1SqlTest() throws ParseException {
|
public void getMatchdaysTippliga1SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 1, "Tippliga");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
@@ -35,7 +35,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysTippliga2SqlTest() throws ParseException {
|
public void getMatchdaysTippliga2SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 2, "Tippliga");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 2, "Tippliga");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
@@ -43,7 +43,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysTippliga51SqlTest() throws ParseException {
|
public void getMatchdaysTippliga51SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 51, "Tippliga");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 51, "Tippliga");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
@@ -51,7 +51,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysTippliga52SqlTest() throws ParseException {
|
public void getMatchdaysTippliga52SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 52, "Tippliga");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 52, "Tippliga");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
@@ -59,7 +59,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysWTLPokal48SqlTest() throws ParseException {
|
public void getMatchdaysWTLPokal48SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 48, "WTL-Pokal");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 48, "WTL-Pokal");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
@@ -67,7 +67,7 @@ public class TLWMatchdaysCreatorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMatchdaysWTLPokal98SqlTest() throws ParseException {
|
public void getMatchdaysWTLPokal98SqlTest() {
|
||||||
|
|
||||||
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 98, "WTL-Pokal");
|
TLWMatchdaysCreator matchdaysCreator = new TLWMatchdaysCreator(2021, 98, "WTL-Pokal");
|
||||||
String sql = matchdaysCreator.getMatchdaysSQL();
|
String sql = matchdaysCreator.getMatchdaysSQL();
|
||||||
|
|||||||
Reference in New Issue
Block a user