Search in sources :

Example 1 with TransferJob

use of org.datatransferproject.types.client.transfer.TransferJob in project data-transfer-project by google.

the class StartTransferJobAction method handle.

@Override
public TransferJob handle(StartTransferJob startTransferJob) {
    String id = startTransferJob.getId();
    Preconditions.checkNotNull(id, "transfer job ID required for StartTransferJobAction");
    UUID jobId = decodeJobId(id);
    PortabilityJob job = jobStore.findJob(jobId);
    String authData = startTransferJob.getEncryptedAuthData();
    job = updateJobWithCredentials(jobId, job, authData);
    return new TransferJob(id, job.exportService(), job.importService(), job.transferDataType(), null, null, null, null, null, null);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) UUID(java.util.UUID) TransferJob(org.datatransferproject.types.client.transfer.TransferJob) StartTransferJob(org.datatransferproject.types.client.transfer.StartTransferJob)

Example 2 with TransferJob

use of org.datatransferproject.types.client.transfer.TransferJob 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);
    }
}
Also used : AuthFlowConfiguration(org.datatransferproject.spi.api.types.AuthFlowConfiguration) ExportInformation(org.datatransferproject.types.common.ExportInformation) PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) AuthDataGenerator(org.datatransferproject.spi.api.auth.AuthDataGenerator) SecretKey(javax.crypto.SecretKey) IOException(java.io.IOException) UUID(java.util.UUID) TransferJob(org.datatransferproject.types.client.transfer.TransferJob) CreateTransferJob(org.datatransferproject.types.client.transfer.CreateTransferJob)

Example 3 with TransferJob

use of org.datatransferproject.types.client.transfer.TransferJob in project data-transfer-project by google.

the class GetTransferJobAction method handle.

@Override
public TransferJob handle(GetTransferJob transferRequest) {
    String id = transferRequest.getId();
    Preconditions.checkNotNull(id, "transfer job ID required for GetTransferJobAction");
    UUID jobId = decodeJobId(id);
    PortabilityJob job = jobStore.findJob(jobId);
    monitor.debug(() -> format("Fetched job with jobId: %s", jobId), jobId, EventCode.API_GOT_TRANSFER_JOB);
    // TODO(#553): This list of nulls should be cleaned up when we refactor TransferJob.
    return new TransferJob(id, job.exportService(), job.importService(), job.transferDataType(), null, null, null, null, null, null);
}
Also used : PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) UUID(java.util.UUID) TransferJob(org.datatransferproject.types.client.transfer.TransferJob) GetTransferJob(org.datatransferproject.types.client.transfer.GetTransferJob)

Aggregations

UUID (java.util.UUID)3 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)3 TransferJob (org.datatransferproject.types.client.transfer.TransferJob)3 IOException (java.io.IOException)1 SecretKey (javax.crypto.SecretKey)1 AuthDataGenerator (org.datatransferproject.spi.api.auth.AuthDataGenerator)1 AuthFlowConfiguration (org.datatransferproject.spi.api.types.AuthFlowConfiguration)1 CreateTransferJob (org.datatransferproject.types.client.transfer.CreateTransferJob)1 GetTransferJob (org.datatransferproject.types.client.transfer.GetTransferJob)1 StartTransferJob (org.datatransferproject.types.client.transfer.StartTransferJob)1 ExportInformation (org.datatransferproject.types.common.ExportInformation)1