|
|
|
|
@@ -8,6 +8,8 @@ import com.google.api.services.calendar.model.EventReminder;
|
|
|
|
|
import com.google.api.services.calendar.model.Events;
|
|
|
|
|
import de.jeyp91.tippliga.TLWLeague;
|
|
|
|
|
import de.jeyp91.tippliga.TLWMatchday;
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
@@ -22,6 +24,7 @@ import static de.jeyp91.googlecalendar.GoogleCalendarConnector.getSerivce;
|
|
|
|
|
public class TippligaGoogleEventManager {
|
|
|
|
|
|
|
|
|
|
private static List<Event> allEvents = null;
|
|
|
|
|
private static final Logger logger = LogManager.getLogger(TippligaGoogleEventManager.class);
|
|
|
|
|
|
|
|
|
|
public static List<Event> getAllEvents(Integer season) {
|
|
|
|
|
if(allEvents == null) {
|
|
|
|
|
@@ -56,8 +59,8 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
|
|
|
|
|
public static Event findEvent(List<Event> allEvents, Integer season, Integer league, Integer matchday, Integer deliveryDateNumber) {
|
|
|
|
|
String description = getDescription(season, league, matchday, deliveryDateNumber);
|
|
|
|
|
for (Event allEvent : allEvents) {
|
|
|
|
|
if (allEvent.getDescription().equals(description)) return allEvent;
|
|
|
|
|
for (Event event : allEvents) {
|
|
|
|
|
if (event.getDescription().replaceAll("\\s+","").equals(description.replaceAll("\\s+",""))) return event;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@@ -75,9 +78,13 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
createNewEvent(matchday, deliveryDateString, deliverDateNumber);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
String googleEventStart = event.getStart().getDateTime().toString();
|
|
|
|
|
String googleEventStartBeautified = googleEventStart.substring(0, 19).replace("T", " ");
|
|
|
|
|
if(!googleEventStartBeautified.equals(deliveryDateString)) {
|
|
|
|
|
updateEvent(event, matchday, deliveryDateString, deliverDateNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void createNewEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) {
|
|
|
|
|
String calendarUrl = CalendarConfigProvider.getCalendarUrl();
|
|
|
|
|
@@ -85,6 +92,7 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
Event event = getEvent(matchday, deliveryDateString, deliverDateNumber);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logger.info("Create new google calendar event for " + matchday.getSeason() + ", " + matchday.getLeague() + ", " + matchday.getMatchday() + ", " + deliverDateNumber);
|
|
|
|
|
getSerivce().events().insert(calendarUrl, event).execute();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
@@ -97,6 +105,7 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
Event event = getEvent(matchday, deliveryDateString, deliverDateNumber);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logger.info("Update google calendar event for " + matchday.getSeason() + ", " + matchday.getLeague() + ", " + matchday.getMatchday() + ", " + deliverDateNumber);
|
|
|
|
|
Calendar.Events events = getSerivce().events();
|
|
|
|
|
events.update(calendarUrl, oldEvent.getId(), event).execute();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
@@ -110,6 +119,7 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
Event event = findEvent(getAllEvents(matchday.getSeason()), matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber);
|
|
|
|
|
if(event != null) {
|
|
|
|
|
try {
|
|
|
|
|
logger.info("Delete google calendar event for " + matchday.getSeason() + ", " + matchday.getLeague() + ", " + matchday.getMatchday() + ", " + deliverDateNumber);
|
|
|
|
|
getSerivce().events().delete(calendarUrl, event.getId()).execute();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
@@ -117,11 +127,19 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteAllEvents(int season) throws IOException {
|
|
|
|
|
String calendarUrl = CalendarConfigProvider.getCalendarUrl();
|
|
|
|
|
List<Event> events = getAllEvents(season);
|
|
|
|
|
for(Event event : events ) {
|
|
|
|
|
getSerivce().events().delete(calendarUrl, event.getId()).execute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Event getEvent(TLWMatchday matchday, String deliveryDateString, Integer deliverDateNumber) {
|
|
|
|
|
String matchdayName = matchday.getMatchdayName().equals("") ? matchday.getMatchday().toString() + ". Spieltag" : matchday.getMatchdayName();
|
|
|
|
|
String summary = TLWLeague.getLeagueNameCalendar(matchday.getLeague()) + " " + matchdayName + " tippen!";
|
|
|
|
|
if(deliverDateNumber > 1) summary += " " + deliverDateNumber + ". Chance \uD83D\uDE43";
|
|
|
|
|
String description = getDescription(matchday.getSeason(), matchday.getLeague() == 2 ? 1 : matchday.getLeague(), matchday.getMatchday(), deliverDateNumber);
|
|
|
|
|
String description = getDescription(matchday.getSeason(), matchday.getLeague(), matchday.getMatchday(), deliverDateNumber);
|
|
|
|
|
String location = "https://tippliga-wuerzburg.de/app.php/football/bet";
|
|
|
|
|
|
|
|
|
|
LocalDateTime deliveryLocalDateTime = LocalDateTime.parse(deliveryDateString.replace(" ", "T"));
|
|
|
|
|
@@ -149,6 +167,7 @@ public class TippligaGoogleEventManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getDescription(Integer season, Integer league, Integer matchday, Integer deliverDateNumber) {
|
|
|
|
|
league = league == 2 ? 1 : league;
|
|
|
|
|
return "Saison: " + season + "\n" + "Liga: " + league + "\n" + "Spieltag: " + matchday + "\n" + "Abgabeschluss: " + deliverDateNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|