throw new IllegalArgumentException("Required parameter 'id' is null or empty.");
}
LOG.info(String.format("Uploading photo id '%s' to Picasa.", photoEntryId));
PhotoEntry photoEntry = photoSubmissionDao.getPhotoEntry(photoEntryId);
com.google.gdata.data.photos.PhotoEntry picasaPhoto = picasaApi.doResumableUpload(photoEntry);
if (picasaPhoto == null) {
// This is an expected exception, and is the mechanism for scheduling the next upload
// chunk, making use of TaskQueue's automatic rescheduling.
throw new IllegalStateException("The resumable upload is still in progress.");
}
photoEntry.setPicasaUrl(picasaPhoto.getEditLink().getHref());
// Let's use the smallest thumbnail from Picasa.
String thumbnailUrl = "";
int minWidth = Integer.MAX_VALUE;
for (MediaThumbnail thumbnail : picasaPhoto.getMediaGroup().getThumbnails()) {
int width = thumbnail.getWidth();
if (width < minWidth) {
minWidth = width;
thumbnailUrl = thumbnail.getUrl();
}
}
photoEntry.setThumbnailUrl(thumbnailUrl);
photoEntry.setImageUrl(picasaPhoto.getMediaGroup().getContents().get(0).getUrl());
if (photoEntry.getBlobKey() != null) {
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
blobstoreService.delete(photoEntry.getBlobKey());
photoEntry.setBlobKey(null);
}
dataChunkDao.deleteChunks(photoEntryId);
photoSubmissionDao.save(photoEntry);
PhotoSubmission photoSubmission = photoSubmissionDao.getSubmissionById(
photoEntry.getSubmissionId());
emailUtil.sendNewSubmissionEmail(photoEntry, photoSubmission);
} catch (IllegalArgumentException e) {
// We don't want to send an error response here, since that will result
// in the TaskQueue retrying and this is not a transient error.
LOG.log(Level.WARNING, "", e);