use of com.google.gdata.data.photos.PhotoEntry 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);
}
}
}
use of com.google.gdata.data.photos.PhotoEntry 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);
}
Aggregations