Search in sources :

Example 1 with KoofrVideosImporter

use of org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter in project data-transfer-project by google.

the class KoofrTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // rather than throwing if called multiple times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    OkHttpClient client = new OkHttpClient.Builder().build();
    ObjectMapper mapper = new ObjectMapper();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("KOOFR_KEY", "KOOFR_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Koofr AppCredentials. Did you set KOOFR_KEY and KOOFR_SECRET?");
        return;
    }
    // Create the KoofrCredentialFactory with the given {@link AppCredentials}.
    KoofrCredentialFactory credentialFactory = new KoofrCredentialFactory(httpTransport, jsonFactory, appCredentials);
    Monitor monitor = context.getMonitor();
    int fileUploadReadTimeout = context.getSetting("koofrFileUploadReadTimeout", 60000);
    int fileUploadWriteTimeout = context.getSetting("koofrFileUploadWriteTimeout", 60000);
    monitor.info(() -> format("Configuring Koofr HTTP file upload client with read timeout %d ms and write timeout %d ms", fileUploadReadTimeout, fileUploadWriteTimeout));
    OkHttpClient fileUploadClient = client.newBuilder().readTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).writeTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).build();
    KoofrClientFactory koofrClientFactory = new KoofrClientFactory(BASE_API_URL, client, fileUploadClient, mapper, monitor, credentialFactory);
    ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
    importBuilder.put(PHOTOS, new KoofrPhotosImporter(koofrClientFactory, monitor, jobStore));
    importBuilder.put(VIDEOS, new KoofrVideosImporter(koofrClientFactory, monitor));
    importerMap = importBuilder.build();
    ImmutableMap.Builder<String, Exporter> exportBuilder = ImmutableMap.builder();
    exportBuilder.put(PHOTOS, new KoofrPhotosExporter(koofrClientFactory, monitor));
    exportBuilder.put(VIDEOS, new KoofrVideosExporter(koofrClientFactory, monitor));
    exporterMap = exportBuilder.build();
    initialized = true;
}
Also used : KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) OkHttpClient(okhttp3.OkHttpClient) KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) KoofrCredentialFactory(org.datatransferproject.transfer.koofr.common.KoofrCredentialFactory) JsonFactory(com.google.api.client.json.JsonFactory) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) IOException(java.io.IOException) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter) Monitor(org.datatransferproject.api.launcher.Monitor) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 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 OkHttpClient (okhttp3.OkHttpClient)1 Monitor (org.datatransferproject.api.launcher.Monitor)1 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)1 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)1 Importer (org.datatransferproject.spi.transfer.provider.Importer)1 KoofrClientFactory (org.datatransferproject.transfer.koofr.common.KoofrClientFactory)1 KoofrCredentialFactory (org.datatransferproject.transfer.koofr.common.KoofrCredentialFactory)1 KoofrPhotosExporter (org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter)1 KoofrPhotosImporter (org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter)1 KoofrVideosExporter (org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter)1 KoofrVideosImporter (org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter)1 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)1