Skip to content

Commit 21d3f17

Browse files
authored
Cleanup Based on Changes in Generated Code (Azure#31594)
Cleanup Based on Changes in Generated Code
1 parent 64fdbdf commit 21d3f17

File tree

17 files changed

+654
-747
lines changed

17 files changed

+654
-747
lines changed

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/ServicesImpl.java

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,73 @@ public Mono<BlobServiceStatistics> getStatisticsAsync(Integer timeout, String re
531531
.flatMap(res -> Mono.justOrEmpty(res.getValue()));
532532
}
533533

534+
/**
535+
* The List Containers Segment operation returns a list of the containers under the specified account.
536+
*
537+
* @param prefix Filters the results to return only containers whose name begins with the specified prefix.
538+
* @param marker A string value that identifies the portion of the list of containers to be returned with the next
539+
* listing operation. The operation returns the NextMarker value within the response body if the listing
540+
* operation did not return all containers remaining to be listed with the current page. The NextMarker value
541+
* can be used as the value for the marker parameter in a subsequent call to request the next page of list
542+
* items. The marker value is opaque to the client.
543+
* @param maxresults Specifies the maximum number of containers to return. If the request does not specify
544+
* maxresults, or specifies a value greater than 5000, the server will return up to 5000 items. Note that if the
545+
* listing operation crosses a partition boundary, then the service will return a continuation token for
546+
* retrieving the remainder of the results. For this reason, it is possible that the service will return fewer
547+
* results than specified by maxresults, or than the default of 5000.
548+
* @param listBlobContainersIncludeType Include this parameter to specify that the container's metadata be returned
549+
* as part of the response body.
550+
* @param timeout The timeout parameter is expressed in seconds. For more information, see &lt;a
551+
* href="https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations"&gt;Setting
552+
* Timeouts for Blob Service Operations.&lt;/a&gt;.
553+
* @param requestId Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the
554+
* analytics logs when storage analytics logging is enabled.
555+
* @throws IllegalArgumentException thrown if parameters fail the validation.
556+
* @throws BlobStorageException thrown if the request is rejected by server.
557+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
558+
* @return an enumeration of containers along with {@link PagedResponse} on successful completion of {@link Mono}.
559+
*/
560+
@ServiceMethod(returns = ReturnType.SINGLE)
561+
public Mono<PagedResponse<BlobContainerItem>> listBlobContainersSegmentSinglePageAsync(
562+
String prefix,
563+
String marker,
564+
Integer maxresults,
565+
List<ListBlobContainersIncludeType> listBlobContainersIncludeType,
566+
Integer timeout,
567+
String requestId) {
568+
final String comp = "list";
569+
final String accept = "application/xml";
570+
String listBlobContainersIncludeTypeConverted =
571+
(listBlobContainersIncludeType == null)
572+
? null
573+
: listBlobContainersIncludeType.stream()
574+
.map(value -> Objects.toString(value, ""))
575+
.collect(Collectors.joining(","));
576+
return FluxUtil.withContext(
577+
context ->
578+
service.listBlobContainersSegment(
579+
this.client.getUrl(),
580+
comp,
581+
prefix,
582+
marker,
583+
maxresults,
584+
listBlobContainersIncludeTypeConverted,
585+
timeout,
586+
this.client.getVersion(),
587+
requestId,
588+
accept,
589+
context))
590+
.map(
591+
res ->
592+
new PagedResponseBase<>(
593+
res.getRequest(),
594+
res.getStatusCode(),
595+
res.getHeaders(),
596+
res.getValue().getBlobContainerItems(),
597+
res.getValue().getNextMarker(),
598+
res.getDeserializedHeaders()));
599+
}
600+
534601
/**
535602
* The List Containers Segment operation returns a list of the containers under the specified account.
536603
*
@@ -632,14 +699,11 @@ public PagedFlux<BlobContainerItem> listBlobContainersSegmentAsync(
632699
List<ListBlobContainersIncludeType> listBlobContainersIncludeType,
633700
Integer timeout,
634701
String requestId) {
635-
// TODO (alzimmer): This wasn't passing context as there is no Context to pass.
636-
// There will be a fix for this in a future Autorest release but for now this was done manually.
637-
// Adding this comment to make this obvious on diff.
638-
return new PagedFlux<>(() -> FluxUtil.withContext(context ->
639-
listBlobContainersSegmentSinglePageAsync(
640-
prefix, marker, maxresults, listBlobContainersIncludeType, timeout, requestId, context)),
641-
nextLink -> FluxUtil.withContext(context ->
642-
listBlobContainersSegmentNextSinglePageAsync(nextLink, requestId, context)));
702+
return new PagedFlux<>(
703+
() ->
704+
listBlobContainersSegmentSinglePageAsync(
705+
prefix, marker, maxresults, listBlobContainersIncludeType, timeout, requestId),
706+
nextLink -> listBlobContainersSegmentNextSinglePageAsync(nextLink, requestId));
643707
}
644708

645709
/**
@@ -1283,6 +1347,42 @@ public Mono<FilterBlobSegment> filterBlobsAsync(
12831347
.flatMap(res -> Mono.justOrEmpty(res.getValue()));
12841348
}
12851349

1350+
/**
1351+
* Get the next page of items.
1352+
*
1353+
* @param nextLink The URL to get the next list of items
1354+
* <p>The nextLink parameter.
1355+
* @param requestId Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the
1356+
* analytics logs when storage analytics logging is enabled.
1357+
* @throws IllegalArgumentException thrown if parameters fail the validation.
1358+
* @throws BlobStorageException thrown if the request is rejected by server.
1359+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
1360+
* @return an enumeration of containers along with {@link PagedResponse} on successful completion of {@link Mono}.
1361+
*/
1362+
@ServiceMethod(returns = ReturnType.SINGLE)
1363+
public Mono<PagedResponse<BlobContainerItem>> listBlobContainersSegmentNextSinglePageAsync(
1364+
String nextLink, String requestId) {
1365+
final String accept = "application/xml";
1366+
return FluxUtil.withContext(
1367+
context ->
1368+
service.listBlobContainersSegmentNext(
1369+
nextLink,
1370+
this.client.getUrl(),
1371+
this.client.getVersion(),
1372+
requestId,
1373+
accept,
1374+
context))
1375+
.map(
1376+
res ->
1377+
new PagedResponseBase<>(
1378+
res.getRequest(),
1379+
res.getStatusCode(),
1380+
res.getHeaders(),
1381+
res.getValue().getBlobContainerItems(),
1382+
res.getValue().getNextMarker(),
1383+
res.getDeserializedHeaders()));
1384+
}
1385+
12861386
/**
12871387
* Get the next page of items.
12881388
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.blob.implementation.accesshelpers;
5+
6+
import com.azure.storage.blob.implementation.models.BlobsQueryHeaders;
7+
import com.azure.storage.blob.models.BlobQueryHeaders;
8+
9+
/**
10+
* Helper class to access private values of {@link BlobQueryHeaders} across package boundaries.
11+
*/
12+
public final class BlobQueryHeadersConstructorProxy {
13+
private static BlobQueryHeadersConstructorAccessor accessor;
14+
15+
private BlobQueryHeadersConstructorProxy() { }
16+
17+
/**
18+
* Type defining the methods to set the non-public properties of a {@link BlobQueryHeaders} instance.
19+
*/
20+
public interface BlobQueryHeadersConstructorAccessor {
21+
/**
22+
* Creates a new instance of {@link BlobQueryHeaders} backed by an internal instance of
23+
* {@link BlobsQueryHeaders}.
24+
*
25+
* @param internalHeader The internal headers.
26+
* @return A new instance of {@link BlobQueryHeaders}.
27+
*/
28+
BlobQueryHeaders create(BlobsQueryHeaders internalHeader);
29+
}
30+
31+
/**
32+
* The method called from {@link BlobQueryHeaders} to set it's accessor.
33+
*
34+
* @param accessor The accessor.
35+
*/
36+
public static void setAccessor(final BlobQueryHeadersConstructorAccessor accessor) {
37+
BlobQueryHeadersConstructorProxy.accessor = accessor;
38+
}
39+
40+
/**
41+
* Creates a new instance of {@link BlobQueryHeaders} backed by an internal instance of
42+
* {@link BlobsQueryHeaders}.
43+
*
44+
* @param internalHeaders The internal headers.
45+
* @return A new instance of {@link BlobQueryHeaders}.
46+
*/
47+
public static BlobQueryHeaders create(BlobsQueryHeaders internalHeaders) {
48+
// This looks odd but is necessary, it is possible to engage the access helper before anywhere else in the
49+
// application accesses BlobQueryHeaders which triggers the accessor to be configured. So, if the accessor
50+
// is null this effectively pokes the class to set up the accessor.
51+
if (accessor == null) {
52+
new BlobQueryHeaders();
53+
}
54+
55+
assert accessor != null;
56+
return accessor.create(internalHeaders);
57+
}
58+
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/ModelHelper.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import com.azure.core.http.rest.SimpleResponse;
1010
import com.azure.core.util.CoreUtils;
1111
import com.azure.core.util.logging.ClientLogger;
12-
import com.azure.core.util.serializer.JacksonAdapter;
13-
import com.azure.core.util.serializer.SerializerAdapter;
1412
import com.azure.storage.blob.BlobAsyncClient;
1513
import com.azure.storage.blob.implementation.accesshelpers.BlobDownloadHeadersConstructorProxy;
1614
import com.azure.storage.blob.implementation.accesshelpers.BlobPropertiesConstructorProxy;
15+
import com.azure.storage.blob.implementation.accesshelpers.BlobQueryHeadersConstructorProxy;
1716
import com.azure.storage.blob.implementation.models.BlobItemInternal;
1817
import com.azure.storage.blob.implementation.models.BlobItemPropertiesInternal;
1918
import com.azure.storage.blob.implementation.models.BlobName;
2019
import com.azure.storage.blob.implementation.models.BlobPropertiesInternalDownload;
2120
import com.azure.storage.blob.implementation.models.BlobTag;
2221
import com.azure.storage.blob.implementation.models.BlobTags;
2322
import com.azure.storage.blob.implementation.models.BlobsDownloadHeaders;
23+
import com.azure.storage.blob.implementation.models.BlobsQueryHeaders;
2424
import com.azure.storage.blob.implementation.models.FilterBlobItem;
2525
import com.azure.storage.blob.models.BlobBeginCopySourceRequestConditions;
2626
import com.azure.storage.blob.models.BlobDownloadAsyncResponse;
@@ -41,7 +41,6 @@
4141
import com.azure.storage.common.Utility;
4242
import com.azure.storage.common.implementation.Constants;
4343

44-
import java.io.IOException;
4544
import java.net.MalformedURLException;
4645
import java.net.URL;
4746
import java.util.ArrayList;
@@ -53,12 +52,10 @@
5352

5453
/**
5554
* This class provides helper methods for common model patterns.
56-
*
55+
* <p>
5756
* RESERVED FOR INTERNAL USE.
5857
*/
5958
public final class ModelHelper {
60-
61-
private static final SerializerAdapter SERIALIZER = JacksonAdapter.createDefaultSerializerAdapter();
6259
private static final ClientLogger LOGGER = new ClientLogger(ModelHelper.class);
6360

6461
/**
@@ -420,19 +417,9 @@ public static BlobsDownloadHeaders transformBlobDownloadHeaders(HttpHeaders head
420417
return new BlobsDownloadHeaders(headers);
421418
}
422419

423-
public static BlobQueryHeaders transformQueryHeaders(HttpHeaders headers) {
424-
return transformHeadersToClass(headers);
425-
}
426-
427-
private static <T> T transformHeadersToClass(HttpHeaders headers) {
428-
if (headers == null) {
429-
return null;
430-
}
431-
try {
432-
return SERIALIZER.deserialize(headers, BlobQueryHeaders.class);
433-
} catch (IOException e) {
434-
throw LOGGER.logExceptionAsError(new RuntimeException(e));
435-
}
420+
public static BlobQueryHeaders transformQueryHeaders(BlobsQueryHeaders headers, HttpHeaders rawHeaders) {
421+
return BlobQueryHeadersConstructorProxy.create(headers)
422+
.setErrorCode(ModelHelper.getErrorCode(rawHeaders));
436423
}
437424

438425
public static void validateConditionsNotPresent(BlobRequestConditions requestConditions,

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlobDownloadHeaders.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ public final class BlobDownloadHeaders {
2929
private final BlobsDownloadHeaders internalHeaders;
3030

3131
static {
32-
BlobDownloadHeadersConstructorProxy.setAccessor(
33-
new BlobDownloadHeadersConstructorProxy.BlobDownloadHeadersConstructorAccessor() {
34-
@Override
35-
public BlobDownloadHeaders create(BlobsDownloadHeaders internalHeaders) {
36-
return new BlobDownloadHeaders(internalHeaders);
37-
}
38-
});
32+
BlobDownloadHeadersConstructorProxy.setAccessor(BlobDownloadHeaders::new);
3933
}
4034

4135
private BlobDownloadHeaders(BlobsDownloadHeaders internalHeaders) {

0 commit comments

Comments
 (0)