From dac3f31a37e67cc4816da3e3f0face15e33e5d39 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Mon, 7 Nov 2022 18:00:29 +0100 Subject: [PATCH] Update dependencies and add support for google calendar html event description --- build.gradle | 16 +++++++-------- .../TippligaGoogleEventManager.java | 20 +++++++++++++------ .../TippligaGoogleEventManagerTest.java | 20 +++++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index fcc3099..5ece322 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ apply plugin: 'java' apply plugin: 'application' mainClassName = 'App' -sourceCompatibility = 11 -targetCompatibility = 11 +sourceCompatibility = 14 +targetCompatibility = 14 version = '1.0' compileJava.options.encoding = 'UTF-8' compileTestJava.options.encoding = "UTF-8" @@ -18,15 +18,15 @@ repositories { } dependencies { - implementation 'mysql:mysql-connector-java:8.0.29' + implementation 'mysql:mysql-connector-java:8.0.30' implementation 'org.apache.httpcomponents:httpclient:4.5.13' implementation 'com.googlecode.json-simple:json-simple:1.1.1' - implementation 'com.google.code.gson:gson:2.9.0' + implementation 'com.google.code.gson:gson:2.10' implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.896') - implementation 'com.amazonaws:aws-java-sdk-s3:1.12.239' - implementation 'com.google.api-client:google-api-client:1.33.2' - implementation 'com.google.oauth-client:google-oauth-client-jetty:1.33.1' - implementation 'com.google.apis:google-api-services-calendar:v3-rev20211026-1.32.1' + implementation 'com.amazonaws:aws-java-sdk-s3:1.12.332' + implementation 'com.google.api-client:google-api-client:2.0.0' + implementation 'com.google.oauth-client:google-oauth-client-jetty:1.34.1' + implementation 'com.google.apis:google-api-services-calendar:v3-rev20220715-2.0.0' testImplementation 'junit:junit:4.13.2' compile 'com.google.guava:guava:31.1-jre' compile group: 'commons-cli', name: 'commons-cli', version: '1.3.1' diff --git a/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java b/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java index f1b0ce8..ccd6e59 100644 --- a/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java +++ b/src/main/java/de/jeyp91/googlecalendar/TippligaGoogleEventManager.java @@ -59,8 +59,14 @@ public class TippligaGoogleEventManager { public static Event findEvent(List allEvents, Integer season, Integer league, Integer matchday, Integer deliveryDateNumber) { String description = getDescription(season, league, matchday, deliveryDateNumber); + String descriptionHtml = getDescriptionHTML(season, league, matchday, deliveryDateNumber); for (Event event : allEvents) { - if (event.getDescription().replaceAll("\\s+","").equals(description.replaceAll("\\s+",""))) return event; + if ( + (event.getDescription().replaceAll("\\s+","").equals(description.replaceAll("\\s+",""))) + || event.getDescription().equals(descriptionHtml) + ) { + return event; + } } return null; } @@ -151,11 +157,7 @@ public class TippligaGoogleEventManager { // Set reminder to 12 hours before Event.Reminders reminders = new Event.Reminders(); - reminders.setUseDefault(false); - EventReminder[] reminderOverrides = new EventReminder[] { - new EventReminder().setMethod("popup").setMinutes(12 * 60), - }; - reminders.setOverrides(Arrays.asList(reminderOverrides)); + reminders.setUseDefault(true); return new Event() .setSummary(summary) @@ -171,6 +173,12 @@ public class TippligaGoogleEventManager { return "Saison: " + season + "\n" + "Liga: " + league + "\n" + "Spieltag: " + matchday + "\n" + "Abgabeschluss: " + deliverDateNumber; } + + private static String getDescriptionHTML(Integer season, Integer league, Integer matchday, Integer deliverDateNumber) { + league = league == 2 ? 1 : league; + return "Saison: " + season + "
" + "Liga: " + league + "
" + "Spieltag: " + matchday + "
" + "Abgabeschluss: " + deliverDateNumber + "
"; + } + public static void updateAllMatchdays(ArrayList matchdays) { matchdays.forEach(tlwMatchday -> { createOrUpdateEvent(tlwMatchday, tlwMatchday.getDeliveryDate(), 1); diff --git a/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java b/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java index 19c18a3..6dad433 100644 --- a/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java +++ b/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java @@ -18,7 +18,7 @@ public class TippligaGoogleEventManagerTest { @Test public void getAllEventsStartingFromDateTimeTest() { - DateTime dateTime = new DateTime("2020-01-01T00:00:00"); + DateTime dateTime = new DateTime("2022-11-07T00:00:00"); List events = getAllEventsStartingFromDateTime(dateTime); @@ -28,7 +28,7 @@ public class TippligaGoogleEventManagerTest { assertEquals(startExpected, startActual); assertEquals("Tippliga 21. Spieltag tippen!", events.get(1).getSummary()); - startExpected = new DateTime("2020-01-24T20:30:00+01:00"); + startExpected = new DateTime("2020- 01-24T20:30:00+01:00"); startActual = events.get(1).getStart().getDateTime(); assertEquals(startExpected, startActual); } @@ -44,7 +44,7 @@ public class TippligaGoogleEventManagerTest { @Test public void findEventTest() { List allEvents = getAllEvents(2023); - Event event = findEvent(allEvents, 2023, 1, 1, 2); + Event event = findEvent(allEvents, 2023, 1, 15, 1); assert event != null; assertEquals(event.getStart().size(), 2); } @@ -52,11 +52,15 @@ public class TippligaGoogleEventManagerTest { @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-06 20:30:00", "", "", "1. Spieltag", 12); - assert event != null; - updateEvent(event, matchday, matchday.getDeliveryDate(), 1); - assertEquals(event.size(), 18); + Event event1 = findEvent(allEvents, 2023, 1, 15, 1); + Event event2 = findEvent(allEvents, 2023, 1, 15, 2); + TLWMatchday matchday = new TLWMatchday(2023, 1, 15, 0, "2022-11-08 18:30:00", "2022-11-09 18:30:00", "", "15. Spieltag", 12); + assert event1 != null; + assert event2 != null; + updateEvent(event1, matchday, matchday.getDeliveryDate(), 1); + updateEvent(event2, matchday, matchday.getDeliveryDate2(), 2); + assertEquals(event1.size(), 18); + assertEquals(event2.size(), 18); } @Test