Search in sources :

Example 1 with PlainTextConstruct

use of com.google.gdata.data.PlainTextConstruct 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 PlainTextConstruct

use of com.google.gdata.data.PlainTextConstruct 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)

Example 3 with PlainTextConstruct

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

the class GooglePhotosImporter method importSinglePhoto.

@VisibleForTesting
void importSinglePhoto(UUID jobId, TokensAndUrlAuthData authData, PhotoModel inputPhoto) throws IOException, ServiceException {
    // Set up photo
    PhotoEntry outputPhoto = new PhotoEntry();
    outputPhoto.setTitle(new PlainTextConstruct("copy of " + inputPhoto.getTitle()));
    outputPhoto.setDescription(new PlainTextConstruct(inputPhoto.getDescription()));
    outputPhoto.setClient(GoogleStaticObjects.APP_NAME);
    String mediaType = inputPhoto.getMediaType();
    if (mediaType == null) {
        mediaType = "image/jpeg";
    }
    MediaStreamSource streamSource = new MediaStreamSource(getImageAsStream(inputPhoto.getFetchableUrl()), mediaType);
    outputPhoto.setMediaSource(streamSource);
    // Find album to upload photo to
    String albumId = jobStore.findData(TempPhotosData.class, jobId).lookupNewAlbumId(inputPhoto.getAlbumId());
    URL uploadUrl = new URL(String.format(PHOTO_POST_URL_FORMATTER, albumId));
    // Upload photo
    getOrCreatePhotosService(authData).insert(uploadUrl, outputPhoto);
}
Also used : TempPhotosData(org.dataportabilityproject.spi.transfer.types.TempPhotosData) MediaStreamSource(com.google.gdata.data.media.MediaStreamSource) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) URL(java.net.URL) PhotoEntry(com.google.gdata.data.photos.PhotoEntry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)3 URL (java.net.URL)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 MediaStreamSource (com.google.gdata.data.media.MediaStreamSource)2 AlbumEntry (com.google.gdata.data.photos.AlbumEntry)2 PhotoEntry (com.google.gdata.data.photos.PhotoEntry)2 TempPhotosData (org.dataportabilityproject.spi.transfer.types.TempPhotosData)2 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