use of org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter 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;
}
Aggregations