Search in sources :

Example 26 with ImportResult

use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.

the class GooglePhotosImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, PhotosContainerResource data) throws Exception {
    if (data == null) {
        // Nothing to do
        return ImportResult.OK;
    }
    // Uploads album metadata
    if (data.getAlbums() != null && data.getAlbums().size() > 0) {
        for (PhotoAlbum album : data.getAlbums()) {
            idempotentImportExecutor.executeAndSwallowIOExceptions(album.getId(), album.getName(), () -> importSingleAlbum(jobId, authData, album));
        }
    }
    long bytes = importPhotos(data.getPhotos(), idempotentImportExecutor, jobId, authData);
    final ImportResult result = ImportResult.OK;
    return result.copyWithBytes(bytes);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum)

Example 27 with ImportResult

use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.

the class GoogleTasksImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, TaskContainerResource data) throws Exception {
    Tasks tasksService = getOrCreateTasksService(authData);
    for (TaskListModel oldTasksList : data.getLists()) {
        TaskList newTaskList = new TaskList().setTitle("Imported copy - " + oldTasksList.getName());
        idempotentImportExecutor.executeAndSwallowIOExceptions(oldTasksList.getId(), oldTasksList.getName(), () -> tasksService.tasklists().insert(newTaskList).execute().getId());
    }
    for (TaskModel oldTask : data.getTasks()) {
        Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
        if (oldTask.getCompletedTime() != null) {
            newTask.setCompleted(new DateTime(oldTask.getCompletedTime().toEpochMilli()));
        }
        if (oldTask.getDueTime() != null) {
            newTask.setDue(new DateTime(oldTask.getDueTime().toEpochMilli()));
        }
        // If its not cached that means the task list create failed.
        if (idempotentImportExecutor.isKeyCached(oldTask.getTaskListId())) {
            String newTaskListId = idempotentImportExecutor.getCachedValue(oldTask.getTaskListId());
            idempotentImportExecutor.executeAndSwallowIOExceptions(oldTask.getTaskListId() + oldTask.getText(), oldTask.getText(), () -> tasksService.tasks().insert(newTaskListId, newTask).execute().getId());
        }
    }
    return new ImportResult(ResultType.OK);
}
Also used : Task(com.google.api.services.tasks.model.Task) Tasks(com.google.api.services.tasks.Tasks) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TaskList(com.google.api.services.tasks.model.TaskList) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) DateTime(com.google.api.client.util.DateTime)

Aggregations

ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)27 Test (org.junit.Test)14 IOException (java.io.IOException)11 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)8 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)6 UUID (java.util.UUID)5 Map (java.util.Map)4 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 List (java.util.List)3 Request (okhttp3.Request)3 Response (okhttp3.Response)3 ResponseBody (okhttp3.ResponseBody)3 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)3 Stopwatch (com.google.common.base.Stopwatch)2 LinkedHashMap (java.util.LinkedHashMap)2 Call (okhttp3.Call)2 Importer (org.datatransferproject.spi.transfer.provider.Importer)2 ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)2 TaskListModel (org.datatransferproject.types.common.models.tasks.TaskListModel)2