Improve Google Calendar Logic
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<Event> allEvents = null;
|
||||
|
||||
private static List<Event> getAllEvents(Integer season) {
|
||||
public static List<Event> 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<Event> items = events.getItems();
|
||||
|
||||
return items;
|
||||
return events.getItems();
|
||||
}
|
||||
|
||||
public static Event findEvent(List<Event> 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<Event> 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<TLWMatchday> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,22 @@ public class TippligaGoogleEventManagerTest {
|
||||
matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findEventTest() {
|
||||
List<Event> allEvents = getAllEvents(2023);
|
||||
Event event = findEvent(allEvents, 2023, 1, 1, 2);
|
||||
assertEquals(event.getStart(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateEventTest() {
|
||||
List<Event> 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<TLWMatchday> 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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user