Search in sources :

Example 6 with CalendarList

use of com.google.api.services.calendar.model.CalendarList in project data-transfer-project by google.

the class GoogleCalendarExporter method exportCalendars.

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);
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) ArrayList(java.util.ArrayList) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) CalendarModel(org.datatransferproject.types.common.models.calendar.CalendarModel) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) CalendarList(com.google.api.services.calendar.model.CalendarList) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 7 with CalendarList

use of com.google.api.services.calendar.model.CalendarList in project borg_calendar by mikeberger.

the class GCal method setIds.

private void setIds() throws Exception {
    String calname = Prefs.getPref(PrefName.GCAL_CAL_ID);
    String taskname = Prefs.getPref(PrefName.GCAL_TASKLIST_ID);
    if (calendarId == null) {
        CalendarList cals = service.calendarList().list().execute();
        for (CalendarListEntry c : cals.getItems()) {
            log.fine("Cal Entry: " + c.getSummary() + " : " + c.getId());
            if (calname.equals(c.getSummary())) {
                calendarId = c.getId();
                break;
            }
        }
    }
    if (taskList == null) {
        TaskLists result = tservice.tasklists().list().execute();
        List<TaskList> taskLists = result.getItems();
        if (taskLists != null) {
            for (TaskList tasklist : taskLists) {
                log.fine("TaskList Entry: " + tasklist.getTitle() + " : " + tasklist.getId());
                if (taskname.equals(tasklist.getTitle())) {
                    taskList = tasklist.getId();
                    break;
                }
            }
        }
    }
    if (calendarId == null)
        throw new Exception("Could not determine calender id matching: " + calname);
    if (taskList == null)
        throw new Exception("Could not determine task list id matching: " + taskname);
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) TaskList(com.google.api.services.tasks.model.TaskList) TaskLists(com.google.api.services.tasks.model.TaskLists) CalendarList(com.google.api.services.calendar.model.CalendarList) MalformedJsonException(com.google.gson.stream.MalformedJsonException)

Example 8 with CalendarList

use of com.google.api.services.calendar.model.CalendarList in project jbpm-work-items by kiegroup.

the class GetEventsWorkitemHandler method getCalendarIdBySummary.

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;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList) IOException(java.io.IOException)

Example 9 with CalendarList

use of com.google.api.services.calendar.model.CalendarList in project syndesis-qe by syndesisio.

the class GoogleCalendarUtils method getCalendarByName.

/**
 * Get calendar by its name (aka summary). The first calendar with matching name is being returned.
 *
 * @param ga           Google Account specification
 * @param calendarName name of the calendar
 * @return Calendar instance with matching name (aka summary)
 * @throws IOException when something goes wrong
 */
public Calendar getCalendarByName(String ga, String calendarName) throws IOException {
    // Iterate through entries in calendar list
    String pageToken = null;
    do {
        CalendarList calendarList = getClient(ga).calendarList().list().setPageToken(pageToken).execute();
        List<CalendarListEntry> items = calendarList.getItems();
        for (CalendarListEntry calendarListEntry : items) {
            if (calendarListEntry.getSummary().equals(calendarName)) {
                return getCalendar(ga, calendarListEntry.getId());
            }
        }
        pageToken = calendarList.getNextPageToken();
    } while (pageToken != null);
    return null;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList)

Example 10 with CalendarList

use of com.google.api.services.calendar.model.CalendarList in project camel by apache.

the class CalendarCalendarListIntegrationTest method isCalendarInList.

protected boolean isCalendarInList(Calendar calendar) {
    CalendarList calendarList = requestBody("direct://LIST", null);
    java.util.List<CalendarListEntry> items = calendarList.getItems();
    boolean found = false;
    for (CalendarListEntry calendarListEntry : items) {
        if (calendar.getSummary().equals(calendarListEntry.getSummary())) {
            found = true;
        }
    }
    return found;
}
Also used : CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) CalendarList(com.google.api.services.calendar.model.CalendarList)

Aggregations

CalendarList (com.google.api.services.calendar.model.CalendarList)14 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)13 IOException (java.io.IOException)7 Calendar (com.google.api.services.calendar.Calendar)5 Event (com.google.api.services.calendar.model.Event)4 Events (com.google.api.services.calendar.model.Events)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 InOrder (org.mockito.InOrder)3 Mockito (org.mockito.Mockito)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.verify (org.mockito.Mockito.verify)3 Mockito.when (org.mockito.Mockito.when)3 List (java.util.List)2 Optional (java.util.Optional)2