Search in sources :

Example 1 with SmugMugResponse

use of org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugResponse in project data-transfer-project by google.

the class SmugMugPhotosImporter method importSingleAlbum.

@VisibleForTesting
void importSingleAlbum(UUID jobId, String folder, PhotoAlbum inputAlbum) throws IOException {
    // Set up album
    Map<String, String> json = new HashMap<>();
    String niceName = "Copy-" + inputAlbum.getName().replace(' ', '-');
    json.put("UrlName", niceName);
    // Allow conflicting names to be changed
    json.put("AutoRename", "true");
    json.put("Name", "Copy of " + inputAlbum.getName());
    // All imported content is private by default.
    json.put("Privacy", "Private");
    HttpContent content = new JsonHttpContent(new JacksonFactory(), json);
    // Upload album
    SmugMugResponse<SmugMugAlbumResponse> response = smugMugInterface.postRequest(folder + "!albums", content, ImmutableMap.of(), new TypeReference<SmugMugResponse<SmugMugAlbumResponse>>() {
    });
    checkState(response.getResponse() != null, "Response is null");
    checkState(response.getResponse().getAlbum() != null, "Album is null");
    // Put new album ID in job store so photos can be assigned to correct album
    // TODO(olsona): thread safety!
    TempPhotosData tempPhotosData = jobStore.findData(TempPhotosData.class, jobId);
    if (tempPhotosData == null) {
        tempPhotosData = new TempPhotosData(jobId);
        jobStore.create(jobId, tempPhotosData);
    }
    tempPhotosData.addAlbumId(inputAlbum.getId(), response.getResponse().getAlbum().getAlbumKey());
}
Also used : TempPhotosData(org.dataportabilityproject.spi.transfer.types.TempPhotosData) HashMap(java.util.HashMap) SmugMugResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugResponse) SmugMugAlbumResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumResponse) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) HttpContent(com.google.api.client.http.HttpContent) JsonHttpContent(com.google.api.client.http.json.JsonHttpContent) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HttpContent (com.google.api.client.http.HttpContent)1 JsonHttpContent (com.google.api.client.http.json.JsonHttpContent)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 TempPhotosData (org.dataportabilityproject.spi.transfer.types.TempPhotosData)1 SmugMugAlbumResponse (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumResponse)1 SmugMugResponse (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugResponse)1