PageRenderTime 2213ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/sdk/advisor/mgmt-v2017_04_19/src/main/java/com/microsoft/azure/management/advisor/v2017_04_19/implementation/OperationsInner.java

http://github.com/WindowsAzure/azure-sdk-for-java
Java | 283 lines | 168 code | 20 blank | 95 comment | 8 complexity | d2223f5ebd54cd7657330e7028bb5731 MD5 | raw file
Possible License(s): MIT
  1. /**
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for
  4. * license information.
  5. *
  6. * Code generated by Microsoft (R) AutoRest Code Generator.
  7. */
  8. package com.microsoft.azure.management.advisor.v2017_04_19.implementation;
  9. import retrofit2.Retrofit;
  10. import com.google.common.reflect.TypeToken;
  11. import com.microsoft.azure.AzureServiceFuture;
  12. import com.microsoft.azure.CloudException;
  13. import com.microsoft.azure.ListOperationCallback;
  14. import com.microsoft.azure.Page;
  15. import com.microsoft.azure.PagedList;
  16. import com.microsoft.rest.ServiceFuture;
  17. import com.microsoft.rest.ServiceResponse;
  18. import java.io.IOException;
  19. import java.util.List;
  20. import okhttp3.ResponseBody;
  21. import retrofit2.http.GET;
  22. import retrofit2.http.Header;
  23. import retrofit2.http.Headers;
  24. import retrofit2.http.Query;
  25. import retrofit2.http.Url;
  26. import retrofit2.Response;
  27. import rx.functions.Func1;
  28. import rx.Observable;
  29. /**
  30. * An instance of this class provides access to all the operations defined
  31. * in Operations.
  32. */
  33. public class OperationsInner {
  34. /** The Retrofit service to perform REST calls. */
  35. private OperationsService service;
  36. /** The service client containing this operation class. */
  37. private AdvisorManagementClientImpl client;
  38. /**
  39. * Initializes an instance of OperationsInner.
  40. *
  41. * @param retrofit the Retrofit instance built from a Retrofit Builder.
  42. * @param client the instance of the service client containing this operation class.
  43. */
  44. public OperationsInner(Retrofit retrofit, AdvisorManagementClientImpl client) {
  45. this.service = retrofit.create(OperationsService.class);
  46. this.client = client;
  47. }
  48. /**
  49. * The interface defining all the services for Operations to be
  50. * used by Retrofit to perform actually REST calls.
  51. */
  52. interface OperationsService {
  53. @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.advisor.v2017_04_19.Operations list" })
  54. @GET("providers/Microsoft.Advisor/operations")
  55. Observable<Response<ResponseBody>> list(@Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
  56. @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.advisor.v2017_04_19.Operations listNext" })
  57. @GET
  58. Observable<Response<ResponseBody>> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);
  59. }
  60. /**
  61. * Lists all the available Advisor REST API operations.
  62. *
  63. * @throws IllegalArgumentException thrown if parameters fail the validation
  64. * @throws CloudException thrown if the request is rejected by server
  65. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  66. * @return the PagedList&lt;OperationEntityInner&gt; object if successful.
  67. */
  68. public PagedList<OperationEntityInner> list() {
  69. ServiceResponse<Page<OperationEntityInner>> response = listSinglePageAsync().toBlocking().single();
  70. return new PagedList<OperationEntityInner>(response.body()) {
  71. @Override
  72. public Page<OperationEntityInner> nextPage(String nextPageLink) {
  73. return listNextSinglePageAsync(nextPageLink).toBlocking().single().body();
  74. }
  75. };
  76. }
  77. /**
  78. * Lists all the available Advisor REST API operations.
  79. *
  80. * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  81. * @throws IllegalArgumentException thrown if parameters fail the validation
  82. * @return the {@link ServiceFuture} object
  83. */
  84. public ServiceFuture<List<OperationEntityInner>> listAsync(final ListOperationCallback<OperationEntityInner> serviceCallback) {
  85. return AzureServiceFuture.fromPageResponse(
  86. listSinglePageAsync(),
  87. new Func1<String, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  88. @Override
  89. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(String nextPageLink) {
  90. return listNextSinglePageAsync(nextPageLink);
  91. }
  92. },
  93. serviceCallback);
  94. }
  95. /**
  96. * Lists all the available Advisor REST API operations.
  97. *
  98. * @throws IllegalArgumentException thrown if parameters fail the validation
  99. * @return the observable to the PagedList&lt;OperationEntityInner&gt; object
  100. */
  101. public Observable<Page<OperationEntityInner>> listAsync() {
  102. return listWithServiceResponseAsync()
  103. .map(new Func1<ServiceResponse<Page<OperationEntityInner>>, Page<OperationEntityInner>>() {
  104. @Override
  105. public Page<OperationEntityInner> call(ServiceResponse<Page<OperationEntityInner>> response) {
  106. return response.body();
  107. }
  108. });
  109. }
  110. /**
  111. * Lists all the available Advisor REST API operations.
  112. *
  113. * @throws IllegalArgumentException thrown if parameters fail the validation
  114. * @return the observable to the PagedList&lt;OperationEntityInner&gt; object
  115. */
  116. public Observable<ServiceResponse<Page<OperationEntityInner>>> listWithServiceResponseAsync() {
  117. return listSinglePageAsync()
  118. .concatMap(new Func1<ServiceResponse<Page<OperationEntityInner>>, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  119. @Override
  120. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(ServiceResponse<Page<OperationEntityInner>> page) {
  121. String nextPageLink = page.body().nextPageLink();
  122. if (nextPageLink == null) {
  123. return Observable.just(page);
  124. }
  125. return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink));
  126. }
  127. });
  128. }
  129. /**
  130. * Lists all the available Advisor REST API operations.
  131. *
  132. * @throws IllegalArgumentException thrown if parameters fail the validation
  133. * @return the PagedList&lt;OperationEntityInner&gt; object wrapped in {@link ServiceResponse} if successful.
  134. */
  135. public Observable<ServiceResponse<Page<OperationEntityInner>>> listSinglePageAsync() {
  136. if (this.client.apiVersion() == null) {
  137. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  138. }
  139. return service.list(this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent())
  140. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  141. @Override
  142. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(Response<ResponseBody> response) {
  143. try {
  144. ServiceResponse<PageImpl<OperationEntityInner>> result = listDelegate(response);
  145. return Observable.just(new ServiceResponse<Page<OperationEntityInner>>(result.body(), result.response()));
  146. } catch (Throwable t) {
  147. return Observable.error(t);
  148. }
  149. }
  150. });
  151. }
  152. private ServiceResponse<PageImpl<OperationEntityInner>> listDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException {
  153. return this.client.restClient().responseBuilderFactory().<PageImpl<OperationEntityInner>, CloudException>newInstance(this.client.serializerAdapter())
  154. .register(200, new TypeToken<PageImpl<OperationEntityInner>>() { }.getType())
  155. .registerError(CloudException.class)
  156. .build(response);
  157. }
  158. /**
  159. * Lists all the available Advisor REST API operations.
  160. *
  161. * @param nextPageLink The NextLink from the previous successful call to List operation.
  162. * @throws IllegalArgumentException thrown if parameters fail the validation
  163. * @throws CloudException thrown if the request is rejected by server
  164. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  165. * @return the PagedList&lt;OperationEntityInner&gt; object if successful.
  166. */
  167. public PagedList<OperationEntityInner> listNext(final String nextPageLink) {
  168. ServiceResponse<Page<OperationEntityInner>> response = listNextSinglePageAsync(nextPageLink).toBlocking().single();
  169. return new PagedList<OperationEntityInner>(response.body()) {
  170. @Override
  171. public Page<OperationEntityInner> nextPage(String nextPageLink) {
  172. return listNextSinglePageAsync(nextPageLink).toBlocking().single().body();
  173. }
  174. };
  175. }
  176. /**
  177. * Lists all the available Advisor REST API operations.
  178. *
  179. * @param nextPageLink The NextLink from the previous successful call to List operation.
  180. * @param serviceFuture the ServiceFuture object tracking the Retrofit calls
  181. * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  182. * @throws IllegalArgumentException thrown if parameters fail the validation
  183. * @return the {@link ServiceFuture} object
  184. */
  185. public ServiceFuture<List<OperationEntityInner>> listNextAsync(final String nextPageLink, final ServiceFuture<List<OperationEntityInner>> serviceFuture, final ListOperationCallback<OperationEntityInner> serviceCallback) {
  186. return AzureServiceFuture.fromPageResponse(
  187. listNextSinglePageAsync(nextPageLink),
  188. new Func1<String, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  189. @Override
  190. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(String nextPageLink) {
  191. return listNextSinglePageAsync(nextPageLink);
  192. }
  193. },
  194. serviceCallback);
  195. }
  196. /**
  197. * Lists all the available Advisor REST API operations.
  198. *
  199. * @param nextPageLink The NextLink from the previous successful call to List operation.
  200. * @throws IllegalArgumentException thrown if parameters fail the validation
  201. * @return the observable to the PagedList&lt;OperationEntityInner&gt; object
  202. */
  203. public Observable<Page<OperationEntityInner>> listNextAsync(final String nextPageLink) {
  204. return listNextWithServiceResponseAsync(nextPageLink)
  205. .map(new Func1<ServiceResponse<Page<OperationEntityInner>>, Page<OperationEntityInner>>() {
  206. @Override
  207. public Page<OperationEntityInner> call(ServiceResponse<Page<OperationEntityInner>> response) {
  208. return response.body();
  209. }
  210. });
  211. }
  212. /**
  213. * Lists all the available Advisor REST API operations.
  214. *
  215. * @param nextPageLink The NextLink from the previous successful call to List operation.
  216. * @throws IllegalArgumentException thrown if parameters fail the validation
  217. * @return the observable to the PagedList&lt;OperationEntityInner&gt; object
  218. */
  219. public Observable<ServiceResponse<Page<OperationEntityInner>>> listNextWithServiceResponseAsync(final String nextPageLink) {
  220. return listNextSinglePageAsync(nextPageLink)
  221. .concatMap(new Func1<ServiceResponse<Page<OperationEntityInner>>, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  222. @Override
  223. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(ServiceResponse<Page<OperationEntityInner>> page) {
  224. String nextPageLink = page.body().nextPageLink();
  225. if (nextPageLink == null) {
  226. return Observable.just(page);
  227. }
  228. return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink));
  229. }
  230. });
  231. }
  232. /**
  233. * Lists all the available Advisor REST API operations.
  234. *
  235. ServiceResponse<PageImpl<OperationEntityInner>> * @param nextPageLink The NextLink from the previous successful call to List operation.
  236. * @throws IllegalArgumentException thrown if parameters fail the validation
  237. * @return the PagedList&lt;OperationEntityInner&gt; object wrapped in {@link ServiceResponse} if successful.
  238. */
  239. public Observable<ServiceResponse<Page<OperationEntityInner>>> listNextSinglePageAsync(final String nextPageLink) {
  240. if (nextPageLink == null) {
  241. throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.");
  242. }
  243. String nextUrl = String.format("%s", nextPageLink);
  244. return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent())
  245. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Page<OperationEntityInner>>>>() {
  246. @Override
  247. public Observable<ServiceResponse<Page<OperationEntityInner>>> call(Response<ResponseBody> response) {
  248. try {
  249. ServiceResponse<PageImpl<OperationEntityInner>> result = listNextDelegate(response);
  250. return Observable.just(new ServiceResponse<Page<OperationEntityInner>>(result.body(), result.response()));
  251. } catch (Throwable t) {
  252. return Observable.error(t);
  253. }
  254. }
  255. });
  256. }
  257. private ServiceResponse<PageImpl<OperationEntityInner>> listNextDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException {
  258. return this.client.restClient().responseBuilderFactory().<PageImpl<OperationEntityInner>, CloudException>newInstance(this.client.serializerAdapter())
  259. .register(200, new TypeToken<PageImpl<OperationEntityInner>>() { }.getType())
  260. .registerError(CloudException.class)
  261. .build(response);
  262. }
  263. }