Search in sources :

Example 1 with GoogleCredentialFactory

use of org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory in project data-transfer-project by google.

the class BloggerTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized) {
        return;
    }
    Monitor monitor = context.getMonitor();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLEBLOGGER_KEY", "GOOGLEBLOGGER_SECRET");
    } catch (IOException e) {
        monitor.info(() -> "Unable to retrieve Google AppCredentials. " + "Did you set GOOGLEBLOGGER_KEY and GOOGLEBLOGGER_SECRET?");
        return;
    }
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("SOCIAL-POSTS", new GoogleBloggerImporter(credentialFactory));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) JsonFactory(com.google.api.client.json.JsonFactory) IOException(java.io.IOException) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) Monitor(org.datatransferproject.api.launcher.Monitor) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 2 with GoogleCredentialFactory

use of org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory in project data-transfer-project by google.

the class GooglePhotosExporterTest method setup.

@Before
public void setup() throws IOException, InvalidTokenException, PermissionDeniedException {
    GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
    jobStore = mock(TemporaryPerJobDataStore.class);
    when(jobStore.getStream(any(), anyString())).thenReturn(mock(InputStreamWrapper.class));
    photosInterface = mock(GooglePhotosInterface.class);
    albumListResponse = mock(AlbumListResponse.class);
    mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
    Monitor monitor = mock(Monitor.class);
    googlePhotosExporter = new GooglePhotosExporter(credentialFactory, jobStore, new JacksonFactory(), photosInterface, monitor);
    when(photosInterface.listAlbums(any(Optional.class))).thenReturn(albumListResponse);
    when(photosInterface.listMediaItems(any(Optional.class), any(Optional.class))).thenReturn(mediaItemSearchResponse);
    verifyNoInteractions(credentialFactory);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) Monitor(org.datatransferproject.api.launcher.Monitor) Optional(java.util.Optional) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Before(org.junit.Before)

Example 3 with GoogleCredentialFactory

use of org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory in project data-transfer-project by google.

the class GoogleVideosExporterTest method setup.

@Before
public void setup() throws IOException {
    GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
    jobStore = mock(TemporaryPerJobDataStore.class);
    videosInterface = mock(GoogleVideosInterface.class);
    albumListResponse = mock(AlbumListResponse.class);
    mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
    googleVideosExporter = new GoogleVideosExporter(credentialFactory, videosInterface);
    when(videosInterface.listVideoItems(any(Optional.class))).thenReturn(mediaItemSearchResponse);
    verifyNoInteractions(credentialFactory);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) Optional(java.util.Optional) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Before(org.junit.Before)

Example 4 with GoogleCredentialFactory

use of org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory in project data-transfer-project by google.

the class GoogleTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLE_KEY", "GOOGLE_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Google AppCredentials. Did you set GOOGLE_KEY and GOOGLE_SECRET?");
        return;
    }
    Monitor monitor = context.getMonitor();
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("BLOBS", new DriveImporter(credentialFactory, jobStore, monitor));
    importerBuilder.put("CONTACTS", new GoogleContactsImporter(credentialFactory));
    importerBuilder.put("CALENDAR", new GoogleCalendarImporter(credentialFactory));
    importerBuilder.put("MAIL", new GoogleMailImporter(credentialFactory, monitor));
    importerBuilder.put("TASKS", new GoogleTasksImporter(credentialFactory));
    importerBuilder.put("PHOTOS", new GooglePhotosImporter(credentialFactory, jobStore, jsonFactory, monitor, context.getSetting("googleWritesPerSecond", 1.0)));
    importerBuilder.put("VIDEOS", new GoogleVideosImporter(appCredentials, jobStore, monitor));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterBuilder.put("BLOBS", new DriveExporter(credentialFactory, jobStore, monitor));
    exporterBuilder.put("CONTACTS", new GoogleContactsExporter(credentialFactory));
    exporterBuilder.put("CALENDAR", new GoogleCalendarExporter(credentialFactory));
    exporterBuilder.put("MAIL", new GoogleMailExporter(credentialFactory));
    exporterBuilder.put("SOCIAL-POSTS", new GooglePlusExporter(credentialFactory));
    exporterBuilder.put("TASKS", new GoogleTasksExporter(credentialFactory, monitor));
    exporterBuilder.put("PHOTOS", new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor));
    exporterBuilder.put("VIDEOS", new GoogleVideosExporter(credentialFactory, jsonFactory));
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) JsonFactory(com.google.api.client.json.JsonFactory) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) Monitor(org.datatransferproject.api.launcher.Monitor) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) HttpTransport(com.google.api.client.http.HttpTransport) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter)

Aggregations

GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)4 Monitor (org.datatransferproject.api.launcher.Monitor)3 HttpTransport (com.google.api.client.http.HttpTransport)2 JsonFactory (com.google.api.client.json.JsonFactory)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Optional (java.util.Optional)2 AlbumListResponse (org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse)2 MediaItemSearchResponse (org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse)2 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)2 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)2 Importer (org.datatransferproject.spi.transfer.provider.Importer)2 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)2 Before (org.junit.Before)2 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 GoogleBloggerImporter (org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter)1 GoogleCalendarExporter (org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter)1 GoogleCalendarImporter (org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter)1 GoogleContactsExporter (org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter)1 GoogleContactsImporter (org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter)1