Search in sources :

Example 21 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) IOException(java.io.IOException)

Example 22 with ImportResult

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);
    }
}
Also used : PeopleService(com.google.api.services.people.v1.PeopleService) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) IOException(java.io.IOException) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person)

Example 23 with ImportResult

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);
}
Also used : Blogger(com.google.api.services.blogger.Blogger) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) BlogList(com.google.api.services.blogger.model.BlogList) SocialActivityModel(org.datatransferproject.types.common.models.social.SocialActivityModel) IOException(java.io.IOException)

Example 24 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) Test(org.junit.Test)

Example 25 with ImportResult

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) Test(org.junit.Test)

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