private ExportResult exportTaskList(RememberTheMilkService service) { List<TaskListModel> lists = new ArrayList<>(); List<IdOnlyContainerResource> subResources = new ArrayList<>(); List<ListInfo> listInfoList; try { listInfoList = service.getLists().lists; } catch (IOException e) { return new ExportResult(e); } for (ListInfo oldListInfo : listInfoList) { if (oldListInfo.name.equals("All Tasks")) { // All Tasks is a special list that contains everything, don't copy that over continue; } lists.add(new TaskListModel(Integer.toString(oldListInfo.id), oldListInfo.name)); subResources.add(new IdOnlyContainerResource(Integer.toString(oldListInfo.id))); } TaskContainerResource taskContainerResource = new TaskContainerResource(lists, null); ContinuationData continuationData = new ContinuationData(null); subResources.forEach(continuationData::addContainerResource); // TODO: what do we do with pagination data? return new ExportResult(ResultType.CONTINUE, taskContainerResource, continuationData); }
ContinuationData continuationData = new ContinuationData(null); for (PhotoAlbum album : photosContainerResource.getAlbums()) { continuationData.addContainerResource(new IdOnlyContainerResource(album.getId()));
continuationData.addContainerResource(new IdOnlyContainerResource(googleAlbum.getId()));
private ExportResult<TaskContainerResource> getTasksList( Tasks tasksService, Optional<PaginationData> paginationData) throws IOException { Tasks.Tasklists.List query = tasksService.tasklists().list().setMaxResults(PAGE_SIZE); if (paginationData.isPresent()) { query.setPageToken(((StringPaginationToken) paginationData.get()).getToken()); } TaskLists result = query.execute(); ImmutableList.Builder<TaskListModel> newTaskListsBuilder = ImmutableList.builder(); ImmutableList.Builder<IdOnlyContainerResource> newResourcesBuilder = ImmutableList.builder(); for (TaskList taskList : result.getItems()) { newTaskListsBuilder.add(new TaskListModel(taskList.getId(), taskList.getTitle())); newResourcesBuilder.add(new IdOnlyContainerResource(taskList.getId())); } PaginationData newPage = null; ResultType resultType = ResultType.END; if (result.getNextPageToken() != null) { newPage = new StringPaginationToken(result.getNextPageToken()); resultType = ResultType.CONTINUE; } List<IdOnlyContainerResource> newResources = newResourcesBuilder.build(); if (!newResources.isEmpty()) { resultType = ResultType.CONTINUE; } TaskContainerResource taskContainerResource = new TaskContainerResource(newTaskListsBuilder.build(), null); ContinuationData continuationData = new ContinuationData(newPage); newResourcesBuilder.build().forEach(continuationData::addContainerResource); return new ExportResult<>(resultType, taskContainerResource, continuationData); }
for (CalendarListEntry calendarData : listResult.getItems()) { CalendarModel model = convertToCalendarModel(calendarData); continuationData.addContainerResource(new IdOnlyContainerResource(calendarData.getId())); calendarModels.add(model);
new PhotoAlbum(photoSet.getId(), photoSet.getTitle(), photoSet.getDescription())); subResources.add(new IdOnlyContainerResource(photoSet.getId()));
@Test public void exportPhotoFirstSet() throws IOException { setUpSingleAlbum(); when(albumListResponse.getNextPageToken()).thenReturn(null); GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID); when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[]{mediaItem}); when(mediaItemSearchResponse.getNextPageToken()).thenReturn(PHOTO_TOKEN); IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID); ExportResult<PhotosContainerResource> result = googlePhotosExporter .exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.empty(), uuid); // Check results // Verify correct methods were called verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.empty()); verify(mediaItemSearchResponse).getMediaItems(); // Check pagination ContinuationData continuationData = result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken.getToken()).isEqualTo(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN); // Check albums field of container (should be empty) Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums(); assertThat(actualAlbums).isEmpty(); // Check photos field of container Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos(); assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())) .containsExactly(IMG_URI + "=d"); // for download assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())) .containsExactly(ALBUM_ID); }
@Test public void exportPhotoSubsequentSet() throws IOException { setUpSingleAlbum(); when(albumListResponse.getNextPageToken()).thenReturn(null); GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID); when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[]{mediaItem}); when(mediaItemSearchResponse.getNextPageToken()).thenReturn(null); StringPaginationToken inputPaginationToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN); IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID); // Run test ExportResult<PhotosContainerResource> result = googlePhotosExporter .exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.of(inputPaginationToken), uuid); // Check results // Verify correct methods were called verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.of(PHOTO_TOKEN)); verify(mediaItemSearchResponse).getMediaItems(); // Check pagination token ContinuationData continuationData = result.getContinuationData(); PaginationData paginationToken = continuationData.getPaginationData(); assertNull(paginationToken); }
if (!album.getPrivacy().equals(PRIVATE_ALBUM)) { albumsList.add(new PhotoAlbum(album.getWebUri(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getUri()));
private ExportResult<PhotosContainerResource> exportAlbums( TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) { Optional<String> paginationToken = stripTokenPrefix(paginationData, ALBUM_TOKEN_PREFIX); ArrayList<PhotoAlbum> exportAlbums = new ArrayList<>(); // Get albums Connection<Album> connection = getOrCreatePhotosInterface(authData).getAlbums(paginationToken); PaginationData nextPageData = null; String token = connection.getAfterCursor(); if (!Strings.isNullOrEmpty(token)) { nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token); } ContinuationData continuationData = new ContinuationData(nextPageData); List<Album> albums = connection.getData(); for (Album album : albums) { exportAlbums.add(new PhotoAlbum(album.getId(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getId())); } return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(exportAlbums, null), continuationData); }
@Test public void testExportPhoto() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ALBUM_ID)))); assertEquals(ExportResult.ResultType.END, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getPhotos().size()); assertEquals( new PhotoModel( PHOTO_ID + ".jpg", PHOTO_SOURCE, PHOTO_NAME, "image/jpg", PHOTO_ID, ALBUM_ID, false), exportedData.getPhotos().toArray()[0]); }
ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID); ExportInformation exportInformation = new ExportInformation(null, containerResource); eventListResponse.setNextPageToken(NEXT_TOKEN);
String photosetsId = "photosetsId"; ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
assertThat(subResources).containsExactly(new IdOnlyContainerResource("photosetId"));
@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(); }
@Test public void verifySerializeDeserialize() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes( ContinuationData.class, IntPaginationToken.class, IdOnlyContainerResource.class); ContinuationData continuationData = new ContinuationData(new IntPaginationToken(100)); continuationData.addContainerResource(new IdOnlyContainerResource("123")); String serialized = objectMapper.writeValueAsString(continuationData); ContinuationData deserialized = objectMapper.readValue(serialized, ContinuationData.class); Assert.assertNotNull(deserialized); Assert.assertEquals(100, ((IntPaginationToken) deserialized.getPaginationData()).getStart()); Assert.assertEquals( "123", ((IdOnlyContainerResource) deserialized.getContainerResources().get(0)).getId()); } }
@Test public void testExportAlbum() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.empty()); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull(result.getContinuationData().getPaginationData()); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }
@Test public void testSpecifiedAlbums() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of( new ExportInformation( new StringPaginationToken(PHOTO_TOKEN_PREFIX), new PhotosContainerResource( Lists.newArrayList(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION)), new ArrayList<>())))); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull((result.getContinuationData().getPaginationData())); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }