use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class RememberTheMilkTasksImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, AuthData authData, TaskContainerResource data) {
String timeline;
try {
RememberTheMilkService service = getOrCreateService(authData);
timeline = service.createTimeline();
for (TaskListModel taskList : data.getLists()) {
idempotentExecutor.executeAndSwallowIOExceptions(taskList.getId(), taskList.getName(), () -> service.createTaskList(taskList.getName(), timeline).id);
}
for (TaskModel task : data.getTasks()) {
// Empty or blank tasks aren't valid in RTM
if (!Strings.isNullOrEmpty(task.getText())) {
idempotentExecutor.executeAndSwallowIOExceptions(Integer.toString(task.hashCode()), task.getText(), () -> {
String newList = idempotentExecutor.getCachedValue(task.getTaskListId());
return insertTask(task, newList, timeline);
});
}
}
} catch (Exception e) {
monitor.severe(() -> "Error importing item", e);
return new ImportResult(e);
}
return new ImportResult(ImportResult.ResultType.OK);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class GoogleContactsImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, TokensAndUrlAuthData authData, ContactsModelWrapper data) throws Exception {
JCardReader reader = new JCardReader(data.getVCards());
try {
// TODO(olsona): address any other problems that might arise in conversion
List<VCard> vCardList = reader.readAll();
PeopleService.People peopleService = getOrCreatePeopleService(authData).people();
for (VCard vCard : vCardList) {
Person person = convert(vCard);
idempotentExecutor.executeAndSwallowIOExceptions(vCard.toString(), vCard.getFormattedName().toString(), () -> peopleService.createContact(person).execute().toPrettyString());
}
return ImportResult.OK;
} catch (IOException e) {
return new ImportResult(e);
}
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class GoogleBloggerImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, TokensAndUrlAuthData authData, SocialActivityContainerResource data) throws Exception {
Blogger blogger = getOrCreateBloggerService(authData);
BlogList blogList = blogger.blogs().listByUser("self").execute();
// NB: we are just publishing everything to the first blog, which is a bit of a hack,
// but there is no API to create a new blog.
String blogId = blogList.getItems().get(0).getId();
for (SocialActivityModel activity : data.getActivities()) {
if (activity.getType() == SocialActivityType.NOTE || activity.getType() == SocialActivityType.POST) {
try {
insertActivity(idempotentExecutor, data.getActor(), activity, blogId, authData);
} catch (IOException | RuntimeException e) {
throw new IOException("Couldn't import: " + activity, e);
}
}
}
return new ImportResult(ResultType.OK);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class BackblazeVideosImporterTest method testNullData.
@Test
public void testNullData() throws Exception {
BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, null);
assertEquals(ImportResult.OK, result);
}
use of org.datatransferproject.spi.transfer.provider.ImportResult in project data-transfer-project by google.
the class BackblazeVideosImporterTest method testEmptyVideos.
@Test
public void testEmptyVideos() throws Exception {
VideosContainerResource data = mock(VideosContainerResource.class);
when(data.getVideos()).thenReturn(new ArrayList<>());
BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
assertEquals(ImportResult.OK, result);
}
Aggregations