diff --git a/src/main/java/de/jeyp91/App.java b/src/main/java/de/jeyp91/App.java index 864e65a..01170e0 100644 --- a/src/main/java/de/jeyp91/App.java +++ b/src/main/java/de/jeyp91/App.java @@ -1,5 +1,6 @@ package de.jeyp91; import de.jeyp91.apifootball.APIFootballUpdater; +import de.jeyp91.googlecalendar.TippligaGoogleEventManager; import de.jeyp91.tippligaforum.MatchesListForumUpdater; import de.jeyp91.tippliga.*; import de.jeyp91.tippligaforum.TippligaConfigProvider; @@ -47,6 +48,7 @@ public class App { TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(season, league, configFile); sql = matchdaysUpdater.getUpdateSql(); beautifulInfo = matchdaysUpdater.getBeautifulInfo(); + matchdaysUpdater.updateGoogleCalendar(); break; case "MatchesCreatorFootball": TLWMatchesCreatorFootball creator = new TLWMatchesCreatorFootball(season, league, configFile); diff --git a/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java b/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java index 1411700..6fb21d3 100644 --- a/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java +++ b/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -22,9 +23,9 @@ public class TippligaGoogleEventManager { private static List allEvents = null; - private static List getAllEvents(Integer season) { + public static List getAllEvents(Integer season) { if(allEvents == null) { - allEvents = getAllEventsStartingFromDateTime(new DateTime(season-1 + "-01-01T00:00:00Z")); + allEvents = getAllEventsStartingFromDateTime(new DateTime(season-1 + "-07-01T00:00:00Z")); } return allEvents; } @@ -50,15 +51,13 @@ public class TippligaGoogleEventManager { } assert events != null; - List items = events.getItems(); - - return items; + return events.getItems(); } public static Event findEvent(List allEvents, Integer season, Integer league, Integer matchday, Integer deliveryDateNumber) { String description = getDescription(season, league, matchday, deliveryDateNumber); - for(int i = 0; i < allEvents.size(); i++) { - if(allEvents.get(i).getDescription().equals(description)) return allEvents.get(i); + for (Event allEvent : allEvents) { + if (allEvent.getDescription().equals(description)) return allEvent; } return null; } @@ -72,10 +71,12 @@ public class TippligaGoogleEventManager { public static void createOrUpdateEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) { List allEvents = getAllEvents(matchday.getSeason()); Event event = findEvent(allEvents, matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber); - if(event == null) + if(event == null) { createNewEvent(matchday, deliveryDateString, deliverDateNumber); - else + } + else { updateEvent(event, matchday, deliveryDateString, deliverDateNumber); + } } private static void createNewEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) { @@ -90,13 +91,14 @@ public class TippligaGoogleEventManager { } } - private static void updateEvent(Event oldEvent, TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) { + public static void updateEvent(Event oldEvent, TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) { String calendarUrl = CalendarConfigProvider.getCalendarUrl(); Event event = getEvent(matchday, deliveryDateString, deliverDateNumber); try { - getSerivce().events().update(calendarUrl, oldEvent.getId(), event).execute(); + Calendar.Events events = getSerivce().events(); + events.update(calendarUrl, oldEvent.getId(), event).execute(); } catch (IOException e) { e.printStackTrace(); } @@ -149,4 +151,20 @@ public class TippligaGoogleEventManager { private static String getDescription(Integer season, Integer league, Integer matchday, Integer deliverDateNumber) { return "Saison: " + season + "\n" + "Liga: " + league + "\n" + "Spieltag: " + matchday + "\n" + "Abgabeschluss: " + deliverDateNumber; } + + public static void updateAllMatchdays(ArrayList matchdays) { + matchdays.forEach(tlwMatchday -> { + createOrUpdateEvent(tlwMatchday, tlwMatchday.getDeliveryDate(), 1); + if(tlwMatchday.getDeliveryDate2().equals("")) { + deleteEvent(tlwMatchday, 2); + } else { + createOrUpdateEvent(tlwMatchday, tlwMatchday.getDeliveryDate2(), 2); + } + if(tlwMatchday.getDeliveryDate3().equals("")) { + deleteEvent(tlwMatchday, 3); + } else { + createOrUpdateEvent(tlwMatchday, tlwMatchday.getDeliveryDate3(), 3); + } + }); + } } \ No newline at end of file diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java index cfe9410..581eada 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchdaysUpdater.java @@ -74,7 +74,6 @@ public class TLWMatchdaysUpdater { condition; this.beautifulInfo += beautifulInfoStart + "Tippabgabeschluss 1 zu '" + matchdayUpdated.getDeliveryDate() + "'.\n"; - createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate(), 1); } if (!matchdayOriginal.getDeliveryDate2().equals(matchdayUpdated.getDeliveryDate2())) { @@ -83,10 +82,6 @@ public class TLWMatchdaysUpdater { condition; this.beautifulInfo += beautifulInfoStart + "Tippabgabeschluss 2 zu '" + matchdayUpdated.getDeliveryDate2() + "'.\n"; - if(!matchdayUpdated.getDeliveryDate2().equals("")) - createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate2(), 2); - else - deleteEvent(matchdayUpdated, 2); } if (!matchdayOriginal.getMatchdayName().equals(matchdayUpdated.getMatchdayName())) { @@ -95,9 +90,6 @@ public class TLWMatchdaysUpdater { condition; this.beautifulInfo += beautifulInfoStart + "Spieltagsname zu '" + matchdayUpdated.getMatchdayName() + "'.\n"; - createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate(), 1); - if(!matchdayUpdated.getDeliveryDate2().equals("")) - createOrUpdateEvent(matchdayUpdated, matchdayUpdated.getDeliveryDate2(), 2); } } } @@ -106,6 +98,10 @@ public class TLWMatchdaysUpdater { return updateSql; } + public void updateGoogleCalendar() { + updateAllMatchdays(matchdaysUpdated); + } + public String getBeautifulInfo() { return this.beautifulInfo; } diff --git a/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java b/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java index a917d92..edca127 100644 --- a/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java +++ b/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java @@ -40,6 +40,22 @@ public class TippligaGoogleEventManagerTest { matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday); } + @Test + public void findEventTest() { + List allEvents = getAllEvents(2023); + Event event = findEvent(allEvents, 2023, 1, 1, 2); + assertEquals(event.getStart(), 2); + } + + @Test + public void updateEventTest() { + List allEvents = getAllEvents(2023); + Event event = findEvent(allEvents, 2023, 1, 1, 1); + TLWMatchday matchday = new TLWMatchday(2023, 1, 1, 0, "2022-08-05 20:30:00", "", "", "1. Spieltag", 12); + updateEvent(event, matchday, matchday.getDeliveryDate(), 1); + assertEquals(event.size(), 18); + } + @Test public void createOrUpdateEventsForMatchdayWTLPokalTest() { TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 48, "WTL-Pokal"); @@ -50,10 +66,9 @@ public class TippligaGoogleEventManagerTest { } @Test - public void updateEventTest() { - TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 1, "Tippliga"); - ArrayList matchdays = creator.getMatchdays(); - createOrUpdateEvent(matchdays.get(28), matchdays.get(28).getDeliveryDate(), 1); + public void createOrUpdateEventTest() { + TLWMatchday matchday = new TLWMatchday(2023, 1, 1, 0, "2022-08-06 20:30:00", "", "", "1. Spieltag", 12); + createOrUpdateEvent(matchday, matchday.getDeliveryDate(), 1); } @Test diff --git a/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java b/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java index 1b4da23..b3247ae 100644 --- a/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java +++ b/src/test/java/de/jeyp91/tippliga/TLWMatchdayUpdaterTest.java @@ -23,4 +23,10 @@ public class TLWMatchdayUpdaterTest { // System.out.println(sql); // System.out.println(matchdaysUpdater.getBeautifulInfo()); } + + @Test + public void updateGoogleCalendarTest() { + TLWMatchdaysUpdater matchdaysUpdater = new TLWMatchdaysUpdater(2023, 1, "Tippliga"); + matchdaysUpdater.updateGoogleCalendar(); + } } diff --git a/tokens/StoredCredential b/tokens/StoredCredential index c17c026..0ee21af 100644 Binary files a/tokens/StoredCredential and b/tokens/StoredCredential differ