diff --git a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/EndpointKeys.java b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/EndpointKeys.java new file mode 100644 index 000000000000..3f17fb84459c --- /dev/null +++ b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/EndpointKeys.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.cognitiveservices.knowledge.qnamaker; + +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.models.EndpointKeysDTO; +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.models.ErrorResponseException; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in EndpointKeys. + */ +public interface EndpointKeys { + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the EndpointKeysDTO object if successful. + */ + EndpointKeysDTO getKeys(); + + /** + * Gets endpoint keys for an endpoint. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + ServiceFuture getKeysAsync(final ServiceCallback serviceCallback); + + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + Observable getKeysAsync(); + + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + Observable> getKeysWithServiceResponseAsync(); + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the EndpointKeysDTO object if successful. + */ + EndpointKeysDTO refreshKeys(String keyType); + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + ServiceFuture refreshKeysAsync(String keyType, final ServiceCallback serviceCallback); + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + Observable refreshKeysAsync(String keyType); + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + Observable> refreshKeysWithServiceResponseAsync(String keyType); + +} diff --git a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/QnAMakerClient.java b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/QnAMakerClient.java index 5193e7c74162..24bd31a62d99 100644 --- a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/QnAMakerClient.java +++ b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/QnAMakerClient.java @@ -96,10 +96,10 @@ public interface QnAMakerClient { QnAMakerClient withGenerateClientRequestId(boolean generateClientRequestId); /** - * Gets the Endpoints object to access its operations. - * @return the Endpoints object. + * Gets the EndpointKeys object to access its operations. + * @return the EndpointKeys object. */ - Endpoints endpoints(); + EndpointKeys endpointKeys(); /** * Gets the Alterations object to access its operations. diff --git a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/EndpointKeysImpl.java b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/EndpointKeysImpl.java new file mode 100644 index 000000000000..b2e2bb4b162d --- /dev/null +++ b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/EndpointKeysImpl.java @@ -0,0 +1,214 @@ +/** + * 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.cognitiveservices.knowledge.qnamaker.implementation; + +import retrofit2.Retrofit; +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.EndpointKeys; +import com.google.common.base.Joiner; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.models.EndpointKeysDTO; +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.models.ErrorResponseException; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import okhttp3.ResponseBody; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in EndpointKeys. + */ +public class EndpointKeysImpl implements EndpointKeys { + /** The Retrofit service to perform REST calls. */ + private EndpointKeysService service; + /** The service client containing this operation class. */ + private QnAMakerClientImpl client; + + /** + * Initializes an instance of EndpointKeysImpl. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public EndpointKeysImpl(Retrofit retrofit, QnAMakerClientImpl client) { + this.service = retrofit.create(EndpointKeysService.class); + this.client = client; + } + + /** + * The interface defining all the services for EndpointKeys to be + * used by Retrofit to perform actually REST calls. + */ + interface EndpointKeysService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.knowledge.qnamaker.EndpointKeys getKeys" }) + @GET("endpointkeys") + Observable> getKeys(@Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.knowledge.qnamaker.EndpointKeys refreshKeys" }) + @PATCH("endpointkeys/{keyType}") + Observable> refreshKeys(@Path("keyType") String keyType, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent); + + } + + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the EndpointKeysDTO object if successful. + */ + public EndpointKeysDTO getKeys() { + return getKeysWithServiceResponseAsync().toBlocking().single().body(); + } + + /** + * Gets endpoint keys for an endpoint. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getKeysAsync(final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getKeysWithServiceResponseAsync(), serviceCallback); + } + + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + public Observable getKeysAsync() { + return getKeysWithServiceResponseAsync().map(new Func1, EndpointKeysDTO>() { + @Override + public EndpointKeysDTO call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets endpoint keys for an endpoint. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + public Observable> getKeysWithServiceResponseAsync() { + if (this.client.endpoint() == null) { + throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null."); + } + String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint()); + return service.getKeys(this.client.acceptLanguage(), parameterizedHost, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getKeysDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getKeysDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the EndpointKeysDTO object if successful. + */ + public EndpointKeysDTO refreshKeys(String keyType) { + return refreshKeysWithServiceResponseAsync(keyType).toBlocking().single().body(); + } + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture refreshKeysAsync(String keyType, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(refreshKeysWithServiceResponseAsync(keyType), serviceCallback); + } + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + public Observable refreshKeysAsync(String keyType) { + return refreshKeysWithServiceResponseAsync(keyType).map(new Func1, EndpointKeysDTO>() { + @Override + public EndpointKeysDTO call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Re-generates an endpoint key. + * + * @param keyType Type of Key + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the EndpointKeysDTO object + */ + public Observable> refreshKeysWithServiceResponseAsync(String keyType) { + if (this.client.endpoint() == null) { + throw new IllegalArgumentException("Parameter this.client.endpoint() is required and cannot be null."); + } + if (keyType == null) { + throw new IllegalArgumentException("Parameter keyType is required and cannot be null."); + } + String parameterizedHost = Joiner.on(", ").join("{Endpoint}", this.client.endpoint()); + return service.refreshKeys(keyType, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = refreshKeysDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse refreshKeysDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/QnAMakerClientImpl.java b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/QnAMakerClientImpl.java index fb33122927ec..61acd0db8625 100644 --- a/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/QnAMakerClientImpl.java +++ b/cognitiveservices/data-plane/knowledge/qnamaker/src/main/java/com/microsoft/azure/cognitiveservices/knowledge/qnamaker/implementation/QnAMakerClientImpl.java @@ -11,7 +11,7 @@ import com.microsoft.azure.AzureClient; import com.microsoft.azure.AzureServiceClient; import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.Alterations; -import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.Endpoints; +import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.EndpointKeys; import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.Knowledgebases; import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.Operations; import com.microsoft.azure.cognitiveservices.knowledge.qnamaker.QnAMakerClient; @@ -126,16 +126,16 @@ public QnAMakerClientImpl withGenerateClientRequestId(boolean generateClientRequ } /** - * The Endpoints object to access its operations. + * The EndpointKeys object to access its operations. */ - private Endpoints endpoints; + private EndpointKeys endpointKeys; /** - * Gets the Endpoints object to access its operations. - * @return the Endpoints object. + * Gets the EndpointKeys object to access its operations. + * @return the EndpointKeys object. */ - public Endpoints endpoints() { - return this.endpoints; + public EndpointKeys endpointKeys() { + return this.endpointKeys; } /** @@ -211,7 +211,7 @@ protected void initialize() { this.acceptLanguage = "en-US"; this.longRunningOperationRetryTimeout = 30; this.generateClientRequestId = true; - this.endpoints = new EndpointsImpl(restClient().retrofit(), this); + this.endpointKeys = new EndpointKeysImpl(restClient().retrofit(), this); this.alterations = new AlterationsImpl(restClient().retrofit(), this); this.knowledgebases = new KnowledgebasesImpl(restClient().retrofit(), this); this.operations = new OperationsImpl(restClient().retrofit(), this);