public ProgressEvent handleRequest()

in aws-licensemanager-grant/src/main/java/software/amazon/licensemanager/grant/ListHandler.java [25:66]


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

        final ResourceModel model = request.getDesiredResourceState();
        try {
            final List<ResourceModel> models = new ArrayList<>();

            // STEP 1 [TODO: construct a body of a request]
            final ListDistributedGrantsRequest listDistributedGrantsRequest = Translator.translateToListRequest(model, request.getNextToken());

            ListDistributedGrantsResponse listDistributedGrantsResponse = null;
            try {
                // STEP 2 [TODO: make an api call]
                listDistributedGrantsResponse = proxy.injectCredentialsAndInvokeV2(
                        listDistributedGrantsRequest, proxyClient.client()::listDistributedGrants);
            } catch (AccessDeniedException e) {
                throw new CfnAccessDeniedException("List:License", e);
            } catch (ValidationException e) {
                throw new CfnInvalidRequestException(e);
            }

            // STEP 3 [TODO: get a token for the next page]
            String nextToken = listDistributedGrantsResponse.nextToken();

            // STEP 4 [TODO: construct resource models]
            // e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/blob/master/aws-logs-loggroup/src/main/java/software/amazon/logs/loggroup/ListHandler.java#L19-L21

            models.addAll(Translator.translateFromListRequest(listDistributedGrantsResponse).stream().collect(Collectors.toList()));
            return ProgressEvent.<ResourceModel, CallbackContext>builder()
                    .resourceModels(models)
                    .nextToken(nextToken)
                    .status(OperationStatus.SUCCESS)
                    .build();
        } catch (final software.amazon.awssdk.services.licensemanager.model.ResourceNotFoundException e) {
            throw new ResourceNotFoundException(ResourceModel.TYPE_NAME, e.getMessage(), e);
        }

    }