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);
}
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);
}
}
}
Aggregations