protected ProgressEvent handleRequest()

in preparedstatement/src/main/java/software/amazon/athena/preparedstatement/UpdateHandler.java [19:63]


    protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        final CallbackContext callbackContext,
        final ProxyClient<AthenaClient> proxyClient,
        final Logger logger) {

        this.logger = logger;

        return ProgressEvent.progress(request.getDesiredResourceState(), callbackContext)
            .then(progress ->
                proxy.initiate("AWS-Athena-PreparedStatement::Update::PreUpdateCheck", proxyClient, progress.getResourceModel(), progress.getCallbackContext())
                    .translateToServiceRequest(Translator::translateToReadRequest)
                    .makeServiceCall((awsRequest, client) -> {
                        GetPreparedStatementResponse awsResponse = client.injectCredentialsAndInvokeV2(
                            awsRequest, client.client()::getPreparedStatement);
                        logger.log(String.format("%s has successfully been read.", ResourceModel.TYPE_NAME));
                        return awsResponse;
                    })
                    .handleError((awsRequest, exception, client, model, context) -> {
                        if (exception instanceof ResourceNotFoundException) { // nothing to delete
                            return ProgressEvent.failed(model, context, HandlerErrorCode.NotFound,
                                exception.getMessage());
                        }
                        throw exception;
                    })
                    .progress()
            )
            .then(progress ->
                proxy.initiate("AWS-Athena-PreparedStatement::Update::first", proxyClient, progress.getResourceModel(), progress.getCallbackContext())
                    .translateToServiceRequest(Translator::translateToFirstUpdateRequest)
                    .makeServiceCall((awsRequest, client) -> {
                        UpdatePreparedStatementResponse awsResponse;
                        try {
                            awsResponse = client.injectCredentialsAndInvokeV2(
                                awsRequest, client.client()::updatePreparedStatement);
                        } catch (final AwsServiceException e) {
                            throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e);
                        }
                        logger.log(String.format("%s has successfully been updated.", ResourceModel.TYPE_NAME));
                        return awsResponse;
                    })
                    .progress())
            .then(progress -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger));
    }