forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CodeGen from PR 26353 in Azure/azure-rest-api-specs
Merge b8277eef0130e92a0903522ff2b4ea4730db2728 into c8d98ad576b439cf4377d8d17122d2e9e831ff9e
- Loading branch information
SDKAuto
committed
Nov 21, 2023
1 parent
7ad2de6
commit f4485a7
Showing
32 changed files
with
4,142 additions
and
3,125 deletions.
There are no files selected for viewing
561 changes: 561 additions & 0 deletions
561
...azure-ai-contentsafety/src/main/java/com/azure/ai/contentsafety/BlocklistAsyncClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
520 changes: 520 additions & 0 deletions
520
...fety/azure-ai-contentsafety/src/main/java/com/azure/ai/contentsafety/BlocklistClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
346 changes: 346 additions & 0 deletions
346
...ure-ai-contentsafety/src/main/java/com/azure/ai/contentsafety/BlocklistClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,346 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) TypeSpec Code Generator. | ||
|
||
package com.azure.ai.contentsafety; | ||
|
||
import com.azure.ai.contentsafety.implementation.BlocklistClientImpl; | ||
import com.azure.core.annotation.Generated; | ||
import com.azure.core.annotation.ServiceClientBuilder; | ||
import com.azure.core.client.traits.ConfigurationTrait; | ||
import com.azure.core.client.traits.EndpointTrait; | ||
import com.azure.core.client.traits.HttpTrait; | ||
import com.azure.core.client.traits.KeyCredentialTrait; | ||
import com.azure.core.client.traits.TokenCredentialTrait; | ||
import com.azure.core.credential.KeyCredential; | ||
import com.azure.core.credential.TokenCredential; | ||
import com.azure.core.http.HttpClient; | ||
import com.azure.core.http.HttpHeaderName; | ||
import com.azure.core.http.HttpHeaders; | ||
import com.azure.core.http.HttpPipeline; | ||
import com.azure.core.http.HttpPipelineBuilder; | ||
import com.azure.core.http.HttpPipelinePosition; | ||
import com.azure.core.http.policy.AddDatePolicy; | ||
import com.azure.core.http.policy.AddHeadersFromContextPolicy; | ||
import com.azure.core.http.policy.AddHeadersPolicy; | ||
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; | ||
import com.azure.core.http.policy.HttpLogOptions; | ||
import com.azure.core.http.policy.HttpLoggingPolicy; | ||
import com.azure.core.http.policy.HttpPipelinePolicy; | ||
import com.azure.core.http.policy.HttpPolicyProviders; | ||
import com.azure.core.http.policy.KeyCredentialPolicy; | ||
import com.azure.core.http.policy.RequestIdPolicy; | ||
import com.azure.core.http.policy.RetryOptions; | ||
import com.azure.core.http.policy.RetryPolicy; | ||
import com.azure.core.http.policy.UserAgentPolicy; | ||
import com.azure.core.util.ClientOptions; | ||
import com.azure.core.util.Configuration; | ||
import com.azure.core.util.CoreUtils; | ||
import com.azure.core.util.builder.ClientBuilderUtil; | ||
import com.azure.core.util.logging.ClientLogger; | ||
import com.azure.core.util.serializer.JacksonAdapter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A builder for creating a new instance of the BlocklistClient type. | ||
*/ | ||
@ServiceClientBuilder(serviceClients = { BlocklistClient.class, BlocklistAsyncClient.class }) | ||
public final class BlocklistClientBuilder implements HttpTrait<BlocklistClientBuilder>, | ||
ConfigurationTrait<BlocklistClientBuilder>, TokenCredentialTrait<BlocklistClientBuilder>, | ||
KeyCredentialTrait<BlocklistClientBuilder>, EndpointTrait<BlocklistClientBuilder> { | ||
@Generated | ||
private static final String SDK_NAME = "name"; | ||
|
||
@Generated | ||
private static final String SDK_VERSION = "version"; | ||
|
||
@Generated | ||
private static final String[] DEFAULT_SCOPES = new String[] { "https://cognitiveservices.azure.com/.default" }; | ||
|
||
@Generated | ||
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-ai-contentsafety.properties"); | ||
|
||
@Generated | ||
private final List<HttpPipelinePolicy> pipelinePolicies; | ||
|
||
/** | ||
* Create an instance of the BlocklistClientBuilder. | ||
*/ | ||
@Generated | ||
public BlocklistClientBuilder() { | ||
this.pipelinePolicies = new ArrayList<>(); | ||
} | ||
|
||
/* | ||
* The HTTP pipeline to send requests through. | ||
*/ | ||
@Generated | ||
private HttpPipeline pipeline; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder pipeline(HttpPipeline pipeline) { | ||
if (this.pipeline != null && pipeline == null) { | ||
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured."); | ||
} | ||
this.pipeline = pipeline; | ||
return this; | ||
} | ||
|
||
/* | ||
* The HTTP client used to send the request. | ||
*/ | ||
@Generated | ||
private HttpClient httpClient; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder httpClient(HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
return this; | ||
} | ||
|
||
/* | ||
* The logging configuration for HTTP requests and responses. | ||
*/ | ||
@Generated | ||
private HttpLogOptions httpLogOptions; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { | ||
this.httpLogOptions = httpLogOptions; | ||
return this; | ||
} | ||
|
||
/* | ||
* The client options such as application ID and custom headers to set on a request. | ||
*/ | ||
@Generated | ||
private ClientOptions clientOptions; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder clientOptions(ClientOptions clientOptions) { | ||
this.clientOptions = clientOptions; | ||
return this; | ||
} | ||
|
||
/* | ||
* The retry options to configure retry policy for failed requests. | ||
*/ | ||
@Generated | ||
private RetryOptions retryOptions; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder retryOptions(RetryOptions retryOptions) { | ||
this.retryOptions = retryOptions; | ||
return this; | ||
} | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { | ||
Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); | ||
pipelinePolicies.add(customPolicy); | ||
return this; | ||
} | ||
|
||
/* | ||
* The configuration store that is used during construction of the service client. | ||
*/ | ||
@Generated | ||
private Configuration configuration; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder configuration(Configuration configuration) { | ||
this.configuration = configuration; | ||
return this; | ||
} | ||
|
||
/* | ||
* The TokenCredential used for authentication. | ||
*/ | ||
@Generated | ||
private TokenCredential tokenCredential; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder credential(TokenCredential tokenCredential) { | ||
this.tokenCredential = tokenCredential; | ||
return this; | ||
} | ||
|
||
/* | ||
* The KeyCredential used for authentication. | ||
*/ | ||
@Generated | ||
private KeyCredential keyCredential; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder credential(KeyCredential keyCredential) { | ||
this.keyCredential = keyCredential; | ||
return this; | ||
} | ||
|
||
/* | ||
* The service endpoint | ||
*/ | ||
@Generated | ||
private String endpoint; | ||
|
||
/** | ||
* {@inheritDoc}. | ||
*/ | ||
@Generated | ||
@Override | ||
public BlocklistClientBuilder endpoint(String endpoint) { | ||
this.endpoint = endpoint; | ||
return this; | ||
} | ||
|
||
/* | ||
* Service version | ||
*/ | ||
@Generated | ||
private ContentSafetyServiceVersion serviceVersion; | ||
|
||
/** | ||
* Sets Service version. | ||
* | ||
* @param serviceVersion the serviceVersion value. | ||
* @return the BlocklistClientBuilder. | ||
*/ | ||
@Generated | ||
public BlocklistClientBuilder serviceVersion(ContentSafetyServiceVersion serviceVersion) { | ||
this.serviceVersion = serviceVersion; | ||
return this; | ||
} | ||
|
||
/* | ||
* The retry policy that will attempt to retry failed requests, if applicable. | ||
*/ | ||
@Generated | ||
private RetryPolicy retryPolicy; | ||
|
||
/** | ||
* Sets The retry policy that will attempt to retry failed requests, if applicable. | ||
* | ||
* @param retryPolicy the retryPolicy value. | ||
* @return the BlocklistClientBuilder. | ||
*/ | ||
@Generated | ||
public BlocklistClientBuilder retryPolicy(RetryPolicy retryPolicy) { | ||
this.retryPolicy = retryPolicy; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds an instance of BlocklistClientImpl with the provided parameters. | ||
* | ||
* @return an instance of BlocklistClientImpl. | ||
*/ | ||
@Generated | ||
private BlocklistClientImpl buildInnerClient() { | ||
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); | ||
ContentSafetyServiceVersion localServiceVersion | ||
= (serviceVersion != null) ? serviceVersion : ContentSafetyServiceVersion.getLatest(); | ||
BlocklistClientImpl client = new BlocklistClientImpl(localPipeline, | ||
JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion); | ||
return client; | ||
} | ||
|
||
@Generated | ||
private HttpPipeline createHttpPipeline() { | ||
Configuration buildConfiguration | ||
= (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; | ||
HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; | ||
ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; | ||
List<HttpPipelinePolicy> policies = new ArrayList<>(); | ||
String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); | ||
String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); | ||
String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); | ||
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); | ||
policies.add(new RequestIdPolicy()); | ||
policies.add(new AddHeadersFromContextPolicy()); | ||
HttpHeaders headers = new HttpHeaders(); | ||
localClientOptions.getHeaders() | ||
.forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue())); | ||
if (headers.getSize() > 0) { | ||
policies.add(new AddHeadersPolicy(headers)); | ||
} | ||
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) | ||
.forEach(p -> policies.add(p)); | ||
HttpPolicyProviders.addBeforeRetryPolicies(policies); | ||
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); | ||
policies.add(new AddDatePolicy()); | ||
if (keyCredential != null) { | ||
policies.add(new KeyCredentialPolicy("Ocp-Apim-Subscription-Key", keyCredential)); | ||
} | ||
if (tokenCredential != null) { | ||
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES)); | ||
} | ||
this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) | ||
.forEach(p -> policies.add(p)); | ||
HttpPolicyProviders.addAfterRetryPolicies(policies); | ||
policies.add(new HttpLoggingPolicy(httpLogOptions)); | ||
HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) | ||
.httpClient(httpClient).clientOptions(localClientOptions).build(); | ||
return httpPipeline; | ||
} | ||
|
||
/** | ||
* Builds an instance of BlocklistAsyncClient class. | ||
* | ||
* @return an instance of BlocklistAsyncClient. | ||
*/ | ||
@Generated | ||
public BlocklistAsyncClient buildAsyncClient() { | ||
return new BlocklistAsyncClient(buildInnerClient()); | ||
} | ||
|
||
/** | ||
* Builds an instance of BlocklistClient class. | ||
* | ||
* @return an instance of BlocklistClient. | ||
*/ | ||
@Generated | ||
public BlocklistClient buildClient() { | ||
return new BlocklistClient(buildInnerClient()); | ||
} | ||
|
||
private static final ClientLogger LOGGER = new ClientLogger(BlocklistClientBuilder.class); | ||
} |
Oops, something went wrong.