public ProgressEvent handleRequest()

in aws-customerprofiles-domain/src/main/java/software/amazon/customerprofiles/domain/CreateHandler.java [32:89]


    public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
            final AmazonWebServicesClientProxy proxy,
            final ResourceHandlerRequest<ResourceModel> request,
            final CallbackContext callbackContext,
            final Logger logger) {

        if (this.client == null) {
            this.client = ClientBuilder.getClient();
        }

        final ResourceModel model = request.getDesiredResourceState();

        Map<String, String> resourceTag;
        if (request.getDesiredResourceTags() == null) {
            resourceTag = null;
        } else if (request.getDesiredResourceTags().isEmpty()) {
            resourceTag = null;
        } else {
            resourceTag = request.getDesiredResourceTags();
        }
        final CreateDomainRequest createDomainRequest = CreateDomainRequest.builder()
                .domainName(model.getDomainName())
                .deadLetterQueueUrl(model.getDeadLetterQueueUrl())
                .defaultEncryptionKey(model.getDefaultEncryptionKey())
                .defaultExpirationDays(model.getDefaultExpirationDays())
                .tags(resourceTag)
                .build();

        final CreateDomainResponse createDomainResponse;
        try {
            createDomainResponse = proxy.injectCredentialsAndInvokeV2(createDomainRequest, client::createDomain);
            logger.log(String.format("Domain Created with domainName = %s", model.getDomainName()));
        } catch (BadRequestException e) {
            if (e.getMessage().contains("Domain " + model.getDomainName() + " already exists")) {
                throw new CfnAlreadyExistsException(e);
            } else {
                throw new CfnInvalidRequestException(e);
            }
        } catch (InternalServerException e) {
            throw new CfnServiceInternalErrorException(e);
        } catch (ResourceNotFoundException e) {
            throw new CfnNotFoundException(e);
        } catch (Exception e) {
            throw new CfnGeneralServiceException(e);
        }

        final ResourceModel responseModel = ResourceModel.builder()
                .createdAt(createDomainResponse.createdAt().toString())
                .deadLetterQueueUrl(createDomainResponse.deadLetterQueueUrl())
                .defaultEncryptionKey(createDomainResponse.defaultEncryptionKey())
                .defaultExpirationDays(createDomainResponse.defaultExpirationDays())
                .domainName(createDomainResponse.domainName())
                .lastUpdatedAt(createDomainResponse.lastUpdatedAt().toString())
                .tags(Translator.mapTagsToList(createDomainResponse.tags()))
                .build();

        return ProgressEvent.defaultSuccessHandler(responseModel);
    }