@Before public void setup() throws IOException { calendarClient = mock(Calendar.class); calendarCalendars = mock(Calendar.Calendars.class); calendarInsertRequest = mock(Calendar.Calendars.Insert.class); calendarEvents = mock(Calendar.Events.class); eventInsertRequest = mock(Calendar.Events.Insert.class); credentialFactory = mock(GoogleCredentialFactory.class); jobStore = new LocalJobStore(); calendarService = new GoogleCalendarImporter(credentialFactory, jobStore, calendarClient); when(calendarClient.calendars()).thenReturn(calendarCalendars); when(calendarClient.events()).thenReturn(calendarEvents); verifyZeroInteractions(credentialFactory); }
@Before public void setup() throws IOException { calendarClient = mock(Calendar.class); calendarCalendars = mock(Calendar.Calendars.class); calendarCalendarList = mock(Calendar.CalendarList.class); calendarListRequest = mock(Calendar.CalendarList.List.class); calendarEvents = mock(Calendar.Events.class); eventListRequest = mock(Calendar.Events.List.class); credentialFactory = mock(GoogleCredentialFactory.class); googleCalendarExporter = new GoogleCalendarExporter(credentialFactory, calendarClient); when(calendarClient.calendars()).thenReturn(calendarCalendars); when(calendarClient.calendarList()).thenReturn(calendarCalendarList); when(calendarCalendarList.list()).thenReturn(calendarListRequest); when(calendarClient.events()).thenReturn(calendarEvents); when(calendarEvents.list(CALENDAR_ID)).thenReturn(eventListRequest); when(eventListRequest.setMaxAttendees(MAX_ATTENDEES)).thenReturn(eventListRequest); verifyZeroInteractions(credentialFactory); }
@VisibleForTesting void importSingleCalendar(UUID jobId, TokensAndUrlAuthData authData, CalendarModel calendarModel) throws IOException { com.google.api.services.calendar.model.Calendar toInsert = convertToGoogleCalendar( calendarModel); com.google.api.services.calendar.model.Calendar calendarResult = getOrCreateCalendarInterface(authData).calendars().insert(toInsert).execute(); TempCalendarData calendarMappings = jobStore.findData(jobId, createCacheKey(), TempCalendarData.class); if (calendarMappings == null) { calendarMappings = new TempCalendarData(jobId); jobStore.create(jobId, createCacheKey(), calendarMappings); } calendarMappings.addIdMapping(calendarModel.getId(), calendarResult.getId()); jobStore.update(jobId, createCacheKey(), calendarMappings); }
private static void deleteCalendar(Calendar calendar) throws IOException { View.header("Delete Calendar"); client.calendars().delete(calendar.getId()).execute(); } }
private static Calendar addCalendar() throws IOException { View.header("Add Calendar"); Calendar entry = new Calendar(); entry.setSummary("Calendar for Testing 3"); Calendar result = client.calendars().insert(entry).execute(); View.display(result); return result; }
private static Calendar updateCalendar(Calendar calendar) throws IOException { View.header("Update Calendar"); Calendar entry = new Calendar(); entry.setSummary("Updated Calendar for Testing"); Calendar result = client.calendars().patch(calendar.getId(), entry).execute(); View.display(result); return result; }
private static void deleteCalendarsUsingBatch() throws IOException { View.header("Delete Calendars Using Batch"); BatchRequest batch = client.batch(); for (Calendar calendar : addedCalendarsUsingBatch) { client.calendars().delete(calendar.getId()).queue(batch, new JsonBatchCallback<Void>() { @Override public void onSuccess(Void content, HttpHeaders responseHeaders) { System.out.println("Delete is successful!"); } @Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }); } batch.execute(); }
private static void addCalendarsUsingBatch() throws IOException { View.header("Add Calendars using Batch"); BatchRequest batch = client.batch(); // Create the callback. JsonBatchCallback<Calendar> callback = new JsonBatchCallback<Calendar>() { @Override public void onSuccess(Calendar calendar, HttpHeaders responseHeaders) { View.display(calendar); addedCalendarsUsingBatch.add(calendar); } @Override public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) { System.out.println("Error Message: " + e.getMessage()); } }; // Create 2 Calendar Entries to insert. Calendar entry1 = new Calendar().setSummary("Calendar for Testing 1"); client.calendars().insert(entry1).queue(batch, callback); Calendar entry2 = new Calendar().setSummary("Calendar for Testing 2"); client.calendars().insert(entry2).queue(batch, callback); batch.execute(); }
private DateTimeZone getCalendarTimeZone(final String id) throws IOException { final String timeZoneName = client.calendars().get(id).execute().getTimeZone(); return DateTimeZone.forID(timeZoneName); }
private static HttpResponse checkGoogleCalendar(Calendar client, Settings settings) throws IOException { String calendarId = settings.getCalendarSettings().getGoogleCalendarSettings().getCalendarId(); Calendar.Calendars.Get metadata = client.calendars().get(calendarId); return metadata.buildHttpRequestUsingHead().execute(); }
@Before public void setUp() { try { CalendarList calendarListModel = new com.google.api.services.calendar.model.CalendarList(); when(client.calendars()).thenReturn(calendars); when(calendars.insert(anyObject())).thenReturn(calendarsInsert); when(calendarsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Calendar()); when(client.calendarList()).thenReturn(calendarsList); when(calendarsList.list()).thenReturn(calendarsListList); when(calendarsListList.execute()).thenReturn(calendarListModel); when(auth.getAuthorizedCalendar(anyString(), anyString())).thenReturn(client); when(client.events()).thenReturn(clientEvents); when(clientEvents.insert(anyString(), anyObject())).thenReturn(calendarEventsInsert); when(calendarEventsInsert.execute()).thenReturn(new com.google.api.services.calendar.model.Event()); when(clientEvents.list(anyString())).thenReturn(calendarEventsList); when(calendarEventsList.execute()).thenReturn(new com.google.api.services.calendar.model.Events()); } catch (Exception e) { fail(e.getMessage()); } }
public WebCalendar fromCalendar(CalendarData cd, GuildSettings gs) { if (cd.getCalendarAddress().equalsIgnoreCase("primary")) { id = "primary"; address = "primary"; link = "N/a"; name = "N/a"; description = "N/a"; timezone = "N/a"; } else { id = cd.getCalendarId(); address = cd.getCalendarAddress(); link = "https://www.discalbot.com/embed/calendar/" + gs.getGuildID(); external = cd.isExternal(); try { Calendar cal = CalendarAuth.getCalendarService(gs).calendars().get(id).execute(); name = cal.getSummary(); description = cal.getDescription(); timezone = cal.getTimeZone().replaceAll("/", "___"); } catch (Exception e) { Logger.getLogger().exception(null, "[WEB] Failed to get calendar!", e, this.getClass()); name = "ERROR!"; description = "ERROR"; timezone = "ERROR"; } } return this; }
Calendar cal = CalendarAuth.getCalendarService(g.getSettings()).calendars().get(g.getCalendar().getId()).execute(); cal.setSummary(queryParams.get("cal-name")); CalendarAuth.getCalendarService(g.getSettings()).calendars().update(g.getCalendar().getId(), cal).execute(); Calendar cal = CalendarAuth.getCalendarService(g.getSettings()).calendars().get(g.getCalendar().getId()).execute(); cal.setDescription(queryParams.get("cal-desc")); CalendarAuth.getCalendarService(g.getSettings()).calendars().update(g.getCalendar().getId(), cal).execute(); Calendar cal = CalendarAuth.getCalendarService(g.getSettings()).calendars().get(g.getCalendar().getId()).execute(); cal.setTimeZone(queryParams.get("cal-tz").replace("___", "/")); CalendarAuth.getCalendarService(g.getSettings()).calendars().update(g.getCalendar().getId(), cal).execute();
com.google.api.services.calendar.Calendar service = CalendarAuth.getCalendarService(g.getSettings()); Calendar confirmed = service.calendars().insert(calendar).execute(); AclRule rule = new AclRule(); AclRule.Scope scope = new AclRule.Scope();
com.google.api.services.calendar.Calendar service = CalendarAuth.getCalendarService(g.getSettings()); Calendar confirmed = service.calendars().insert(calendar).execute(); AclRule rule = new AclRule(); AclRule.Scope scope = new AclRule.Scope();
com.google.api.services.calendar.Calendar service = CalendarAuth.getCalendarService(g.getSettings()); Calendar confirmed = service.calendars().insert(calendar).execute(); AclRule rule = new AclRule(); AclRule.Scope scope = new AclRule.Scope();
break; case CALENDARS: apiProxy = getClient().calendars(); break; case CHANNELS:
service.calendars().delete(data.getCalendarAddress()).execute();
public static boolean calendarExists(CalendarData data, GuildSettings settings) { try { return CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute() != null; } catch (GoogleJsonResponseException ge) { if (ge.getStatusCode() == 410 || ge.getStatusCode() == 404) { //Calendar does not exist... remove from db... settings.setUseExternalCalendar(false); settings.setEncryptedRefreshToken("N/a"); settings.setEncryptedAccessToken("N/a"); DatabaseManager.getManager().updateSettings(settings); DatabaseManager.getManager().deleteCalendar(data); DatabaseManager.getManager().deleteAllEventData(data.getGuildId()); DatabaseManager.getManager().deleteAllRSVPData(data.getGuildId()); DatabaseManager.getManager().deleteAllAnnouncementData(data.getGuildId()); return false; } else { Logger.getLogger().exception(null, "Unknown google error when checking for calendar exist", ge, CalendarUtils.class); return true; } } catch (Exception e) { Logger.getLogger().exception(null, "Unknown error when checking for calendar exist", e, CalendarUtils.class); return true; } } }
cal = CalendarAuth.getCalendarService(settings).calendars().get(data.getCalendarAddress()).execute(); } catch (Exception ex) { Logger.getLogger().exception(null, "Failed to get proper date time for event!", ex, this.getClass());