From 0484ce66e17388acab01e5f5d316190b2a8fa43b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Mon, 12 Sep 2016 17:35:15 -0700 Subject: [PATCH] Generate graph and keyvault clients --- .../management/graphrbac/GraphError.java | 71 + .../graphrbac/GraphErrorException.java | 87 ++ .../KeyCredentialsUpdateParameters.java | 43 + .../PasswordCredentialsUpdateParameters.java | 43 + .../implementation/AADObjectInner.java | 20 +- .../implementation/ADGroupInner.java | 10 +- .../ApplicationCreateParametersInner.java | 19 +- .../implementation/ApplicationInner.java | 14 +- .../ApplicationUpdateParametersInner.java | 43 +- .../implementation/ApplicationsInner.java | 973 +++++++++--- .../GraphRbacManagementClientImpl.java | 6 +- .../graphrbac/implementation/GroupsInner.java | 1307 ++++++++++------- .../KeyCredentialInner.java} | 42 +- .../implementation/ObjectsInner.java | 89 +- .../PasswordCredentialInner.java} | 30 +- ...ServicePrincipalCreateParametersInner.java | 53 +- .../implementation/ServicePrincipalInner.java | 10 +- .../ServicePrincipalsInner.java | 1090 ++++++++++---- .../graphrbac/implementation/UserInner.java | 12 +- .../graphrbac/implementation/UsersInner.java | 869 ++++++----- .../keyvault/AccessPolicyEntry.java | 7 +- .../management/keyvault/KeyPermissions.java | 98 ++ .../management/keyvault/Permissions.java | 12 +- .../keyvault/SecretPermissions.java | 68 + .../azure/management/keyvault/Sku.java | 10 +- .../azure/management/keyvault/SkuFamily.java | 20 - .../keyvault/implementation/VaultInner.java | 1 - .../keyvault/implementation/VaultsInner.java | 990 ++++++++----- gulpfile.js | 4 +- 29 files changed, 4090 insertions(+), 1951 deletions(-) create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java create mode 100644 azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java rename azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/{KeyCredential.java => implementation/KeyCredentialInner.java} (69%) rename azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/{PasswordCredential.java => implementation/PasswordCredentialInner.java} (70%) create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java create mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java delete mode 100644 azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java new file mode 100644 index 000000000000..033bb358f3d5 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphError.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Active Directory error information. + */ +@JsonFlatten +public class GraphError { + /** + * Error code. + */ + @JsonProperty(value = "odata\\.error.code") + private String code; + + /** + * Error message value. + */ + @JsonProperty(value = "odata\\.error.message.value") + private String message; + + /** + * Get the code value. + * + * @return the code value + */ + public String code() { + return this.code; + } + + /** + * Set the code value. + * + * @param code the code value to set + * @return the GraphError object itself. + */ + public GraphError withCode(String code) { + this.code = code; + return this; + } + + /** + * Get the message value. + * + * @return the message value + */ + public String message() { + return this.message; + } + + /** + * Set the message value. + * + * @param message the message value to set + * @return the GraphError object itself. + */ + public GraphError withMessage(String message) { + this.message = message; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java new file mode 100644 index 000000000000..e6b4aeeeecb8 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/GraphErrorException.java @@ -0,0 +1,87 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import com.microsoft.rest.RestException; +import retrofit2.Response; + +/** + * Exception thrown for an invalid response with GraphError information. + */ +public class GraphErrorException extends RestException { + /** + * Information about the associated HTTP response. + */ + private Response response; + /** + * The actual response body. + */ + private GraphError body; + /** + * Initializes a new instance of the GraphErrorException class. + */ + public GraphErrorException() { } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param message The exception message. + */ + public GraphErrorException(final String message) { + super(message); + } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param message the exception message + * @param cause exception that caused this exception to occur + */ + public GraphErrorException(final String message, final Throwable cause) { + super(message, cause); + } + /** + * Initializes a new instance of the GraphErrorException class. + * + * @param cause exception that caused this exception to occur + */ + public GraphErrorException(final Throwable cause) { + super(cause); + } + /** + * Gets information about the associated HTTP response. + * + * @return the HTTP response + */ + public Response getResponse() { + return response; + } + /** + * Gets the HTTP response body. + * + * @return the response body + */ + public GraphError getBody() { + return body; + } + /** + * Sets the HTTP response. + * + * @param response the HTTP response + */ + public void setResponse(Response response) { + this.response = response; + } + /** + * Sets the HTTP response body. + * + * @param body the response body + */ + public void setBody(GraphError body) { + this.body = body; + } +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java new file mode 100644 index 000000000000..9fd5ff8b29f5 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredentialsUpdateParameters.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.implementation.KeyCredentialInner; + +/** + * Request parameters for KeyCredentials update operation. + */ +public class KeyCredentialsUpdateParameters { + /** + * KeyCredential list. + */ + private List value; + + /** + * Get the value value. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the KeyCredentialsUpdateParameters object itself. + */ + public KeyCredentialsUpdateParameters withValue(List value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java new file mode 100644 index 000000000000..adc5d0ccec51 --- /dev/null +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredentialsUpdateParameters.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.graphrbac; + +import java.util.List; +import com.microsoft.azure.management.graphrbac.implementation.PasswordCredentialInner; + +/** + * Request paramters for PasswordCredentials update operation. + */ +public class PasswordCredentialsUpdateParameters { + /** + * PasswordCredential list. + */ + private List value; + + /** + * Get the value value. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set the value value. + * + * @param value the value value to set + * @return the PasswordCredentialsUpdateParameters object itself. + */ + public PasswordCredentialsUpdateParameters withValue(List value) { + this.value = value; + return this; + } + +} diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java index 87922b8c92fd..79a109bb42d7 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/AADObjectInner.java @@ -15,52 +15,52 @@ */ public class AADObjectInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets object display name. + * object display name. */ private String displayName; /** - * Gets or sets principal name. + * principal name. */ private String userPrincipalName; /** - * Gets or sets mail. + * mail. */ private String mail; /** - * Gets or sets MailEnabled field. + * MailEnabled field. */ private Boolean mailEnabled; /** - * Gets or sets SecurityEnabled field. + * SecurityEnabled field. */ private Boolean securityEnabled; /** - * Gets or sets signIn name. + * signIn name. */ private String signInName; /** - * Gets or sets the list of service principal names. + * the list of service principal names. */ private List servicePrincipalNames; /** - * Gets or sets the user type. + * the user type. */ private String userType; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java index d2fd0568b922..b5108f421d70 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ADGroupInner.java @@ -14,27 +14,27 @@ */ public class ADGroupInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets group display name. + * group display name. */ private String displayName; /** - * Gets or sets security enabled field. + * security enabled field. */ private Boolean securityEnabled; /** - * Gets or sets mail field. + * mail field. */ private String mail; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java index 334e0768005b..ac996c9c89fa 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationCreateParametersInner.java @@ -9,8 +9,6 @@ package com.microsoft.azure.management.graphrbac.implementation; import java.util.List; -import com.microsoft.azure.management.graphrbac.KeyCredential; -import com.microsoft.azure.management.graphrbac.PasswordCredential; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -32,7 +30,6 @@ public class ApplicationCreateParametersInner { /** * Application homepage. */ - @JsonProperty(required = true) private String homepage; /** @@ -47,14 +44,14 @@ public class ApplicationCreateParametersInner { private List replyUrls; /** - * Gets or sets the list of KeyCredential objects. + * the list of KeyCredential objects. */ - private List keyCredentials; + private List keyCredentials; /** - * Gets or sets the list of PasswordCredential objects. + * the list of PasswordCredential objects. */ - private List passwordCredentials; + private List passwordCredentials; /** * Get the availableToOtherTenants value. @@ -161,7 +158,7 @@ public ApplicationCreateParametersInner withReplyUrls(List replyUrls) { * * @return the keyCredentials value */ - public List keyCredentials() { + public List keyCredentials() { return this.keyCredentials; } @@ -171,7 +168,7 @@ public List keyCredentials() { * @param keyCredentials the keyCredentials value to set * @return the ApplicationCreateParametersInner object itself. */ - public ApplicationCreateParametersInner withKeyCredentials(List keyCredentials) { + public ApplicationCreateParametersInner withKeyCredentials(List keyCredentials) { this.keyCredentials = keyCredentials; return this; } @@ -181,7 +178,7 @@ public ApplicationCreateParametersInner withKeyCredentials(List k * * @return the passwordCredentials value */ - public List passwordCredentials() { + public List passwordCredentials() { return this.passwordCredentials; } @@ -191,7 +188,7 @@ public List passwordCredentials() { * @param passwordCredentials the passwordCredentials value to set * @return the ApplicationCreateParametersInner object itself. */ - public ApplicationCreateParametersInner withPasswordCredentials(List passwordCredentials) { + public ApplicationCreateParametersInner withPasswordCredentials(List passwordCredentials) { this.passwordCredentials = passwordCredentials; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java index 1e4259ec221d..443db8cdc1d1 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationInner.java @@ -15,22 +15,22 @@ */ public class ApplicationInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets application Id. + * application Id. */ private String appId; /** - * Gets or sets application permissions. + * application permissions. */ private List appPermissions; @@ -40,17 +40,17 @@ public class ApplicationInner { private Boolean availableToOtherTenants; /** - * Gets or sets the displayName. + * the displayName. */ private String displayName; /** - * Gets or sets the application identifier Uris. + * the application identifier Uris. */ private List identifierUris; /** - * Gets or sets the application reply Urls. + * the application reply Urls. */ private List replyUrls; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java index ea7d6deeb662..759d2d37df6d 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationUpdateParametersInner.java @@ -9,13 +9,16 @@ package com.microsoft.azure.management.graphrbac.implementation; import java.util.List; -import com.microsoft.azure.management.graphrbac.KeyCredential; -import com.microsoft.azure.management.graphrbac.PasswordCredential; /** * Request parameters for updating an existing application. */ public class ApplicationUpdateParametersInner { + /** + * Indicates if the application will be available to other tenants. + */ + private Boolean availableToOtherTenants; + /** * Application display name. */ @@ -37,14 +40,34 @@ public class ApplicationUpdateParametersInner { private List replyUrls; /** - * Gets or sets the list of KeyCredential objects. + * the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * the list of PasswordCredential objects. */ - private List keyCredentials; + private List passwordCredentials; /** - * Gets or sets the list of PasswordCredential objects. + * Get the availableToOtherTenants value. + * + * @return the availableToOtherTenants value */ - private List passwordCredentials; + public Boolean availableToOtherTenants() { + return this.availableToOtherTenants; + } + + /** + * Set the availableToOtherTenants value. + * + * @param availableToOtherTenants the availableToOtherTenants value to set + * @return the ApplicationUpdateParametersInner object itself. + */ + public ApplicationUpdateParametersInner withAvailableToOtherTenants(Boolean availableToOtherTenants) { + this.availableToOtherTenants = availableToOtherTenants; + return this; + } /** * Get the displayName value. @@ -131,7 +154,7 @@ public ApplicationUpdateParametersInner withReplyUrls(List replyUrls) { * * @return the keyCredentials value */ - public List keyCredentials() { + public List keyCredentials() { return this.keyCredentials; } @@ -141,7 +164,7 @@ public List keyCredentials() { * @param keyCredentials the keyCredentials value to set * @return the ApplicationUpdateParametersInner object itself. */ - public ApplicationUpdateParametersInner withKeyCredentials(List keyCredentials) { + public ApplicationUpdateParametersInner withKeyCredentials(List keyCredentials) { this.keyCredentials = keyCredentials; return this; } @@ -151,7 +174,7 @@ public ApplicationUpdateParametersInner withKeyCredentials(List k * * @return the passwordCredentials value */ - public List passwordCredentials() { + public List passwordCredentials() { return this.passwordCredentials; } @@ -161,7 +184,7 @@ public List passwordCredentials() { * @param passwordCredentials the passwordCredentials value to set * @return the ApplicationUpdateParametersInner object itself. */ - public ApplicationUpdateParametersInner withPasswordCredentials(List passwordCredentials) { + public ApplicationUpdateParametersInner withPasswordCredentials(List passwordCredentials) { this.passwordCredentials = passwordCredentials; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java index 9c6b519e4ea3..d77097b6d262 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ApplicationsInner.java @@ -11,16 +11,16 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.KeyCredentialsUpdateParameters; +import com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -31,6 +31,8 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -60,23 +62,39 @@ public ApplicationsInner(Retrofit retrofit, GraphRbacManagementClientImpl client interface ApplicationsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/applications") - Call create(@Path("tenantID") String tenantID, @Body ApplicationCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body ApplicationCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/applications") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/applications/{applicationObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/applications/{applicationObjectId}") - Call get(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PATCH("{tenantID}/applications/{applicationObjectId}") - Call patch(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Body ApplicationUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> patch(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Body ApplicationUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Observable> listKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/keyCredentials") + Observable> updateKeyCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Observable> listPasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/applications/{applicationObjectId}/passwordCredentials") + Observable> updatePasswordCredentials(@Path(value = "applicationObjectId", encoded = true) String applicationObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); } @@ -84,24 +102,13 @@ interface ApplicationsService { * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param parameters Parameters to create an application. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. + * @return the ApplicationInner object if successful. */ - public ServiceResponse create(ApplicationCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ApplicationInner create(ApplicationCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -109,57 +116,107 @@ public ServiceResponse create(ApplicationCreateParametersInner * * @param parameters Parameters to create an application. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(ApplicationCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @return the observable to the ApplicationInner object + */ + public Observable createAsync(ApplicationCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ApplicationInner>() { + @Override + public ApplicationInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a new application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param parameters Parameters to create an application. + * @return the observable to the ApplicationInner object + */ + public Observable> createWithServiceResponseAsync(ApplicationCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + * @return the List<ApplicationInner> object if successful. + */ + public List list() throws GraphErrorException, IOException, IllegalArgumentException { + return listWithServiceResponseAsync().toBlocking().single().getBody(); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listAsync(final ServiceCallback> serviceCallback) { + return ServiceCall.create(listWithServiceResponseAsync(), serviceCallback); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @return the observable to the List<ApplicationInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync().map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @return the observable to the List<ApplicationInner> object */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { + public Observable>> listWithServiceResponseAsync() { if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } @@ -167,191 +224,451 @@ public ServiceResponse> list() throws CloudException, IOE throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * + * @param filter The filters to apply on the operation + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<ApplicationInner> object if successful. + */ + public List list(String filter) throws GraphErrorException, IOException, IllegalArgumentException { + return listWithServiceResponseAsync(filter).toBlocking().single().getBody(); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } - if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; - } - if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { + public ServiceCall> listAsync(String filter, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listWithServiceResponseAsync(filter), serviceCallback); + } + + /** + * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param filter The filters to apply on the operation + * @return the observable to the List<ApplicationInner> object + */ + public Observable> listAsync(String filter) { + return listWithServiceResponseAsync(filter).map(new Func1>, List>() { @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); - } + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } /** * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param filter The filters to apply on the operation - * @throws CloudException exception thrown from REST call - * @throws IOException exception thrown from serialization/deserialization - * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ApplicationInner> object wrapped in {@link ServiceResponse} if successful. + * @return the observable to the List<ApplicationInner> object */ - public ServiceResponse> list(String filter) throws CloudException, IOException, IllegalArgumentException { + public Observable>> listWithServiceResponseAsync(String filter) { if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Lists applications by filter parameters. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * - * @param filter The filters to apply on the operation + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void delete(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object + */ + public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. */ - public ServiceCall listAsync(String filter, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); + public Observable deleteAsync(String applicationObjectId) { + return deleteWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ApplicationInner object if successful. + */ + public ApplicationInner get(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the observable to the ApplicationInner object + */ + public Observable getAsync(String applicationObjectId) { + return getWithServiceResponseAsync(applicationObjectId).map(new Func1, ApplicationInner>() { + @Override + public ApplicationInner call(ServiceResponse response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) - .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + /** + * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @return the observable to the ApplicationInner object + */ + public Observable> getWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. * * @param applicationObjectId Application object id - * @throws CloudException exception thrown from REST call + * @param parameters Parameters to update an existing application. + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + patchWithServiceResponseAsync(applicationObjectId, parameters).toBlocking().single().getBody(); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(patchWithServiceResponseAsync(applicationObjectId, parameters), serviceCallback); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + public Observable patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { + return patchWithServiceResponseAsync(applicationObjectId, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * + * @param applicationObjectId Application object id + * @param parameters Parameters to update an existing application. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> patchWithServiceResponseAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + Validator.validate(parameters); + return service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = patchDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse patchDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Delete an application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object if successful. + */ + public List listKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listKeyCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listKeyCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable> listKeyCredentialsAsync(String applicationObjectId) { + return listKeyCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Get keyCredentials associated with the application by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable>> listKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.listKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ApplicationInner object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse get(String applicationObjectId) throws CloudException, IOException, IllegalArgumentException { + public void updateKeyCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String applicationObjectId) { + return updateKeyCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } @@ -361,132 +678,332 @@ public ServiceResponse get(String applicationObjectId) throws if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Get an application by object Id. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updateKeyCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param applicationObjectId Application object id + * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String applicationObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateKeyCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String applicationObjectId, List value) { + return updateKeyCredentialsWithServiceResponseAsync(applicationObjectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param applicationObjectId Application object id + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updateKeyCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object if successful. + */ + public List listPasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listPasswordCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listPasswordCredentialsAsync(String applicationObjectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listPasswordCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable> listPasswordCredentialsAsync(String applicationObjectId) { + return listPasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + /** + * Gets passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable>> listPasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { + if (applicationObjectId == null) { + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listPasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id - * @param parameters Parameters to update an existing application. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String applicationObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse patch(String applicationObjectId, ApplicationUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + public Observable updatePasswordCredentialsAsync(String applicationObjectId) { + return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId) { if (applicationObjectId == null) { throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters); - Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return patchDelegate(call.execute()); + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Update existing application. Reference: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx. + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * * @param applicationObjectId Application object id - * @param parameters Parameters to update an existing application. + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String applicationObjectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall patchAsync(String applicationObjectId, ApplicationUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updatePasswordCredentialsAsync(String applicationObjectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String applicationObjectId, List value) { + return updatePasswordCredentialsWithServiceResponseAsync(applicationObjectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing application. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param applicationObjectId Application object id + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String applicationObjectId, List value) { if (applicationObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter applicationObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; - } - if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.patch(applicationObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(patchDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updatePasswordCredentials(applicationObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse patchDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java index e95756e1703d..56062b62394e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GraphRbacManagementClientImpl.java @@ -40,11 +40,11 @@ public String apiVersion() { return this.apiVersion; } - /** Gets or sets the tenant Id. */ + /** the tenant Id. */ private String tenantID; /** - * Gets Gets or sets the tenant Id. + * Gets the tenant Id. * * @return the tenantID value. */ @@ -53,7 +53,7 @@ public String tenantID() { } /** - * Sets Gets or sets the tenant Id. + * Sets the tenant Id. * * @param tenantID the tenantID value. * @return the service client itself diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java index dc6fb1951e64..909a198bd288 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/GroupsInner.java @@ -10,22 +10,22 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.azure.management.graphrbac.GroupAddMemberParameters; import com.microsoft.azure.management.graphrbac.GroupGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -35,6 +35,8 @@ import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -64,47 +66,47 @@ public GroupsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface GroupsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/isMemberOf") - Call isMemberOf(@Path("tenantID") String tenantID, @Body CheckGroupMembershipParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> isMemberOf(@Path("tenantID") String tenantID, @Body CheckGroupMembershipParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/groups/{groupObjectId}/$links/members/{memberObjectId}", method = "DELETE", hasBody = true) - Call removeMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path(value = "memberObjectId", encoded = true) String memberObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> removeMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path(value = "memberObjectId", encoded = true) String memberObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups/{groupObjectId}/$links/members") - Call addMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupAddMemberParameters parameters, @Header("User-Agent") String userAgent); + Observable> addMember(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupAddMemberParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/groups/{groupObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "groupObjectId", encoded = true) String groupObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups") - Call create(@Path("tenantID") String tenantID, @Body GroupCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body GroupCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups/{objectId}/members") - Call getGroupMembers(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getGroupMembers(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/groups/{objectId}") - Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/groups/{objectId}/getMemberGroups") - Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + Observable> getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body GroupGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call getGroupMembersNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getGroupMembersNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -112,24 +114,13 @@ interface GroupsService { * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. * * @param parameters Check group membership parameters. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the CheckGroupMembershipResultInner object wrapped in {@link ServiceResponse} if successful. + * @return the CheckGroupMembershipResultInner object if successful. */ - public ServiceResponse isMemberOf(CheckGroupMembershipParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return isMemberOfDelegate(call.execute()); + public CheckGroupMembershipResultInner isMemberOf(CheckGroupMembershipParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return isMemberOfWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -137,45 +128,62 @@ public ServiceResponse isMemberOf(CheckGroupMem * * @param parameters Check group membership parameters. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall isMemberOfAsync(CheckGroupMembershipParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(isMemberOfWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @return the observable to the CheckGroupMembershipResultInner object + */ + public Observable isMemberOfAsync(CheckGroupMembershipParametersInner parameters) { + return isMemberOfWithServiceResponseAsync(parameters).map(new Func1, CheckGroupMembershipResultInner>() { + @Override + public CheckGroupMembershipResultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Checks whether the specified user, group, contact, or service principal is a direct or a transitive member of the specified group. + * + * @param parameters Check group membership parameters. + * @return the observable to the CheckGroupMembershipResultInner object + */ + public Observable> isMemberOfWithServiceResponseAsync(CheckGroupMembershipParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(isMemberOfDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.isMemberOf(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = isMemberOfDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse isMemberOfDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse isMemberOfDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -184,26 +192,12 @@ private ServiceResponse isMemberOfDelegate(Resp * * @param groupObjectId Group object id * @param memberObjectId Member Object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse removeMember(String groupObjectId, String memberObjectId) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (memberObjectId == null) { - throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return removeMemberDelegate(call.execute()); + public void removeMember(String groupObjectId, String memberObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).toBlocking().single().getBody(); } /** @@ -212,47 +206,66 @@ public ServiceResponse removeMember(String groupObjectId, String memberObj * @param groupObjectId Group object id * @param memberObjectId Member Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall removeMemberAsync(String groupObjectId, String memberObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId), serviceCallback); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable removeMemberAsync(String groupObjectId, String memberObjectId) { + return removeMemberWithServiceResponseAsync(groupObjectId, memberObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Remove a memeber from a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#DeleteGroupMember. + * + * @param groupObjectId Group object id + * @param memberObjectId Member Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> removeMemberWithServiceResponseAsync(String groupObjectId, String memberObjectId) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (memberObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter memberObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter memberObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(removeMemberDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.removeMember(groupObjectId, memberObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = removeMemberDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse removeMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse removeMemberDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -261,28 +274,12 @@ private ServiceResponse removeMemberDelegate(Response respon * * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse addMember(String groupObjectId, String url) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - if (url == null) { - throw new IllegalArgumentException("Parameter url is required and cannot be null."); - } - GroupAddMemberParameters parameters = new GroupAddMemberParameters(); - parameters.withUrl(url); - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - return addMemberDelegate(call.execute()); + public void addMember(String groupObjectId, String url) throws GraphErrorException, IOException, IllegalArgumentException { + addMemberWithServiceResponseAsync(groupObjectId, url).toBlocking().single().getBody(); } /** @@ -291,49 +288,68 @@ public ServiceResponse addMember(String groupObjectId, String url) throws * @param groupObjectId Group object id * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall addMemberAsync(String groupObjectId, String url, final ServiceCallback serviceCallback) { + return ServiceCall.create(addMemberWithServiceResponseAsync(groupObjectId, url), serviceCallback); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable addMemberAsync(String groupObjectId, String url) { + return addMemberWithServiceResponseAsync(groupObjectId, url).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Add a memeber to a group. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/groups-operations#AddGroupMembers. + * + * @param groupObjectId Group object id + * @param url Member Object Url as "https://graph.windows.net/0b1f9851-1bf0-433f-aec3-cb9272f093dc/directoryObjects/f260bbc4-c254-447b-94cf-293b5ec434dd", where "0b1f9851-1bf0-433f-aec3-cb9272f093dc" is the tenantId and "f260bbc4-c254-447b-94cf-293b5ec434dd" is the objectId of the member (user, application, servicePrincipal, group) to be added. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> addMemberWithServiceResponseAsync(String groupObjectId, String url) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } if (url == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter url is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter url is required and cannot be null."); } GroupAddMemberParameters parameters = new GroupAddMemberParameters(); parameters.withUrl(url); - Call call = service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(addMemberDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.addMember(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = addMemberDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse addMemberDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse addMemberDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -341,23 +357,12 @@ private ServiceResponse addMemberDelegate(Response response) * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. * * @param groupObjectId Object id - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String groupObjectId) throws CloudException, IOException, IllegalArgumentException { - if (groupObjectId == null) { - throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String groupObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(groupObjectId).toBlocking().single().getBody(); } /** @@ -365,43 +370,61 @@ public ServiceResponse delete(String groupObjectId) throws CloudException, * * @param groupObjectId Object id * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String groupObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(groupObjectId), serviceCallback); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String groupObjectId) { + return deleteWithServiceResponseAsync(groupObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param groupObjectId Object id + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String groupObjectId) { if (groupObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter groupObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter groupObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(groupObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -409,24 +432,13 @@ private ServiceResponse deleteDelegate(Response response) th * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. * * @param parameters Parameters to create a group - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + * @return the ADGroupInner object if successful. */ - public ServiceResponse create(GroupCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ADGroupInner create(GroupCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -434,142 +446,179 @@ public ServiceResponse create(GroupCreateParametersInner parameter * * @param parameters Parameters to create a group * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(GroupCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @return the observable to the ADGroupInner object + */ + public Observable createAsync(GroupCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ADGroupInner>() { + @Override + public ADGroupInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a group in the directory. Reference: http://msdn.microsoft.com/en-us/library/azure/dn151676.aspx. + * + * @param parameters Parameters to create a group + * @return the observable to the ADGroupInner object + */ + public Observable> createWithServiceResponseAsync(GroupCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of groups for the current tenant. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ADGroupInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of groups for the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of groups for the current tenant. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ADGroupInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -577,47 +626,87 @@ public Page nextPage(String nextLink) throws CloudException, IOExc * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -625,30 +714,19 @@ private ServiceResponse> listDelegate(Response> getGroupMembers(final String objectId) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = getGroupMembersDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList getGroupMembers(final String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = getGroupMembersSinglePageAsync(objectId).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return getGroupMembersNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -656,51 +734,90 @@ public Page nextPage(String nextLink) throws CloudException, IOE * * @param objectId Group object Id who's members should be retrieved. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getGroupMembersAsync(final String objectId, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + getGroupMembersSinglePageAsync(objectId), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable> getGroupMembersAsync(final String objectId) { + return getGroupMembersWithServiceResponseAsync(objectId) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets the members of a group. + * + * @param objectId Group object Id who's members should be retrieved. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable>> getGroupMembersWithServiceResponseAsync(final String objectId) { + return getGroupMembersSinglePageAsync(objectId) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(getGroupMembersNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets the members of a group. + * + ServiceResponse> * @param objectId Group object Id who's members should be retrieved. + * @return the PagedList<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> getGroupMembersSinglePageAsync(final String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.getGroupMembers(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getGroupMembersDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> getGroupMembersDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getGroupMembersDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -708,23 +825,13 @@ private ServiceResponse> getGroupMembersDelegate(Respo * Gets group information from the directory. * * @param objectId User objectId to get group information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ADGroupInner object wrapped in {@link ServiceResponse} if successful. + * @return the ADGroupInner object if successful. */ - public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public ADGroupInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); } /** @@ -732,44 +839,61 @@ public ServiceResponse get(String objectId) throws CloudException, * * @param objectId User objectId to get group information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @return the observable to the ADGroupInner object + */ + public Observable getAsync(String objectId) { + return getWithServiceResponseAsync(objectId).map(new Func1, ADGroupInner>() { + @Override + public ADGroupInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets group information from the directory. + * + * @param objectId User objectId to get group information. + * @return the observable to the ADGroupInner object + */ + public Observable> getWithServiceResponseAsync(String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -778,27 +902,13 @@ private ServiceResponse getDelegate(Response respons * * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + * @return the List<String> object if successful. */ - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); } /** @@ -807,47 +917,66 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId Group filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { + return ServiceCall.create(getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly), serviceCallback); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly) { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the group is a member. + * + * @param objectId Group filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } GroupGetMemberGroupsParameters parameters = new GroupGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getMemberGroupsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -855,23 +984,19 @@ private ServiceResponse> getMemberGroupsDelegate(Response> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -880,51 +1005,90 @@ public ServiceResponse> listNext(final String nextLink) * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ADGroupInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of groups for the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<ADGroupInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -932,23 +1096,19 @@ private ServiceResponse> listNextDelegate(Response> getGroupMembersNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getGroupMembersNextDelegate(call.execute()); + public PagedList getGroupMembersNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return getGroupMembersNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -957,51 +1117,90 @@ public ServiceResponse> getGroupMembersNext(final Stri * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getGroupMembersNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getGroupMembersNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + getGroupMembersNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable> getGroupMembersNextAsync(final String nextLink) { + return getGroupMembersNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets the members of a group. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<AADObjectInner> object + */ + public Observable>> getGroupMembersNextWithServiceResponseAsync(final String nextLink) { + return getGroupMembersNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(getGroupMembersNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets the members of a group. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<AADObjectInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> getGroupMembersNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getGroupMembersNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - getGroupMembersNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.getGroupMembersNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getGroupMembersNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> getGroupMembersNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getGroupMembersNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java similarity index 69% rename from azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java rename to azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java index a872fc2465af..9ce3370d8ebf 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/KeyCredential.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/KeyCredentialInner.java @@ -6,41 +6,41 @@ * Code generated by Microsoft (R) AutoRest Code Generator. */ -package com.microsoft.azure.management.graphrbac; +package com.microsoft.azure.management.graphrbac.implementation; import org.joda.time.DateTime; /** - * Active Directory service principal Key Credential information. + * Active Directory Key Credential information. */ -public class KeyCredential { +public class KeyCredentialInner { /** - * Gets or sets start date. + * start date. */ private DateTime startDate; /** - * Gets or sets end date. + * end date. */ private DateTime endDate; /** - * Gets or sets value. + * value. */ private String value; /** - * Gets or sets key Id. + * key Id. */ private String keyId; /** - * Gets or sets usage. + * usage. Acceptable values are 'Verify' and 'Sign'. */ private String usage; /** - * Gets or sets type. + * type. Acceptable values are 'AsymmetricX509Cert' and 'Symmetric'. */ private String type; @@ -57,9 +57,9 @@ public DateTime startDate() { * Set the startDate value. * * @param startDate the startDate value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withStartDate(DateTime startDate) { + public KeyCredentialInner withStartDate(DateTime startDate) { this.startDate = startDate; return this; } @@ -77,9 +77,9 @@ public DateTime endDate() { * Set the endDate value. * * @param endDate the endDate value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withEndDate(DateTime endDate) { + public KeyCredentialInner withEndDate(DateTime endDate) { this.endDate = endDate; return this; } @@ -97,9 +97,9 @@ public String value() { * Set the value value. * * @param value the value value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withValue(String value) { + public KeyCredentialInner withValue(String value) { this.value = value; return this; } @@ -117,9 +117,9 @@ public String keyId() { * Set the keyId value. * * @param keyId the keyId value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withKeyId(String keyId) { + public KeyCredentialInner withKeyId(String keyId) { this.keyId = keyId; return this; } @@ -137,9 +137,9 @@ public String usage() { * Set the usage value. * * @param usage the usage value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withUsage(String usage) { + public KeyCredentialInner withUsage(String usage) { this.usage = usage; return this; } @@ -157,9 +157,9 @@ public String type() { * Set the type value. * * @param type the type value to set - * @return the KeyCredential object itself. + * @return the KeyCredentialInner object itself. */ - public KeyCredential withType(String type) { + public KeyCredentialInner withType(String type) { this.type = type; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java index 51d87506eece..98ae94a7696e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ObjectsInner.java @@ -11,20 +11,20 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.graphrbac.GraphErrorException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import java.io.IOException; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.Path; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -54,67 +54,76 @@ public ObjectsInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface ObjectsService { @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/me") - Call getCurrentUser(@Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> getCurrentUser(@Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } /** * Gets the details for current logged in user. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the AADObjectInner object wrapped in {@link ServiceResponse} if successful. + * @return the AADObjectInner object if successful. */ - public ServiceResponse getCurrentUser() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getCurrentUserDelegate(call.execute()); + public AADObjectInner getCurrentUser() throws GraphErrorException, IOException, IllegalArgumentException { + return getCurrentUserWithServiceResponseAsync().toBlocking().single().getBody(); } /** * Gets the details for current logged in user. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getCurrentUserAsync(final ServiceCallback serviceCallback) { + return ServiceCall.create(getCurrentUserWithServiceResponseAsync(), serviceCallback); + } + + /** + * Gets the details for current logged in user. + * + * @return the observable to the AADObjectInner object + */ + public Observable getCurrentUserAsync() { + return getCurrentUserWithServiceResponseAsync().map(new Func1, AADObjectInner>() { + @Override + public AADObjectInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets the details for current logged in user. + * + * @return the observable to the AADObjectInner object + */ + public Observable> getCurrentUserWithServiceResponseAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getCurrentUserDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getCurrentUser(this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getCurrentUserDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getCurrentUserDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getCurrentUserDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java similarity index 70% rename from azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java rename to azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java index 67660ebb9d30..c39714365dbf 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/PasswordCredential.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/PasswordCredentialInner.java @@ -6,31 +6,31 @@ * Code generated by Microsoft (R) AutoRest Code Generator. */ -package com.microsoft.azure.management.graphrbac; +package com.microsoft.azure.management.graphrbac.implementation; import org.joda.time.DateTime; /** - * Active Directory service principal Password Credential information. + * Active Directory PasswordCredential information. */ -public class PasswordCredential { +public class PasswordCredentialInner { /** - * Gets or sets start date. + * start date. */ private DateTime startDate; /** - * Gets or sets end date. + * end date. */ private DateTime endDate; /** - * Gets or sets key Id. + * key Id. */ private String keyId; /** - * Gets or sets value. + * value. */ private String value; @@ -47,9 +47,9 @@ public DateTime startDate() { * Set the startDate value. * * @param startDate the startDate value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withStartDate(DateTime startDate) { + public PasswordCredentialInner withStartDate(DateTime startDate) { this.startDate = startDate; return this; } @@ -67,9 +67,9 @@ public DateTime endDate() { * Set the endDate value. * * @param endDate the endDate value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withEndDate(DateTime endDate) { + public PasswordCredentialInner withEndDate(DateTime endDate) { this.endDate = endDate; return this; } @@ -87,9 +87,9 @@ public String keyId() { * Set the keyId value. * * @param keyId the keyId value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withKeyId(String keyId) { + public PasswordCredentialInner withKeyId(String keyId) { this.keyId = keyId; return this; } @@ -107,9 +107,9 @@ public String value() { * Set the value value. * * @param value the value value to set - * @return the PasswordCredential object itself. + * @return the PasswordCredentialInner object itself. */ - public PasswordCredential withValue(String value) { + public PasswordCredentialInner withValue(String value) { this.value = value; return this; } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java index aa4aa749bece..83174b9cb180 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalCreateParametersInner.java @@ -8,6 +8,7 @@ package com.microsoft.azure.management.graphrbac.implementation; +import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -15,7 +16,7 @@ */ public class ServicePrincipalCreateParametersInner { /** - * Gets or sets application Id. + * application Id. */ @JsonProperty(required = true) private String appId; @@ -26,6 +27,16 @@ public class ServicePrincipalCreateParametersInner { @JsonProperty(required = true) private boolean accountEnabled; + /** + * the list of KeyCredential objects. + */ + private List keyCredentials; + + /** + * the list of PasswordCredential objects. + */ + private List passwordCredentials; + /** * Get the appId value. * @@ -66,4 +77,44 @@ public ServicePrincipalCreateParametersInner withAccountEnabled(boolean accountE return this; } + /** + * Get the keyCredentials value. + * + * @return the keyCredentials value + */ + public List keyCredentials() { + return this.keyCredentials; + } + + /** + * Set the keyCredentials value. + * + * @param keyCredentials the keyCredentials value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withKeyCredentials(List keyCredentials) { + this.keyCredentials = keyCredentials; + return this; + } + + /** + * Get the passwordCredentials value. + * + * @return the passwordCredentials value + */ + public List passwordCredentials() { + return this.passwordCredentials; + } + + /** + * Set the passwordCredentials value. + * + * @param passwordCredentials the passwordCredentials value to set + * @return the ServicePrincipalCreateParametersInner object itself. + */ + public ServicePrincipalCreateParametersInner withPasswordCredentials(List passwordCredentials) { + this.passwordCredentials = passwordCredentials; + return this; + } + } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java index c5b41719ebd7..b3c2dd63a739 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalInner.java @@ -15,27 +15,27 @@ */ public class ServicePrincipalInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets service principal display name. + * service principal display name. */ private String displayName; /** - * Gets or sets app id. + * app id. */ private String appId; /** - * Gets or sets the list of names. + * the list of names. */ private List servicePrincipalNames; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java index d24ea4be93f1..963ea8bfe284 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/ServicePrincipalsInner.java @@ -10,29 +10,34 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.KeyCredentialsUpdateParameters; +import com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.HTTP; +import retrofit2.http.PATCH; import retrofit2.http.Path; import retrofit2.http.POST; import retrofit2.http.Query; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -62,23 +67,39 @@ public ServicePrincipalsInner(Retrofit retrofit, GraphRbacManagementClientImpl c interface ServicePrincipalsService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/servicePrincipals") - Call create(@Path("tenantID") String tenantID, @Body ServicePrincipalCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body ServicePrincipalCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/servicePrincipals") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/servicePrincipals/{objectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/servicePrincipals/{objectId}") - Call get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Observable> listKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/keyCredentials") + Observable> updateKeyCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body KeyCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @GET("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Observable> listPasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers("Content-Type: application/json; charset=utf-8") + @PATCH("{tenantID}/servicePrincipals/{objectId}/passwordCredentials") + Observable> updatePasswordCredentials(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body PasswordCredentialsUpdateParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -86,24 +107,13 @@ interface ServicePrincipalsService { * Creates a service principal in the directory. * * @param parameters Parameters to create a service principal. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. + * @return the ServicePrincipalInner object if successful. */ - public ServiceResponse create(ServicePrincipalCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public ServicePrincipalInner create(ServicePrincipalCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -111,142 +121,179 @@ public ServiceResponse create(ServicePrincipalCreateParam * * @param parameters Parameters to create a service principal. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(ServicePrincipalCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @return the observable to the ServicePrincipalInner object + */ + public Observable createAsync(ServicePrincipalCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, ServicePrincipalInner>() { + @Override + public ServicePrincipalInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Creates a service principal in the directory. + * + * @param parameters Parameters to create a service principal. + * @return the observable to the ServicePrincipalInner object + */ + public Observable> createWithServiceResponseAsync(ServicePrincipalCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of service principals from the current tenant. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ServicePrincipalInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of service principals from the current tenant. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of service principals from the current tenant. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<ServicePrincipalInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -254,47 +301,87 @@ public Page nextPage(String nextLink) throws CloudExcepti * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -302,12 +389,47 @@ private ServiceResponse> listDelegate(Response< * Deletes service principal from the directory. * * @param objectId Object id to delete service principal information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void delete(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String objectId) { + return deleteWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Deletes service principal from the directory. + * + * @param objectId Object id to delete service principal information. * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String objectId) throws CloudException, IOException, IllegalArgumentException { + public Observable> deleteWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -317,65 +439,225 @@ public ServiceResponse delete(String objectId) throws CloudException, IOEx if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + return service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); } /** - * Deletes service principal from the directory. + * Gets service principal information from the directory. * - * @param objectId Object id to delete service principal information. + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the ServicePrincipalInner object if successful. + */ + public ServicePrincipalInner get(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @return the observable to the ServicePrincipalInner object + */ + public Observable getAsync(String objectId) { + return getWithServiceResponseAsync(objectId).map(new Func1, ServicePrincipalInner>() { + @Override + public ServicePrincipalInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets service principal information from the directory. + * + * @param objectId Object id to get service principal information. + * @return the observable to the ServicePrincipalInner object + */ + public Observable> getWithServiceResponseAsync(String objectId) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<KeyCredentialInner> object if successful. + */ + public List listKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listKeyCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listKeyCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable> listKeyCredentialsAsync(String objectId) { + return listKeyCredentialsWithServiceResponseAsync(objectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(204, new TypeToken() { }.getType()) + /** + * Get keyCredentials associated with the service principal by object Id. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<KeyCredentialInner> object + */ + public Observable>> listKeyCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listKeyCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Gets service principal information from the directory. + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param objectId Object id to get service principal information. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the ServicePrincipalInner object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse get(String objectId) throws CloudException, IOException, IllegalArgumentException { + public void updateKeyCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updateKeyCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String objectId) { + return updateKeyCredentialsWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId) { if (objectId == null) { throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } @@ -385,68 +667,229 @@ public ServiceResponse get(String objectId) throws CloudE if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + final List value = null; + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); } /** - * Gets service principal information from the directory. + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. * * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updateKeyCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updateKeyCredentialsWithServiceResponseAsync(objectId, value).toBlocking().single().getBody(); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String objectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateKeyCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateKeyCredentialsWithServiceResponseAsync(objectId, value), serviceCallback); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateKeyCredentialsAsync(String objectId, List value) { + return updateKeyCredentialsWithServiceResponseAsync(objectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Update keyCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type. + * + * @param objectId Object id to get service principal information. + * @param value KeyCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateKeyCredentialsWithServiceResponseAsync(String objectId, List value) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(value); + KeyCredentialsUpdateParameters parameters = new KeyCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updateKeyCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateKeyCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } + }); + } + + private ServiceResponse updateKeyCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the List<PasswordCredentialInner> object if successful. + */ + public List listPasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + return listPasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall> listPasswordCredentialsAsync(String objectId, final ServiceCallback> serviceCallback) { + return ServiceCall.create(listPasswordCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable> listPasswordCredentialsAsync(String objectId) { + return listPasswordCredentialsWithServiceResponseAsync(objectId).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); } }); - return serviceCall; } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) - .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + /** + * Gets passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the observable to the List<PasswordCredentialInner> object + */ + public Observable>> listPasswordCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listPasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listPasswordCredentialsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listPasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } /** - * Gets list of service principals from the current tenant. + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. * - * @param nextLink Next link for list operation. - * @throws CloudException exception thrown from REST call + * @param objectId Object id to get service principal information. + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. */ - public ServiceResponse> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); + public void updatePasswordCredentials(String objectId) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(objectId).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(objectId), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String objectId) { + return updatePasswordCredentialsWithServiceResponseAsync(objectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); @@ -454,8 +897,122 @@ public ServiceResponse> listNext(final String n if (this.client.apiVersion() == null) { throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + final List value = null; + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(null); + return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + */ + public void updatePasswordCredentials(String objectId, List value) throws GraphErrorException, IOException, IllegalArgumentException { + updatePasswordCredentialsWithServiceResponseAsync(objectId, value).toBlocking().single().getBody(); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @return the {@link ServiceCall} object + */ + public ServiceCall updatePasswordCredentialsAsync(String objectId, List value, final ServiceCallback serviceCallback) { + return ServiceCall.create(updatePasswordCredentialsWithServiceResponseAsync(objectId, value), serviceCallback); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updatePasswordCredentialsAsync(String objectId, List value) { + return updatePasswordCredentialsWithServiceResponseAsync(objectId, value).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates passwordCredentials associated with an existing service principal. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#passwordcredential-type. + * + * @param objectId Object id to get service principal information. + * @param value PasswordCredential list. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updatePasswordCredentialsWithServiceResponseAsync(String objectId, List value) { + if (objectId == null) { + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); + } + if (this.client.tenantID() == null) { + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(value); + PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters(); + parameters.withValue(value); + return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updatePasswordCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse updatePasswordCredentialsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) + .build(response); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @throws GraphErrorException exception thrown from REST call + * @throws IOException exception thrown from serialization/deserialization + * @throws IllegalArgumentException exception thrown from invalid parameters + * @return the PagedList<ServicePrincipalInner> object if successful. + */ + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -464,51 +1021,90 @@ public ServiceResponse> listNext(final String n * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<ServicePrincipalInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of service principals from the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<ServicePrincipalInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java index 33cff51127ea..00785fa6dc3e 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UserInner.java @@ -14,32 +14,32 @@ */ public class UserInner { /** - * Gets or sets object Id. + * object Id. */ private String objectId; /** - * Gets or sets object type. + * object type. */ private String objectType; /** - * Gets or sets user principal name. + * user principal name. */ private String userPrincipalName; /** - * Gets or sets user display name. + * user display name. */ private String displayName; /** - * Gets or sets user signIn name. + * user signIn name. */ private String signInName; /** - * Gets or sets user mail. + * user mail. */ private String mail; diff --git a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java index d9a3e5da72c7..91499376d8cd 100644 --- a/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java +++ b/azure-mgmt-graph-rbac/src/main/java/com/microsoft/azure/management/graphrbac/implementation/UsersInner.java @@ -8,34 +8,35 @@ package com.microsoft.azure.management.graphrbac.implementation; +import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; -import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.graphrbac.GraphErrorException; +import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; -import com.microsoft.azure.management.graphrbac.UserGetMemberGroupsParameters; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Response; -import retrofit2.Retrofit; import retrofit2.http.Body; import retrofit2.http.GET; -import retrofit2.http.HTTP; import retrofit2.http.Header; import retrofit2.http.Headers; +import retrofit2.http.HTTP; import retrofit2.http.PATCH; -import retrofit2.http.POST; import retrofit2.http.Path; +import retrofit2.http.POST; import retrofit2.http.Query; - -import java.io.IOException; -import java.util.List; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -65,31 +66,31 @@ public UsersInner(Retrofit retrofit, GraphRbacManagementClientImpl client) { interface UsersService { @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/users") - Call create(@Path("tenantID") String tenantID, @Body UserCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> create(@Path("tenantID") String tenantID, @Body UserCreateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/users") - Call list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("tenantID") String tenantID, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/users/{upnOrObjectId}") - Call get(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @PATCH("{tenantID}/users/{upnOrObjectId}") - Call update(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Body UserUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> update(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Body UserUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "{tenantID}/users/{upnOrObjectId}", method = "DELETE", hasBody = true) - Call delete(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path(value = "upnOrObjectId", encoded = true) String upnOrObjectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @POST("{tenantID}/users/{objectId}/getMemberGroups") - Call getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UserGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); + Observable> getMemberGroups(@Path(value = "objectId", encoded = true) String objectId, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UserGetMemberGroupsParameters parameters, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("{tenantID}/{nextLink}") - Call listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextLink, @Path("tenantID") String tenantID, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -97,24 +98,13 @@ interface UsersService { * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. * * @param parameters Parameters to create a user. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the UserInner object wrapped in {@link ServiceResponse} if successful. + * @return the UserInner object if successful. */ - public ServiceResponse create(UserCreateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return createDelegate(call.execute()); + public UserInner create(UserCreateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + return createWithServiceResponseAsync(parameters).toBlocking().single().getBody(); } /** @@ -122,142 +112,179 @@ public ServiceResponse create(UserCreateParametersInner parameters) t * * @param parameters Parameters to create a user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createAsync(UserCreateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createWithServiceResponseAsync(parameters), serviceCallback); + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @return the observable to the UserInner object + */ + public Observable createAsync(UserCreateParametersInner parameters) { + return createWithServiceResponseAsync(parameters).map(new Func1, UserInner>() { + @Override + public UserInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create a new user. Reference: https://msdn.microsoft.com/library/azure/ad/graph/api/users-operations#CreateUser. + * + * @param parameters Parameters to create a user. + * @return the observable to the UserInner object + */ + public Observable> createWithServiceResponseAsync(UserCreateParametersInner parameters) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.create(this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse createDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse createDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(201, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<UserInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final String filter = null; - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. * * @param filter The filter to apply on the operation. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<UserInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<UserInner> object if successful. */ - public ServiceResponse> list(final String filter) throws CloudException, IOException, IllegalArgumentException { - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final String filter) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(filter).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextLink) throws CloudException, IOException { - return listNext(nextLink).getBody(); + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -265,47 +292,87 @@ public Page nextPage(String nextLink) throws CloudException, IOExcept * * @param filter The filter to apply on the operation. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final String filter, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final String filter, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(filter), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listAsync(final String filter) { + return listWithServiceResponseAsync(filter) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + * @param filter The filter to apply on the operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listWithServiceResponseAsync(final String filter) { + return listSinglePageAsync(filter) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. Reference https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsers. + * + ServiceResponse> * @param filter The filter to apply on the operation. + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String filter) { if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.tenantID(), filter, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -313,23 +380,13 @@ private ServiceResponse> listDelegate(Response get(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public UserInner get(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); } /** @@ -337,44 +394,61 @@ public ServiceResponse get(String upnOrObjectId) throws CloudExceptio * * @param upnOrObjectId User object Id or user principal name to get user information. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(upnOrObjectId), serviceCallback); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @return the observable to the UserInner object + */ + public Observable getAsync(String upnOrObjectId) { + return getWithServiceResponseAsync(upnOrObjectId).map(new Func1, UserInner>() { + @Override + public UserInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets user information from the directory. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetAUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @return the observable to the UserInner object + */ + public Observable> getWithServiceResponseAsync(String upnOrObjectId) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse getDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(200, new TypeToken() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -383,27 +457,12 @@ private ServiceResponse getDelegate(Response response) * * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse update(String upnOrObjectId, UserUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return updateDelegate(call.execute()); + public void update(String upnOrObjectId, UserUpdateParametersInner parameters) throws GraphErrorException, IOException, IllegalArgumentException { + updateWithServiceResponseAsync(upnOrObjectId, parameters).toBlocking().single().getBody(); } /** @@ -412,48 +471,67 @@ public ServiceResponse update(String upnOrObjectId, UserUpdateParametersIn * @param upnOrObjectId User object Id or user principal name to get user information. * @param parameters Parameters to update an exisitng user. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(updateWithServiceResponseAsync(upnOrObjectId, parameters), serviceCallback); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable updateAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { + return updateWithServiceResponseAsync(upnOrObjectId, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Updates an exisitng user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser. + * + * @param upnOrObjectId User object Id or user principal name to get user information. + * @param parameters Parameters to update an exisitng user. + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> updateWithServiceResponseAsync(String upnOrObjectId, UserUpdateParametersInner parameters) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(updateDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.update(upnOrObjectId, this.client.tenantID(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse updateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse updateDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -461,23 +539,12 @@ private ServiceResponse updateDelegate(Response response) th * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. * * @param upnOrObjectId user object id or user principal name (upn) - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the {@link ServiceResponse} object if successful. */ - public ServiceResponse delete(String upnOrObjectId) throws CloudException, IOException, IllegalArgumentException { - if (upnOrObjectId == null) { - throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String upnOrObjectId) throws GraphErrorException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(upnOrObjectId).toBlocking().single().getBody(); } /** @@ -485,43 +552,61 @@ public ServiceResponse delete(String upnOrObjectId) throws CloudException, * * @param upnOrObjectId user object id or user principal name (upn) * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String upnOrObjectId, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(upnOrObjectId), serviceCallback); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String upnOrObjectId) { + return deleteWithServiceResponseAsync(upnOrObjectId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Delete a user. Reference: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#DeleteUser. + * + * @param upnOrObjectId user object id or user principal name (upn) + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String upnOrObjectId) { if (upnOrObjectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter upnOrObjectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(upnOrObjectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder(this.client.mapperAdapter()) + private ServiceResponse deleteDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder(this.client.mapperAdapter()) .register(204, new TypeToken() { }.getType()) + .registerError(GraphErrorException.class) .build(response); } @@ -530,27 +615,13 @@ private ServiceResponse deleteDelegate(Response response) th * * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked - * @throws CloudException exception thrown from REST call + * @throws GraphErrorException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<String> object wrapped in {@link ServiceResponse} if successful. + * @return the List<String> object if successful. */ - public ServiceResponse> getMemberGroups(String objectId, boolean securityEnabledOnly) throws CloudException, IOException, IllegalArgumentException { - if (objectId == null) { - throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); - parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - ServiceResponse> response = getMemberGroupsDelegate(call.execute()); - List result = response.getBody().getItems(); - return new ServiceResponse<>(result, response.getResponse()); + public List getMemberGroups(String objectId, boolean securityEnabledOnly) throws GraphErrorException, IOException, IllegalArgumentException { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).toBlocking().single().getBody(); } /** @@ -559,47 +630,66 @@ public ServiceResponse> getMemberGroups(String objectId, boolean se * @param objectId User filtering parameters. * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly, final ServiceCallback> serviceCallback) { + return ServiceCall.create(getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly), serviceCallback); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable> getMemberGroupsAsync(String objectId, boolean securityEnabledOnly) { + return getMemberGroupsWithServiceResponseAsync(objectId, securityEnabledOnly).map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets a collection that contains the Object IDs of the groups of which the user is a member. + * + * @param objectId User filtering parameters. + * @param securityEnabledOnly If true only membership in security enabled groups should be checked. Otherwise membership in all groups should be checked + * @return the observable to the List<String> object + */ + public Observable>> getMemberGroupsWithServiceResponseAsync(String objectId, boolean securityEnabledOnly) { if (objectId == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter objectId is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter objectId is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } UserGetMemberGroupsParameters parameters = new UserGetMemberGroupsParameters(); parameters.withSecurityEnabledOnly(securityEnabledOnly); - Call call = service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = getMemberGroupsDelegate(response); - serviceCallback.success(new ServiceResponse<>(result.getBody().getItems(), result.getResponse())); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.getMemberGroups(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = getMemberGroupsDelegate(response); + ServiceResponse> clientResponse = new ServiceResponse>(result.getBody().getItems(), result.getResponse()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } - private ServiceResponse> getMemberGroupsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> getMemberGroupsDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } @@ -607,23 +697,19 @@ private ServiceResponse> getMemberGroupsDelegate(Response> listNext(final String nextLink) throws CloudException, IOException, IllegalArgumentException { - if (nextLink == null) { - throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); - } - if (this.client.tenantID() == null) { - throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextLink) throws GraphErrorException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextLink) throws RestException, IOException { + return listNextSinglePageAsync(nextLink).toBlocking().single().getBody(); + } + }; } /** @@ -632,51 +718,90 @@ public ServiceResponse> listNext(final String nextLink) thr * @param nextLink Next link for list operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextLink), + new Func1>>>() { + @Override + public Observable>> call(String nextLink) { + return listNextSinglePageAsync(nextLink); + } + }, + serviceCallback); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable> listNextAsync(final String nextLink) { + return listNextWithServiceResponseAsync(nextLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * Gets list of users for the current tenant. + * + * @param nextLink Next link for list operation. + * @return the observable to the PagedList<UserInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextLink) { + return listNextSinglePageAsync(nextLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextLink = page.getBody().getNextPageLink(); + if (nextLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextLink)); + } + }); + } + + /** + * Gets list of users for the current tenant. + * + ServiceResponse> * @param nextLink Next link for list operation. + * @return the PagedList<UserInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextLink) { if (nextLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextLink is required and cannot be null."); } if (this.client.tenantID() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextLink, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } - private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { - return new AzureServiceResponseBuilder, CloudException>(this.client.mapperAdapter()) + private ServiceResponse> listNextDelegate(Response response) throws GraphErrorException, IOException, IllegalArgumentException { + return new AzureServiceResponseBuilder, GraphErrorException>(this.client.mapperAdapter()) .register(200, new TypeToken>() { }.getType()) - .registerError(CloudException.class) + .registerError(GraphErrorException.class) .build(response); } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java index 1bc9de5052af..65c9e483215b 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/AccessPolicyEntry.java @@ -9,6 +9,7 @@ package com.microsoft.azure.management.keyvault; import java.util.UUID; +import com.fasterxml.jackson.annotation.JsonProperty; /** * An array of 0 to 16 identities that have access to the key vault. All @@ -20,12 +21,15 @@ public class AccessPolicyEntry { * The Azure Active Directory tenant ID that should be used for * authenticating requests to the key vault. */ + @JsonProperty(required = true) private UUID tenantId; /** * The object ID of a user or service principal in the Azure Active - * Directory tenant for the vault. + * Directory tenant for the vault. The object ID must be unique for the + * list of access policies. */ + @JsonProperty(required = true) private UUID objectId; /** @@ -36,6 +40,7 @@ public class AccessPolicyEntry { /** * Permissions the identity has for keys and secrets. */ + @JsonProperty(required = true) private Permissions permissions; /** diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java new file mode 100644 index 000000000000..1e9996897691 --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/KeyPermissions.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for KeyPermissions. + */ +public final class KeyPermissions { + /** Static value all for KeyPermissions. */ + public static final KeyPermissions ALL = new KeyPermissions("all"); + + /** Static value encrypt for KeyPermissions. */ + public static final KeyPermissions ENCRYPT = new KeyPermissions("encrypt"); + + /** Static value decrypt for KeyPermissions. */ + public static final KeyPermissions DECRYPT = new KeyPermissions("decrypt"); + + /** Static value wrapkey for KeyPermissions. */ + public static final KeyPermissions WRAPKEY = new KeyPermissions("wrapkey"); + + /** Static value unwrapkey for KeyPermissions. */ + public static final KeyPermissions UNWRAPKEY = new KeyPermissions("unwrapkey"); + + /** Static value sign for KeyPermissions. */ + public static final KeyPermissions SIGN = new KeyPermissions("sign"); + + /** Static value verify for KeyPermissions. */ + public static final KeyPermissions VERIFY = new KeyPermissions("verify"); + + /** Static value get for KeyPermissions. */ + public static final KeyPermissions GET = new KeyPermissions("get"); + + /** Static value list for KeyPermissions. */ + public static final KeyPermissions LIST = new KeyPermissions("list"); + + /** Static value create for KeyPermissions. */ + public static final KeyPermissions CREATE = new KeyPermissions("create"); + + /** Static value update for KeyPermissions. */ + public static final KeyPermissions UPDATE = new KeyPermissions("update"); + + /** Static value import for KeyPermissions. */ + public static final KeyPermissions IMPORT = new KeyPermissions("import"); + + /** Static value delete for KeyPermissions. */ + public static final KeyPermissions DELETE = new KeyPermissions("delete"); + + /** Static value backup for KeyPermissions. */ + public static final KeyPermissions BACKUP = new KeyPermissions("backup"); + + /** Static value restore for KeyPermissions. */ + public static final KeyPermissions RESTORE = new KeyPermissions("restore"); + + private String value; + + /** + * Creates a custom value for KeyPermissions. + * @param value the custom value + */ + public KeyPermissions(String value) { + this.value = value; + } + + @JsonValue + @Override + public String toString() { + return value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof KeyPermissions)) { + return false; + } + if (obj == this) { + return true; + } + KeyPermissions rhs = (KeyPermissions) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java index 1db622fd6ac4..b6ef1c6dadda 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Permissions.java @@ -17,19 +17,19 @@ public class Permissions { /** * Permissions to keys. */ - private List keys; + private List keys; /** * Permissions to secrets. */ - private List secrets; + private List secrets; /** * Get the keys value. * * @return the keys value */ - public List keys() { + public List keys() { return this.keys; } @@ -39,7 +39,7 @@ public List keys() { * @param keys the keys value to set * @return the Permissions object itself. */ - public Permissions withKeys(List keys) { + public Permissions withKeys(List keys) { this.keys = keys; return this; } @@ -49,7 +49,7 @@ public Permissions withKeys(List keys) { * * @return the secrets value */ - public List secrets() { + public List secrets() { return this.secrets; } @@ -59,7 +59,7 @@ public List secrets() { * @param secrets the secrets value to set * @return the Permissions object itself. */ - public Permissions withSecrets(List secrets) { + public Permissions withSecrets(List secrets) { this.secrets = secrets; return this; } diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java new file mode 100644 index 000000000000..4891a939903d --- /dev/null +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SecretPermissions.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.keyvault; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for SecretPermissions. + */ +public final class SecretPermissions { + /** Static value all for SecretPermissions. */ + public static final SecretPermissions ALL = new SecretPermissions("all"); + + /** Static value get for SecretPermissions. */ + public static final SecretPermissions GET = new SecretPermissions("get"); + + /** Static value list for SecretPermissions. */ + public static final SecretPermissions LIST = new SecretPermissions("list"); + + /** Static value set for SecretPermissions. */ + public static final SecretPermissions SET = new SecretPermissions("set"); + + /** Static value delete for SecretPermissions. */ + public static final SecretPermissions DELETE = new SecretPermissions("delete"); + + private String value; + + /** + * Creates a custom value for SecretPermissions. + * @param value the custom value + */ + public SecretPermissions(String value) { + this.value = value; + } + + @JsonValue + @Override + public String toString() { + return value; + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof SecretPermissions)) { + return false; + } + if (obj == this) { + return true; + } + SecretPermissions rhs = (SecretPermissions) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java index 7403d947e9c4..79b8ab8b0e29 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/Sku.java @@ -15,8 +15,9 @@ */ public class Sku { /** - * SKU family name. Possible values include: 'A'. + * SKU family name. */ + @JsonProperty(required = true) private String family; /** @@ -26,6 +27,13 @@ public class Sku { @JsonProperty(required = true) private SkuName name; + /** + * Creates an instance of Sku class. + */ + public Sku() { + family = "A"; + } + /** * Get the family value. * diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java deleted file mode 100644 index 3b170cc4be9d..000000000000 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/SkuFamily.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for - * license information. - * - * Code generated by Microsoft (R) AutoRest Code Generator. - */ - -package com.microsoft.azure.management.keyvault; - -/** - * Defines values for SkuFamily. - */ -public final class SkuFamily { - /** Static value A for SkuFamily. */ - public static final String A = "A"; - - private SkuFamily() { - } -} diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java index 7f85bfedae22..89d9902415de 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultInner.java @@ -11,7 +11,6 @@ import com.microsoft.azure.management.keyvault.VaultProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.microsoft.azure.Resource; -import com.microsoft.azure.Resource; /** * Resource information with extended details. diff --git a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java index 68d2d771e5ee..4f28b7533faf 100644 --- a/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java +++ b/azure-mgmt-keyvault/src/main/java/com/microsoft/azure/management/keyvault/implementation/VaultsInner.java @@ -10,20 +10,20 @@ import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceCall; import com.microsoft.azure.AzureServiceResponseBuilder; import com.microsoft.azure.CloudException; import com.microsoft.azure.ListOperationCallback; import com.microsoft.azure.Page; import com.microsoft.azure.PagedList; +import com.microsoft.rest.RestException; import com.microsoft.rest.ServiceCall; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; -import com.microsoft.rest.ServiceResponseCallback; import com.microsoft.rest.Validator; import java.io.IOException; import java.util.List; import okhttp3.ResponseBody; -import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; @@ -32,8 +32,9 @@ import retrofit2.http.Path; import retrofit2.http.PUT; import retrofit2.http.Query; -import retrofit2.http.Url; import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; /** * An instance of this class provides access to all the operations defined @@ -63,31 +64,31 @@ public VaultsInner(Retrofit retrofit, KeyVaultManagementClientImpl client) { interface VaultsService { @Headers("Content-Type: application/json; charset=utf-8") @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") - Call createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Body VaultCreateOrUpdateParametersInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Body VaultCreateOrUpdateParametersInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}", method = "DELETE", hasBody = true) - Call delete(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> delete(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults/{vaultName}") - Call get(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> get(@Path("resourceGroupName") String resourceGroupName, @Path("vaultName") String vaultName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.KeyVault/vaults") - Call listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") @GET("subscriptions/{subscriptionId}/resources") - Call list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("$top") Integer top, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET - Call listByResourceGroupNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET("{nextLink}") + Observable> listByResourceGroupNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers("Content-Type: application/json; charset=utf-8") - @GET - Call listNext(@Url String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + @GET("{nextLink}") + Observable> listNext(@Path(value = "nextLink", encoded = true) String nextPageLink, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } @@ -100,27 +101,10 @@ interface VaultsService { * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + * @return the VaultInner object if successful. */ - public ServiceResponse createOrUpdate(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - if (parameters == null) { - throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); - } - Validator.validate(parameters); - Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); - return createOrUpdateDelegate(call.execute()); + public VaultInner createOrUpdate(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) throws CloudException, IOException, IllegalArgumentException { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters).toBlocking().single().getBody(); } /** @@ -130,47 +114,66 @@ public ServiceResponse createOrUpdate(String resourceGroupName, Stri * @param vaultName Name of the vault * @param parameters Parameters to create or update the vault * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters, final ServiceCallback serviceCallback) { + return ServiceCall.create(createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters), serviceCallback); + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @return the observable to the VaultInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, vaultName, parameters).map(new Func1, VaultInner>() { + @Override + public VaultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Create or update a key vault in the specified subscription. + * + * @param resourceGroupName The name of the Resource Group to which the server belongs. + * @param vaultName Name of the vault + * @param parameters Parameters to create or update the vault + * @return the observable to the VaultInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String vaultName, VaultCreateOrUpdateParametersInner parameters) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } if (parameters == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter parameters is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); } - Validator.validate(parameters, serviceCallback); - Call call = service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(createOrUpdateDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + Validator.validate(parameters); + return service.createOrUpdate(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse createOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -189,23 +192,9 @@ private ServiceResponse createOrUpdateDelegate(Response delete(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return deleteDelegate(call.execute()); + public void delete(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + deleteWithServiceResponseAsync(resourceGroupName, vaultName).toBlocking().single().getBody(); } /** @@ -214,42 +203,60 @@ public ServiceResponse delete(String resourceGroupName, String vaultName) * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param vaultName The name of the vault to delete * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall deleteAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall deleteAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) { + return ServiceCall.create(deleteWithServiceResponseAsync(resourceGroupName, vaultName), serviceCallback); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String vaultName) { + return deleteWithServiceResponseAsync(resourceGroupName, vaultName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Deletes the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault to delete + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String vaultName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(deleteDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.delete(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse deleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -266,23 +273,10 @@ private ServiceResponse deleteDelegate(Response response) th * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the VaultInner object wrapped in {@link ServiceResponse} if successful. + * @return the VaultInner object if successful. */ - public ServiceResponse get(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (vaultName == null) { - throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - return getDelegate(call.execute()); + public VaultInner get(String resourceGroupName, String vaultName) throws CloudException, IOException, IllegalArgumentException { + return getWithServiceResponseAsync(resourceGroupName, vaultName).toBlocking().single().getBody(); } /** @@ -291,42 +285,60 @@ public ServiceResponse get(String resourceGroupName, String vaultNam * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param vaultName The name of the vault. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall getAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall getAsync(String resourceGroupName, String vaultName, final ServiceCallback serviceCallback) { + return ServiceCall.create(getWithServiceResponseAsync(resourceGroupName, vaultName), serviceCallback); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @return the observable to the VaultInner object + */ + public Observable getAsync(String resourceGroupName, String vaultName) { + return getWithServiceResponseAsync(resourceGroupName, vaultName).map(new Func1, VaultInner>() { + @Override + public VaultInner call(ServiceResponse response) { + return response.getBody(); + } + }); + } + + /** + * Gets the specified Azure key vault. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param vaultName The name of the vault. + * @return the observable to the VaultInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String vaultName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (vaultName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter vaultName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter vaultName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - serviceCallback.success(getDelegate(response)); - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); + return service.get(resourceGroupName, vaultName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } } - } - }); - return serviceCall; + }); } private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -343,28 +355,16 @@ private ServiceResponse getDelegate(Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listByResourceGroup(final String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - final Integer top = null; - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList listByResourceGroup(final String resourceGroupName) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listByResourceGroupNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -372,46 +372,85 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } final Integer top = null; - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -422,27 +461,16 @@ public void onResponse(Call call, Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listByResourceGroup(final String resourceGroupName, final Integer top) throws CloudException, IOException, IllegalArgumentException { - if (resourceGroupName == null) { - throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); - } - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - if (this.client.apiVersion() == null) { - throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); - } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listByResourceGroupDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList listByResourceGroup(final String resourceGroupName, final Integer top) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName, top).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listByResourceGroupNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -451,45 +479,87 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * @param resourceGroupName The name of the Resource Group to which the vault belongs. * @param top Maximum number of results to return. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupAsync(final String resourceGroupName, final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupAsync(final String resourceGroupName, final Integer top, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupSinglePageAsync(resourceGroupName, top), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName, final Integer top) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName, top) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param resourceGroupName The name of the Resource Group to which the vault belongs. + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName, final Integer top) { + return listByResourceGroupSinglePageAsync(resourceGroupName, top) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + ServiceResponse> * @param resourceGroupName The name of the Resource Group to which the vault belongs. + ServiceResponse> * @param top Maximum number of results to return. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName, final Integer top) { if (resourceGroupName == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } if (this.client.apiVersion() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); } - Call call = service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), top, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -505,64 +575,94 @@ private ServiceResponse> listByResourceGroupDelegate(Respon * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> list() throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; - final String apiVersion = "2015-11-01"; - final Integer top = null; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list() throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** * The List operation gets information about the vaults associated with the subscription. * * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; final String apiVersion = "2015-11-01"; final Integer top = null; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } /** @@ -572,23 +672,16 @@ public void onResponse(Call call, Response response) * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> list(final Integer top) throws CloudException, IOException, IllegalArgumentException { - if (this.client.subscriptionId() == null) { - throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); - } - final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; - final String apiVersion = "2015-11-01"; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - ServiceResponse> response = listDelegate(call.execute()); - PagedList result = new PagedList(response.getBody()) { + public PagedList list(final Integer top) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listSinglePageAsync(top).toBlocking().single(); + return new PagedList(response.getBody()) { @Override - public Page nextPage(String nextPageLink) throws CloudException, IOException { - return listNext(nextPageLink).getBody(); + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); } }; - return new ServiceResponse<>(result, response.getResponse()); } /** @@ -596,39 +689,80 @@ public Page nextPage(String nextPageLink) throws CloudException, IOE * * @param top Maximum number of results to return. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listAsync(final Integer top, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listAsync(final Integer top, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listSinglePageAsync(top), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listAsync(final Integer top) { + return listWithServiceResponseAsync(top) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param top Maximum number of results to return. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listWithServiceResponseAsync(final Integer top) { + return listSinglePageAsync(top) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + ServiceResponse> * @param top Maximum number of results to return. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final Integer top) { if (this.client.subscriptionId() == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); } final String filter = "resourceType eq 'Microsoft.KeyVault/vaults'"; final String apiVersion = "2015-11-01"; - Call call = service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); - final ServiceCall serviceCall = new ServiceCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.list(this.client.subscriptionId(), filter, top, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -645,14 +779,16 @@ private ServiceResponse> listDelegate(Response> listByResourceGroupNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { - if (nextPageLink == null) { - throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); - } - Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - return listByResourceGroupNextDelegate(call.execute()); + public PagedList listByResourceGroupNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); + } + }; } /** @@ -661,37 +797,78 @@ public ServiceResponse> listByResourceGroupNext(final Strin * @param nextPageLink The NextLink from the previous successful call to List operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listByResourceGroupNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listByResourceGroupNextAsync(final String nextPageLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription and within the specified resource group. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { if (nextPageLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - Call call = service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listByResourceGroupNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listByResourceGroupNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listByResourceGroupNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { @@ -708,14 +885,16 @@ private ServiceResponse> listByResourceGroupNextDelegate(Re * @throws CloudException exception thrown from REST call * @throws IOException exception thrown from serialization/deserialization * @throws IllegalArgumentException exception thrown from invalid parameters - * @return the List<VaultInner> object wrapped in {@link ServiceResponse} if successful. + * @return the PagedList<VaultInner> object if successful. */ - public ServiceResponse> listNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { - if (nextPageLink == null) { - throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); - } - Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - return listNextDelegate(call.execute()); + public PagedList listNext(final String nextPageLink) throws CloudException, IOException, IllegalArgumentException { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.getBody()) { + @Override + public Page nextPage(String nextPageLink) throws RestException, IOException { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().getBody(); + } + }; } /** @@ -724,37 +903,78 @@ public ServiceResponse> listNext(final String nextPageLink) * @param nextPageLink The NextLink from the previous successful call to List operation. * @param serviceCall the ServiceCall object tracking the Retrofit calls * @param serviceCallback the async ServiceCallback to handle successful and failed responses. - * @throws IllegalArgumentException thrown if callback is null - * @return the {@link Call} object + * @return the {@link ServiceCall} object */ - public ServiceCall listNextAsync(final String nextPageLink, final ServiceCall serviceCall, final ListOperationCallback serviceCallback) throws IllegalArgumentException { - if (serviceCallback == null) { - throw new IllegalArgumentException("ServiceCallback is required for async calls."); - } + public ServiceCall> listNextAsync(final String nextPageLink, final ServiceCall> serviceCall, final ListOperationCallback serviceCallback) { + return AzureServiceCall.create( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.getBody(); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the observable to the PagedList<VaultInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.getBody().getNextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * The List operation gets information about the vaults associated with the subscription. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @return the PagedList<VaultInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { if (nextPageLink == null) { - serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.")); - return null; + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); } - Call call = service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()); - serviceCall.newCall(call); - call.enqueue(new ServiceResponseCallback>(serviceCallback) { - @Override - public void onResponse(Call call, Response response) { - try { - ServiceResponse> result = listNextDelegate(response); - serviceCallback.load(result.getBody().getItems()); - if (result.getBody().getNextPageLink() != null - && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) { - listNextAsync(result.getBody().getNextPageLink(), serviceCall, serviceCallback); - } else { - serviceCallback.success(new ServiceResponse<>(serviceCallback.get(), result.getResponse())); + return service.listNext(nextPageLink, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.getBody(), result.getResponse())); + } catch (Throwable t) { + return Observable.error(t); } - } catch (CloudException | IOException exception) { - serviceCallback.failure(exception); } - } - }); - return serviceCall; + }); } private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { diff --git a/gulpfile.js b/gulpfile.js index 387f37e2594a..c24bfbba123d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,13 +11,13 @@ var mappings = { 'package': 'com.microsoft.azure.management.compute', 'args': '-FT 1' }, - 'graph': { + 'graphrbac': { 'dir': 'azure-mgmt-graph-rbac', 'source': 'arm-graphrbac/1.6/swagger/graphrbac.json', 'package': 'com.microsoft.azure.management.graphrbac', 'args': '-FT 1' }, - 'keyvault': { + 'arm-keyvault': { 'dir': 'azure-mgmt-keyvault', 'source': 'arm-keyvault/2015-06-01/swagger/keyvault.json', 'package': 'com.microsoft.azure.management.keyvault',