@Override public void update(Absence absence, String eventId, CalendarSettings calendarSettings) { googleCalendarClient = getOrCreateGoogleCalendarClient(); if (googleCalendarClient != null) { String calendarId = settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings().getCalendarId(); try { // gather exiting event Event event = googleCalendarClient.events().get(calendarId, eventId).execute(); // update event with absence fillEvent(absence, event); // sync event to calendar googleCalendarClient.events().patch(calendarId, eventId, event).execute(); LOG.info(String.format("Event %s has been updated in calendar '%s'.", eventId, calendarId)); } catch (IOException ex) { LOG.warn(String.format("Could not update event %s in calendar '%s'.", eventId, calendarId), ex); mailService.sendCalendarUpdateErrorNotification(calendarId, absence, eventId, ex.getMessage()); } } }
@Override public void updateAppointment(final AppointmentDto appointment) throws IOException { final GoogleAppointmentDto googleAppointmentDto = (GoogleAppointmentDto) appointment; final Event event = client.events().get(calendarId, googleAppointmentDto.getGoogleId()).execute(); populateEventFromAppointmentDto(appointment, event); client.events().update(calendarId, event.getId(), event).execute(); LOG.info("Updated Google appointment " + appointment.getSummary()); }
public static boolean inPast(String eventId, GuildSettings settings) { //TODO: Support multiple calendars if (EventUtils.eventExists(settings, eventId)) { try { Calendar service = CalendarAuth.getCalendarService(settings); CalendarData calendarData = DatabaseManager.getManager().getMainCalendar(settings.getGuildID()); Event e = service.events().get(calendarData.getCalendarId(), eventId).execute(); return inPast(e); } catch (Exception e) { Logger.getLogger().exception(null, "Failed to get calendar auth", e, TimeUtils.class); //Return false and allow RSVP so user is not adversely affected. return false; } } return false; }
public static boolean eventExists(GuildSettings settings, String eventId) { //TODO: Support multiple calendars... String calendarId = DatabaseManager.getManager().getMainCalendar(settings.getGuildID()).getCalendarAddress(); try { Calendar service = CalendarAuth.getCalendarService(settings); return service.events().get(calendarId, eventId).execute() != null; } catch (Exception e) { //Failed to check event, probably doesn't exist, safely ignore. } return false; }