Search in sources :

Example 16 with ContinuationInformation

use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.

the class RememberTheMilkTaskService method exportTaskLists.

private TaskModelWrapper exportTaskLists(Optional<PaginationInformation> paginationInformation) throws IOException {
    List<TaskListModel> lists = new ArrayList<>();
    List<Resource> subResources = new ArrayList<>();
    for (ListInfo oldListInfo : getLists().listInfoList.lists) {
        if (oldListInfo.name.equals("All Tasks")) {
            // don't copy that over.
            continue;
        }
        lists.add(new TaskListModel(Integer.toString(oldListInfo.id), oldListInfo.name));
        subResources.add(new IdOnlyResource(Integer.toString(oldListInfo.id)));
    }
    return new TaskModelWrapper(lists, null, new ContinuationInformation(subResources, null));
}
Also used : TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) ListInfo(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.ListInfo) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel)

Example 17 with ContinuationInformation

use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.

the class FlickrPhotoServiceTest method exportAlbumInitial.

@Test
public void exportAlbumInitial() throws IOException, FlickrException {
    // Set up initial export information, such as what FlickrPhotoService would see when a transfer
    // is initiated
    ExportInformation emptyExportInfo = new ExportInformation(Optional.empty(), Optional.empty());
    // Set up auth
    when(user.getId()).thenReturn("userId");
    // Set up photoset
    String photosetId = "photosetId";
    String photosetTitle = "title";
    String photosetDescription = "description";
    Photoset photoset = initializePhotoset(photosetId, photosetTitle, photosetDescription);
    // Set up photosets list (aka album view)
    int page = 1;
    Photosets photosetList = new Photosets();
    photosetList.setPage(page);
    photosetList.setPages(page + 1);
    photosetList.setPhotosets(Collections.singletonList(photoset));
    when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetList);
    // Run test
    PhotosModelWrapper result = photoService.export(emptyExportInfo);
    // Make sure album/photo information is correct
    assertThat(result.getPhotos()).isEmpty();
    Collection<PhotoAlbum> albums = result.getAlbums();
    assertThat(albums.size()).isEqualTo(1);
    assertThat(albums).containsExactly(new PhotoAlbum(photosetId, photosetTitle, photosetDescription));
    // Make sure continuation information is correct
    ContinuationInformation continuationInformation = result.getContinuationInformation();
    assertThat((FlickrPaginationInformation) continuationInformation.getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
    Collection<? extends Resource> subResources = continuationInformation.getSubResources();
    assertThat(subResources.size()).isEqualTo(1);
    assertThat(subResources).containsExactly(new IdOnlyResource(photosetId));
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Matchers.anyString(org.mockito.Matchers.anyString) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Test(org.junit.Test)

Example 18 with ContinuationInformation

use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.

the class FlickrPhotoServiceTest method importStoresAlbumsInJobCache.

@Test
public void importStoresAlbumsInJobCache() throws IOException, FlickrException {
    // Set up input: a single photo album with a single photo
    PhotosModelWrapper wrapper = new PhotosModelWrapper(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL), new ContinuationInformation(null, null));
    // Set up mocks
    when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
    when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
    String flickrAlbumTitle = FlickrPhotoService.COPY_PREFIX + ALBUM_NAME;
    Photoset photoSet = initializePhotoset(FLICKR_ALBUM_ID, flickrAlbumTitle, ALBUM_DESCRIPTION);
    when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoSet);
    // Run test
    photoService.importItem(wrapper);
    // Verify the image stream provider got the correct url
    verify(imageStreamProvider).get(FETCHABLE_URL);
    // Verify the correct photo information was uploaded
    ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
    verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
    UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
    assertThat(actualUploadMetaData.getTitle()).isEqualTo(FlickrPhotoService.COPY_PREFIX + PHOTO_TITLE);
    assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
    // Verify the photosets interface got the command to create the correct album
    verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
    // Check jobDataCache contents
    String expectedAlbumKey = FlickrPhotoService.CACHE_ALBUM_METADATA_PREFIX + ALBUM_ID;
    assertThat(jobDataCache.hasKey(expectedAlbumKey)).isTrue();
    assertThat(jobDataCache.getData(expectedAlbumKey, PhotoAlbum.class)).isEqualTo(PHOTO_ALBUM);
    assertThat(jobDataCache.getData(ALBUM_ID, String.class)).isEqualTo(FLICKR_ALBUM_ID);
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) BufferedInputStream(java.io.BufferedInputStream) Photoset(com.flickr4java.flickr.photosets.Photoset) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)18 ArrayList (java.util.ArrayList)13 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)11 Resource (org.dataportabilityproject.dataModels.Resource)10 IOException (java.io.IOException)8 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)8 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)8 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)7 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)5 Photoset (com.flickr4java.flickr.photosets.Photoset)4 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)4 Photosets (com.flickr4java.flickr.photosets.Photosets)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FlickrException (com.flickr4java.flickr.FlickrException)2 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)2 Credential (com.google.api.client.auth.oauth2.Credential)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 BufferedInputStream (java.io.BufferedInputStream)2