protected ProgressEvent handleRequest()

in aws-licensemanager-grant/src/main/java/software/amazon/licensemanager/grant/DeleteHandler.java [23:70]


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

        this.logger = logger;

        // TODO: Adjust Progress Chain according to your implementation
        // https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/blob/master/src/main/java/software/amazon/cloudformation/proxy/CallChain.java

        return ProgressEvent.progress(request.getDesiredResourceState(), callbackContext)

                // STEP 1 [check if resource already exists]
                // for more information -> https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/resource-type-test-contract.html
                // if target API does not support 'ResourceNotFoundException' then following check is required
                .then(progress -> {
                            try {
                                ProgressEvent readHandlerResponse = new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger);
                                request.getDesiredResourceState()
                                        .setVersion(((ResourceModel) readHandlerResponse.getResourceModel()).getVersion());
                                return ProgressEvent.progress(request.getDesiredResourceState(), callbackContext);
                            } catch (final CfnNotFoundException e) {
                                logger.log(request.getDesiredResourceState().getPrimaryIdentifier()
                                        + " does not exist; Therefore, can not be deleted.");
                                return ProgressEvent.defaultFailureHandler(e, HandlerErrorCode.NotFound);
                            }
                        }
                )

                // STEP 2.0 [delete/stabilize progress chain - required for resource deletion]
                .then(progress ->
                        // If your service API throws 'ResourceNotFoundException' for delete requests then DeleteHandler can return just proxy.initiate construction
                        // STEP 2.0 [initialize a proxy context]
                        // Implement client invocation of the delete request through the proxyClient, which is already initialised with
                        // caller credentials, correct region and retry settings
                        proxy.initiate("AWS-LicenseManager-Grant::Delete", proxyClient, progress.getResourceModel(), progress.getCallbackContext())

                                // STEP 2.1 [TODO: construct a body of a request]
                                .translateToServiceRequest(Translator::translateToDeleteRequest)

                                // STEP 2.2 [TODO: make an api call]
                                .makeServiceCall((awsRequest, client) -> deleteGrant(progress.getResourceModel(), awsRequest, client))
                                .done(awsResponse -> ProgressEvent.<ResourceModel, CallbackContext>builder()
                                        .status(OperationStatus.SUCCESS)
                                        .build()));
    }