use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.
the class DeleteApp method deletePinApp.
// snippet-start:[pinpoint.java2.deleteapp.main]
public static void deletePinApp(PinpointClient pinpoint, String appId) {
try {
DeleteAppRequest appRequest = DeleteAppRequest.builder().applicationId(appId).build();
DeleteAppResponse result = pinpoint.deleteApp(appRequest);
String appName = result.applicationResponse().name();
System.out.println("Application " + appName + " has been deleted.");
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.
the class ExportEndpoints method exportEndpointsToS3.
public static List<String> exportEndpointsToS3(PinpointClient pinpoint, S3Client s3Client, String s3BucketName, String iamExportRoleArn, String applicationId) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH_mm:ss.SSS_z");
String endpointsKeyPrefix = "exports/" + applicationId + "_" + dateFormat.format(new Date());
String s3UrlPrefix = "s3://" + s3BucketName + "/" + endpointsKeyPrefix + "/";
List<String> objectKeys = new ArrayList<>();
String key = "";
try {
// Defines the export job that Amazon Pinpoint runs
ExportJobRequest jobRequest = ExportJobRequest.builder().roleArn(iamExportRoleArn).s3UrlPrefix(s3UrlPrefix).build();
CreateExportJobRequest exportJobRequest = CreateExportJobRequest.builder().applicationId(applicationId).exportJobRequest(jobRequest).build();
System.out.format("Exporting endpoints from Amazon Pinpoint application %s to Amazon S3 " + "bucket %s . . .\n", applicationId, s3BucketName);
CreateExportJobResponse exportResult = pinpoint.createExportJob(exportJobRequest);
String jobId = exportResult.exportJobResponse().id();
System.out.println(jobId);
printExportJobStatus(pinpoint, applicationId, jobId);
ListObjectsV2Request v2Request = ListObjectsV2Request.builder().bucket(s3BucketName).prefix(endpointsKeyPrefix).build();
// Create a list of object keys
ListObjectsV2Response v2Response = s3Client.listObjectsV2(v2Request);
List<S3Object> objects = v2Response.contents();
for (S3Object object : objects) {
key = object.key();
objectKeys.add(key);
}
return objectKeys;
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.
the class ImportSegment method createImportSegment.
// snippet-start:[pinpoint.java2.importsegment.main]
public static ImportJobResponse createImportSegment(PinpointClient client, String appId, String bucket, String key, String roleArn) {
try {
ImportJobRequest importRequest = ImportJobRequest.builder().defineSegment(true).registerEndpoints(true).roleArn(roleArn).format(Format.JSON).s3Url("s3://" + bucket + "/" + key).build();
CreateImportJobRequest jobRequest = CreateImportJobRequest.builder().importJobRequest(importRequest).applicationId(appId).build();
CreateImportJobResponse jobResponse = client.createImportJob(jobRequest);
return jobResponse.importJobResponse();
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.
the class ListSegments method listSegs.
// snippet-start:[pinpoint.java2.listsegments.main]
public static void listSegs(PinpointClient pinpoint, String appId) {
try {
GetSegmentsRequest request = GetSegmentsRequest.builder().applicationId(appId).build();
GetSegmentsResponse response = pinpoint.getSegments(request);
List<SegmentResponse> segments = response.segmentsResponse().item();
for (SegmentResponse segment : segments) {
System.out.println("Segement " + segment.id() + " " + segment.name() + " " + segment.lastModifiedDate());
}
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.pinpoint.model.PinpointException in project aws-doc-sdk-examples by awsdocs.
the class SendEmailMessage method sendEmail.
// snippet-start:[pinpoint.java2.send_email.main]
public static void sendEmail(PinpointClient pinpoint, String subject, String appId, String senderAddress, String toAddress) {
try {
Map<String, AddressConfiguration> addressMap = new HashMap<String, AddressConfiguration>();
AddressConfiguration configuration = AddressConfiguration.builder().channelType(ChannelType.EMAIL).build();
addressMap.put(toAddress, configuration);
SimpleEmailPart emailPart = SimpleEmailPart.builder().data(htmlBody).charset(charset).build();
SimpleEmailPart subjectPart = SimpleEmailPart.builder().data(subject).charset(charset).build();
SimpleEmail simpleEmail = SimpleEmail.builder().htmlPart(emailPart).subject(subjectPart).build();
EmailMessage emailMessage = EmailMessage.builder().body(htmlBody).fromAddress(senderAddress).simpleEmail(simpleEmail).build();
DirectMessageConfiguration directMessageConfiguration = DirectMessageConfiguration.builder().emailMessage(emailMessage).build();
MessageRequest messageRequest = MessageRequest.builder().addresses(addressMap).messageConfiguration(directMessageConfiguration).build();
SendMessagesRequest messagesRequest = SendMessagesRequest.builder().applicationId(appId).messageRequest(messageRequest).build();
pinpoint.sendMessages(messagesRequest);
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations