Search in sources :

Example 1 with GoogleBloggerImporter

use of org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter 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)

Aggregations

HttpTransport (com.google.api.client.http.HttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Monitor (org.datatransferproject.api.launcher.Monitor)1 GoogleBloggerImporter (org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter)1 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)1 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)1 Importer (org.datatransferproject.spi.transfer.provider.Importer)1 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)1