@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));
    }

    final LongAdder totalImportedFilesSizes = new LongAdder();
    for (PhotoModel photoModel : resource.getPhotos()) {
      idempotentImportExecutor.importAndSwallowIOExceptions(
          photoModel,
          photo -> {
            ItemImportResult<String> fileImportResult =
                importSinglePhoto(photoModel, jobId, idempotentImportExecutor, koofrClient);
            if (fileImportResult != null && fileImportResult.hasBytes()) {
              totalImportedFilesSizes.add(fileImportResult.getBytes());
            }
            return fileImportResult;
          });
    }
    return ImportResult.OK.copyWithBytes(totalImportedFilesSizes.longValue());
  }
@Test
  public void testImportItemFromJobStore() throws Exception {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] {0, 1, 2, 3, 4});
    when(client.ensureRootFolder()).thenReturn("/root");
    when(jobStore.getStream(any(), any())).thenReturn(new InputStreamWrapper(inputStream, 5L));
    doNothing().when(jobStore).removeData(any(), anyString());
    when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");

    UUID jobId = UUID.randomUUID();

    Collection<PhotoAlbum> albums =
        ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"));

    Collection<PhotoModel> photos =
        ImmutableList.of(
            new PhotoModel(
                "pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true),
            new PhotoModel(
                "pic2.png", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));

    PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos));

    importer.importItem(jobId, executor, authData, resource);

    InOrder clientInOrder = Mockito.inOrder(client);

    verify(resource).transmogrify(any(KoofrTransmogrificationConfig.class));
    clientInOrder.verify(client).ensureRootFolder();
    clientInOrder.verify(client).ensureFolder("/root", "Album 1");
    clientInOrder
        .verify(client)
        .uploadFile(
            eq("/root/Album 1"), eq("pic1.jpg"), any(), eq("image/jpeg"), isNull(), eq("A pic"));
    clientInOrder
        .verify(client)
        .uploadFile(
            eq("/root/Album 1"), eq("pic2.png"), any(), eq("image/png"), isNull(), eq("fine art"));
    verify(jobStore, Mockito.times(2)).removeData(any(), anyString());
  }