use of org.datatransferproject.types.common.models.videos.VideoAlbum 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;
}
use of org.datatransferproject.types.common.models.videos.VideoAlbum in project data-transfer-project by google.
the class KoofrVideosExporterTest method testExport.
@Test
public void testExport() throws Exception {
when(client.getRootPath()).thenReturn("/Data transfer");
when(client.listRecursive("/Data transfer")).thenReturn(Fixtures.listRecursiveItems);
when(client.fileLink("/Data transfer/Album 2 :heart:/Video 1.mp4")).thenReturn("https://app-1.koofr.net/content/files/get/Video+1.mp4?base=TESTBASE");
when(client.fileLink("/Data transfer/Videos/Video 2.mp4")).thenReturn("https://app-1.koofr.net/content/files/get/Video+2.mp4?base=TESTBASE");
UUID jobId = UUID.randomUUID();
ExportResult<VideosContainerResource> result = exporter.export(jobId, authData, Optional.empty());
assertEquals(ExportResult.ResultType.END, result.getType());
assertNull(result.getContinuationData());
VideosContainerResource exportedData = result.getExportedData();
List<VideoAlbum> expectedAlbums = ImmutableList.of(new VideoAlbum("/Album 2 :heart:", "Album 2 ❤️", "Album 2 description ❤️"), new VideoAlbum("/Videos", "Videos", null));
assertEquals(expectedAlbums, exportedData.getAlbums());
List<VideoModel> expectedVideos = ImmutableList.of(new VideoModel("Video 1.mp4", "https://app-1.koofr.net/content/files/get/Video+1.mp4?base=TESTBASE", null, "video/mp4", "/Album 2 :heart:/Video 1.mp4", "/Album 2 :heart:", false), new VideoModel("Video 2.mp4", "https://app-1.koofr.net/content/files/get/Video+2.mp4?base=TESTBASE", "Video 3 description", "video/mp4", "/Videos/Video 2.mp4", "/Videos", false));
assertEquals(expectedVideos, exportedData.getVideos());
}
use of org.datatransferproject.types.common.models.videos.VideoAlbum in project data-transfer-project by google.
the class KoofrVideosImporterTest method testImportItemFromURLWithAlbum.
@Test
public void testImportItemFromURLWithAlbum() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("123"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("4567"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("89"));
when(client.ensureRootFolder()).thenReturn("/root");
when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
when(executor.getCachedValue(eq("id2"))).thenReturn("/root/Album");
when(client.fileExists("/root/Album 1/video1.mp4")).thenReturn(false);
when(client.fileExists("/root/Album 1/video2.mp4")).thenReturn(true);
when(client.fileExists("/root/Album/video3.mp4")).thenReturn(false);
String description1000 = new String(new char[1000]).replace("\0", "a");
String description1001 = new String(new char[1001]).replace("\0", "a");
UUID jobId = UUID.randomUUID();
Collection<VideoAlbum> albums = ImmutableList.of(new VideoAlbum("id1", "Album 1", "This is a fake album"), new VideoAlbum("id2", "", description1001));
Collection<VideoModel> videos = ImmutableList.of(new VideoModel("video1.mp4", server.url("/1.mp4").toString(), "A video 1", "video/mp4", "video1", "id1", false), new VideoModel("video2.mp4", server.url("/2.mp4").toString(), "A video 2", "video/mp4", "video2", "id1", false), new VideoModel("video3.mp4", server.url("/3.mp4").toString(), description1001, "video/mp4", "video3", "id2", false));
VideosContainerResource resource = spy(new VideosContainerResource(albums, videos));
importer.importItem(jobId, executor, authData, resource);
InOrder clientInOrder = Mockito.inOrder(client);
clientInOrder.verify(client).ensureRootFolder();
clientInOrder.verify(client).ensureFolder("/root", "Album 1");
clientInOrder.verify(client).addDescription("/root/Album 1", "This is a fake album");
clientInOrder.verify(client).ensureFolder("/root", "Album");
clientInOrder.verify(client).addDescription("/root/Album", description1000);
clientInOrder.verify(client).fileExists(eq("/root/Album 1/video1.mp4"));
clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("video1.mp4"), any(), eq("video/mp4"), isNull(), eq("A video 1"));
clientInOrder.verify(client).fileExists(eq("/root/Album 1/video2.mp4"));
clientInOrder.verify(client).fileExists(eq("/root/Album/video3.mp4"));
clientInOrder.verify(client).uploadFile(eq("/root/Album"), eq("video3.mp4"), any(), eq("video/mp4"), isNull(), eq(description1000));
clientInOrder.verifyNoMoreInteractions();
}
use of org.datatransferproject.types.common.models.videos.VideoAlbum in project data-transfer-project by google.
the class KoofrVideosImporterTest method testImportItemFromURLWithoutAlbum.
@Test
public void testImportItemFromURLWithoutAlbum() throws Exception {
server.enqueue(new MockResponse().setResponseCode(200).setBody("123"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("4567"));
when(client.ensureVideosFolder()).thenReturn("/root/Videos");
UUID jobId = UUID.randomUUID();
Collection<VideoAlbum> albums = ImmutableList.of();
Collection<VideoModel> videos = ImmutableList.of(new VideoModel("video1.mp4", server.url("/1.mp4").toString(), "A video 1", "video/mp4", "video1", null, false), new VideoModel("video2.mp4", server.url("/2.mp4").toString(), "A video 2", "video/mp4", "video2", null, false));
VideosContainerResource resource = spy(new VideosContainerResource(albums, videos));
importer.importItem(jobId, executor, authData, resource);
InOrder clientInOrder = Mockito.inOrder(client);
clientInOrder.verify(client).ensureVideosFolder();
clientInOrder.verify(client).fileExists(eq("/root/Videos/video1.mp4"));
clientInOrder.verify(client).uploadFile(eq("/root/Videos"), eq("video1.mp4"), any(), eq("video/mp4"), isNull(), eq("A video 1"));
clientInOrder.verify(client).fileExists(eq("/root/Videos/video2.mp4"));
clientInOrder.verify(client).uploadFile(eq("/root/Videos"), eq("video2.mp4"), any(), eq("video/mp4"), isNull(), eq("A video 2"));
clientInOrder.verifyNoMoreInteractions();
}
use of org.datatransferproject.types.common.models.videos.VideoAlbum in project data-transfer-project by google.
the class KoofrVideosImporterTest method testSkipNotFoundVideo.
@Test
public void testSkipNotFoundVideo() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404).setBody("4567"));
UUID jobId = UUID.randomUUID();
Collection<VideoAlbum> albums = ImmutableList.of();
Collection<VideoModel> videos = ImmutableList.of(new VideoModel("not_found_video_1.mp4", server.url("/not_found.mp4").toString(), "Video not founded in CDN", "video/mp4", "not_found_video_1", null, false));
VideosContainerResource resource = spy(new VideosContainerResource(albums, videos));
importer.importItem(jobId, executor, authData, resource);
InOrder clientInOrder = Mockito.inOrder(client);
clientInOrder.verifyNoMoreInteractions();
}
Aggregations