use of org.datatransferproject.types.client.transfer.CreateTransferJob in project data-transfer-project by google.
the class CreateTransferJobAction method handle.
@Override
public TransferJob handle(CreateTransferJob request) {
String dataType = request.getDataType();
String exportService = request.getExportService();
String importService = request.getImportService();
Optional<ExportInformation> exportInformation = Optional.ofNullable(request.getExportInformation());
String exportCallbackUrl = request.getExportCallbackUrl();
String importCallbackUrl = request.getImportCallbackUrl();
// Create a new job and persist
UUID jobId = UUID.randomUUID();
SecretKey sessionKey = symmetricKeyGenerator.generate();
String encodedSessionKey = BaseEncoding.base64Url().encode(sessionKey.getEncoded());
String encryptionScheme = request.getEncryptionScheme();
PortabilityJob job;
try {
job = createJob(encodedSessionKey, dataType, exportService, importService, exportInformation, encryptionScheme);
} catch (IOException e) {
throw new RuntimeException(e);
}
AuthDataGenerator exportGenerator = registry.getAuthDataGenerator(job.exportService(), job.transferDataType(), EXPORT);
Preconditions.checkNotNull(exportGenerator, "Generator not found for type: %s, service: %s", job.transferDataType(), job.exportService());
AuthDataGenerator importGenerator = registry.getAuthDataGenerator(job.importService(), job.transferDataType(), IMPORT);
Preconditions.checkNotNull(importGenerator, "Generator not found for type: %s, service: %s", job.transferDataType(), job.importService());
try {
String encodedJobId = encodeJobId(jobId);
AuthFlowConfiguration exportConfiguration = exportGenerator.generateConfiguration(exportCallbackUrl, encodedJobId);
AuthFlowConfiguration importConfiguration = importGenerator.generateConfiguration(importCallbackUrl, encodedJobId);
job = setInitialAuthDataOnJob(sessionKey, job, exportConfiguration, importConfiguration);
jobStore.createJob(jobId, job);
monitor.debug(() -> format("Created new transfer of type '%s' from '%s' to '%s' with jobId: %s", dataType, exportService, importService, jobId), jobId, EventCode.API_JOB_CREATED);
return new TransferJob(encodedJobId, job.exportService(), job.importService(), job.transferDataType(), exportConfiguration.getAuthUrl(), importConfiguration.getAuthUrl(), exportConfiguration.getTokenUrl(), importConfiguration.getTokenUrl(), exportConfiguration.getAuthProtocol(), importConfiguration.getAuthProtocol());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations