private static CalendarModel convertToCalendarModel(CalendarListEntry calendarData) { return new CalendarModel( calendarData.getId(), calendarData.getSummary(), calendarData.getDescription()); }
static com.google.api.services.calendar.model.Calendar convertToGoogleCalendar( CalendarModel calendarModel) { return new com.google.api.services.calendar.model.Calendar() .setSummary("Copy of - " + calendarModel.getName()) .setDescription(calendarModel.getDescription()); }
private static EventAttendee transformToEventAttendee(CalendarAttendeeModel attendee) { return new EventAttendee() .setDisplayName(attendee.getDisplayName()) .setEmail(attendee.getEmail()) .setOptional(attendee.getOptional()); }
static Event convertToGoogleCalendarEvent(CalendarEventModel eventModel) { Event event = new Event() .setLocation(eventModel.getLocation()) .setDescription(eventModel.getTitle()) .setSummary(eventModel.getNotes()) .setStart(getEventDateTime(eventModel.getStartTime())) .setEnd(getEventDateTime(eventModel.getEndTime())); if (eventModel.getAttendees() != null) { event.setAttendees(eventModel.getAttendees().stream() .map(GoogleCalendarImporter::transformToEventAttendee) .collect(Collectors.toList())); } return event; }
private static CalendarEventModel convertToCalendarEventModel(String id, Event eventData) { List<EventAttendee> attendees = eventData.getAttendees(); List<String> recurrenceRulesStrings = eventData.getRecurrence(); return new CalendarEventModel( id, eventData.getDescription(), eventData.getSummary(), attendees == null ? null : attendees .stream() .map(GoogleCalendarExporter::transformToModelAttendee) .collect(Collectors.toList()), eventData.getLocation(), getEventTime(eventData.getStart()), getEventTime(eventData.getEnd()), recurrenceRulesStrings == null ? null : getRecurrenceRule(recurrenceRulesStrings)); }
private static EventDateTime getEventDateTime(CalendarEventModel.CalendarEventTime dateTime) { if (dateTime == null) { return null; } EventDateTime eventDateTime = new EventDateTime(); // google's APIs want millisecond from epoch, and the timezone offset in minutes. if (dateTime.isDateOnly()) { eventDateTime.setDate(new DateTime(true, dateTime.getDateTime().toEpochSecond() * 1000, dateTime.getDateTime().getOffset().getTotalSeconds() / 60)); } else { eventDateTime.setDateTime(new DateTime( dateTime.getDateTime().toEpochSecond() * 1000, dateTime.getDateTime().getOffset().getTotalSeconds() / 60)); } return eventDateTime; }
GoogleCalendarImporter.convertToGoogleCalendar(calendarModel); com.google.api.services.calendar.model.Calendar responseCalendar = new com.google.api.services.calendar.model.Calendar().setId(googleCalendarId); Event responseEvent = new Event();
private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) { if (dateTime == null) { return null; } OffsetDateTime offsetDateTime; if (dateTime.getDate() == null) { offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString()); } else { offsetDateTime = OffsetDateTime.from( LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC"))); } return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null); }
if (listResult.getNextPageToken() != null) { nextPageData = new StringPaginationToken(EVENT_TOKEN_PREFIX + listResult.getNextPageToken()); List<CalendarEventModel> eventModels = new ArrayList<>(listResult.getItems().size()); for (Event eventData : listResult.getItems()) { CalendarEventModel model = convertToCalendarEventModel(id, eventData); eventModels.add(model);
if (listResult.getNextPageToken() != null) { nextPageData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + listResult.getNextPageToken()); 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);
private static CalendarAttendeeModel transformToModelAttendee(EventAttendee attendee) { return new CalendarAttendeeModel( attendee.getDisplayName(), attendee.getEmail(), Boolean.TRUE.equals(attendee.getOptional())); }
static void display(Calendar entry) { System.out.println("ID: " + entry.getId()); System.out.println("Summary: " + entry.getSummary()); if (entry.getDescription() != null) { System.out.println("Description: " + entry.getDescription()); } }
@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); }
/** Sets up a response with a single calendar, containing a single event */ private void setUpSingleCalendarResponse() throws IOException { setUpSingleEventResponse(); calendarListResponse = new CalendarList().setItems(Collections.singletonList(CALENDAR_LIST_ENTRY)); when(calendarListRequest.execute()).thenReturn(calendarListResponse); }
@Test public void exportCalendarSubsequentSet() throws IOException { setUpSingleCalendarResponse(); // Looking at subsequent page, with no page after it PaginationData paginationData = new StringPaginationToken(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, null); calendarListResponse.setNextPageToken(null); // Run test ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation)); // Check results // Verify correct calls were made InOrder inOrder = Mockito.inOrder(calendarListRequest); inOrder.verify(calendarListRequest).setPageToken(NEXT_TOKEN); inOrder.verify(calendarListRequest).execute(); // Check pagination token ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken).isNull(); }
@Test public void exportEventSubsequentSet() throws IOException { setUpSingleEventResponse(); // Looking at subsequent page, with no pages after it ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID); PaginationData paginationData = new StringPaginationToken(EVENT_TOKEN_PREFIX + NEXT_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, containerResource); eventListResponse.setNextPageToken(null); // Run test ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation)); // Check results // Verify correct methods were called in order InOrder inOrder = Mockito.inOrder(eventListRequest); inOrder.verify(eventListRequest).setPageToken(NEXT_TOKEN); inOrder.verify(eventListRequest).execute(); // Check pagination token ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken).isNull(); }
calendarListResponse.setNextPageToken(NEXT_TOKEN);
eventListResponse.setNextPageToken(NEXT_TOKEN);