Ejemplo n.º 1
0
  public Calendar getCalendars(String name) throws IOException {
    View.header("Show Calendars");
    CalendarList feed = client.calendarList().list().execute();

    Calendar calendar = null;

    for (CalendarListEntry entry : feed.getItems()) {
      System.out.println();
      System.out.println("-----------------------------------------------");
      if (entry.getSummary().matches(name)) {

        calendar = client.calendars().get(entry.getId()).execute();
        return calendar;
      }
    }
    return null;
  }
  private void loadHistory(UpdateInfo updateInfo, boolean incremental) throws Exception {
    Calendar calendar = getCalendar(updateInfo.apiKey);
    String pageToken = null;
    long apiKeyId = updateInfo.apiKey.getId();
    settingsService.getConnectorSettings(updateInfo.apiKey.getId());
    List<String> existingCalendarIds = getExistingCalendarIds(apiKeyId);
    List<CalendarListEntry> remoteCalendars = new ArrayList<CalendarListEntry>();
    List<CalendarConfig> configs = new ArrayList<CalendarConfig>();
    do {
      final long then = System.currentTimeMillis();
      final Calendar.CalendarList.List list =
          calendar.calendarList().list().setPageToken(pageToken);
      final String query = list.getUriTemplate();
      CalendarList calendarList = null;
      try {
        calendarList = list.execute();
        countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, query);
      } catch (IOException e) {
        countFailedApiCall(
            updateInfo.apiKey,
            updateInfo.objectTypes,
            then,
            query,
            ExceptionUtils.getStackTrace(e),
            list.getLastStatusCode(),
            list.getLastStatusMessage());
      }
      if (calendarList == null)
        throw new Exception("Could not get calendar list, apiKeyId=" + updateInfo.apiKey.getId());
      List<CalendarListEntry> items = calendarList.getItems();
      for (CalendarListEntry item : items) {
        existingCalendarIds.remove(item.getId());
        remoteCalendars.add(item);
        configs.add(entry2Config(item));
      }
      pageToken = calendarList.getNextPageToken();
    } while (pageToken != null);
    initChannelMapping(updateInfo.apiKey, configs);

    updateInfo.setContext(REMOTE_CALLENDARS_KEY, remoteCalendars);

    for (CalendarListEntry remoteCalendar : remoteCalendars)
      loadCalendarHistory(calendar, remoteCalendar, updateInfo, incremental);
    deleteCalendars(apiKeyId, existingCalendarIds);
  }
Ejemplo n.º 3
0
  public void showCalendars() throws IOException {
    View.header("Show Calendars");
    CalendarList feed = client.calendarList().list().execute();

    View.display(feed);
  }