use of com.azure.core.http.rest.PagedResponse in project vividus by vividus-framework.
the class BlobStorageSteps method findBlobs.
/**
* Finds blobs with names filtered by the specified rules in the container.
*
* @param filter Filter to apply to blob names.
* <div>Example:</div>
* <code>
* <br>When I filter blobs by:
* <br>|blobNamePrefix|blobNameFilterRule|blobNameFilterValue|resultsLimit|
* <br>|data/ |contains |file-key.txt |10 |
* <br>in container `global` of storage account `storage`
* <br> and save result to story variable `blobs`
* </code>
* <br>
* <br>where all filters are optional, but at least one rule is required.
* <ul>
* <li><code>blobNameFilterRule</code> The blob name comparison rule: "is equal to",
* "contains", "does not contain" or "matches".
* Should be specified along with <i>blobNameFilterValue</i>.</li>
* <li><code>blobNameFilterValue</code> The full or partial blob name to be matched.
* Should be specified along with <i>blobNameFilterRule</i>.</li>
* <li><code>blobNamePrefix</code> The prefix which blob names should start with.</li>
* <li><code>resultsLimit</code> Maximum number of blob names to return.</li>
* </ul>
* @param containerName The name of the container to point to.
* @param storageAccountKey The key to Storage Account endpoint.
* @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable
* scopes.<br>
* <i>Available scopes:</i>
* <ul>
* <li><b>STEP</b> - the variable will be available only within the step,
* <li><b>SCENARIO</b> - the variable will be available only within the scenario,
* <li><b>STORY</b> - the variable will be available within the whole story,
* <li><b>NEXT_BATCHES</b> - the variable will be available starting from next batch
* </ul>
* @param variableName The variable name to store the list of found blob names.
*/
@When("I filter blobs by:$filter in container `$containerName` of storage account `$storageAccountKey`" + " and save result to $scopes variable `$variableName`")
public void findBlobs(BlobFilter filter, String containerName, String storageAccountKey, Set<VariableScope> scopes, String variableName) {
BlobContainerClient blobContainerClient = createBlobContainerClient(containerName, storageAccountKey);
ListBlobsOptions options = new ListBlobsOptions();
filter.getBlobNamePrefix().ifPresent(options::setPrefix);
options.setMaxResultsPerPage(filter.getResultsLimit().map(limit -> Math.min(limit, DEFAULT_MAX_RESULTS_PER_PAGE)).orElse(DEFAULT_MAX_RESULTS_PER_PAGE));
PagedIterable<BlobItem> blobItems = blobContainerClient.listBlobs(options, null);
Stream<String> blobNames = StreamSupport.stream(blobItems.iterableByPage().spliterator(), false).map(PagedResponse::getValue).flatMap(List::stream).map(BlobItem::getName);
Stream<String> filteredBlobNames = filter.getBlobNameMatcher().map(matcher -> blobNames.filter(matcher::matches)).orElse(blobNames);
List<String> result = filter.getResultsLimit().map(filteredBlobNames::limit).orElse(filteredBlobNames).collect(Collectors.toList());
variableContext.putVariable(scopes, variableName, result);
}
Aggregations