Search in sources :

Example 1 with PinpointException

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);
    }
}
Also used : DeleteAppResponse(software.amazon.awssdk.services.pinpoint.model.DeleteAppResponse) DeleteAppRequest(software.amazon.awssdk.services.pinpoint.model.DeleteAppRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException)

Example 2 with PinpointException

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;
}
Also used : CreateExportJobRequest(software.amazon.awssdk.services.pinpoint.model.CreateExportJobRequest) ExportJobRequest(software.amazon.awssdk.services.pinpoint.model.ExportJobRequest) GetExportJobRequest(software.amazon.awssdk.services.pinpoint.model.GetExportJobRequest) CreateExportJobRequest(software.amazon.awssdk.services.pinpoint.model.CreateExportJobRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) ArrayList(java.util.ArrayList) Date(java.util.Date) ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) CreateExportJobResponse(software.amazon.awssdk.services.pinpoint.model.CreateExportJobResponse) S3Object(software.amazon.awssdk.services.s3.model.S3Object) SimpleDateFormat(java.text.SimpleDateFormat) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response)

Example 3 with PinpointException

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;
}
Also used : CreateImportJobResponse(software.amazon.awssdk.services.pinpoint.model.CreateImportJobResponse) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) CreateImportJobRequest(software.amazon.awssdk.services.pinpoint.model.CreateImportJobRequest) CreateImportJobRequest(software.amazon.awssdk.services.pinpoint.model.CreateImportJobRequest) ImportJobRequest(software.amazon.awssdk.services.pinpoint.model.ImportJobRequest)

Example 4 with PinpointException

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);
    }
}
Also used : GetSegmentsRequest(software.amazon.awssdk.services.pinpoint.model.GetSegmentsRequest) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) GetSegmentsResponse(software.amazon.awssdk.services.pinpoint.model.GetSegmentsResponse) SegmentResponse(software.amazon.awssdk.services.pinpoint.model.SegmentResponse)

Example 5 with PinpointException

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);
    }
}
Also used : EmailMessage(software.amazon.awssdk.services.pinpoint.model.EmailMessage) MessageRequest(software.amazon.awssdk.services.pinpoint.model.MessageRequest) SendMessagesRequest(software.amazon.awssdk.services.pinpoint.model.SendMessagesRequest) HashMap(java.util.HashMap) PinpointException(software.amazon.awssdk.services.pinpoint.model.PinpointException) SimpleEmailPart(software.amazon.awssdk.services.pinpoint.model.SimpleEmailPart) DirectMessageConfiguration(software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration) AddressConfiguration(software.amazon.awssdk.services.pinpoint.model.AddressConfiguration) SimpleEmail(software.amazon.awssdk.services.pinpoint.model.SimpleEmail)

Aggregations

PinpointException (software.amazon.awssdk.services.pinpoint.model.PinpointException)19 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 EndpointRequest (software.amazon.awssdk.services.pinpoint.model.EndpointRequest)3 EndpointUser (software.amazon.awssdk.services.pinpoint.model.EndpointUser)3 GetEndpointRequest (software.amazon.awssdk.services.pinpoint.model.GetEndpointRequest)3 UpdateEndpointRequest (software.amazon.awssdk.services.pinpoint.model.UpdateEndpointRequest)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 AddressConfiguration (software.amazon.awssdk.services.pinpoint.model.AddressConfiguration)2 DirectMessageConfiguration (software.amazon.awssdk.services.pinpoint.model.DirectMessageConfiguration)2 EndpointResponse (software.amazon.awssdk.services.pinpoint.model.EndpointResponse)2 GetEndpointResponse (software.amazon.awssdk.services.pinpoint.model.GetEndpointResponse)2 GetExportJobRequest (software.amazon.awssdk.services.pinpoint.model.GetExportJobRequest)2 MessageRequest (software.amazon.awssdk.services.pinpoint.model.MessageRequest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DateFormat (java.text.DateFormat)1 List (java.util.List)1