Search in sources :

Example 1 with KoofrClient

use of org.datatransferproject.transfer.koofr.common.KoofrClient in project data-transfer-project by google.

the class KoofrPhotosImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, PhotosContainerResource resource) throws Exception {
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    monitor.debug(() -> String.format("%s: Importing %s albums and %s photos before transmogrification", jobId, resource.getAlbums().size(), resource.getPhotos().size()));
    // Make the data Koofr compatible
    resource.transmogrify(transmogrificationConfig);
    monitor.debug(() -> String.format("%s: Importing %s albums and %s photos after transmogrification", jobId, resource.getAlbums().size(), resource.getPhotos().size()));
    for (PhotoAlbum album : resource.getAlbums()) {
        // Create a Koofr folder and then save the id with the mapping data
        idempotentImportExecutor.executeAndSwallowIOExceptions(album.getId(), album.getName(), () -> createAlbumFolder(album, koofrClient));
    }
    for (PhotoModel photoModel : resource.getPhotos()) {
        idempotentImportExecutor.executeAndSwallowIOExceptions(IdempotentImportExecutorHelper.getPhotoIdempotentId(photoModel), photoModel.getTitle(), () -> importSinglePhoto(photoModel, jobId, idempotentImportExecutor, koofrClient));
    }
    return ImportResult.OK;
}
Also used : PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum)

Example 2 with KoofrClient

use of org.datatransferproject.transfer.koofr.common.KoofrClient in project data-transfer-project by google.

the class KoofrVideosImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, VideosContainerResource resource) throws Exception {
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    monitor.debug(() -> String.format("%s: Importing %s albums and %s videos", jobId, resource.getAlbums().size(), resource.getVideos().size()));
    for (VideoAlbum album : resource.getAlbums()) {
        // Create a Koofr folder and then save the id with the mapping data
        idempotentImportExecutor.executeAndSwallowIOExceptions(album.getId(), album.getName(), () -> createAlbumFolder(album, koofrClient));
    }
    for (VideoModel videoModel : resource.getVideos()) {
        String id;
        if (videoModel.getAlbumId() == null) {
            id = videoModel.getDataId();
        } else {
            id = videoModel.getAlbumId() + "-" + videoModel.getDataId();
        }
        idempotentImportExecutor.executeAndSwallowIOExceptions(id, videoModel.getName(), () -> importSingleVideo(videoModel, jobId, idempotentImportExecutor, koofrClient));
    }
    return ImportResult.OK;
}
Also used : KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) VideoAlbum(org.datatransferproject.types.common.models.videos.VideoAlbum) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel)

Example 3 with KoofrClient

use of org.datatransferproject.transfer.koofr.common.KoofrClient in project data-transfer-project by google.

the class KoofrPhotosExporter method export.

@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws CopyExceptionWithFailureReason {
    Preconditions.checkNotNull(authData);
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    KoofrMediaExport export = new KoofrMediaExport(koofrClient, monitor);
    try {
        export.export();
        List<PhotoAlbum> exportAlbums = export.getPhotoAlbums();
        List<PhotoModel> exportPhotos = export.getPhotos();
        PhotosContainerResource containerResource = new PhotosContainerResource(exportAlbums, exportPhotos);
        return new ExportResult<>(ExportResult.ResultType.END, containerResource, null);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) IOException(java.io.IOException) KoofrMediaExport(org.datatransferproject.transfer.koofr.common.KoofrMediaExport) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 4 with KoofrClient

use of org.datatransferproject.transfer.koofr.common.KoofrClient in project data-transfer-project by google.

the class KoofrVideosExporter method export.

@Override
public ExportResult<VideosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws CopyExceptionWithFailureReason {
    Preconditions.checkNotNull(authData);
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    KoofrMediaExport export = new KoofrMediaExport(koofrClient, monitor);
    try {
        export.export();
        List<VideoAlbum> exportAlbums = export.getVideoAlbums();
        List<VideoModel> exportVideos = export.getVideos();
        VideosContainerResource containerResource = new VideosContainerResource(exportAlbums, exportVideos);
        return new ExportResult<>(ExportResult.ResultType.END, containerResource, null);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
}
Also used : VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) IOException(java.io.IOException) VideoAlbum(org.datatransferproject.types.common.models.videos.VideoAlbum) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) KoofrMediaExport(org.datatransferproject.transfer.koofr.common.KoofrMediaExport) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

KoofrClient (org.datatransferproject.transfer.koofr.common.KoofrClient)4 IOException (java.io.IOException)2 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)2 KoofrMediaExport (org.datatransferproject.transfer.koofr.common.KoofrMediaExport)2 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)2 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)2 VideoAlbum (org.datatransferproject.types.common.models.videos.VideoAlbum)2 VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)2 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)1 VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)1