Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserves photos filenames when importing #1227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private long importPhotoBatch(

try (InputStream s = streamWrapper.getStream()) {
String uploadToken = getOrCreatePhotosInterface(jobId, authData).uploadPhotoContent(s,
photo.getSha1());
photo.getSha1(), photo.getTitle());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note I think this now lives in GPhotosUpload class, so you'll have to revert this file, merge ,and then re-add this param in the new class.

String description = GooglePhotosImportUtils.cleanDescription(photo.getDescription());
mediaItems.add(new NewMediaItem(description, uploadToken));
uploadTokenToDataId.put(uploadToken, photo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ GoogleAlbum createAlbum(GoogleAlbum googleAlbum)
GoogleAlbum.class);
}

String uploadPhotoContent(InputStream inputStream, @Nullable String sha1)
String uploadPhotoContent(InputStream inputStream, @Nullable String sha1, String title)
throws IOException, InvalidTokenException, PermissionDeniedException, UploadErrorException {
// TODO: add filename
InputStreamContent content = new InputStreamContent(null, inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
content.writeTo(outputStream);
Expand All @@ -179,6 +178,10 @@ String uploadPhotoContent(InputStream inputStream, @Nullable String sha1)
.encodeToString(BaseEncoding.base16().decode(sha1.toUpperCase())));
}

if(!title.isEmpty())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style here is a bit weird - I'm guessing this was just wonkiness from your new IDE setup

{
headers.put("X-Goog-Upload-File-Name",title);
}
return makePostRequest(BASE_URL + "uploads/", Optional.of(PHOTO_UPLOAD_PARAMS),
Optional.of(headers.build()), httpContent, String.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void importTwoPhotos() throws Exception {
OLD_ALBUM_ID,
false,
SHA1);
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(SHA1))).thenReturn("token1");
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(SHA1), eq(PHOTO_TITLE))).thenReturn("token1");

PhotoModel photoModel2 =
new PhotoModel(
Expand All @@ -147,7 +147,7 @@ public void importTwoPhotos() throws Exception {
"oldPhotoID2",
OLD_ALBUM_ID,
false);
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE)))
.thenReturn("token2");

BatchMediaItemResponse batchMediaItemResponse =
Expand All @@ -161,6 +161,7 @@ public void importTwoPhotos() throws Exception {

long length = googlePhotosImporter.importPhotos(Lists.newArrayList(photoModel1, photoModel2),
executor, UUID.randomUUID(), Mockito.mock(TokensAndUrlAuthData.class));

// Two photos of 32L each imported
assertEquals(64L, length);
assertTrue(executor.isKeyCached(String.format("%s-%s", OLD_ALBUM_ID, "oldPhotoID1")));
Expand Down Expand Up @@ -202,7 +203,7 @@ public void importTwoPhotosWithFailure() throws Exception {
OLD_ALBUM_ID,
false);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE)))
.thenReturn("token1", "token2");
BatchMediaItemResponse batchMediaItemResponse =
new BatchMediaItemResponse(
Expand Down Expand Up @@ -240,7 +241,7 @@ public void importOnePhotoWithHashMismatch() throws Exception {
false,
SHA1);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(SHA1)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(SHA1), eq(PHOTO_TITLE)))
.thenThrow(new UploadErrorException("Hash mismatch will be thrown", new Throwable()));
BatchMediaItemResponse batchMediaItemResponse = new BatchMediaItemResponse(
new NewMediaItemResult[]{});
Expand Down Expand Up @@ -328,7 +329,7 @@ public void importPhotoInTempStore() throws Exception {
OLD_ALBUM_ID,
true);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null))).thenReturn("token1");
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE))).thenReturn("token1");
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any()))
.thenReturn(
Expand Down Expand Up @@ -369,7 +370,7 @@ public void importPhotoInTempStoreFailure() throws Exception {
OLD_ALBUM_ID,
true);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE)))
.thenThrow(new IOException("Unit Testing"));
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any()))
Expand Down Expand Up @@ -410,7 +411,7 @@ public void importPhotoFailedToFindAlbum() throws Exception {
OLD_ALBUM_ID,
true);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE)))
.thenReturn("token1", "token2");
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any()))
Expand Down Expand Up @@ -445,7 +446,7 @@ public void importPhotoCreatePhotosOtherException() throws Exception {
OLD_ALBUM_ID,
true);

Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null)))
Mockito.when(googlePhotosInterface.uploadPhotoContent(any(), eq(null), eq(PHOTO_TITLE)))
.thenReturn("token1", "token2");
JobStore jobStore = Mockito.mock(LocalJobStore.class);
Mockito.when(jobStore.getStream(any(), any()))
Expand Down