Java Code Examples for com.google.api.services.calendar.model.CalendarList#getItems()

The following examples show how to use com.google.api.services.calendar.model.CalendarList#getItems() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddEventWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public String getCalendarIdBySummary(com.google.api.services.calendar.Calendar client,
                                     String summary) {
    String resultId = null;
    try {
        CalendarList calendarList = getAllCalendars(client);
        List<CalendarListEntry> entryList = calendarList.getItems();
        for (CalendarListEntry entry : entryList) {
            if (entry.getSummary().equalsIgnoreCase(summary)) {
                resultId = entry.getId();
            }
        }
    } catch (Exception e) {
        logger.error(MessageFormat.format("Error retrieveing calendars: {0}",
                                          e.getMessage()));
    }
    return resultId;
}
 
Example 2
Source File: GetEventsWorkitemHandler.java    From jbpm-work-items with Apache License 2.0 6 votes vote down vote up
public String getCalendarIdBySummary(com.google.api.services.calendar.Calendar client,
                                     String summary) {
    String resultId = null;
    try {
        CalendarList calendarList = getAllCalendars(client);
        List<CalendarListEntry> entryList = calendarList.getItems();
        for (CalendarListEntry entry : entryList) {
            if (entry.getSummary().equalsIgnoreCase(summary)) {
                resultId = entry.getId();
            }
        }
    } catch (Exception e) {
        logger.error(MessageFormat.format("Error retrieveing calendars: {0}",
                                          e.getMessage()));
    }
    return resultId;
}
 
Example 3
Source File: GoogleCalendarMetaDataExtension.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<MetaData> meta(Map<String, Object> parameters) {
    String clientId = ConnectorOptions.extractOption(parameters, "clientId");
    if (clientId == null) {
        return Optional.empty();
    }

    LOG.debug("Retrieving calendars for connection to google calendar");
    String clientSecret = ConnectorOptions.extractOption(parameters, "clientSecret");
    String googleScopes = "https://www.googleapis.com/auth/calendar";
    String applicationName = ConnectorOptions.extractOption(parameters, "applicationName");
    String accessToken = ConnectorOptions.extractOption(parameters, "accessToken");
    String refreshToken = ConnectorOptions.extractOption(parameters, "refreshToken");

    Calendar client = new BatchGoogleCalendarClientFactory().makeClient(clientId, clientSecret,
        getScopes(googleScopes), applicationName, refreshToken, accessToken, null, null, "me");

    final CalendarList calendars;
    try {
        calendars = client.calendarList().list().execute();
    } catch (IOException e) {
        throw new IllegalStateException("Unable to fetch the list of calendars", e);
    }

    Set<CalendarListEntry> setCalendars = new HashSet<CalendarListEntry>();
    if (calendars.getItems() != null) {
        for (CalendarListEntry entry : calendars.getItems()) {
            setCalendars.add(entry);
        }
    }

    return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain")
        .withAttribute(MetaData.JAVA_TYPE, String.class).withPayload(setCalendars).build());

}
 
Example 4
Source File: GoogleCalendarExporter.java    From data-transfer-project with Apache License 2.0 4 votes vote down vote up
private ExportResult<CalendarContainerResource> exportCalendars(
    TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
  Calendar.CalendarList.List listRequest;
  CalendarList listResult;

  // Get calendar information
  try {
    listRequest = getOrCreateCalendarInterface(authData).calendarList().list();

    if (pageData.isPresent()) {
      StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
      Preconditions.checkState(
          paginationToken.getToken().startsWith(CALENDAR_TOKEN_PREFIX),
          "Token is not applicable");
      listRequest.setPageToken(
          ((StringPaginationToken) pageData.get())
              .getToken()
              .substring(CALENDAR_TOKEN_PREFIX.length()));
    }

    listResult = listRequest.execute();
  } catch (IOException e) {
    return new ExportResult<>(e);
  }

  // Set up continuation data
  PaginationData nextPageData = null;
  if (listResult.getNextPageToken() != null) {
    nextPageData =
        new StringPaginationToken(CALENDAR_TOKEN_PREFIX + listResult.getNextPageToken());
  }
  ContinuationData continuationData = new ContinuationData(nextPageData);

  // Process calendar list
  List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size());
  for (CalendarListEntry calendarData : listResult.getItems()) {
    CalendarModel model = convertToCalendarModel(calendarData);
    continuationData.addContainerResource(new IdOnlyContainerResource(calendarData.getId()));
    calendarModels.add(model);
  }
  CalendarContainerResource calendarContainerResource =
      new CalendarContainerResource(calendarModels, null);

  // Get result type
  ExportResult.ResultType resultType = ResultType.CONTINUE;
  if (calendarModels.isEmpty()) {
    resultType = ResultType.END;
  }

  return new ExportResult<>(resultType, calendarContainerResource, continuationData);
}