use of com.amazonaws.services.pinpoint.model.GetImportJobResult in project aws-doc-sdk-examples by awsdocs.
the class ImportEndpoints method importToPinpoint.
private static void importToPinpoint(String endpointsFileName, String s3BucketName, String iamImportRoleArn, String applicationId) {
// The S3 URL that Amazon Pinpoint requires to find the endpoints file.
String s3Url = "s3://" + s3BucketName + "/imports/" + endpointsFileName;
// Defines the import job that Amazon Pinpoint runs.
ImportJobRequest importJobRequest = new ImportJobRequest().withS3Url(s3Url).withRegisterEndpoints(true).withRoleArn(iamImportRoleArn).withFormat(Format.JSON);
CreateImportJobRequest createImportJobRequest = new CreateImportJobRequest().withApplicationId(applicationId).withImportJobRequest(importJobRequest);
// Initializes the Amazon Pinpoint client.
AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
System.out.format("Importing endpoints in %s to Amazon Pinpoint application %s . . .\n", endpointsFileName, applicationId);
try {
// Runs the import job with Amazon Pinpoint.
CreateImportJobResult importResult = pinpointClient.createImportJob(createImportJobRequest);
String jobId = importResult.getImportJobResponse().getId();
GetImportJobResult getImportJobResult = null;
String jobStatus = null;
// Checks the job status until the job completes or fails.
do {
getImportJobResult = pinpointClient.getImportJob(new GetImportJobRequest().withJobId(jobId).withApplicationId(applicationId));
jobStatus = getImportJobResult.getImportJobResponse().getJobStatus();
System.out.format("Import job %s . . .\n", jobStatus.toLowerCase());
TimeUnit.SECONDS.sleep(3);
} while (!jobStatus.equals("COMPLETED") && !jobStatus.equals("FAILED"));
if (jobStatus.equals("COMPLETED")) {
System.out.println("Finished importing endpoints.");
} else {
System.err.println("Failed to import endpoints.");
System.exit(1);
}
// Checks for entries that failed to import.
// getFailures provides up to 100 of the first failed entries for the job, if any exist.
List<String> failedEndpoints = getImportJobResult.getImportJobResponse().getFailures();
if (failedEndpoints != null) {
System.out.println("Failed to import the following entries:");
for (String failedEndpoint : failedEndpoints) {
System.out.println(failedEndpoint);
}
}
} catch (AmazonServiceException | InterruptedException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
Aggregations