Search in sources :

Example 1 with AlbumEntry

use of com.google.gdata.data.photos.AlbumEntry in project data-transfer-project by google.

the class GooglePhotosImporter method importSingleAlbum.

@VisibleForTesting
void importSingleAlbum(UUID jobId, TokensAndUrlAuthData authData, PhotoAlbum inputAlbum) throws IOException, ServiceException {
    // Set up album
    AlbumEntry outputAlbum = new AlbumEntry();
    outputAlbum.setTitle(new PlainTextConstruct("copy of " + inputAlbum.getName()));
    outputAlbum.setDescription(new PlainTextConstruct(inputAlbum.getDescription()));
    // Upload album
    AlbumEntry insertedEntry = getOrCreatePhotosService(authData).insert(new URL(ALBUM_POST_URL), outputAlbum);
    // Put new album ID in job store so photos can be assigned to the correct album
    TempPhotosData photoMappings = jobStore.findData(TempPhotosData.class, jobId);
    if (photoMappings == null) {
        photoMappings = new TempPhotosData(jobId);
        jobStore.create(jobId, photoMappings);
    }
    photoMappings.addAlbumId(inputAlbum.getId(), insertedEntry.getGphotoId());
    jobStore.update(jobId, photoMappings);
}
Also used : AlbumEntry(com.google.gdata.data.photos.AlbumEntry) TempPhotosData(org.dataportabilityproject.spi.transfer.types.TempPhotosData) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) URL(java.net.URL) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with AlbumEntry

use of com.google.gdata.data.photos.AlbumEntry in project data-transfer-project by google.

the class GooglePhotosService method importItem.

@Override
public void importItem(PhotosModelWrapper wrapper) throws IOException {
    for (PhotoAlbum album : wrapper.getAlbums()) {
        if (true) {
            // Google doesn't support creating albums anymore
            continue;
        }
        AlbumEntry myAlbum = new AlbumEntry();
        myAlbum.setTitle(new PlainTextConstruct("copy of " + album.getName()));
        myAlbum.setDescription(new PlainTextConstruct(album.getDescription()));
        URL albumUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default");
        AlbumEntry insertedEntry;
        try {
            // https://developers.google.com/picasa-web/docs/2.0/developers_guide_java#AddAlbums
            insertedEntry = service.insert(albumUrl, myAlbum);
            jobDataCache.store(album.getId(), insertedEntry.getGphotoId());
        } catch (ServiceException e) {
            throw new IOException("Problem copying" + album.getName() + " request to: " + albumUrl, e);
        }
    }
    for (PhotoModel photo : wrapper.getPhotos()) {
        // String newAlbumId = jobDataCache.getData(photo.getAlbumId(), String.class);
        String newAlbumId = "default";
        URL photoPostUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + newAlbumId);
        PhotoEntry myPhoto = new PhotoEntry();
        myPhoto.setTitle(new PlainTextConstruct("copy of " + photo.getTitle()));
        myPhoto.setDescription(new PlainTextConstruct(photo.getDescription()));
        myPhoto.setClient(CLIENT_NAME);
        String mediaType = photo.getMediaType();
        if (mediaType == null) {
            mediaType = "image/jpeg";
        }
        MediaStreamSource streamSource = new MediaStreamSource(getImageAsStream(photo.getFetchableUrl()), mediaType);
        myPhoto.setMediaSource(streamSource);
        try {
            service.insert(photoPostUrl, myPhoto);
        } catch (ServiceException e) {
            throw new IOException("Problem adding " + photo.getTitle() + " to " + newAlbumId, e);
        }
    }
}
Also used : AlbumEntry(com.google.gdata.data.photos.AlbumEntry) ServiceException(com.google.gdata.util.ServiceException) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IOException(java.io.IOException) MediaStreamSource(com.google.gdata.data.media.MediaStreamSource) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) URL(java.net.URL) PhotoEntry(com.google.gdata.data.photos.PhotoEntry)

Aggregations

PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)2 AlbumEntry (com.google.gdata.data.photos.AlbumEntry)2 URL (java.net.URL)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MediaStreamSource (com.google.gdata.data.media.MediaStreamSource)1 PhotoEntry (com.google.gdata.data.photos.PhotoEntry)1 ServiceException (com.google.gdata.util.ServiceException)1 IOException (java.io.IOException)1 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)1 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)1 TempPhotosData (org.dataportabilityproject.spi.transfer.types.TempPhotosData)1