public ProgressEvent handleRequest()

in aws-customerprofiles-domain/src/main/java/software/amazon/customerprofiles/domain/UpdateHandler.java [36:127]


    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();

        final GetDomainRequest getDomainRequest = GetDomainRequest.builder()
                .domainName(model.getDomainName())
                .build();

        // If this domain is never created, can not be updated
        try {
            proxy.injectCredentialsAndInvokeV2(getDomainRequest, client::getDomain);
            logger.log(String.format("Get Domain with domainName = %s",
                    model.getDomainName()));
        } catch (BadRequestException e) {
            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 List<Tag> previousTags = request.getPreviousResourceTags() == null ? Lists.newArrayList() :
                Translator.mapTagsToList(request.getPreviousResourceTags());

        if (previousTags != null) {
            final List<String> tagsToRemove = previousTags.stream()
                    .map(Tag::getKey)
                    .collect(Collectors.toList());

            // Remove previous tags
            if (tagsToRemove.size() > 0) {
                final UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder()
                        .resourceArn(Translator.toDomainARN(request))
                        .tagKeys(tagsToRemove)
                        .build();
                proxy.injectCredentialsAndInvokeV2(untagResourceRequest, client::untagResource);
            }
        }

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

        final UpdateDomainResponse updateDomainResponse;
        try {
            updateDomainResponse = proxy.injectCredentialsAndInvokeV2(updateDomainRequest, client::updateDomain);
            logger.log(String.format("Update Domain with domainName = %s",
                    model.getDomainName()));
        } catch (BadRequestException e) {
            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(updateDomainResponse.createdAt().toString())
                .deadLetterQueueUrl(updateDomainResponse.deadLetterQueueUrl())
                .defaultExpirationDays(updateDomainResponse.defaultExpirationDays())
                .defaultEncryptionKey(updateDomainResponse.defaultEncryptionKey())
                .domainName(updateDomainResponse.domainName())
                .lastUpdatedAt(updateDomainResponse.lastUpdatedAt().toString())
                .tags(Translator.mapTagsToList(updateDomainResponse.tags()))
                .build();

        return ProgressEvent.defaultSuccessHandler(responseModel);
    }