private List listSchedulingPolicies()

in aws-batch-schedulingpolicy/src/main/java/software/amazon/batch/schedulingpolicy/ListHandler.java [52:91]


    private List<ResourceModel> listSchedulingPolicies(final ResourceHandlerRequest<ResourceModel> request,
            final CallbackContext callbackContext, final Logger logger, final AmazonWebServicesClientProxy proxy) {
        List<ResourceModel> schedulingPolicies = new ArrayList<>();
        String nextToken = null;

        do {
            try {
                // List API call returns the arns of the Scheduling Policies.
                ListSchedulingPoliciesResponse listSchedulingPoliciesResponse =
                        proxy.injectCredentialsAndInvokeV2(Translator.toListSchedulingPoliciesRequest(nextToken),
                                this.client::listSchedulingPolicies);

                List<String> arns = listSchedulingPoliciesResponse.schedulingPolicies()
                                                                  .stream()
                                                                  .map(SchedulingPolicyListingDetail::arn)
                                                                  .collect(Collectors.toList());

                if (!arns.isEmpty()) {
                    // Get specific information about all the Scheduling Policies with Describe API call.
                    DescribeSchedulingPoliciesResponse describeSchedulingPoliciesResponse =
                            proxy.injectCredentialsAndInvokeV2(Translator.toDescribeSchedulingPoliciesRequest(arns),
                                    this.client::describeSchedulingPolicies);

                    List<ResourceModel> models =
                            describeSchedulingPoliciesResponse.schedulingPolicies()
                                                              .stream()
                                                              .map(Translator::toModelSchedulingPolicy)
                                                              .collect(Collectors.toList());

                    schedulingPolicies.addAll(models);
                }
                nextToken = listSchedulingPoliciesResponse.nextToken();
            } catch (final BatchException e) {
                Exceptions.handleBatchExceptions(request, callbackContext, e);
            }
        } while (!Strings.isNullOrEmpty(nextToken));
        logger.log("List scheduling policy handler final result: " + schedulingPolicies.toString());

        return schedulingPolicies;
    }