/** * 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.search.implementation; import retrofit2.Retrofit; import com.google.common.reflect.TypeToken; import com.microsoft.azure.CloudException; import com.microsoft.rest.ServiceFuture; import com.microsoft.rest.ServiceCallback; import com.microsoft.rest.ServiceResponse; import com.microsoft.rest.Validator; import java.io.IOException; import okhttp3.ResponseBody; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.Header; import retrofit2.http.Headers; import retrofit2.http.HTTP; import retrofit2.http.Path; import retrofit2.http.PUT; 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 * in Services. */ public final class ServicesInner { /** The Retrofit service to perform REST calls. */ private ServicesService service; /** The service client containing this operation class. */ private SearchManagementClientImpl client; /** * Initializes an instance of ServicesInner. * * @param retrofit the Retrofit instance built from a Retrofit Builder. * @param client the instance of the service client containing this operation class. */ public ServicesInner(Retrofit retrofit, SearchManagementClientImpl client) { this.service = retrofit.create(ServicesService.class); this.client = client; } /** * The interface defining all the services for Services to be * used by Retrofit to perform actually REST calls. */ interface ServicesService { @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.search.Services createOrUpdate" }) @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}") Observable<Response<ResponseBody>> createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("serviceName") String serviceName, @Path("subscriptionId") String subscriptionId, @Body SearchServiceCreateOrUpdateParametersInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.search.Services delete" }) @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{serviceName}", method = "DELETE", hasBody = true) Observable<Response<ResponseBody>> delete(@Path("resourceGroupName") String resourceGroupName, @Path("serviceName") String serviceName, @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", "x-ms-logging-context: com.microsoft.azure.management.search.Services list" }) @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices") Observable<Response<ResponseBody>> list(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); } /** * Creates or updates a Search service in the given resource group. If the Search service already exists, all properties will be updated with the given values. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to create or update. * @param parameters The properties to set or update on the Search service. * @return the SearchServiceResourceInner object if successful. */ public SearchServiceResourceInner createOrUpdate(String resourceGroupName, String serviceName, SearchServiceCreateOrUpdateParametersInner parameters) { return createOrUpdateWithServiceResponseAsync(resourceGroupName, serviceName, parameters).toBlocking().single().body(); } /** * Creates or updates a Search service in the given resource group. If the Search service already exists, all properties will be updated with the given values. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to create or update. * @param parameters The properties to set or update on the Search service. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. * @return the {@link ServiceFuture} object */ public ServiceFuture<SearchServiceResourceInner> createOrUpdateAsync(String resourceGroupName, String serviceName, SearchServiceCreateOrUpdateParametersInner parameters, final ServiceCallback<SearchServiceResourceInner> serviceCallback) { return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, serviceName, parameters), serviceCallback); } /** * Creates or updates a Search service in the given resource group. If the Search service already exists, all properties will be updated with the given values. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to create or update. * @param parameters The properties to set or update on the Search service. * @return the observable to the SearchServiceResourceInner object */ public Observable<SearchServiceResourceInner> createOrUpdateAsync(String resourceGroupName, String serviceName, SearchServiceCreateOrUpdateParametersInner parameters) { return createOrUpdateWithServiceResponseAsync(resourceGroupName, serviceName, parameters).map(new Func1<ServiceResponse<SearchServiceResourceInner>, SearchServiceResourceInner>() { @Override public SearchServiceResourceInner call(ServiceResponse<SearchServiceResourceInner> response) { return response.body(); } }); } /** * Creates or updates a Search service in the given resource group. If the Search service already exists, all properties will be updated with the given values. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to create or update. * @param parameters The properties to set or update on the Search service. * @return the observable to the SearchServiceResourceInner object */ public Observable<ServiceResponse<SearchServiceResourceInner>> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String serviceName, SearchServiceCreateOrUpdateParametersInner parameters) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (serviceName == null) { throw new IllegalArgumentException("Parameter serviceName 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 (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); return service.createOrUpdate(resourceGroupName, serviceName, this.client.subscriptionId(), parameters, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SearchServiceResourceInner>>>() { @Override public Observable<ServiceResponse<SearchServiceResourceInner>> call(Response<ResponseBody> response) { try { ServiceResponse<SearchServiceResourceInner> clientResponse = createOrUpdateDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); } private ServiceResponse<SearchServiceResourceInner> createOrUpdateDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException { return this.client.restClient().responseBuilderFactory().<SearchServiceResourceInner, CloudException>newInstance(this.client.serializerAdapter()) .register(200, new TypeToken<SearchServiceResourceInner>() { }.getType()) .register(201, new TypeToken<SearchServiceResourceInner>() { }.getType()) .registerError(CloudException.class) .build(response); } /** * Deletes a Search service in the given resource group, along with its associated resources. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to delete. */ public void delete(String resourceGroupName, String serviceName) { deleteWithServiceResponseAsync(resourceGroupName, serviceName).toBlocking().single().body(); } /** * Deletes a Search service in the given resource group, along with its associated resources. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to delete. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. * @return the {@link ServiceFuture} object */ public ServiceFuture<Void> deleteAsync(String resourceGroupName, String serviceName, final ServiceCallback<Void> serviceCallback) { return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, serviceName), serviceCallback); } /** * Deletes a Search service in the given resource group, along with its associated resources. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to delete. * @return the {@link ServiceResponse} object if successful. */ public Observable<Void> deleteAsync(String resourceGroupName, String serviceName) { return deleteWithServiceResponseAsync(resourceGroupName, serviceName).map(new Func1<ServiceResponse<Void>, Void>() { @Override public Void call(ServiceResponse<Void> response) { return response.body(); } }); } /** * Deletes a Search service in the given resource group, along with its associated resources. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceName The name of the Search service to delete. * @return the {@link ServiceResponse} object if successful. */ public Observable<ServiceResponse<Void>> deleteWithServiceResponseAsync(String resourceGroupName, String serviceName) { if (resourceGroupName == null) { throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); } if (serviceName == null) { throw new IllegalArgumentException("Parameter serviceName 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."); } return service.delete(resourceGroupName, serviceName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() { @Override public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) { try { ServiceResponse<Void> clientResponse = deleteDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); } private ServiceResponse<Void> deleteDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException { return this.client.restClient().responseBuilderFactory().<Void, CloudException>newInstance(this.client.serializerAdapter()) .register(200, new TypeToken<Void>() { }.getType()) .register(404, new TypeToken<Void>() { }.getType()) .register(204, new TypeToken<Void>() { }.getType()) .build(response); } /** * Returns a list of all Search services in the given resource group. * * @param resourceGroupName The name of the resource group within the current subscription. * @return the SearchServiceListResultInner object if successful. */ public SearchServiceListResultInner list(String resourceGroupName) { return listWithServiceResponseAsync(resourceGroupName).toBlocking().single().body(); } /** * Returns a list of all Search services in the given resource group. * * @param resourceGroupName The name of the resource group within the current subscription. * @param serviceCallback the async ServiceCallback to handle successful and failed responses. * @return the {@link ServiceFuture} object */ public ServiceFuture<SearchServiceListResultInner> listAsync(String resourceGroupName, final ServiceCallback<SearchServiceListResultInner> serviceCallback) { return ServiceFuture.fromResponse(listWithServiceResponseAsync(resourceGroupName), serviceCallback); } /** * Returns a list of all Search services in the given resource group. * * @param resourceGroupName The name of the resource group within the current subscription. * @return the observable to the SearchServiceListResultInner object */ public Observable<SearchServiceListResultInner> listAsync(String resourceGroupName) { return listWithServiceResponseAsync(resourceGroupName).map(new Func1<ServiceResponse<SearchServiceListResultInner>, SearchServiceListResultInner>() { @Override public SearchServiceListResultInner call(ServiceResponse<SearchServiceListResultInner> response) { return response.body(); } }); } /** * Returns a list of all Search services in the given resource group. * * @param resourceGroupName The name of the resource group within the current subscription. * @return the observable to the SearchServiceListResultInner object */ public Observable<ServiceResponse<SearchServiceListResultInner>> listWithServiceResponseAsync(String resourceGroupName) { 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."); } return service.list(resourceGroupName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SearchServiceListResultInner>>>() { @Override public Observable<ServiceResponse<SearchServiceListResultInner>> call(Response<ResponseBody> response) { try { ServiceResponse<SearchServiceListResultInner> clientResponse = listDelegate(response); return Observable.just(clientResponse); } catch (Throwable t) { return Observable.error(t); } } }); } private ServiceResponse<SearchServiceListResultInner> listDelegate(Response<ResponseBody> response) throws CloudException, IOException, IllegalArgumentException { return this.client.restClient().responseBuilderFactory().<SearchServiceListResultInner, CloudException>newInstance(this.client.serializerAdapter()) .register(200, new TypeToken<SearchServiceListResultInner>() { }.getType()) .registerError(CloudException.class) .build(response); } }