Skip to content

Commit

Permalink
If temp data exists in the FlickrImporter, don't try to create it aga…
Browse files Browse the repository at this point in the history
…in (#790)

* fix typo in flickr extension

* Add check if temp data exists (because the job was restarted) to not create the tmep data again
  • Loading branch information
seehamrun authored Nov 19, 2019
1 parent 5aed2b9 commit bbc38c8
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.RateLimiter;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collection;
import java.util.UUID;
import org.datatransferproject.api.launcher.Monitor;
import org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore;
import org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor;
Expand All @@ -42,13 +48,6 @@
import org.datatransferproject.types.transfer.auth.AuthData;
import org.datatransferproject.types.transfer.serviceconfig.TransferServiceConfig;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Collection;
import java.util.UUID;

public class FlickrPhotosImporter implements Importer<AuthData, PhotosContainerResource> {

@VisibleForTesting
Expand Down Expand Up @@ -114,7 +113,7 @@ public ImportResult importItem(
data.getAlbums() != null || data.getPhotos() != null, "Error: There is no data to import");

if (data.getAlbums() != null) {
storeAlbumbs(jobId, data.getAlbums());
storeAlbums(jobId, data.getAlbums());
}

if (data.getPhotos() != null) {
Expand All @@ -135,11 +134,19 @@ public ImportResult importItem(

// Store any album data in the cache because Flickr only allows you to create an album with a
// photo in it, so we have to wait for the first photo to create the album
private void storeAlbumbs(UUID jobId, Collection<PhotoAlbum> albums) throws IOException {
private void storeAlbums(UUID jobId, Collection<PhotoAlbum> albums) throws IOException {
for (PhotoAlbum album : albums) {
jobStore.create(jobId,
FlickrTempPhotoData temp =
jobStore.findData(
jobId,
ORIGINAL_ALBUM_PREFIX + album.getId(),
new FlickrTempPhotoData(album.getName(), album.getDescription()));
FlickrTempPhotoData.class);

if (temp == null) {
jobStore.create(jobId,
ORIGINAL_ALBUM_PREFIX + album.getId(),
new FlickrTempPhotoData(album.getName(), album.getDescription()));
}
}
}

Expand Down

0 comments on commit bbc38c8

Please sign in to comment.