public ProgressEvent handleRequest()

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


    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 requestModel = request.getDesiredResourceState();

        final GetIntegrationRequest getIntegrationRequest = GetIntegrationRequest.builder()
                .domainName(requestModel.getDomainName())
                .uri(requestModel.getUri())
                .build();

        // If this integration is never created, can not be updated
        try {
            proxy.injectCredentialsAndInvokeV2(getIntegrationRequest, client::getIntegration);
            logger.log(String.format("Get Integration with domainName = %s, uri = %s",
                    requestModel.getDomainName(), requestModel.getUri()));
        } 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.toIntegrationArn(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 PutIntegrationRequest putIntegrationRequest = PutIntegrationRequest.builder()
                .domainName(requestModel.getDomainName())
                // ObjectTypeName can be updated
                .objectTypeName(requestModel.getObjectTypeName())
                .uri(requestModel.getUri())
                .tags(resourceTag)
                .objectTypeNames(Translator.mapListToObjectTypeNames(requestModel.getObjectTypeNames()))
                .build();

        final PutIntegrationResponse putIntegrationResponse;
        try {
            putIntegrationResponse = proxy.injectCredentialsAndInvokeV2(putIntegrationRequest, client::putIntegration);
            logger.log(String.format("Update Integration with domainName = %s, uri = %s",
                    requestModel.getDomainName(), requestModel.getUri()));
        } 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(putIntegrationResponse.createdAt().toString())
                .domainName(putIntegrationResponse.domainName())
                .lastUpdatedAt(putIntegrationResponse.lastUpdatedAt().toString())
                .objectTypeName(putIntegrationResponse.objectTypeName())
                .tags(Translator.mapTagsToList(putIntegrationResponse.tags()))
                .uri(putIntegrationResponse.uri())
                .objectTypeNames(Translator.mapObjectTypeNamesToList(putIntegrationResponse.objectTypeNames()))
                .build();

        return ProgressEvent.defaultSuccessHandler(responseModel);
    }