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