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